Skip to content

Commit

Permalink
fix(uriel): when merged scoreboard module is present, consider freeze…
Browse files Browse the repository at this point in the history
… time in previous contest (#504)
  • Loading branch information
fushar authored Aug 29, 2023
1 parent 9d1baf6 commit 051a6f1
Show file tree
Hide file tree
Showing 13 changed files with 97 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import judgels.uriel.api.contest.scoreboard.Scoreboard;
import judgels.uriel.api.contest.scoreboard.ScoreboardEntry;
import judgels.uriel.api.contest.scoreboard.ScoreboardState;
import judgels.uriel.contest.ContestStore;
import judgels.uriel.contest.ContestTimer;
import judgels.uriel.contest.contestant.ContestContestantStore;
import judgels.uriel.contest.module.ContestModuleStore;
Expand All @@ -41,6 +42,7 @@
public class ContestScoreboardUpdater {
private final ObjectMapper objectMapper;
private final ContestTimer contestTimer;
private final ContestStore contestStore;
private final ContestScoreboardStore scoreboardStore;
private final ContestModuleStore moduleStore;
private final ContestContestantStore contestantStore;
Expand All @@ -55,6 +57,7 @@ public class ContestScoreboardUpdater {
public ContestScoreboardUpdater(
ObjectMapper objectMapper,
ContestTimer contestTimer,
ContestStore contestStore,
ContestScoreboardStore scoreboardStore,
ContestModuleStore moduleStore,
ContestContestantStore contestantStore,
Expand All @@ -68,6 +71,7 @@ public ContestScoreboardUpdater(

this.objectMapper = objectMapper;
this.contestTimer = contestTimer;
this.contestStore = contestStore;
this.scoreboardStore = scoreboardStore;
this.moduleStore = moduleStore;
this.contestantStore = contestantStore;
Expand Down Expand Up @@ -170,14 +174,21 @@ public void update(Contest contest) {
Map<ContestScoreboardType, Scoreboard> scoreboards = new HashMap<>();
Map<ContestScoreboardType, ScoreboardIncrementalContent> incrementalContents = new HashMap<>();

Map<String, Instant> freezeTimesMap = new HashMap<>();
for (ContestScoreboardType type : new ContestScoreboardType[]{OFFICIAL, FROZEN}) {
Optional<Instant> freezeTime = Optional.empty();
if (type == FROZEN) {
if (!contestModulesConfig.getFrozenScoreboard().isPresent()) {
putFreezeTime(freezeTimesMap, contest);

if (previousContestJid.isPresent()) {
Optional<Contest> previousContest = contestStore.getContestByJid(previousContestJid.get());
if (previousContest.isPresent()) {
putFreezeTime(freezeTimesMap, previousContest.get());
}
}

if (freezeTimesMap.isEmpty()) {
continue;
}
Duration duration = contestModulesConfig.getFrozenScoreboard().get().getFreezeDurationBeforeEndTime();
freezeTime = Optional.of(contest.getEndTime().minus(duration));
}

Optional<ScoreboardIncrementalContent> incrementalContent = Optional.ofNullable(
Expand All @@ -192,7 +203,7 @@ public void update(Contest contest) {
profilesMap,
programmingSubmissions,
bundleItemSubmissions,
freezeTime);
freezeTimesMap);

Scoreboard scoreboard = processor.create(state, result.getEntries());

Expand Down Expand Up @@ -236,4 +247,13 @@ public void update(Contest contest) {
scoreboards);
}
}

private void putFreezeTime(Map<String, Instant> freezeTimesMap, Contest contest) {
ContestModulesConfig config = moduleStore.getConfig(contest.getJid(), contest.getStyle());

if (config.getFrozenScoreboard().isPresent()) {
Duration duration = config.getFrozenScoreboard().get().getFreezeDurationBeforeEndTime();
freezeTimesMap.put(contest.getJid(), contest.getEndTime().minus(duration));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ static ContestScoreboardUpdater contestScoreboardUpdater(
UnitOfWorkAwareProxyFactory unitOfWorkAwareProxyFactory,
ObjectMapper objectMapper,
ContestTimer contestTimer,
ContestStore contestStore,
ContestScoreboardStore scoreboardStore,
ContestModuleStore moduleStore,
ContestContestantStore contestantStore,
Expand All @@ -64,6 +65,7 @@ static ContestScoreboardUpdater contestScoreboardUpdater(
new Class<?>[] {
ObjectMapper.class,
ContestTimer.class,
ContestStore.class,
ContestScoreboardStore.class,
ContestModuleStore.class,
ContestContestantStore.class,
Expand All @@ -77,6 +79,7 @@ static ContestScoreboardUpdater contestScoreboardUpdater(
new Object[] {
objectMapper,
contestTimer,
contestStore,
scoreboardStore,
moduleStore,
contestantStore,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ ScoreboardProcessResult process(
Map<String, Profile> profilesMap,
List<Submission> programmingSubmissions,
List<ItemSubmission> bundleItemSubmissions,
Optional<Instant> freezeTime);
Map<String, Instant> freezeTimesMap);

ScoreboardEntry clearEntryRank(ScoreboardEntry entry);
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public ScoreboardProcessResult process(
Map<String, Profile> profilesMap,
List<Submission> programmingSubmissions,
List<ItemSubmission> bundleItemSubmissions,
Optional<Instant> freezeTime) {
Map<String, Instant> freezeTimesMap) {

List<String> problemJids = scoreboardState.getProblemJids();
Set<String> contestantJids = contestants.stream().map(ContestContestant::getUserJid).collect(toSet());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public ScoreboardProcessResult process(
Map<String, Profile> profilesMap,
List<Submission> programmingSubmissions,
List<ItemSubmission> bundleItemSubmissions,
Optional<Instant> freezeTime) {
Map<String, Instant> freezeTimesMap) {

GcjStyleModuleConfig gcjStyleModuleConfig = (GcjStyleModuleConfig) styleModuleConfig;

Expand Down Expand Up @@ -137,7 +137,7 @@ public ScoreboardProcessResult process(
for (Submission submission : submissionsMap.get(contestantJid)) {
String problemJid = submission.getProblemJid();

if (submission.getTime().isBefore(freezeTime.orElse(Instant.MAX))) {
if (submission.getTime().isBefore(freezeTimesMap.getOrDefault(submission.getContainerJid(), Instant.MAX))) {
Verdict verdict = submission.getLatestGrading().get().getVerdict();
if (verdict.equals(Verdict.PENDING)) {
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public ScoreboardProcessResult process(
Map<String, Profile> profilesMap,
List<Submission> programmingSubmissions,
List<ItemSubmission> bundleItemSubmissions,
Optional<Instant> freezeTime) {
Map<String, Instant> freezeTimesMap) {

IcpcStyleModuleConfig icpcStyleModuleConfig = (IcpcStyleModuleConfig) styleModuleConfig;

Expand Down Expand Up @@ -142,7 +142,7 @@ public ScoreboardProcessResult process(
continue;
}

if (submission.getTime().isBefore(freezeTime.orElse(Instant.MAX))) {
if (submission.getTime().isBefore(freezeTimesMap.getOrDefault(submission.getContainerJid(), Instant.MAX))) {
Verdict verdict = submission.getLatestGrading().get().getVerdict();
if (verdict.equals(Verdict.PENDING)) {
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public ScoreboardProcessResult process(
Map<String, Profile> profilesMap,
List<Submission> programmingSubmissions,
List<ItemSubmission> bundleItemSubmissions,
Optional<Instant> freezeTime) {
Map<String, Instant> freezeTimesMap) {

IoiStyleModuleConfig ioiStyleModuleConfig = (IoiStyleModuleConfig) styleModuleConfig;

Expand Down Expand Up @@ -158,7 +158,7 @@ public ScoreboardProcessResult process(
score = grading.getScore();
}

if (submission.getTime().isBefore(freezeTime.orElse(Instant.MAX))) {
if (submission.getTime().isBefore(freezeTimesMap.getOrDefault(submission.getContainerJid(), Instant.MAX))) {
if (!scoresMap.get(problemJid).isPresent() || score > scoresMap.get(problemJid).get()) {
scoresMap.put(problemJid, Optional.of(score));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public ScoreboardProcessResult process(
Map<String, Profile> profilesMap,
List<Submission> programmingSubmissions,
List<ItemSubmission> bundleItemSubmissions,
Optional<Instant> freezeTime) {
Map<String, Instant> freezeTimesMap) {

TrocStyleModuleConfig trocStyleModuleConfig = (TrocStyleModuleConfig) styleModuleConfig;
List<String> problemJids = scoreboardState.getProblemJids();
Expand Down Expand Up @@ -145,7 +145,7 @@ public ScoreboardProcessResult process(
continue;
}

if (submission.getTime().isBefore(freezeTime.orElse(Instant.MAX))) {
if (submission.getTime().isBefore(freezeTimesMap.getOrDefault(submission.getContainerJid(), Instant.MAX))) {
Verdict verdict = submission.getLatestGrading().get().getVerdict();
if (verdict.equals(Verdict.PENDING) || verdict.equals(Verdict.COMPILATION_ERROR)) {
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ void latest_answered_time_calculation() {
profilesMap,
ImmutableList.of(),
submissions,
Optional.empty());
Map.of());

assertThat(Lists.transform(result.getEntries(), e -> (BundleScoreboardEntry) e)).containsExactly(
new BundleScoreboardEntry.Builder()
Expand Down Expand Up @@ -198,7 +198,7 @@ void total_answered_items_over_last_answered_time() {
profilesMap,
ImmutableList.of(),
submissions,
Optional.empty());
Map.of());

assertThat(Lists.transform(result.getEntries(), e -> (BundleScoreboardEntry) e)).containsExactly(
new BundleScoreboardEntry.Builder()
Expand Down Expand Up @@ -257,7 +257,7 @@ void last_answered_time_as_tiebreaker() {
profilesMap,
ImmutableList.of(),
submissions,
Optional.empty());
Map.of());

assertThat(Lists.transform(result.getEntries(), e -> (BundleScoreboardEntry) e)).containsExactly(
new BundleScoreboardEntry.Builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ void time_calculation() {
profilesMap,
submissions,
ImmutableList.of(),
Optional.empty());
Map.of());

assertThat(Lists.transform(result.getEntries(), e -> (GcjScoreboardEntry) e)).containsExactly(
new GcjScoreboardEntry.Builder()
Expand Down Expand Up @@ -129,7 +129,7 @@ void base_case() {
profilesMap,
submissions,
ImmutableList.of(),
Optional.empty());
Map.of());

assertThat(Lists.transform(result.getEntries(), e -> (GcjScoreboardEntry) e)).containsExactly(
new GcjScoreboardEntry.Builder()
Expand Down Expand Up @@ -179,7 +179,7 @@ void reversed_case() {
profilesMap,
submissions,
ImmutableList.of(),
Optional.empty());
Map.of());

assertThat(Lists.transform(result.getEntries(), e -> (GcjScoreboardEntry) e)).containsExactly(
new GcjScoreboardEntry.Builder()
Expand Down Expand Up @@ -230,7 +230,7 @@ void points_over_penalty() {
profilesMap,
submissions,
ImmutableList.of(),
Optional.empty());
Map.of());

assertThat(Lists.transform(result.getEntries(), e -> (GcjScoreboardEntry) e)).containsExactly(
new GcjScoreboardEntry.Builder()
Expand Down Expand Up @@ -278,7 +278,7 @@ void penalty_as_tiebreaker() {
profilesMap,
submissions,
ImmutableList.of(),
Optional.empty());
Map.of());

assertThat(Lists.transform(result.getEntries(), e -> (GcjScoreboardEntry) e)).containsExactly(
new GcjScoreboardEntry.Builder()
Expand Down Expand Up @@ -339,7 +339,7 @@ void same_rank_if_equal() {
profilesMap,
submissions,
ImmutableList.of(),
Optional.empty());
Map.of());

assertThat(Lists.transform(result.getEntries(), e -> (GcjScoreboardEntry) e)).containsExactly(
new GcjScoreboardEntry.Builder()
Expand Down Expand Up @@ -412,7 +412,7 @@ void zero_points_ordering() {
profilesMap,
submissions,
ImmutableList.of(),
Optional.empty());
Map.of());

assertThat(Lists.transform(result.getEntries(), e -> (GcjScoreboardEntry) e)).containsExactly(
new GcjScoreboardEntry.Builder()
Expand Down Expand Up @@ -462,7 +462,7 @@ void zero_points_ordering() {

@Nested
class PendingAfterFreeze {
private Optional<Instant> freezeTime = Optional.of(Instant.ofEpochSecond(500));
private Map<String, Instant> freezeTimesMap = Map.of(contest.getJid(), Instant.ofEpochSecond(500));

private List<Submission> baseSubmissions = ImmutableList.of(
createSubmission(1, 100, "c1", "p1", 100, Verdict.ACCEPTED),
Expand All @@ -480,7 +480,7 @@ void no_pending() {
profilesMap,
baseSubmissions,
ImmutableList.of(),
freezeTime);
freezeTimesMap);

assertThat(Lists.transform(result.getEntries(), e -> (GcjScoreboardEntry) e)).containsExactly(
new GcjScoreboardEntry.Builder()
Expand Down Expand Up @@ -529,7 +529,7 @@ void pending_does_not_overwrite_accepted() {
profilesMap,
submissions,
ImmutableList.of(),
freezeTime);
freezeTimesMap);

assertThat(Lists.transform(result.getEntries(), e -> (GcjScoreboardEntry) e)).containsExactly(
new GcjScoreboardEntry.Builder()
Expand Down Expand Up @@ -578,7 +578,7 @@ void pending_does_overwrite_not_accepted() {
profilesMap,
submissions,
ImmutableList.of(),
freezeTime);
freezeTimesMap);

assertThat(Lists.transform(result.getEntries(), e -> (GcjScoreboardEntry) e)).containsExactly(
new GcjScoreboardEntry.Builder()
Expand Down Expand Up @@ -627,7 +627,7 @@ void pending_counts_on_freeze_time() {
profilesMap,
submissions,
ImmutableList.of(),
freezeTime);
freezeTimesMap);

assertThat(Lists.transform(result.getEntries(), e -> (GcjScoreboardEntry) e)).containsExactly(
new GcjScoreboardEntry.Builder()
Expand Down Expand Up @@ -707,7 +707,7 @@ void empty_initial_incremental_content() {
profilesMap,
submissions,
ImmutableList.of(),
Optional.empty());
Map.of());

assertThat(result.getIncrementalContent()).isEqualTo(new GcjScoreboardIncrementalContent.Builder()
.lastSubmissionId(9)
Expand Down Expand Up @@ -735,7 +735,7 @@ void empty_new_submissions() {
profilesMap,
ImmutableList.of(),
ImmutableList.of(),
Optional.empty());
Map.of());

assertThat(result.getIncrementalContent()).isEqualTo(new GcjScoreboardIncrementalContent.Builder()
.from(incrementalContent)
Expand All @@ -754,7 +754,7 @@ void existing_incremental_content() {
profilesMap,
submissions,
ImmutableList.of(),
Optional.empty());
Map.of());

assertThat(result.getIncrementalContent()).isEqualTo(new GcjScoreboardIncrementalContent.Builder()
.lastSubmissionId(9)
Expand Down
Loading

0 comments on commit 051a6f1

Please sign in to comment.