Skip to content

Commit

Permalink
refactor: moved pojos to package pojo, totally refactor submission bu…
Browse files Browse the repository at this point in the history
…siness
  • Loading branch information
kastnerorz committed Nov 7, 2019
1 parent dd6f299 commit 4a5d64f
Show file tree
Hide file tree
Showing 27 changed files with 334 additions and 439 deletions.
8 changes: 5 additions & 3 deletions src/main/java/cn/kastner/oj/OjApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableScheduling;

@SpringBootApplication
@EnableScheduling
public class OjApplication {

public static void main(String[] args) {
SpringApplication.run(OjApplication.class, args);
}
public static void main(String[] args) {
SpringApplication.run(OjApplication.class, args);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package cn.kastner.oj.controller;

import cn.kastner.oj.domain.JudgeServerStatus;
import cn.kastner.oj.domain.pojos.JudgeServerStatus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;
Expand Down
63 changes: 31 additions & 32 deletions src/main/java/cn/kastner/oj/domain/Contest.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@

import javax.persistence.*;
import java.time.LocalDateTime;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import java.util.*;

@Data
@Entity
Expand All @@ -23,7 +20,7 @@ public class Contest {

@Id
@Column(length = 40)
private String id;
private String id = UUID.randomUUID().toString();

@Column(updatable = false, unique = true, nullable = false)
private Long idx;
Expand All @@ -41,15 +38,12 @@ public class Contest {
private String password;

@Enumerated(EnumType.STRING)
private ContestType contestType;
private ContestType contestType = ContestType.PUBLIC;

@Enumerated(EnumType.STRING)
private JudgeType judgeType;
private JudgeType judgeType = JudgeType.IMMEDIATELY;

@OneToOne(cascade = CascadeType.ALL)
private Ranking ranking;

private Boolean realTimeRank;
private Boolean realTimeRank = true;
private LocalDateTime startDate;
private LocalDateTime endDate;
private LocalDateTime createDate;
Expand All @@ -61,7 +55,7 @@ public class Contest {

@OneToMany(mappedBy = "contest")
@JsonIgnore
private Set<ContestProblem> contestProblemSet;
private Set<ContestProblem> contestProblemSet = new HashSet<>();

@OneToMany(mappedBy = "contest")
@JsonIgnore
Expand All @@ -73,29 +67,34 @@ public class Contest {
name = "contest_user",
joinColumns = {@JoinColumn(name = "contest_id", referencedColumnName = "id")},
inverseJoinColumns = {@JoinColumn(name = "user_id", referencedColumnName = "id")})
private Set<User> userSet;
@JsonIgnore
private Set<User> userSet = new HashSet<>();

private Boolean frozen;
private Boolean enable;
private Boolean visible;
@OneToMany(
mappedBy = "contest",
fetch = FetchType.LAZY,
cascade = {CascadeType.ALL})
@Fetch(FetchMode.SUBSELECT)
@JsonIgnore
private List<RankingUser> rankingUserList = new ArrayList<>();

@Fetch(FetchMode.SUBSELECT)
@ManyToMany(fetch = FetchType.LAZY)
@JoinTable(
name = "contest_excluded_user",
joinColumns = {@JoinColumn(name = "contest_id", referencedColumnName = "id")},
inverseJoinColumns = {@JoinColumn(name = "user_id", referencedColumnName = "id")})
@JsonIgnore
private Set<User> userListExcluded = new HashSet<>();

private Boolean frozen = false;
private Boolean enable = false;
private Boolean visible = false;

@Enumerated(EnumType.STRING)
private ContestStatus status;

private Boolean couldShare;

public Contest() {
this.id = UUID.randomUUID().toString();
this.contestType = ContestType.PUBLIC;
this.judgeType = JudgeType.IMMEDIATELY;
this.realTimeRank = true;
this.contestProblemSet = new HashSet<>();
this.userSet = new HashSet<>();
this.visible = false;
this.enable = false;
this.status = ContestStatus.NOT_STARTED;
this.couldShare = true;
}
private ContestStatus status = ContestStatus.NOT_STARTED;

private Boolean couldShare = true;

public void setPassword(String password) {
BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
Expand Down
53 changes: 20 additions & 33 deletions src/main/java/cn/kastner/oj/domain/ContestProblem.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
package cn.kastner.oj.domain;

import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

@Data
Expand All @@ -22,27 +27,23 @@ public class ContestProblem {
@JoinColumn(name = "problem_id")
private Problem problem;

private Integer acceptCountBefore = 0;
private Integer acceptCount = 0;

private Integer submitCountBefore = 0;
private Integer submitCount = 0;

private Double acceptRateBefore = 0.0;

private Integer acceptCountAfter = 0;

private Integer submitCountAfter = 0;

private Double acceptRateAfter = 0.0;
private Double acceptRate = 0.0;

private Integer score = 0;

@OneToOne(cascade = CascadeType.ALL)
private TimeCost timeListAfter;
@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL, mappedBy = "contestProblem")
@Fetch(FetchMode.SUBSELECT)
@OrderBy("id DESC ")
@JsonIgnore
private List<TimeCost> timeList = new ArrayList<>();

@OneToOne
private Submission firstSubmission;


public String getContestId() {
return this.contest.getId();
}
Expand Down Expand Up @@ -73,31 +74,17 @@ public int hashCode() {
return code;
}

public void addAcceptCountBefore(Integer acceptCount) {
this.acceptCountBefore += acceptCount;
}

public void addSubmitCountBefore(Integer submitCount) {
this.submitCountBefore += submitCount;
public void increaseAcceptCount() {
this.acceptCount++;
}

public void addAcceptCountAfter(Integer acceptCount) {
this.acceptCountAfter += acceptCount;
}

public void addSubmitCountAfter(Integer submitCount) {
this.submitCountAfter += submitCount;
}

public void computeAcceptRateBefore() {
if (submitCountBefore != 0) {
acceptRateBefore = (double) acceptCountBefore / submitCountBefore;
}
public void increaseSubmitCount() {
this.submitCount++;
}

public void computeAcceptRateAfter() {
if (submitCountAfter != 0) {
acceptRateAfter = (double) acceptCountAfter / submitCountAfter;
public void computeAcceptRate() {
if (submitCount != 0) {
acceptRate = (double) acceptCount / submitCount;
}
}
}
1 change: 1 addition & 0 deletions src/main/java/cn/kastner/oj/domain/Problem.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public class Problem {
name = "problem_tag",
joinColumns = {@JoinColumn(name = "problem_id", referencedColumnName = "id")},
inverseJoinColumns = {@JoinColumn(name = "tag_id", referencedColumnName = "id")})
@JsonIgnore
private Set<Tag> tagList = new HashSet<>();

@Column(columnDefinition = "TEXT")
Expand Down
35 changes: 1 addition & 34 deletions src/main/java/cn/kastner/oj/domain/Ranking.java
Original file line number Diff line number Diff line change
@@ -1,44 +1,11 @@
package cn.kastner.oj.domain;

import lombok.Data;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

@Entity
@Data
@Table(name = "ranking")
public class Ranking {

@Id
@Column(length = 40)
private String id;

@OneToOne
private Contest contest;

@OneToMany(
mappedBy = "ranking",
fetch = FetchType.LAZY,
cascade = {CascadeType.ALL})
@Fetch(FetchMode.SUBSELECT)
private List<RankingUser> rankingUserList;

@Fetch(FetchMode.SUBSELECT)
@ManyToMany(fetch = FetchType.LAZY)
@JoinTable(
name = "ranking_user",
joinColumns = {@JoinColumn(name = "ranking_id", referencedColumnName = "id")},
inverseJoinColumns = {@JoinColumn(name = "user_id", referencedColumnName = "id")})
private List<User> userListExcluded;

public Ranking() {
this.id = UUID.randomUUID().toString();
this.rankingUserList = new ArrayList<>();
this.userListExcluded = new ArrayList<>();
}
private String id = UUID.randomUUID().toString();
}
74 changes: 31 additions & 43 deletions src/main/java/cn/kastner/oj/domain/RankingUser.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package cn.kastner.oj.domain;

import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;
Expand All @@ -16,72 +17,59 @@ public class RankingUser {

@Id
@Column(length = 40)
private String id;
private String id = UUID.randomUUID().toString();

@ManyToOne
@JoinColumn(name = "user_id")
private User user;

@ManyToOne
@JoinColumn(name = "ranking_id")
private Ranking ranking;
@JoinColumn(name = "contest_id")
private Contest contest;

private Integer acceptCountBefore;
private Integer passedCount = 0;

private Integer submitCountBefore;
private Integer acceptCount = 0;

@OneToOne(cascade = {CascadeType.ALL})
private TimeCost totalTimeBefore;
private Integer submitCount = 0;

@OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@Fetch(FetchMode.SUBSELECT)
@JoinTable(name = "time_cost_before")
@OrderBy("id DESC ")
private List<TimeCost> timeListBefore;
private Integer errorCount = 0;

private Integer acceptCountAfter;
private Double score = 0.0;

private Integer submitCountAfter;
private Long time = 0L;

@OneToOne(cascade = {CascadeType.ALL})
private TimeCost totalTimeAfter;

@OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL, mappedBy = "rankingUser")
@Fetch(FetchMode.SUBSELECT)
@JoinTable(name = "time_cost_after")
@OrderBy("id DESC ")
private List<TimeCost> timeListAfter;

private Boolean ranked;
private Long rankingNumber;

public RankingUser() {
this.id = UUID.randomUUID().toString();
this.acceptCountBefore = 0;
this.submitCountBefore = 0;
this.totalTimeBefore = new TimeCost();
this.timeListBefore = new ArrayList<>();
this.acceptCountAfter = 0;
this.submitCountAfter = 0;
this.totalTimeAfter = new TimeCost();
this.timeListAfter = new ArrayList<>();
this.ranked = true;
@JsonIgnore
private List<TimeCost> timeList = new ArrayList<>();

private Boolean ranked = true;

private Integer rankingNumber;

public void increasePassedCount() {
this.passedCount++;
}

public void addAcceptCountBefore(Integer acceptCount) {
this.acceptCountBefore += acceptCount;
public void increaseAcceptCount() {
this.acceptCount++;
}

public void addSubmitCountBefore(Integer submitCount) {
this.submitCountBefore += submitCount;
public void increaseSubmitCount() {
this.submitCount++;
}

public void addAcceptCountAfter(Integer acceptCount) {
this.acceptCountAfter += acceptCount;
public void increaseErrorCount() {
this.errorCount++;
}

public void addSubmitCountAfter(Integer submitCount) {
this.submitCountAfter += submitCount;
public void addTime(Long milliseconds) {
this.time += milliseconds;
}

public void addScore(Double score) {
this.score += score;
}
}
Loading

0 comments on commit 4a5d64f

Please sign in to comment.