From 0ec85727876f43d51f85f2fb09d1f6fb43a5c5d7 Mon Sep 17 00:00:00 2001 From: cubercsl <2014cais01@gmail.com> Date: Tue, 30 Jul 2024 22:57:35 +0800 Subject: [PATCH] feat: follow medal categories when export results 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 <2014cais01@gmail.com> --- webapp/src/Service/ImportExportService.php | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/webapp/src/Service/ImportExportService.php b/webapp/src/Service/ImportExportService.php index 399c1a4c66..bf91a56cb0 100644 --- a/webapp/src/Service/ImportExportService.php +++ b/webapp/src/Service/ImportExportService.php @@ -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; @@ -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) { @@ -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';