[web] Format and add CPP to db
This commit is contained in:
parent
6b955857bf
commit
d2d686133c
@ -80,6 +80,7 @@ model Team {
|
||||
enum Language {
|
||||
Java
|
||||
CSharp
|
||||
CPP
|
||||
}
|
||||
|
||||
model ActiveTeam {
|
||||
|
@ -36,7 +36,8 @@ export const actions = {
|
||||
}
|
||||
try {
|
||||
await db.contest.delete({ where: { id: parseInt(params.contestId) } });
|
||||
} catch {
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
return { success: false };
|
||||
}
|
||||
redirect(302, '/admin/contests');
|
||||
|
@ -7,34 +7,34 @@ import { genPassword } from '../../teams/util';
|
||||
export const load = (async () => {}) satisfies PageServerLoad;
|
||||
|
||||
export type ContestImportData = {
|
||||
Name: string,
|
||||
Problems: ProblemImportData[],
|
||||
Teams: TeamImportData[],
|
||||
Submissions: SubmissionImportData[]
|
||||
}
|
||||
Name: string;
|
||||
Problems: ProblemImportData[];
|
||||
Teams: TeamImportData[];
|
||||
Submissions: SubmissionImportData[];
|
||||
};
|
||||
|
||||
export type ProblemImportData = {
|
||||
ProblemName: string,
|
||||
ShortName: string,
|
||||
SampleInput: string,
|
||||
SampleOutput: string,
|
||||
RealInput: string,
|
||||
RealOutput: string
|
||||
}
|
||||
ProblemName: string;
|
||||
ShortName: string;
|
||||
SampleInput: string;
|
||||
SampleOutput: string;
|
||||
RealInput: string;
|
||||
RealOutput: string;
|
||||
};
|
||||
|
||||
export type TeamImportData = {
|
||||
TeamName: string
|
||||
}
|
||||
TeamName: string;
|
||||
};
|
||||
|
||||
export type SubmissionImportData = {
|
||||
TeamName: string,
|
||||
ProblemShortName: string,
|
||||
State: string,
|
||||
SubmitTime: number,
|
||||
TeamOutput: string,
|
||||
Code: string | null,
|
||||
Language: "Java" | "C#" | "C++" | null
|
||||
}
|
||||
TeamName: string;
|
||||
ProblemShortName: string;
|
||||
State: string;
|
||||
SubmitTime: number;
|
||||
TeamOutput: string;
|
||||
Code: string | null;
|
||||
Language: 'Java' | 'C#' | 'C++' | null;
|
||||
};
|
||||
|
||||
export const actions = {
|
||||
default: async ({ request }) => {
|
||||
@ -45,14 +45,13 @@ export const actions = {
|
||||
const formData = await request.formData();
|
||||
const contestJson = formData.get('jsonText')?.toString();
|
||||
if (!contestJson) {
|
||||
return fail(400, { message: "Could not get json text" });
|
||||
return fail(400, { message: 'Could not get json text' });
|
||||
}
|
||||
|
||||
parsedContest = JSON.parse(contestJson);
|
||||
includeSubmissions = formData.get('includeSubmissions')?.toString() == "on";
|
||||
}
|
||||
catch (err) {
|
||||
return fail(400, { message: "Could not parse contest data: " + err?.toString() });
|
||||
includeSubmissions = formData.get('includeSubmissions')?.toString() == 'on';
|
||||
} catch (err) {
|
||||
return fail(400, { message: 'Could not parse contest data: ' + err?.toString() });
|
||||
}
|
||||
|
||||
try {
|
||||
@ -62,7 +61,9 @@ export const actions = {
|
||||
if (includeSubmissions && parsedContest.Submissions.length > 0) {
|
||||
hasSubmissions = true;
|
||||
|
||||
const maxSubmitTimeMinutes = Math.max(...parsedContest.Submissions.map(s => s.SubmitTime));
|
||||
const maxSubmitTimeMinutes = Math.max(
|
||||
...parsedContest.Submissions.map((s) => s.SubmitTime)
|
||||
);
|
||||
const now = new Date();
|
||||
contestStart = new Date(now.getTime() - maxSubmitTimeMinutes * 60 * 1000);
|
||||
}
|
||||
@ -73,24 +74,24 @@ export const actions = {
|
||||
name: parsedContest.Name,
|
||||
startTime: contestStart,
|
||||
teams: {
|
||||
connectOrCreate: parsedContest.Teams.map(team => ({
|
||||
connectOrCreate: parsedContest.Teams.map((team) => ({
|
||||
where: { name: team.TeamName },
|
||||
create: {
|
||||
name: team.TeamName,
|
||||
password: genPassword(),
|
||||
language: inferTeamLanguage(parsedContest, team) ?? Language.Java
|
||||
}
|
||||
})),
|
||||
}))
|
||||
},
|
||||
problems: {
|
||||
connectOrCreate: parsedContest.Problems.map(problem => ({
|
||||
connectOrCreate: parsedContest.Problems.map((problem) => ({
|
||||
where: {
|
||||
friendlyName: problem.ProblemName,
|
||||
pascalName: problem.ShortName,
|
||||
sampleInput: problem.SampleInput,
|
||||
sampleOutput: problem.SampleOutput,
|
||||
realInput: problem.RealInput,
|
||||
realOutput: problem.RealOutput,
|
||||
realOutput: problem.RealOutput
|
||||
},
|
||||
create: {
|
||||
friendlyName: problem.ProblemName,
|
||||
@ -100,16 +101,17 @@ export const actions = {
|
||||
realInput: problem.RealInput,
|
||||
realOutput: problem.RealOutput
|
||||
}
|
||||
})),
|
||||
}))
|
||||
},
|
||||
submissions: {
|
||||
create: hasSubmissions
|
||||
? parsedContest.Submissions.toSorted((a, b) => a.SubmitTime - b.SubmitTime).map(submission => ({
|
||||
? parsedContest.Submissions.toSorted((a, b) => a.SubmitTime - b.SubmitTime).map(
|
||||
(submission) => ({
|
||||
createdAt: dateFromContestMinutes(contestStart!, submission.SubmitTime),
|
||||
gradedAt: dateFromContestMinutes(contestStart!, submission.SubmitTime + 1),
|
||||
state: convertSubmissionState(submission),
|
||||
actualOutput: submission.TeamOutput,
|
||||
commitHash: "",
|
||||
commitHash: '',
|
||||
problem: {
|
||||
connect: {
|
||||
pascalName: submission.ProblemShortName
|
||||
@ -120,45 +122,51 @@ export const actions = {
|
||||
name: submission.TeamName
|
||||
}
|
||||
}
|
||||
}))
|
||||
})
|
||||
)
|
||||
: []
|
||||
}
|
||||
}
|
||||
});
|
||||
} catch (err) {
|
||||
return fail(400, { message: "Error updating database: " + err?.toString() });
|
||||
return fail(400, { message: 'Error updating database: ' + err?.toString() });
|
||||
}
|
||||
|
||||
return redirect(303, "/admin/contests");
|
||||
return redirect(303, '/admin/contests');
|
||||
}
|
||||
} satisfies Actions;
|
||||
|
||||
function convertSubmissionState(submission: SubmissionImportData): SubmissionState {
|
||||
switch (submission.State) {
|
||||
case "Correct":
|
||||
case 'Correct':
|
||||
return SubmissionState.Correct;
|
||||
case "Incorrect":
|
||||
case 'Incorrect':
|
||||
return SubmissionState.Incorrect;
|
||||
default:
|
||||
return SubmissionState.InReview;
|
||||
}
|
||||
}
|
||||
|
||||
function inferTeamLanguage(parsedContest: ContestImportData, team: TeamImportData): Language | null {
|
||||
const submissionWithCode = parsedContest.Submissions.find(s => s.TeamName == team.TeamName && s.Code != null);
|
||||
function inferTeamLanguage(
|
||||
parsedContest: ContestImportData,
|
||||
team: TeamImportData
|
||||
): Language | null {
|
||||
const submissionWithCode = parsedContest.Submissions.find(
|
||||
(s) => s.TeamName == team.TeamName && s.Code != null
|
||||
);
|
||||
if (!submissionWithCode) {
|
||||
return null;
|
||||
}
|
||||
|
||||
switch (submissionWithCode.Language) {
|
||||
case "Java":
|
||||
case 'Java':
|
||||
return Language.Java;
|
||||
case "C#":
|
||||
case 'C#':
|
||||
return Language.CSharp;
|
||||
case "C++":
|
||||
case 'C++':
|
||||
return Language.CPP;
|
||||
default:
|
||||
throw new Error("Unrecognized language: " + submissionWithCode.Language);
|
||||
throw new Error('Unrecognized language: ' + submissionWithCode.Language);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
<script lang="ts">
|
||||
import { enhance } from '$app/forms';
|
||||
import { goto } from '$app/navigation';
|
||||
import FormAlert from '$lib/FormAlert.svelte';
|
||||
import type { Actions } from './$types';
|
||||
@ -48,7 +49,7 @@
|
||||
|
||||
<FormAlert />
|
||||
|
||||
<form method="POST">
|
||||
<form method="POST" use:enhance>
|
||||
<div class="mb-4">
|
||||
<h3>Contest JSON:</h3>
|
||||
<textarea
|
||||
@ -57,7 +58,9 @@
|
||||
class="form-control"
|
||||
rows="10"
|
||||
bind:value={jsonText}
|
||||
style="{parsesCorrectly == null ? "" : `border: 2px solid ${parsesCorrectly ? 'green' : 'red'}`}"
|
||||
style={parsesCorrectly == null
|
||||
? ''
|
||||
: `border: 2px solid ${parsesCorrectly ? 'green' : 'red'}`}
|
||||
/>
|
||||
</div>
|
||||
|
||||
|
@ -73,7 +73,12 @@
|
||||
<textarea use:stretchTextarea class="code mb-3 form-control" disabled>{data.output}</textarea>
|
||||
|
||||
<h3>Diff</h3>
|
||||
<div class="mt-3" id="diff" class:d2h-dark-color-scheme={$theme === 'dark'} class:d2h-light-color-scheme={$theme === 'light'}/>
|
||||
<div
|
||||
class="mt-3"
|
||||
id="diff"
|
||||
class:d2h-dark-color-scheme={$theme === 'dark'}
|
||||
class:d2h-light-color-scheme={$theme === 'light'}
|
||||
/>
|
||||
|
||||
<form method="POST" action="?/submit" use:enhance>
|
||||
<h5>Message</h5>
|
||||
|
Loading…
Reference in New Issue
Block a user