Skip to content

Commit

Permalink
grader: allow floor rounding mode more properly
Browse files Browse the repository at this point in the history
  • Loading branch information
fushar committed Aug 17, 2024
1 parent 91ada5f commit c1c9d37
Show file tree
Hide file tree
Showing 19 changed files with 166 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
package judgels.gabriel.api;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import java.util.List;
import java.util.Map;
import org.immutables.value.Value;

public interface GradingConfig {
Map<String, String> getSourceFileFields();
int getTimeLimit();
int getMemoryLimit();
List<TestGroup> getTestData();
List<Subtask> getSubtasks();

@Value.Default
@JsonInclude(Include.NON_DEFAULT)
default ScoringConfig getScoringConfig() {
return ScoringConfig.DEFAULT;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package judgels.gabriel.api;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import org.immutables.value.Value;

@Value.Immutable
@JsonDeserialize(as = ImmutableScoringConfig.class)
public interface ScoringConfig {
ScoringConfig DEFAULT = new Builder().build();

@Value.Default
@JsonInclude(Include.NON_DEFAULT)
default ScoringRoundingMode getRoundingMode() {
return ScoringRoundingMode.ROUND;
}

class Builder extends ImmutableScoringConfig.Builder {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package judgels.gabriel.api;

public enum ScoringRoundingMode {
ROUND,
FLOOR,
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import judgels.gabriel.api.GradingSource;
import judgels.gabriel.api.PreparationException;
import judgels.gabriel.api.SandboxFactory;
import judgels.gabriel.api.ScoringRoundingMode;
import judgels.gabriel.api.Subtask;
import judgels.gabriel.api.SubtaskResult;
import judgels.gabriel.api.SubtaskVerdict;
Expand Down Expand Up @@ -333,9 +334,16 @@ private GradingResult buildResult() throws GradingException {
throw new GradingException(e);
}

int score;
if (config.getScoringConfig().getRoundingMode() == ScoringRoundingMode.ROUND) {
score = (int) Math.round(gradingVerdict.getPoints());
} else {
score = (int) Math.floor(gradingVerdict.getPoints());
}

return new GradingResult.Builder()
.verdict(gradingVerdict.getVerdict())
.score((int) Math.floor(gradingVerdict.getPoints()))
.score(score)
.details(detailsString)
.build();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package judgels.sandalphon.api.problem.programming;

import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import java.time.Instant;
import java.util.Map;
import judgels.gabriel.api.LanguageRestriction;
import org.immutables.value.Value;

@Value.Immutable
@JsonDeserialize(as = ImmutableProblemSubmissionConfig.class)
public interface ProblemSubmissionConfig {
Map<String, String> getSourceKeys();
String getGradingEngine();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.core.UriInfo;
import judgels.gabriel.api.GradingConfig;
import judgels.gabriel.api.ScoringConfig;
import judgels.sandalphon.api.lesson.Lesson;
import judgels.sandalphon.api.lesson.LessonInfo;
import judgels.sandalphon.api.lesson.LessonStatement;
Expand Down Expand Up @@ -155,6 +156,14 @@ public Map<String, ProblemSubmissionConfig> getProgrammingProblemSubmissionConfi
return Set.copyOf(problemJids).stream().collect(toMap(jid -> jid, this::getProgrammingProblemSubmissionConfig));
}

public ScoringConfig getProgrammingProblemScoringConfig(String problemJid) {
return programmingProblemStore.getProgrammingProblemScoringConfig(problemJid);
}

public Map<String, ScoringConfig> getProgrammingProblemScoringConfigs(Collection<String> problemJids) {
return Set.copyOf(problemJids).stream().collect(toMap(jid -> jid, this::getProgrammingProblemScoringConfig));
}

public judgels.sandalphon.api.problem.programming.ProblemWorksheet getProgrammingProblemWorksheet(
HttpServletRequest req,
UriInfo uriInfo,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import judgels.fs.FileSystem;
import judgels.gabriel.api.GradingConfig;
import judgels.gabriel.api.LanguageRestriction;
import judgels.gabriel.api.ScoringConfig;
import judgels.gabriel.engines.GradingEngineRegistry;
import judgels.sandalphon.api.problem.programming.ProblemSubmissionConfig;
import judgels.sandalphon.problem.base.BaseProblemStore;
Expand Down Expand Up @@ -137,6 +138,10 @@ public ProblemSubmissionConfig getProgrammingProblemSubmissionConfig(String prob
.build();
}

public ScoringConfig getProgrammingProblemScoringConfig(String problemJid) {
return getGradingConfig(null, problemJid).getScoringConfig();
}

private void updateGradingLastUpdateTime(String userJid, String problemJid) {
problemFs.writeToFile(getGradingLastUpdateTimeFilePath(userJid, problemJid), "" + System.currentTimeMillis());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import judgels.gabriel.api.ScoringConfig;
import judgels.jophiel.JophielClient;
import judgels.jophiel.api.profile.Profile;
import judgels.sandalphon.SandalphonClient;
import judgels.sandalphon.api.submission.bundle.ItemSubmission;
import judgels.sandalphon.api.submission.programming.Submission;
import judgels.sandalphon.submission.bundle.ItemSubmissionStore;
Expand Down Expand Up @@ -53,6 +55,7 @@ public class ContestScoreboardUpdater {
private final ScoreboardProcessorRegistry scoreboardProcessorRegistry;
private final ContestScoreboardPusher scoreboardPusher;
private final JophielClient jophielClient;
private final SandalphonClient sandalphonClient;

public ContestScoreboardUpdater(
ObjectMapper objectMapper,
Expand All @@ -67,7 +70,8 @@ public ContestScoreboardUpdater(
ScoreboardIncrementalMarker scoreboardIncrementalMarker,
ScoreboardProcessorRegistry scoreboardProcessorRegistry,
ContestScoreboardPusher scoreboardPusher,
JophielClient jophielClient) {
JophielClient jophielClient,
SandalphonClient sandalphonClient) {

this.objectMapper = objectMapper;
this.contestTimer = contestTimer;
Expand All @@ -82,6 +86,7 @@ public ContestScoreboardUpdater(
this.scoreboardProcessorRegistry = scoreboardProcessorRegistry;
this.scoreboardPusher = scoreboardPusher;
this.jophielClient = jophielClient;
this.sandalphonClient = sandalphonClient;
}

@UnitOfWork
Expand Down Expand Up @@ -119,6 +124,7 @@ public void update(Contest contest) {
Set<ContestContestant> contestants = ImmutableSet.copyOf(contestantsMap.values());
Set<String> contestantJidsSet = contestants.stream().map(ContestContestant::getUserJid).collect(toSet());
Map<String, Profile> profilesMap = jophielClient.getProfiles(contestantJidsSet, contest.getBeginTime());
Map<String, ScoringConfig> scoringConfigsMap = sandalphonClient.getProgrammingProblemScoringConfigs(problemJidsSet);

ScoreboardState state = new ScoreboardState.Builder()
.problemJids(problemJids)
Expand Down Expand Up @@ -201,6 +207,7 @@ public void update(Contest contest) {
styleModuleConfig,
contestants,
profilesMap,
scoringConfigsMap,
programmingSubmissions,
bundleItemSubmissions,
freezeTimesMap);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import judgels.gabriel.api.ScoringConfig;
import judgels.jophiel.api.profile.Profile;
import judgels.sandalphon.api.submission.bundle.ItemSubmission;
import judgels.sandalphon.api.submission.programming.Submission;
Expand All @@ -29,6 +30,7 @@ ScoreboardProcessResult process(
StyleModuleConfig styleModuleConfig,
Set<ContestContestant> contestants,
Map<String, Profile> profilesMap,
Map<String, ScoringConfig> scoringConfigsMap,
List<Submission> programmingSubmissions,
List<ItemSubmission> bundleItemSubmissions,
Map<String, Instant> freezeTimesMap);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import judgels.gabriel.api.ScoringConfig;
import judgels.jophiel.api.profile.Profile;
import judgels.sandalphon.api.submission.bundle.ItemSubmission;
import judgels.sandalphon.api.submission.programming.Submission;
Expand Down Expand Up @@ -61,6 +62,7 @@ public ScoreboardProcessResult process(
StyleModuleConfig styleModuleConfig,
Set<ContestContestant> contestants,
Map<String, Profile> profilesMap,
Map<String, ScoringConfig> scoringConfigsMap,
List<Submission> programmingSubmissions,
List<ItemSubmission> bundleItemSubmissions,
Map<String, Instant> freezeTimesMap) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import judgels.gabriel.api.ScoringConfig;
import judgels.gabriel.api.Verdict;
import judgels.jophiel.api.profile.Profile;
import judgels.jophiel.api.user.rating.UserRating;
Expand Down Expand Up @@ -70,6 +71,7 @@ public ScoreboardProcessResult process(
StyleModuleConfig styleModuleConfig,
Set<ContestContestant> contestants,
Map<String, Profile> profilesMap,
Map<String, ScoringConfig> scoringConfigsMap,
List<Submission> programmingSubmissions,
List<ItemSubmission> bundleItemSubmissions,
Map<String, Instant> freezeTimesMap) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import judgels.gabriel.api.ScoringConfig;
import judgels.gabriel.api.Verdict;
import judgels.jophiel.api.profile.Profile;
import judgels.jophiel.api.user.rating.UserRating;
Expand Down Expand Up @@ -70,6 +71,7 @@ public ScoreboardProcessResult process(
StyleModuleConfig styleModuleConfig,
Set<ContestContestant> contestants,
Map<String, Profile> profilesMap,
Map<String, ScoringConfig> scoringConfigsMap,
List<Submission> programmingSubmissions,
List<ItemSubmission> bundleItemSubmissions,
Map<String, Instant> freezeTimesMap) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import judgels.gabriel.api.ScoringConfig;
import judgels.gabriel.api.ScoringRoundingMode;
import judgels.gabriel.api.SubtaskResult;
import judgels.gabriel.api.Verdict;
import judgels.jophiel.api.profile.Profile;
Expand Down Expand Up @@ -72,6 +74,7 @@ public ScoreboardProcessResult process(
StyleModuleConfig styleModuleConfig,
Set<ContestContestant> contestants,
Map<String, Profile> profilesMap,
Map<String, ScoringConfig> scoringConfigsMap,
List<Submission> programmingSubmissions,
List<ItemSubmission> bundleItemSubmissions,
Map<String, Instant> freezeTimesMap) {
Expand Down Expand Up @@ -153,7 +156,12 @@ public ScoreboardProcessResult process(
}

maxScorePerSubtaskMap.put(problemJid, newMaxScorePerSubtask);
score = (int) Math.round(newScore);

if (scoringConfigsMap.get(problemJid).getRoundingMode() == ScoringRoundingMode.ROUND) {
score = (int) Math.round(newScore);
} else {
score = (int) Math.floor(newScore);
}
} else {
score = grading.getScore();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import judgels.gabriel.api.ScoringConfig;
import judgels.gabriel.api.Verdict;
import judgels.jophiel.api.profile.Profile;
import judgels.jophiel.api.user.rating.UserRating;
Expand Down Expand Up @@ -70,6 +71,7 @@ public ScoreboardProcessResult process(
StyleModuleConfig styleModuleConfig,
Set<ContestContestant> contestants,
Map<String, Profile> profilesMap,
Map<String, ScoringConfig> scoringConfigsMap,
List<Submission> programmingSubmissions,
List<ItemSubmission> bundleItemSubmissions,
Map<String, Instant> freezeTimesMap) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import judgels.gabriel.api.ScoringConfig;
import judgels.jophiel.api.profile.Profile;
import judgels.sandalphon.api.submission.bundle.Grading;
import judgels.sandalphon.api.submission.bundle.ItemSubmission;
Expand Down Expand Up @@ -57,6 +58,10 @@ class Process {
"c1", new Profile.Builder().username("c1").build(),
"c2", new Profile.Builder().username("c2").build());

private Map<String, ScoringConfig> scoringConfigsMap = Map.of(
"p1", ScoringConfig.DEFAULT,
"p2", ScoringConfig.DEFAULT);

@Test
void latest_answered_time_calculation() {
List<ItemSubmission> submissions = ImmutableList.of(
Expand Down Expand Up @@ -121,6 +126,7 @@ void latest_answered_time_calculation() {
styleModuleConfig,
contestants,
profilesMap,
scoringConfigsMap,
ImmutableList.of(),
submissions,
Map.of());
Expand Down Expand Up @@ -196,6 +202,7 @@ void total_answered_items_over_last_answered_time() {
styleModuleConfig,
contestants,
profilesMap,
scoringConfigsMap,
ImmutableList.of(),
submissions,
Map.of());
Expand Down Expand Up @@ -255,6 +262,7 @@ void last_answered_time_as_tiebreaker() {
styleModuleConfig,
contestants,
profilesMap,
scoringConfigsMap,
ImmutableList.of(),
submissions,
Map.of());
Expand Down
Loading

0 comments on commit c1c9d37

Please sign in to comment.