Skip to content

Commit

Permalink
HACK: refactor OSN 2024 hacks on grader-side
Browse files Browse the repository at this point in the history
  • Loading branch information
fushar committed Aug 18, 2024
1 parent 6b74bb8 commit af95f25
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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<String> 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, hacked.length() - 1);
hacked = hacked + ",\"scoringConfig\":{\"roundingMode\":\"FLOOR\"}}";
return hacked;
}
return gradingConfig;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,20 @@
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;
import judgels.sandalphon.problem.base.BaseProblemStore;
import judgels.sandalphon.problem.base.ProblemFs;

public final class ProgrammingProblemStore extends BaseProblemStore {
// HACK for OSN 2024
private static final List<String> OSN_2024_CERTAIN_PROBLEMS = Arrays.asList(
"JIDPROG0NHjqvK7B7oiYf6mOOov",
"JIDPROGiZN73iuSVYJE5btHUzni",
"JIDPROGbDLh6vwDRHTXFijN3HYC",
"JIDPROGSohGUsEykcREuewkE2cn"
);

@Inject
public ProgrammingProblemStore(ObjectMapper mapper, @ProblemFs FileSystem problemFs) {
super(mapper, problemFs);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit af95f25

Please sign in to comment.