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

Make scoreboard type explicit. #2942

Merged
merged 1 commit into from
Mar 2, 2025
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: 36 additions & 0 deletions webapp/migrations/Version20250302132831.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

namespace DoctrineMigrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20250302132831 extends AbstractMigration
{
public function getDescription(): string
{
return 'Add explicit scoring type.';
}

public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE contest ADD scoreboard_type VARCHAR(255) DEFAULT \'pass-fail\' NOT NULL');
}

public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE contest DROP scoreboard_type');
}

public function isTransactional(): bool
{
return false;
}
}
3 changes: 2 additions & 1 deletion webapp/src/Controller/BaseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use App\Entity\ExternalIdFromInternalIdInterface;
use App\Entity\Problem;
use App\Entity\RankCache;
use App\Entity\ScoreboardType;
use App\Entity\ScoreCache;
use App\Entity\Team;
use App\Entity\TeamCategory;
Expand Down Expand Up @@ -168,7 +169,7 @@ protected function getDatabaseRelations(array $files): array {
$shortClass = str_replace('.php', '', $parts[count($parts) - 1]);
$class = sprintf('App\\Entity\\%s', $shortClass);
if (class_exists($class) && !in_array($class,
[RankCache::class, ScoreCache::class, BaseApiEntity::class])) {
[RankCache::class, ScoreCache::class, BaseApiEntity::class, ScoreboardType::class])) {
$metadata = $this->em->getClassMetadata($class);

$tableRelations = [];
Expand Down
21 changes: 12 additions & 9 deletions webapp/src/Controller/Jury/ContestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,15 @@ public function indexAction(Request $request): Response
->getQuery()->getResult();

$table_fields = [
'cid' => ['title' => 'CID', 'sort' => true],
'externalid' => ['title' => "external ID", 'sort' => true],
'shortname' => ['title' => 'shortname', 'sort' => true],
'name' => ['title' => 'name', 'sort' => true],
'activatetime' => ['title' => 'activate', 'sort' => true],
'starttime' => ['title' => 'start', 'sort' => true,
'default_sort' => true, 'default_sort_order' => 'desc'],
'endtime' => ['title' => 'end', 'sort' => true],
'cid' => ['title' => 'CID', 'sort' => true],
'externalid' => ['title' => "external ID", 'sort' => true],
'shortname' => ['title' => 'shortname', 'sort' => true],
'name' => ['title' => 'name', 'sort' => true],
'scoreboard_type' => ['title' => 'scoreboard type', 'sort' => true],
'activatetime' => ['title' => 'activate', 'sort' => true],
'starttime' => ['title' => 'start', 'sort' => true,
'default_sort' => true, 'default_sort_order' => 'desc'],
'endtime' => ['title' => 'end', 'sort' => true],
];

$currentContests = $this->dj->getCurrentContests();
Expand Down Expand Up @@ -137,7 +138,9 @@ public function indexAction(Request $request): Response
$contestactions = [];
// Get whatever fields we can from the contest object itself
foreach ($table_fields as $k => $v) {
if ($propertyAccessor->isReadable($contest, $k)) {
if ($k == 'scoreboard_type') {
$contestdata[$k] = ['value' => $contest->getScoreboardType()->value];
} elseif ($propertyAccessor->isReadable($contest, $k)) {
$contestdata[$k] = ['value' => $propertyAccessor->getValue($contest, $k)];
}
}
Expand Down
28 changes: 23 additions & 5 deletions webapp/src/Entity/Contest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,6 @@
exp: 'object.getName()',
options: [new Serializer\Type('string')]
)]
#[Serializer\VirtualProperty(
name: 'scoreboard_type',
exp: '"pass-fail"',
options: [new Serializer\Type('string')]
)]
#[UniqueEntity(fields: 'shortname')]
#[UniqueEntity(fields: 'externalid')]
class Contest extends BaseApiEntity implements
Expand Down Expand Up @@ -161,6 +156,18 @@ class Contest extends BaseApiEntity implements
#[Serializer\Exclude]
private ?int $b = 0;

#[ORM\Column(type: 'string', enumType: ScoreboardType::class, options: ['default' => 'pass-fail'])]
#[Serializer\Exclude]
private ScoreboardType $scoreboardType = ScoreboardType::PASS_FAIL;

#[Serializer\VirtualProperty]
#[Serializer\SerializedName('scoreboard_type')]
#[Serializer\Type('string')]
public function getScoreboardTypeString(): string
{
return $this->scoreboardType->value;
}

#[ORM\Column(
options: ['default' => 0]
)]
Expand Down Expand Up @@ -861,6 +868,17 @@ public function getPublic(): bool
return $this->public;
}

public function setScoreboardType(ScoreboardType $scoreboardType): Contest
{
$this->scoreboardType = $scoreboardType;
return $this;
}

public function getScoreboardType(): ScoreboardType
{
return $this->scoreboardType;
}

public function setOpenToAllTeams(bool $openToAllTeams): Contest
{
$this->openToAllTeams = $openToAllTeams;
Expand Down
9 changes: 9 additions & 0 deletions webapp/src/Entity/ScoreboardType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php declare(strict_types=1);

namespace App\Entity;

enum ScoreboardType: string
{
case PASS_FAIL = 'pass-fail';
case SCORING = 'scoring';
}
5 changes: 5 additions & 0 deletions webapp/templates/jury/contest.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@
<td>{{ contest.shortname }}</td>
<td></td>
</tr>
<tr>
<th>Scoreboard type</th>
<td>{{ contest.scoreboardType.value }}</td>
<td></td>
</tr>
{% for type, data in contest.dataForJuryInterface %}
<tr>
<td class="{{ data.class|default('') }}"><b>{{ data.label }}:</b></td>
Expand Down
Loading