Skip to content

Commit

Permalink
Implementing a flag for an assignment that permits the students to se…
Browse files Browse the repository at this point in the history
…e absolute values of measured time and memory of their solutions.
  • Loading branch information
krulis-martin committed Jul 12, 2024
1 parent 371bc4b commit c6073d3
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 4 deletions.
6 changes: 6 additions & 0 deletions app/V1Module/presenters/AssignmentsPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,8 @@ public function checkUpdateDetail(string $id)
* description="Date from which this assignment will be visible to students")
* @Param(type="post", name="canViewLimitRatios", validation="bool",
* description="Can all users view ratio of theirs solution memory and time usages and assignment limits?")
* @Param(type="post", name="canViewMeasuredValues", validation="bool",
* description="Can all users view absolute memory and time values?")
* @Param(type="post", name="canViewJudgeStdout", validation="bool",
* description="Can all users view judge primary log (stdout) of theirs solution?")
* @Param(type="post", name="canViewJudgeStderr", validation="bool",
Expand Down Expand Up @@ -347,6 +349,10 @@ public function actionUpdateDetail(string $id)
$assignment->setAllowSecondDeadline($allowSecondDeadline);
$assignment->setMaxPointsDeadlineInterpolation($maxPointsDeadlineInterpolation);
$assignment->setCanViewLimitRatios(filter_var($req->getPost("canViewLimitRatios"), FILTER_VALIDATE_BOOLEAN));
$assignment->setCanViewMeasuredValues(filter_var(
$req->getPost("canViewMeasuredValues"),
FILTER_VALIDATE_BOOLEAN
));
$assignment->setCanViewJudgeStdout(filter_var($req->getPost("canViewJudgeStdout"), FILTER_VALIDATE_BOOLEAN));
$assignment->setCanViewJudgeStderr(filter_var($req->getPost("canViewJudgeStderr"), FILTER_VALIDATE_BOOLEAN));
$assignment->setIsBonus(filter_var($req->getPost("isBonus"), FILTER_VALIDATE_BOOLEAN));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ public function areEvaluationDetailsPublic(Identity $identity, AssignmentSolutio
return $solution->getAssignment() && $solution->getAssignment()->getCanViewLimitRatios();
}

public function areMeasuredValuesPublic(Identity $identity, AssignmentSolution $solution)
{
return $solution->getAssignment() && $solution->getAssignment()->getCanViewMeasuredValues();
}

public function areJudgeStdoutsPublic(Identity $identity, AssignmentSolution $solution)
{
return $solution->getAssignment() && $solution->getAssignment()->getCanViewJudgeStdout();
Expand Down
11 changes: 11 additions & 0 deletions app/config/permissions.neon
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,17 @@ permissions:
- assignmentSolution.isAuthor
- assignmentSolution.userIsNotLockedElsewhereStrictly

- allow: true
role: student
resource: assignmentSolution
actions:
- viewEvaluationValues
conditions:
- assignmentSolution.areEvaluationDetailsPublic
- assignmentSolution.areMeasuredValuesPublic
- assignmentSolution.isAuthor
- assignmentSolution.userIsNotLockedElsewhereStrictly

- allow: true
role: supervisor-student
resource: assignmentSolution
Expand Down
28 changes: 24 additions & 4 deletions app/model/entity/Assignment.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ private function __construct(
DateTime $secondDeadline = null,
int $maxPointsBeforeSecondDeadline = 0,
bool $canViewLimitRatios = false,
bool $canViewMeasuredValues = false,
bool $isBonus = false,
$pointsPercentualThreshold = 0,
?DateTime $visibleFrom = null,
Expand Down Expand Up @@ -62,6 +63,7 @@ private function __construct(
$this->localizedTexts = new ArrayCollection($exercise->getLocalizedTexts()->toArray());
$this->localizedAssignments = new ArrayCollection();
$this->canViewLimitRatios = $canViewLimitRatios;
$this->canViewMeasuredValues = $canViewMeasuredValues;
$this->canViewJudgeStdout = $canViewJudgeStdout;
$this->canViewJudgeStderr = $canViewJudgeStderr;
$this->mergeJudgeLogs = $exercise->getMergeJudgeLogs();
Expand Down Expand Up @@ -254,23 +256,31 @@ public function hasAssignedPoints(): bool

/**
* @ORM\Column(type="boolean")
* Whether a student can see the relative consumed time and memory (for each test).
*/
protected $canViewLimitRatios;
protected $canViewLimitRatios = false;

/**
* @ORM\Column(type="boolean")
* Whether a student can see the absolute values of consumed time and memory (for each test).
* This only applies if $canViewLimitRatios is true.
*/
protected $canViewJudgeStdout;
protected $canViewMeasuredValues = false;

/**
* @ORM\Column(type="boolean")
*/
protected $canViewJudgeStderr;
protected $canViewJudgeStdout = false;

/**
* @ORM\Column(type="boolean")
*/
protected $mergeJudgeLogs;
protected $canViewJudgeStderr = false;

/**
* @ORM\Column(type="boolean")
*/
protected $mergeJudgeLogs = false;

/**
* @ORM\Column(type="boolean")
Expand Down Expand Up @@ -578,6 +588,16 @@ public function setCanViewLimitRatios(bool $canViewLimitRatios): void
$this->canViewLimitRatios = $canViewLimitRatios;
}

public function getCanViewMeasuredValues(): bool
{
return $this->canViewMeasuredValues;
}

public function setCanViewMeasuredValues(bool $canViewMeasuredValues): void
{
$this->canViewMeasuredValues = $canViewMeasuredValues;
}

public function getFirstDeadline(): DateTime
{
return $this->firstDeadline;
Expand Down
1 change: 1 addition & 0 deletions app/model/view/AssignmentViewFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ function (LocalizedExercise $text) use ($assignment) {
"runtimeEnvironmentIds" => $assignment->getAllRuntimeEnvironmentsIds(),
"disabledRuntimeEnvironmentIds" => $assignment->getDisabledRuntimeEnvironmentsIds(),
"canViewLimitRatios" => $assignment->getCanViewLimitRatios(),
"canViewMeasuredValues" => $assignment->getCanViewMeasuredValues(),
"canViewJudgeStdout" => $assignment->getCanViewJudgeStdout(),
"canViewJudgeStderr" => $assignment->getCanViewJudgeStderr(),
"mergeJudgeLogs" => $assignment->getMergeJudgeLogs(),
Expand Down
60 changes: 60 additions & 0 deletions tests/Presenters/AssignmentsPresenter.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ class TestAssignmentsPresenter extends Tester\TestCase
$submissionsCountLimit = 32;
$allowSecondDeadline = true;
$canViewLimitRatios = false;
$canViewMeasuredValues = false;
$canViewJudgeStdout = true;
$canViewJudgeStderr = false;
$secondDeadline = (new DateTime())->getTimestamp() + 10;
Expand All @@ -177,6 +178,7 @@ class TestAssignmentsPresenter extends Tester\TestCase
'allowSecondDeadline' => $allowSecondDeadline,
'maxPointsDeadlineInterpolation' => false,
'canViewLimitRatios' => $canViewLimitRatios,
'canViewMeasuredValues' => $canViewMeasuredValues,
'canViewJudgeStdout' => $canViewJudgeStdout,
'canViewJudgeStderr' => $canViewJudgeStderr,
'secondDeadline' => $secondDeadline,
Expand All @@ -203,6 +205,7 @@ class TestAssignmentsPresenter extends Tester\TestCase
Assert::equal($submissionsCountLimit, $updatedAssignment["submissionsCountLimit"]);
Assert::equal($allowSecondDeadline, $updatedAssignment["allowSecondDeadline"]);
Assert::equal($canViewLimitRatios, $updatedAssignment["canViewLimitRatios"]);
Assert::equal($canViewMeasuredValues, $updatedAssignment["canViewMeasuredValues"]);
Assert::equal($canViewJudgeStdout, $updatedAssignment["canViewJudgeStdout"]);
Assert::equal($canViewJudgeStderr, $updatedAssignment["canViewJudgeStderr"]);
Assert::equal($secondDeadline, $updatedAssignment["secondDeadline"]);
Expand Down Expand Up @@ -256,6 +259,7 @@ class TestAssignmentsPresenter extends Tester\TestCase
'allowSecondDeadline' => false,
'maxPointsDeadlineInterpolation' => true,
'canViewLimitRatios' => false,
'canViewMeasuredValues' => false,
'canViewJudgeStdout' => false,
'canViewJudgeStderr' => false,
'isBonus' => false,
Expand Down Expand Up @@ -308,6 +312,7 @@ class TestAssignmentsPresenter extends Tester\TestCase
$submissionsCountLimit = 32;
$allowSecondDeadline = true;
$canViewLimitRatios = false;
$canViewMeasuredValues = false;
$canViewJudgeStdout = true;
$canViewJudgeStderr = false;
$secondDeadline = (new DateTime())->getTimestamp() + 1000;
Expand All @@ -333,6 +338,7 @@ class TestAssignmentsPresenter extends Tester\TestCase
'allowSecondDeadline' => $allowSecondDeadline,
'maxPointsDeadlineInterpolation' => false,
'canViewLimitRatios' => $canViewLimitRatios,
'canViewMeasuredValues' => $canViewMeasuredValues,
'canViewJudgeStdout' => $canViewJudgeStdout,
'canViewJudgeStderr' => $canViewJudgeStderr,
'secondDeadline' => $secondDeadline,
Expand All @@ -359,6 +365,7 @@ class TestAssignmentsPresenter extends Tester\TestCase
Assert::equal($submissionsCountLimit, $updatedAssignment["submissionsCountLimit"]);
Assert::equal($allowSecondDeadline, $updatedAssignment["allowSecondDeadline"]);
Assert::equal($canViewLimitRatios, $updatedAssignment["canViewLimitRatios"]);
Assert::equal($canViewMeasuredValues, $updatedAssignment["canViewMeasuredValues"]);
Assert::equal($canViewJudgeStdout, $updatedAssignment["canViewJudgeStdout"]);
Assert::equal($canViewJudgeStderr, $updatedAssignment["canViewJudgeStderr"]);
Assert::equal($secondDeadline, $updatedAssignment["secondDeadline"]);
Expand Down Expand Up @@ -402,6 +409,7 @@ class TestAssignmentsPresenter extends Tester\TestCase
'allowSecondDeadline' => true,
'maxPointsDeadlineInterpolation' => true,
'canViewLimitRatios' => false,
'canViewMeasuredValues' => false,
'canViewJudgeStdout' => false,
'canViewJudgeStderr' => false,
'secondDeadline' => (new DateTime())->getTimestamp() + 10,
Expand Down Expand Up @@ -448,6 +456,7 @@ class TestAssignmentsPresenter extends Tester\TestCase
'allowSecondDeadline' => true,
'maxPointsDeadlineInterpolation' => false,
'canViewLimitRatios' => false,
'canViewMeasuredValues' => false,
'canViewJudgeStdout' => false,
'canViewJudgeStderr' => false,
'secondDeadline' => (new DateTime())->getTimestamp() + 10,
Expand All @@ -467,6 +476,55 @@ class TestAssignmentsPresenter extends Tester\TestCase
Assert::true(in_array($disabledEnv->getId(), $updatedAssignment["runtimeEnvironmentIds"]));
}

public function testSetVisibilityFlags()
{
PresenterTestHelper::loginDefaultAdmin($this->container);

$assignments = $this->assignments->findAll();
/** @var Assignment $assignment */
$assignment = array_pop($assignments);

$payload = PresenterTestHelper::performPresenterRequest(
$this->presenter,
'V1:Assignments',
'POST',
['action' => 'updateDetail', 'id' => $assignment->getId()],
[
'isPublic' => true,
'version' => 1,
'localizedTexts' => [
["locale" => "locA", "text" => "descA", "name" => "nameA"]
],
'firstDeadline' => (new DateTime())->getTimestamp(),
'maxPointsBeforeFirstDeadline' => 123,
'submissionsCountLimit' => 32,
'allowSecondDeadline' => true,
'maxPointsDeadlineInterpolation' => false,
'canViewLimitRatios' => true,
'canViewMeasuredValues' => true,
'canViewJudgeStdout' => true,
'canViewJudgeStderr' => true,
'secondDeadline' => (new DateTime())->getTimestamp() + 10,
'maxPointsBeforeSecondDeadline' => 543,
'isBonus' => true,
'pointsPercentualThreshold' => 90.0,
'solutionFilesLimit' => null,
'solutionSizeLimit' => null,
'isExam' => false,
]
);

Assert::true($payload["canViewLimitRatios"]);
Assert::true($payload["canViewMeasuredValues"]);
Assert::true($payload["canViewJudgeStdout"]);
Assert::true($payload["canViewJudgeStderr"]);
$this->presenter->assignments->refresh($assignment);
Assert::true($assignment->getCanViewLimitRatios());
Assert::true($assignment->getCanViewMeasuredValues());
Assert::true($assignment->getCanViewJudgeStdout());
Assert::true($assignment->getCanViewJudgeStderr());
}

public function testSetExamFlag()
{
PresenterTestHelper::loginDefaultAdmin($this->container);
Expand All @@ -492,6 +550,7 @@ class TestAssignmentsPresenter extends Tester\TestCase
'allowSecondDeadline' => true,
'maxPointsDeadlineInterpolation' => false,
'canViewLimitRatios' => false,
'canViewMeasuredValues' => false,
'canViewJudgeStdout' => false,
'canViewJudgeStderr' => false,
'secondDeadline' => (new DateTime())->getTimestamp() + 10,
Expand Down Expand Up @@ -538,6 +597,7 @@ class TestAssignmentsPresenter extends Tester\TestCase
'allowSecondDeadline' => true,
'maxPointsDeadlineInterpolation' => false,
'canViewLimitRatios' => false,
'canViewMeasuredValues' => false,
'canViewJudgeStdout' => false,
'canViewJudgeStderr' => false,
'secondDeadline' => (new DateTime())->getTimestamp() + 10,
Expand Down

0 comments on commit c6073d3

Please sign in to comment.