Esempio n. 1
0
function calcStats($row, $ninetyDayKillID)
{
    global $mdb, $debug;
    $type = $row['type'];
    $id = $row['id'];
    $killID = (int) @$row['killID'];
    $key = ['type' => $type, 'id' => $id];
    if ($killID < $ninetyDayKillID) {
        $mdb->getCollection('statistics')->update($key, ['$unset' => ['recentShipsLost' => 1, 'recentPointsLost' => 1, 'recentIskLost' => 1, 'recentShipsDestroyed' => 1, 'recentPointsDestroyed' => 1, 'recentIskDestroyed' => 1, 'recentOverallRank' => 1, 'recentOverallScore' => 1]]);
        return;
    }
    $stats = [];
    for ($i = 0; $i <= 1; ++$i) {
        $isVictim = $i == 0;
        if (($type == 'regionID' || $type == 'solarSystemID') && $isVictim == true) {
            continue;
        }
        // build the query
        $query = [$row['type'] => $row['id'], 'isVictim' => $isVictim];
        $query = MongoFilter::buildQuery($query);
        // set the proper sequence values
        $query = ['$and' => [['killID' => ['$gte' => $ninetyDayKillID]], $query]];
        $recent = $mdb->group('killmails', [], $query, 'killID', ['zkb.points', 'zkb.totalValue']);
        mergeAllTime($stats, $recent, $isVictim);
    }
    $mdb->getCollection('statistics')->update($key, ['$set' => $stats]);
}
Esempio n. 2
0
 /**
  * Gets killmails.
  *
  * @param $parameters an array of parameters to fetch mails for
  * @param $allTime gets all mails from the beginning of time or not
  *
  * @return array
  */
 public static function getKills($parameters = array(), $allTime = true, $includeKillDetails = true)
 {
     global $mdb;
     $hashKey = 'Kills::getKills:' . serialize($parameters);
     $result = Cache::get($hashKey);
     //if ($result != null) return $result;
     $kills = MongoFilter::getKills($parameters);
     if ($includeKillDetails == false) {
         return $kills;
     }
     $details = [];
     foreach ($kills as $kill) {
         $killID = (int) $kill['killID'];
         $killHashKey = "killDetail:{$killID}";
         $killmail = Cache::get($killHashKey);
         if ($killmail == null) {
             $killmail = $mdb->findDoc('killmails', ['killID' => $killID, 'cacheTime' => 3600]);
             Info::addInfo($killmail);
             $killmail['victim'] = $killmail['involved'][0];
             $killmail['victim']['killID'] = $killID;
             foreach ($killmail['involved'] as $inv) {
                 if (@$inv['finalBlow'] === true) {
                     $killmail['finalBlow'] = $inv;
                 }
             }
             $killmail['finalBlow']['killID'] = $killID;
             unset($killmail['_id']);
             Cache::set($killHashKey, $killmail, 3600);
         }
         $details[$killID] = $killmail;
     }
     Cache::set($hashKey, $details, 60);
     return $details;
 }
