mirror of
https://codeberg.org/demostf/api.git
synced 2026-06-03 09:54:17 +02:00
filter players with no activity
This commit is contained in:
parent
16585f4968
commit
13e6f950d2
1 changed files with 29 additions and 5 deletions
|
|
@ -75,9 +75,38 @@ class Parser {
|
|||
if (!isset($data['users'])) {
|
||||
throw new \Exception('Error while parsing demo, no users field found');
|
||||
}
|
||||
|
||||
$deaths = array_filter($data['deaths'], function ($death) {
|
||||
return $death['killer'] !== $death['victim'];
|
||||
});
|
||||
/** @var ParsedKill[] $kills */
|
||||
$kills = array_map(function (array $death) {
|
||||
return new ParsedKill($death['killer'] ?? 0, $death['assister'] ?? 0, $death['victim'] ?? 0,
|
||||
$death['weapon']);
|
||||
}, $deaths);
|
||||
$activityMap = [];
|
||||
foreach ($kills as $kill) {
|
||||
if (!isset($activityMap[$kill->getAttackerDemoId()])) {
|
||||
$activityMap[$kill->getAttackerDemoId()] = 0;
|
||||
}
|
||||
$activityMap[$kill->getAttackerDemoId()]++;
|
||||
if (!isset($activityMap[$kill->getAssisterDemoId()])) {
|
||||
$activityMap[$kill->getAssisterDemoId()] = 0;
|
||||
}
|
||||
$activityMap[$kill->getAssisterDemoId()]++;
|
||||
if (!isset($activityMap[$kill->getVictimDemoId()])) {
|
||||
$activityMap[$kill->getVictimDemoId()] = 0;
|
||||
}
|
||||
$activityMap[$kill->getVictimDemoId()]++;
|
||||
}
|
||||
|
||||
foreach ($data['users'] as $player) {
|
||||
$class = 0;
|
||||
$classSpawns = 0;
|
||||
if (!isset($activityMap[$player['userId']])) {
|
||||
// skip players with no kills, assists or deaths
|
||||
continue;
|
||||
}
|
||||
foreach ($player['classes'] as $classId => $spawns) {
|
||||
if ($spawns > $classSpawns) {
|
||||
$classSpawns = $spawns;
|
||||
|
|
@ -95,11 +124,6 @@ class Parser {
|
|||
}
|
||||
}
|
||||
|
||||
$kills = array_map(function (array $death) {
|
||||
return new ParsedKill($death['killer'] ?? 0, $death['assister'] ?? 0, $death['victim'] ?? 0,
|
||||
$death['weapon']);
|
||||
}, $data['deaths']);
|
||||
|
||||
return new ParsedDemo(
|
||||
$red,
|
||||
$blue,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue