-
Notifications
You must be signed in to change notification settings - Fork 279
Allow selecting new problem types as part of the problem entity. #2979
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?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 Version20250323190305 extends AbstractMigration | ||
{ | ||
public function getDescription(): string | ||
{ | ||
return ''; | ||
} | ||
|
||
public function up(Schema $schema): void | ||
{ | ||
// this up() migration is auto-generated, please modify it to your needs | ||
$this->addSql('ALTER TABLE problem ADD types INT NOT NULL COMMENT \'Bitset of problem types, default is pass-fail.\''); | ||
$this->addSql('UPDATE problem SET types = 1'); | ||
$this->addSql('UPDATE problem SET types = 5 WHERE is_multipass_problem = 1'); | ||
$this->addSql('UPDATE problem SET types = 9 WHERE combined_run_compare = 1'); | ||
$this->addSql('UPDATE problem SET types = 13 WHERE combined_run_compare = 1 AND is_multipass_problem = 1'); | ||
$this->addSql('ALTER TABLE problem DROP combined_run_compare, DROP is_multipass_problem'); | ||
} | ||
|
||
public function down(Schema $schema): void | ||
{ | ||
// this down() migration is auto-generated, please modify it to your needs | ||
$this->addSql('ALTER TABLE problem ADD combined_run_compare TINYINT(1) DEFAULT 0 NOT NULL COMMENT \'Use the exit code of the run script to compute the verdict\', ADD is_multipass_problem TINYINT(1) DEFAULT 0 NOT NULL COMMENT \'Whether this problem is a multi-pass problem.\''); | ||
$this->addSql('UPDATE problem SET combined_run_compare = 1 WHERE types = 9 OR types = 13'); | ||
$this->addSql('UPDATE problem SET is_multipass_problem = 1 WHERE types = 5 OR types = 13'); | ||
$this->addSql('ALTER TABLE problem DROP types'); | ||
} | ||
|
||
public function isTransactional(): bool | ||
{ | ||
return false; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -86,13 +86,6 @@ class Problem extends BaseApiEntity implements | |
#[Serializer\Exclude] | ||
private ?string $special_compare_args = null; | ||
|
||
#[ORM\Column(options: [ | ||
'comment' => 'Use the exit code of the run script to compute the verdict', | ||
'default' => 0, | ||
])] | ||
#[Serializer\Exclude] | ||
private bool $combined_run_compare = false; | ||
|
||
#[Assert\File] | ||
#[Serializer\Exclude] | ||
private ?UploadedFile $problemstatementFile = null; | ||
|
@@ -108,12 +101,24 @@ class Problem extends BaseApiEntity implements | |
#[Serializer\Exclude] | ||
private ?string $problemstatement_type = null; | ||
|
||
#[ORM\Column(options: [ | ||
'comment' => 'Whether this problem is a multi-pass problem.', | ||
'default' => 0, | ||
])] | ||
// These types are encoded as bitset - if you add a new type, use the next power of 2. | ||
public const TYPE_PASS_FAIL = 1; | ||
meisterT marked this conversation as resolved.
Show resolved
Hide resolved
|
||
public const TYPE_SCORING = 2; | ||
public const TYPE_MULTI_PASS = 4; | ||
public const TYPE_INTERACTIVE = 8; | ||
public const TYPE_SUBMIT_ANSWER = 16; | ||
|
||
private array $typesToString = [ | ||
self::TYPE_PASS_FAIL => 'pass-fail', | ||
self::TYPE_SCORING => 'scoring', | ||
self::TYPE_MULTI_PASS => 'multi-pass', | ||
self::TYPE_INTERACTIVE => 'interactive', | ||
self::TYPE_SUBMIT_ANSWER => 'submit-answer', | ||
]; | ||
|
||
#[ORM\Column(options: ['comment' => 'Bitmask of problem types, default is pass-fail.'])] | ||
#[Serializer\Exclude] | ||
private bool $isMultipassProblem = false; | ||
private int $types = self::TYPE_PASS_FAIL; | ||
|
||
#[ORM\Column( | ||
nullable: true, | ||
|
@@ -287,26 +292,84 @@ public function getSpecialCompareArgs(): ?string | |
return $this->special_compare_args; | ||
} | ||
|
||
public function setCombinedRunCompare(bool $combinedRunCompare): Problem | ||
public function setTypesAsString(array $types): Problem | ||
{ | ||
$this->combined_run_compare = $combinedRunCompare; | ||
$stringToTypes = array_flip($this->typesToString); | ||
$typeConstants = []; | ||
foreach ($types as $type) { | ||
if (!isset($stringToTypes[$type])) { | ||
throw new Exception("Unknown problem type: '$type', must be one of " . implode(', ', array_keys($stringToTypes))); | ||
} | ||
meisterT marked this conversation as resolved.
Show resolved
Hide resolved
|
||
$typeConstants[$type] = $stringToTypes[$type]; | ||
} | ||
$this->setTypes($typeConstants); | ||
|
||
return $this; | ||
} | ||
|
||
public function getCombinedRunCompare(): bool | ||
public function getTypesAsString(): string | ||
{ | ||
$typeConstants = $this->getTypes(); | ||
$typeStrings = []; | ||
foreach ($typeConstants as $type) { | ||
if (!isset($this->typesToString[$type])) { | ||
throw new Exception("Unknown problem type: '$type'"); | ||
} | ||
$typeStrings[] = $this->typesToString[$type]; | ||
} | ||
eldering marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return implode(', ', $typeStrings); | ||
} | ||
|
||
public function getTypes(): array | ||
{ | ||
return $this->combined_run_compare; | ||
$ret = []; | ||
foreach (array_keys($this->typesToString) as $type) { | ||
if ($this->types & $type) { | ||
$ret[] = $type; | ||
} | ||
} | ||
return $ret; | ||
} | ||
|
||
public function setMultipassProblem(bool $isMultipassProblem): Problem | ||
public function setTypes(array $types): Problem | ||
{ | ||
$this->isMultipassProblem = $isMultipassProblem; | ||
$types = array_unique($types); | ||
$this->types = 0; | ||
foreach ($types as $type) { | ||
$this->types |= $type; | ||
} | ||
if (!($this->types & self::TYPE_PASS_FAIL) xor ($this->types & self::TYPE_SCORING)) { | ||
throw new Exception("Invalid problem type: must be exactly one of 'pass-fail' or 'scoring'."); | ||
} | ||
Comment on lines
+341
to
+343
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note that See also: Kattis/problem-package-format#440 EDIT: Looks like this was fixed in It's now also in the spec, see Kattis/problem-package-format#471 😄 |
||
if ($this->types & self::TYPE_SUBMIT_ANSWER) { | ||
if ($this->types & self::TYPE_MULTI_PASS) { | ||
throw new Exception("Invalid problem type: 'submit-answer' and 'multi-pass' are mutually exclusive."); | ||
} | ||
if ($this->types & self::TYPE_INTERACTIVE) { | ||
throw new Exception("Invalid problem type: 'submit-answer' and 'interactive' are mutually exclusive."); | ||
} | ||
} | ||
return $this; | ||
} | ||
|
||
public function isInteractiveProblem(): bool | ||
{ | ||
return (bool)($this->types & self::TYPE_INTERACTIVE); | ||
} | ||
|
||
public function isMultipassProblem(): bool | ||
{ | ||
return $this->isMultipassProblem; | ||
return (bool)($this->types & self::TYPE_MULTI_PASS); | ||
} | ||
|
||
public function isPassFailProblem(): bool | ||
{ | ||
return (bool)($this->types & self::TYPE_PASS_FAIL); | ||
} | ||
|
||
public function isScoringProblem(): bool | ||
{ | ||
return (bool)($this->types & self::TYPE_SCORING); | ||
} | ||
|
||
public function setMultipassLimit(?int $multipassLimit): Problem | ||
|
@@ -317,7 +380,7 @@ public function setMultipassLimit(?int $multipassLimit): Problem | |
|
||
public function getMultipassLimit(): int | ||
{ | ||
if ($this->isMultipassProblem) { | ||
if ($this->isMultipassProblem()) { | ||
return $this->multipassLimit ?? 2; | ||
} | ||
return 1; | ||
|
Uh oh!
There was an error while loading. Please reload this page.