Skip to content

Commit

Permalink
feat: follow medal categories when export results
Browse files Browse the repository at this point in the history
When export the result, follow medal categories in contest setting.
This will be consistent with the results generated by the award API.

Signed-off-by: cubercsl <[email protected]>
  • Loading branch information
cubercsl committed Jul 30, 2024
1 parent c01749d commit 0ec8572
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions webapp/src/Service/ImportExportService.php
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,10 @@ public function getResultsData(
$data = [];
$lowestMedalPoints = 0;

// For every team that we skip because it is not in a medal category, we need to include one
// additional rank. So keep track of the number of skipped teams
$skippedTeams = 0;

foreach ($scoreboard->getScores() as $teamScore) {
if ($teamScore->team->getCategory()->getSortorder() !== $sortOrder) {
continue;
Expand All @@ -522,13 +526,20 @@ public function getResultsData(

$rank = $teamScore->rank;
$numPoints = $teamScore->numPoints;
if ($rank <= $contest->getGoldMedals()) {
$skip = false;

if (!$contest->getMedalCategories()->contains($teamScore->team->getCategory())) {
$skip = true;
$skippedTeams++;
}

if (!$skip && $rank - $skippedTeams <= $contest->getGoldMedals()) {
$awardString = 'Gold Medal';
$lowestMedalPoints = $teamScore->numPoints;
} elseif ($rank <= $contest->getGoldMedals() + $contest->getSilverMedals()) {
} elseif (!$skip && $rank - $skippedTeams <= $contest->getGoldMedals() + $contest->getSilverMedals()) {
$awardString = 'Silver Medal';
$lowestMedalPoints = $teamScore->numPoints;
} elseif ($rank <= $contest->getGoldMedals() + $contest->getSilverMedals() + $contest->getBronzeMedals() + $contest->getB()) {
} elseif (!$skip && $rank - $skippedTeams <= $contest->getGoldMedals() + $contest->getSilverMedals() + $contest->getBronzeMedals() + $contest->getB()) {
$awardString = 'Bronze Medal';
$lowestMedalPoints = $teamScore->numPoints;
} elseif ($numPoints >= $median) {
Expand All @@ -540,7 +551,8 @@ public function getResultsData(
$rank = $ranks[$numPoints];
}
if ($honors) {
if ($numPoints === $lowestMedalPoints) {
if ($numPoints >= $lowestMedalPoints) {
// Some teams out of the medal categories may get more points than the lowest medalist.
$awardString = 'Highest Honors';
} elseif ($numPoints === $lowestMedalPoints - 1) {
$awardString = 'High Honors';
Expand Down

0 comments on commit 0ec8572

Please sign in to comment.