From 4a171d75f2972906366fe27666c7dc863f3b9c15 Mon Sep 17 00:00:00 2001 From: Ashar Fuadi Date: Sun, 18 Aug 2024 09:45:28 +0700 Subject: [PATCH] HACK: refactor OSN 2024 hacks on grader-side --- .../gabriel/grading/GradingWorker.java | 5 ++++ .../judgels/gabriel/api/Osn2024Hacks.java | 25 +++++++++++++++++++ .../programming/ProgrammingProblemStore.java | 15 ++--------- 3 files changed, 32 insertions(+), 13 deletions(-) create mode 100644 judgels-backends/judgels-grader-engines/src/main/java/judgels/gabriel/api/Osn2024Hacks.java diff --git a/judgels-backends/judgels-grader-app/src/main/java/judgels/gabriel/grading/GradingWorker.java b/judgels-backends/judgels-grader-app/src/main/java/judgels/gabriel/grading/GradingWorker.java index ac9ab5e27..bd50041a3 100644 --- a/judgels-backends/judgels-grader-app/src/main/java/judgels/gabriel/grading/GradingWorker.java +++ b/judgels-backends/judgels-grader-app/src/main/java/judgels/gabriel/grading/GradingWorker.java @@ -24,6 +24,7 @@ import judgels.gabriel.api.GradingResponse; import judgels.gabriel.api.GradingResult; import judgels.gabriel.api.GradingSource; +import judgels.gabriel.api.Osn2024Hacks; import judgels.gabriel.api.SandboxFactory; import judgels.gabriel.api.SourceFile; import judgels.gabriel.api.SubmissionSource; @@ -242,6 +243,10 @@ private GradingEngine getGradingEngine(Path problemGradingDir) throws IOExceptio private GradingConfig parseGradingConfig(Path problemGradingDir, GradingEngine engine) throws IOException { Path gradingConfig = problemGradingDir.resolve("config.json"); String configAsJson = Files.readString(gradingConfig, StandardCharsets.UTF_8); + + // HACK for OSN 2024 + configAsJson = Osn2024Hacks.checkForHack(request.getProblemJid(), configAsJson); + return engine.parseConfig(MAPPER, configAsJson); } diff --git a/judgels-backends/judgels-grader-engines/src/main/java/judgels/gabriel/api/Osn2024Hacks.java b/judgels-backends/judgels-grader-engines/src/main/java/judgels/gabriel/api/Osn2024Hacks.java new file mode 100644 index 000000000..ddb9c8850 --- /dev/null +++ b/judgels-backends/judgels-grader-engines/src/main/java/judgels/gabriel/api/Osn2024Hacks.java @@ -0,0 +1,25 @@ +package judgels.gabriel.api; + +import java.util.Arrays; +import java.util.List; + +public class Osn2024Hacks { + private Osn2024Hacks() {} + + private static final List CERTAIN_PROBLEM_JIDS = Arrays.asList( + "JIDPROG0NHjqvK7B7oiYf6mOOov", + "JIDPROGiZN73iuSVYJE5btHUzni", + "JIDPROGbDLh6vwDRHTXFijN3HYC", + "JIDPROGSohGUsEykcREuewkE2cn" + ); + + public static String checkForHack(String problemJid, String gradingConfig) { + if (CERTAIN_PROBLEM_JIDS.contains(problemJid)) { + String hacked = gradingConfig; + hacked = hacked.substring(0, gradingConfig.length() - 1); + hacked = hacked + ",\"scoringConfig\":{\"roundingMode\":\"FLOOR\"}}"; + return hacked; + } + return gradingConfig; + } +} diff --git a/judgels-backends/judgels-server-app/src/main/java/judgels/sandalphon/problem/programming/ProgrammingProblemStore.java b/judgels-backends/judgels-server-app/src/main/java/judgels/sandalphon/problem/programming/ProgrammingProblemStore.java index 86448338e..feec13c4a 100644 --- a/judgels-backends/judgels-server-app/src/main/java/judgels/sandalphon/problem/programming/ProgrammingProblemStore.java +++ b/judgels-backends/judgels-server-app/src/main/java/judgels/sandalphon/problem/programming/ProgrammingProblemStore.java @@ -5,13 +5,13 @@ import java.io.InputStream; import java.nio.file.Path; import java.time.Instant; -import java.util.Arrays; import java.util.List; import javax.inject.Inject; import judgels.fs.FileInfo; import judgels.fs.FileSystem; import judgels.gabriel.api.GradingConfig; import judgels.gabriel.api.LanguageRestriction; +import judgels.gabriel.api.Osn2024Hacks; import judgels.gabriel.api.ScoringConfig; import judgels.gabriel.engines.GradingEngineRegistry; import judgels.sandalphon.api.problem.programming.ProblemSubmissionConfig; @@ -19,14 +19,6 @@ import judgels.sandalphon.problem.base.ProblemFs; public final class ProgrammingProblemStore extends BaseProblemStore { - // HACK for OSN 2024 - private static final List OSN_2024_CERTAIN_PROBLEMS = Arrays.asList( - "JIDPROG0NHjqvK7B7oiYf6mOOov", - "JIDPROGiZN73iuSVYJE5btHUzni", - "JIDPROGbDLh6vwDRHTXFijN3HYC", - "JIDPROGSohGUsEykcREuewkE2cn" - ); - @Inject public ProgrammingProblemStore(ObjectMapper mapper, @ProblemFs FileSystem problemFs) { super(mapper, problemFs); @@ -60,10 +52,7 @@ public GradingConfig getGradingConfig(String userJid, String problemJid) { String gradingConfig = problemFs.readFromFile(getGradingConfigFilePath(userJid, problemJid)); // HACK for OSN 2024 - if (OSN_2024_CERTAIN_PROBLEMS.contains(problemJid)) { - gradingConfig = gradingConfig.substring(0, gradingConfig.length() - 1); - gradingConfig = gradingConfig + ",\"scoringConfig\":{\"roundingMode\":\"FLOOR\"}}"; - } + gradingConfig = Osn2024Hacks.checkForHack(problemJid, gradingConfig); try { return GradingEngineRegistry.getInstance().get(gradingEngine).parseConfig(mapper, gradingConfig);