Ejemplo 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]);
}
Ejemplo n.º 2
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}");
    }
}