Esempio n. 3
0
function doSupers($row)
{
    global $mdb;
    $type = $row['type'];
    $id = (int) $row['id'];
    $query = [$type => (int) $id, 'isVictim' => false, 'groupID' => [659, 30], 'pastSeconds' => 90 * 86400];
    $query = MongoFilter::buildQuery($query);
    $hasSupers = $mdb->exists('killmails', $query);
    if ($hasSupers == false) {
        $mdb->set("statistics", ['type' => $type, 'id' => $id], ['hasSupers' => false, 'supers' => []]);
    } else {
        $supers = Stats::getSupers($type, $id);
        $mdb->set("statistics", ['type' => $type, 'id' => $id], ['hasSupers' => true, 'supers' => $supers]);
    }
}
Esempio n. 4
0
function calcStats($row)
{
    global $mdb, $debug;
    $type = $row['type'];
    $id = $row['id'];
    $newSequence = $row['sequence'];
    $key = ['type' => $type, 'id' => $id];
    $stats = $mdb->findDoc('statistics', $key);
    if ($stats === null) {
        $stats = [];
        $stats['type'] = $type;
        $stats['id'] = $id;
    }
    $oldSequence = (int) @$stats['sequence'];
    if ($newSequence <= $oldSequence) {
        return;
    }
    for ($i = 0; $i <= 1; ++$i) {
        $isVictim = $i == 0;
        if (($type == 'locationID' || $type == 'regionID' || $type == 'solarSystemID') && $isVictim == true) {
            continue;
        }
        // build the query
        $query = [$row['type'] => $row['id'], 'isVictim' => $isVictim];
        $query = MongoFilter::buildQuery($query);
        // set the proper sequence values
        $query = ['$and' => [['sequence' => ['$gt' => $oldSequence]], ['sequence' => ['$lte' => $newSequence]], $query]];
        $allTime = $mdb->group('killmails', [], $query, 'killID', ['zkb.points', 'zkb.totalValue']);
        mergeAllTime($stats, $allTime, $isVictim);
        $groups = $mdb->group('killmails', 'vGroupID', $query, 'killID', ['zkb.points', 'zkb.totalValue'], ['vGroupID' => 1]);
        mergeGroups($stats, $groups, $isVictim);
        $months = $mdb->group('killmails', ['year' => 'dttm', 'month' => 'dttm'], $query, 'killID', ['zkb.points', 'zkb.totalValue'], ['year' => 1, 'month' => 1]);
        mergeMonths($stats, $months, $isVictim);
    }
    // Update the sequence
    $stats['sequence'] = $newSequence;
    // save it
    $mdb->getCollection('statistics')->save($stats);
    $r = $mdb->getDb()->command(['getLastError' => 1]);
    if ($r['ok'] != 1) {
        die('stats update failure');
    }
    if ($debug) {
        Util::out("Stats completed for: {$type} {$id} {$newSequence}");
    }
}
Esempio n. 5
0
if (false && $pageType == 'wars' && $extra['hasWars']) {
    $extra['wars'][] = War::getNamedWars('Active Wars - Aggressor', "select * from zz_wars where aggressor = {$warID} and timeFinished is null order by timeStarted desc");
    $extra['wars'][] = War::getNamedWars('Active Wars - Defending', "select * from zz_wars where defender = {$warID} and timeFinished is null order by timeStarted desc");
    $extra['wars'][] = War::getNamedWars('Closed Wars - Aggressor', "select * from zz_wars where aggressor = {$warID} and timeFinished is not null order by timeFinished desc");
    $extra['wars'][] = War::getNamedWars('Closed Wars - Defending', "select * from zz_wars where defender = {$warID} and timeFinished is not null order by timeFinished desc");
}
$filter = '';
switch ($key) {
    case 'corporation':
    case 'alliance':
    case 'faction':
        $filter = "{$key}ID = :id";
}
if ($filter != '') {
    $query = ["{$key}ID" => (int) $id, 'isVictim' => false, 'groupID' => [659, 30], 'pastSeconds' => 90 * 86400];
    $query = MongoFilter::buildQuery($query);
    $hasSupers = $mdb->exists('killmails', $query);
    $extra['hasSupers'] = $hasSupers;
    $extra['supers'] = array();
    if ($pageType == 'supers' && $hasSupers) {
        $data = array();
        $parameters = ["{$key}ID" => (int) $id, 'groupID' => 30, 'isVictim' => false, 'pastSeconds' => 86400 * 90, 'nolimit' => true];
        $data['titans']['data'] = Stats::getTop('characterID', $parameters);
        $data['titans']['title'] = 'Titans';
        $parameters = ["{$key}ID" => (int) $id, 'groupID' => 659, 'isVictim' => false, 'pastSeconds' => 86400 * 90, 'nolimit' => true];
        $data['moms']['data'] = Stats::getTop('characterID', $parameters);
        $data['moms']['title'] = 'Supercarriers';
        Info::addInfo($data);
        $extra['supers'] = $data;
        $extra['hasSupers'] = sizeof($data['titans']['data']) || sizeof($data['moms']['data']);
    }
Esempio n. 6
0
 public static function getActivePvpStats($parameters)
 {
     global $mdb;
     $types = ['characterID', 'corporationID', 'allianceID', 'shipTypeID', 'solarSystemID', 'regionID'];
     $activePvP = [];
     foreach ($types as $type) {
         $result = self::getDistinctCount($type, $parameters);
         if ((int) $result <= 1) {
             continue;
         }
         $type = str_replace('ID', '', $type);
         if ($type == 'shipType') {
             $type = 'Ship';
         } elseif ($type == 'solarSystem') {
             $type = 'System';
         } else {
             $type = ucfirst($type);
         }
         $type = $type . 's';
         $row['type'] = $type;
         $row['count'] = $result;
         $activePvP[strtolower($type)] = $row;
     }
     $mongoParams = MongoFilter::buildQuery($parameters);
     $killCount = $mdb->getCollection('oneWeek')->count($mongoParams);
     if ($killCount > 0) {
         $activePvP['kills'] = ['type' => 'Total Kills', 'count' => $killCount];
     }
     return $activePvP;
 }
Esempio n. 7
0
function getLatestKillID($type, $id, $ninetyDayKillID)
{
    global $mdb;
    // build the query
    $query = [$type => $id, 'isVictim' => false];
    $query = MongoFilter::buildQuery($query);
    // set the proper sequence values
    $query = ['$and' => [['killID' => ['$gte' => $ninetyDayKillID]], $query]];
    $killmail = $mdb->findDoc("killmails", $query);
    if ($killmail == null) {
        return 0;
    }
    return $killmail['killID'];
}
Esempio n. 8
0
 public static function getTrophies($charID)
 {
     global $mdb;
     $charID = (int) $charID;
     $type = 'characterID';
     $stats = $mdb->findDoc("statistics", ['type' => $type, 'id' => $charID]);
     $trophies = [];
     $maxTrophyCount = 0;
     $trophyCount = 0;
     foreach (static::$conditions as $condition) {
         $maxTrophyCount++;
         if (isset($condition['filter'])) {
             $filter = $condition['filter'];
             if (isset($filter['characterID'])) {
                 $filter['characterID'] = $charID;
             }
             $query = MongoFilter::buildQuery($filter);
             if (isset($filter['compare'])) {
                 $part2 = ['characterID' => $charID, 'isVictim' => !$filter['isVictim']];
                 $part2 = MongoFilter::buildQuery($part2);
                 $query = ['$and' => [$query, $part2]];
             }
             $exists = $mdb->exists("killmails", $query);
             $rank = $exists ? $condition['rank'] : 0;
             $trophyCount += static::addTrophy($trophies, $condition, $exists, $rank, true);
         }
         if (isset($condition['stats'])) {
             $field = $condition['stats']['field'];
             $value = $condition['stats']['value'];
             $met = @$stats[$field] >= $value;
             $trophyCount += static::addTrophy($trophies, $condition, $met, (int) @$stats[$field]);
         }
         if (isset($condition['statGroup'])) {
             $group = @$stats['groups'][$condition['statGroup']['groupID']];
             $field = $condition['statGroup']['field'];
             $value = $condition['statGroup']['value'];
             $trophyCount += static::addTrophy($trophies, $condition, @$group[$field] >= $value, @$group[$field]);
         }
     }
     $groups = $mdb->find("information", ['type' => 'groupID', 'cacheTime' => 3600], ['name' => 1]);
     foreach ($groups as $row) {
         if (@$row['categoryID'] != 6) {
             continue;
         }
         $groupID = (int) $row['id'];
         $count = $mdb->count("information", ['groupID' => $groupID]);
         if ($count == 0) {
             continue;
         }
         $groupName = $row['name'];
         //Info::getInfoField('groupID', $groupID, 'name');
         $a = in_array(substr(strtolower($groupName), 0, 1), ['a', 'e', 'i', 'o', 'u']) ? "an" : "a";
         $values = @$stats['groups'][$groupID];
         $level = static::getLevel(@$values['shipsDestroyed']);
         $trophies['trophies']['Killed']["Kill {$a} {$groupName}"] = ['met' => @$values['shipsDestroyed'] > 0, 'level' => $level, 'value' => (int) @$values['shipsDestroyed'], 'next' => static::getNext(@$values['shipsDestroyed']), 'link' => "/character/{$charID}/kills/reset/group/{$groupID}/losses/"];
         $trophyCount += @$values['shipsDestroyed'] > 0;
         $level = static::getLevel(@$values['shipsLost']);
         $trophies['trophies']['Lost']["Lose {$a} {$groupName}"] = ['met' => @$values['shipsLost'] > 0, 'level' => $level, 'value' => (int) @$values['shipsLost'], 'next' => static::getNext(@$values['shipsLost']), 'link' => "/character/{$charID}/losses/group/{$groupID}/"];
         $trophyCount += @$values['shipsLost'] > 0;
         $maxTrophyCount += 2;
     }
     $level = 0;
     $total = 1;
     do {
         $total = $total * 2;
         $level++;
     } while ($total < $trophyCount);
     $completed = number_format($trophyCount / $maxTrophyCount * 100, 0);
     $total = 0;
     $count = 0;
     foreach ($trophies['trophies'] as $cat => $more) {
         foreach ($more as $trophy => $condition) {
             $total += @$condition['level'];
             $count++;
         }
     }
     $levelAvg = floor($total / ($count * 5) * 10);
     $trophies['level'] = $level;
     $trophies['levelAvg'] = $levelAvg;
     $trophies['trophyCount'] = $trophyCount;
     $trophies['maxTrophyCount'] = $maxTrophyCount;
     $trophies['nextLevel'] = pow(2, $level);
     $trophies['completedPct'] = $completed;
     $trophies['misc'] = "Level {$level} / {$trophyCount} of {$maxTrophyCount} trophies / {$completed}% complete.";
     return $trophies;
 }