Skip to content
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

Follow medal in contest setting categories when export results #2638

Merged
merged 4 commits into from
Aug 11, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
36 changes: 32 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,35 @@ public function getResultsData(

$rank = $teamScore->rank;
$numPoints = $teamScore->numPoints;
if ($rank <= $contest->getGoldMedals()) {
$skip = false;
nickygerritsen marked this conversation as resolved.
Show resolved Hide resolved

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

if ($numPoints === 0) {
// Teams with 0 points won't get a medal, a rank or an honor.
// They will always get an honorable mention.
$data[] = new ResultRow(
$teamScore->team->getIcpcId(),
null,
'Honorable',
$teamScore->numPoints,
$teamScore->totalTime,
$maxTime,
null
);
continue;
}

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 +566,9 @@ public function getResultsData(
$rank = $ranks[$numPoints];
}
if ($honors) {
if ($numPoints === $lowestMedalPoints) {
if ($numPoints === $lowestMedalPoints
|| $rank - $skippedTeams <= $contest->getGoldMedals() + $contest->getSilverMedals() + $contest->getBronzeMedals() + $contest->getB()) {
// Some teams out of the medal categories but ranked higher than bronze medallists may get more points.
$awardString = 'Highest Honors';
} elseif ($numPoints === $lowestMedalPoints - 1) {
$awardString = 'High Honors';
Expand Down
10 changes: 5 additions & 5 deletions webapp/tests/Unit/Controller/Jury/ImportExportControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,8 @@ public function testResultsHtmlExport(bool $individuallyRanked, bool $honors, st
'export_results[format]' => $format,
]);
self::assertSelectorExists('h1:contains("Results for Demo contest")');
self::assertSelectorExists('th:contains("Example teamname")');
self::assertSelectorExists('th:contains("A: Hello World")');
self::assertSelectorExists('td:contains("Example teamname")');
}

public function provideResultsHtmlExport(): Generator
Expand Down Expand Up @@ -219,16 +219,16 @@ public function testResultsTsvExport(
public function provideResultsTsvExport(): Generator
{
yield [0, true, true, 'results 1
exteam 1 Gold Medal 0 0 0 Participants
exteam Honorable 0 0 0
'];
yield [0, true, false, 'results 1
exteam 1 Gold Medal 0 0 0 Participants
exteam Honorable 0 0 0
'];
yield [0, false, true, 'results 1
exteam 1 Gold Medal 0 0 0 Participants
exteam Honorable 0 0 0
'];
yield [0, false, true, 'results 1
exteam 1 Gold Medal 0 0 0 Participants
exteam Honorable 0 0 0
'];
yield [1, true, true, 'results 1
'];
Expand Down
10 changes: 10 additions & 0 deletions webapp/tests/Unit/Fixtures/sample/results-full-honors.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
results 1
10001 1 Gold Medal 4 36 20 Sample Group A
10002 2 Gold Medal 2 5 3
10003 2 Gold Medal 2 5 3
10004 4 Highest Honors 1 12 12 Sample Group B
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not really defined what order this file should be in, nor what should happen when some categories have no medals. It looks a bit weird like this, but I think this is the best we can do,

10005 5 Highest Honors 1 13 13
10006 6 Highest Honors 1 14 14
10007 7 Bronze Medal 1 15 15 Sample Group C
10008 Honorable 0 0 0
10009 Honorable 0 0 0
10 changes: 10 additions & 0 deletions webapp/tests/Unit/Fixtures/sample/results-full-ranked.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
results 1
10001 1 Gold Medal 4 36 20 Sample Group A
10002 2 Gold Medal 2 5 3
10003 2 Gold Medal 2 5 3
10004 4 Ranked 1 12 12 Sample Group B
10005 5 Ranked 1 13 13
10006 6 Ranked 1 14 14
10007 7 Bronze Medal 1 15 15 Sample Group C
10008 Honorable 0 0 0
10009 Honorable 0 0 0
10 changes: 10 additions & 0 deletions webapp/tests/Unit/Fixtures/sample/results-wf-honors.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
results 1
10001 1 Gold Medal 4 36 20 Sample Group A
10002 2 Gold Medal 2 5 3
10003 2 Gold Medal 2 5 3
10004 4 Highest Honors 1 12 12 Sample Group B
10005 4 Highest Honors 1 13 13
10006 4 Highest Honors 1 14 14
10007 7 Bronze Medal 1 15 15 Sample Group C
10008 Honorable 0 0 0
10009 Honorable 0 0 0
10 changes: 10 additions & 0 deletions webapp/tests/Unit/Fixtures/sample/results-wf-ranked.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
results 1
10001 1 Gold Medal 4 36 20 Sample Group A
10002 2 Gold Medal 2 5 3
10003 2 Gold Medal 2 5 3
10004 4 Ranked 1 12 12 Sample Group B
10005 4 Ranked 1 13 13
10006 4 Ranked 1 14 14
10007 7 Bronze Medal 1 15 15 Sample Group C
10008 Honorable 0 0 0
10009 Honorable 0 0 0
32 changes: 32 additions & 0 deletions webapp/tests/Unit/Fixtures/sample/sample-groups.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[
{
"hidden": false,
"categoryid": 5,
"id": "10001",
"icpc_id": "10001",
"name": "Sample Group A",
"sortorder": 0,
"color": null,
"allow_self_registration": false
},
{
"hidden": false,
"categoryid": 6,
"id": "10002",
"icpc_id": "10002",
"name": "Sample Group B",
"sortorder": 0,
"color": null,
"allow_self_registration": false
},
{
"hidden": false,
"categoryid": 7,
"id": "10003",
"icpc_id": "10003",
"name": "Sample Group C",
"sortorder": 0,
"color": null,
"allow_self_registration": false
}
]
11 changes: 11 additions & 0 deletions webapp/tests/Unit/Fixtures/sample/sample-medals.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"medals": {
"gold": 2,
"silver": 1,
"bronze": 1
},
"medal_categories": [
"10001",
"10003"
]
}
78 changes: 78 additions & 0 deletions webapp/tests/Unit/Fixtures/sample/sample-problems.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
[
{
"ordinal": 0,
"probid": 1,
"short_name": "A",
"rgb": "#FF0000",
"color": "red",
"label": "A",
"time_limit": 1.0,
"statement": [
{
"href": "contests/sample_contests/problems/sample-problem-a/statement",
"mime": "application/pdf",
"filename": "A.pdf"
}
],
"id": "sample-problem-a",
"name": "Sample Problem A",
"test_data_count": 50
},
{
"ordinal": 1,
"probid": 2,
"short_name": "B",
"rgb": "#00FF00",
"color": "lime",
"label": "B",
"time_limit": 2.0,
"statement": [
{
"href": "contests/sample_contests/problems/sample-problem-b/statement",
"mime": "application/pdf",
"filename": "B.pdf"
}
],
"id": "sample-problem-b",
"name": "Sample Problem B",
"test_data_count": 32
},
{
"ordinal": 2,
"probid": 3,
"short_name": "C",
"rgb": "#0000FF",
"color": "blue",
"label": "C",
"time_limit": 3.0,
"statement": [
{
"href": "contests/sample_contests/problems/sample-problem-c/statement",
"mime": "application/pdf",
"filename": "C.pdf"
}
],
"id": "sample-problem-c",
"name": "Sample Problem C",
"test_data_count": 78
},
{
"ordinal": 3,
"probid": 4,
"short_name": "D",
"rgb": "#FFFF00",
"color": "yellow",
"label": "D",
"time_limit": 4.0,
"statement": [
{
"href": "contests/sample_contests/problems/sample-problem-d/statement",
"mime": "application/pdf",
"filename": "D.pdf"
}
],
"id": "sample-problem-d",
"name": "Sample Problem D",
"test_data_count": 100
}
]
Loading
Loading