Skip to content

Follow medal in contest setting categories when export results #2638

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 11, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
7 changes: 5 additions & 2 deletions webapp/tests/Unit/Service/ImportExportServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1181,8 +1181,6 @@ public function testGetResultsData(bool $full, bool $honors, string $expectedRes
->setShortname('wf47')
->setStarttimeString($startTime->format(DateTimeInterface::ATOM))
->setEndtimeString($startTime->add(new DateInterval('PT5H'))->format(DateTimeInterface::ATOM));
$em->persist($contest);
$em->flush();

$groupsById = [];
$groupsData = json_decode(file_get_contents(__DIR__ . '/../Fixtures/sample-groups.json'), true);
Expand All @@ -1194,7 +1192,12 @@ public function testGetResultsData(bool $full, bool $honors, string $expectedRes
$em->persist($group);
$em->flush();
$groupsById[$group->getExternalid()] = $group;
$contest->addMedalCategory($group);
}

$em->persist($contest);
$em->flush();

$teamsData = json_decode(file_get_contents(__DIR__ . '/../Fixtures/sample-teams.json'), true);
/** @var array<string,Team> $teamsById */
$teamsById = [];
Expand Down
Loading