|
2 | 2 |
|
3 | 3 | namespace App\Service;
|
4 | 4 |
|
| 5 | +use App\DataTransferObject\ResultRow; |
5 | 6 | use App\Entity\Configuration;
|
6 | 7 | use App\Entity\Contest;
|
7 | 8 | use App\Entity\ContestProblem;
|
@@ -456,16 +457,7 @@ public function getTeamData(): array
|
456 | 457 | /**
|
457 | 458 | * Get results data for the given sortorder.
|
458 | 459 | *
|
459 |
| - * We'll here assume that the requested file will be of the current contest, |
460 |
| - * as all our scoreboard interfaces do: |
461 |
| - * 0 ICPC ID 24314 string |
462 |
| - * 1 Rank in contest 1 integer|'' |
463 |
| - * 2 Award Gold Medal string |
464 |
| - * 3 Number of problems the team has solved 4 integer |
465 |
| - * 4 Total Time 534 integer |
466 |
| - * 5 Time of the last submission 233 integer |
467 |
| - * 6 Group Winner North American string |
468 |
| - * @return array<array{0: string, 1: integer|string, 2: string, 3: integer, 4: integer, 5: integer, 6: string}> |
| 460 | + * @return ResultRow[] |
469 | 461 | */
|
470 | 462 | public function getResultsData(int $sortOrder, bool $full = false): array
|
471 | 463 | {
|
@@ -545,55 +537,47 @@ public function getResultsData(int $sortOrder, bool $full = false): array
|
545 | 537 | $awardString = 'Ranked';
|
546 | 538 | } else {
|
547 | 539 | $awardString = 'Honorable';
|
548 |
| - $rank = ''; |
| 540 | + $rank = null; |
549 | 541 | }
|
550 | 542 |
|
551 |
| - $groupWinner = ""; |
| 543 | + $groupWinner = null; |
552 | 544 | $categoryId = $teamScore->team->getCategory()->getCategoryid();
|
553 | 545 | if (!isset($groupWinners[$categoryId])) {
|
554 | 546 | $groupWinners[$categoryId] = true;
|
555 | 547 | $groupWinner = $teamScore->team->getCategory()->getName();
|
556 | 548 | }
|
557 | 549 |
|
558 |
| - $data[] = [ |
| 550 | + $data[] = new ResultRow( |
559 | 551 | $teamScore->team->getIcpcId(),
|
560 | 552 | $rank,
|
561 | 553 | $awardString,
|
562 | 554 | $teamScore->numPoints,
|
563 | 555 | $teamScore->totalTime,
|
564 | 556 | $maxTime,
|
565 |
| - $groupWinner |
566 |
| - ]; |
| 557 | + $groupWinner, |
| 558 | + ); |
567 | 559 | }
|
568 | 560 |
|
569 | 561 | // Sort by rank/name.
|
570 |
| - uasort($data, function ($a, $b) use ($teams) { |
571 |
| - if ($a[1] != $b[1]) { |
| 562 | + uasort($data, function (ResultRow $a, ResultRow $b) use ($teams) { |
| 563 | + if ($a->rank !== $b->rank) { |
572 | 564 | // Honorable mention has no rank.
|
573 |
| - if ($a[1] === '') { |
| 565 | + if ($a->rank === null) { |
574 | 566 | return 1;
|
575 |
| - } elseif ($b[1] === '') { |
| 567 | + } elseif ($b->rank === null) { |
576 | 568 | return -11;
|
577 | 569 | }
|
578 |
| - return $a[1] - $b[1]; |
579 |
| - } |
580 |
| - $teamA = $teams[$a[0]] ?? null; |
581 |
| - $teamB = $teams[$b[0]] ?? null; |
582 |
| - if ($teamA) { |
583 |
| - $nameA = $teamA->getEffectiveName(); |
584 |
| - } else { |
585 |
| - $nameA = ''; |
586 |
| - } |
587 |
| - if ($teamB) { |
588 |
| - $nameB = $teamB->getEffectiveName(); |
589 |
| - } else { |
590 |
| - $nameB = ''; |
| 570 | + return $a->rank <=> $b->rank; |
591 | 571 | }
|
| 572 | + $teamA = $teams[$a->teamId] ?? null; |
| 573 | + $teamB = $teams[$b->teamId] ?? null; |
| 574 | + $nameA = $teamA?->getEffectiveName(); |
| 575 | + $nameB = $teamB?->getEffectiveName(); |
592 | 576 | $collator = new Collator('en');
|
593 | 577 | return $collator->compare($nameA, $nameB);
|
594 | 578 | });
|
595 | 579 |
|
596 |
| - return $data; |
| 580 | + return array_values($data); |
597 | 581 | }
|
598 | 582 |
|
599 | 583 | /**
|
|
0 commit comments