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

Add support for subtasked tasks #53

Merged
merged 8 commits into from
Dec 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
3 changes: 3 additions & 0 deletions backend/terry/handlers/info_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,10 @@ def patch_submission(submission):

del result["output"]
result = BaseHandler.format_dates(result)

result["output"] = temp
if "subtasks" in feedback:
result["subtasks"] = feedback["subtasks"]

return result

Expand Down
8 changes: 8 additions & 0 deletions format-specs.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,12 @@ The checker should print to its standard output a JSON value with _at least_ the
- `severity`: a string with one of the following values: `"warning"`
- `message`: the message to show to the contestant.

The following field must be present if and only if the problem is scored with subtasks:
- `subtasks`: the subtasks of the task. It is an array with an entry for each subtask. Each entry is an object with _at least_ the following fields:
- `score`: a number indicating the score of the contestant on the subtask.
- `max_score`: a number indicating the maximum score on the subtask.
- `testcases`: an array of numbers, containing the testcases belonging to the subtask.

Note that is the checker's responsibility to make sure that the information contained in `subtasks` is accurate.

The checker should be very resilient to invalid output files submitted by the contestant. To avoid writing every time the parsing code a Python library is available [here](https://github.com/algorithm-ninja/territoriali-cli/blob/master/terry_cli/parser.py). Note that it's useful only for the `Case #1: ...` output format.
1 change: 1 addition & 0 deletions frontend/src/contest/submission/FeedbackView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export function FeedbackView({ submission, task }: Props) {
<ResultView
cases={submission.feedback.cases}
alerts={submission.feedback.alerts}
subtasks={submission.subtasks}
renderCase={renderCase}
renderCaseSummary={renderCaseSummary}
/>
Expand Down
6 changes: 6 additions & 0 deletions frontend/src/contest/submission/GridList.css
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,9 @@ dl.terry-grid-list > dd {
-ms-flex: 1 1 100%;
flex: 1 1 100%;
}

dl.terry-grid-list > dd > table {
border-spacing: 10px 0;
border-collapse: separate;
margin-left: -10px;
}
59 changes: 49 additions & 10 deletions frontend/src/contest/submission/ResultView.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,63 @@
import React from "react";
import { Trans } from "@lingui/macro";
import { Alert } from "src/types/contest";
import { Alert, Subtask } from "src/types/contest";

type Props<T> = {
cases: T[];
alerts: Alert[];
subtasks?: Subtask[];
renderCase: (c: T, i: number) => React.ReactNode;
renderCaseSummary: (c: T, i: number) => React.ReactNode;
};

export function ResultView<T>({
cases, alerts, renderCase, renderCaseSummary,
cases, alerts, subtasks, renderCase, renderCaseSummary,
}: Props<T>) {
const renderGridWithSubtasks = (subtasks: Subtask[], cases: T[]) => {
return (
<>
<table>
<tbody>
{subtasks.map((s: Subtask, i: number) => (
<tr>
<td>
Subtask {i + 1} ({s.score}/{s.max_score})
</td>
<td>
<ul className="list-inline mb-0">
{s.testcases.map((i: number, _: number) => (
// eslint-disable-next-line react/no-array-index-key
<li className="list-inline-item" key={i}>
{renderCaseSummary(cases[i], i + 1)}
</li>
))}
</ul>
</td>
</tr>
))}
</tbody>
</table>
</>
)
};

const renderGridWithoutSubtasks = (cases: T[]) => {
return (
<>
<ul className="list-inline mb-0">
{cases.map((c: T, i: number) => (
// eslint-disable-next-line react/no-array-index-key
<li className="list-inline-item" key={i}>
{renderCaseSummary(c, i + 1)}
</li>
))}
</ul>
</>
);
}

const summary = subtasks ? renderGridWithSubtasks(subtasks, cases) : renderGridWithoutSubtasks(cases);

return (
<>
<ul className="list-unstyled">
Expand All @@ -34,14 +80,7 @@ export function ResultView<T>({
:
</dt>
<dd>
<ul className="list-inline mb-0">
{cases.map((c: T, i: number) => (
// eslint-disable-next-line react/no-array-index-key
<li className="list-inline-item" key={i}>
{renderCaseSummary(c, i + 1)}
</li>
))}
</ul>
{summary}
</dd>
</dl>
<div className="result-detail">
Expand Down
1 change: 1 addition & 0 deletions frontend/src/contest/submission/ValidationView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export function ValidationView({ output }: Props) {
<ResultView
alerts={output.validation.alerts}
cases={output.validation.cases}
subtasks={undefined}
renderCase={renderCase}
renderCaseSummary={renderCaseSummary}
/>
Expand Down
7 changes: 7 additions & 0 deletions frontend/src/types/contest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ type FeedbackData = {
cases: FeedbackCaseInfo[];
};

export type Subtask = {
max_score: number;
score: number;
testcases: number[];
};

export type Submission = {
id: string;
date: string;
Expand All @@ -26,6 +32,7 @@ export type Submission = {
input: InputData;
output: UploadedOutput;
source: UploadedSource;
subtasks: Subtask[];
feedback: FeedbackData;
};

Expand Down
Loading