Various improvements
All checks were successful
Gitea/swiss-backend/pipeline/head This commit looks good
All checks were successful
Gitea/swiss-backend/pipeline/head This commit looks good
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
package nl.connectedit.swiss.domain;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import nl.connectedit.swiss.domain.entity.Team;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
public class StandingsEntry {
|
||||
|
||||
public StandingsEntry(Team team) {
|
||||
this.team = team;
|
||||
}
|
||||
|
||||
private Long position;
|
||||
|
||||
private Team team;
|
||||
|
||||
private Long played = 0L;
|
||||
|
||||
private Long won = 0L;
|
||||
|
||||
private Long lost = 0L;
|
||||
|
||||
private Long points = 0L;
|
||||
|
||||
private Long gamesWon = 0L;
|
||||
|
||||
private Long gamesLost = 0L;
|
||||
|
||||
private Long pointsWon = 0L;
|
||||
|
||||
private Long pointsLost = 0L;
|
||||
|
||||
public static int compare(StandingsEntry s1, StandingsEntry s2) {
|
||||
var pointsPerMatchS1 = safeDivide(s1.points, s1.played);
|
||||
var pointsPerMatchS2 = safeDivide(s2.points, s2.played);
|
||||
if (pointsPerMatchS1 > pointsPerMatchS2) {
|
||||
return -1;
|
||||
} else if (pointsPerMatchS1 < pointsPerMatchS2) {
|
||||
return 1;
|
||||
} else {
|
||||
if (s1.played < s2.played) {
|
||||
return -1;
|
||||
} else if (s1.played > s2.played) {
|
||||
return 1;
|
||||
} else {
|
||||
var gamesPerMatchS1 = safeDivide(s1.gamesWon - s1.gamesLost, s1.played);
|
||||
var gamesPerMatchS2 = safeDivide(s2.gamesWon - s2.gamesLost, s2.played);
|
||||
if (gamesPerMatchS1 > gamesPerMatchS2) {
|
||||
return -1;
|
||||
} else if (gamesPerMatchS1 < gamesPerMatchS2) {
|
||||
return 1;
|
||||
} else {
|
||||
var ptsPerMatchS1 = safeDivide(s1.pointsWon - s1.pointsLost, s1.played);
|
||||
var ptsPerMatchS2 = safeDivide(s2.pointsWon - s2.pointsLost, s2.played);
|
||||
return Double.compare(ptsPerMatchS2, ptsPerMatchS1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static double safeDivide(Long a, Long b) {
|
||||
return (a == 0 && b == 0) ? 0 : (double) a / b;
|
||||
}
|
||||
}
|
||||
@@ -27,8 +27,7 @@ public class Event extends AbstractEntity {
|
||||
private Tournament tournament;
|
||||
|
||||
@OneToMany(cascade = CascadeType.MERGE, fetch = FetchType.LAZY)
|
||||
// @Builder.Default
|
||||
private List<Registration> registrations;// = new ArrayList<>();
|
||||
private List<Registration> registrations;
|
||||
|
||||
@Enumerated(EnumType.STRING)
|
||||
private Status status;
|
||||
@@ -37,7 +36,7 @@ public class Event extends AbstractEntity {
|
||||
private EventType type;
|
||||
|
||||
@OneToMany(cascade = CascadeType.MERGE, fetch = FetchType.LAZY)
|
||||
private List<Group> groups;// = new ArrayList<>();
|
||||
private List<Group> groups;
|
||||
|
||||
public static List<Event> getBlankEventSet(Tournament tournament) {
|
||||
return Arrays.stream(EventType.values())
|
||||
|
||||
@@ -33,7 +33,12 @@ public class Group extends AbstractEntity {
|
||||
@OrderBy("name")
|
||||
private List<Round> rounds;
|
||||
|
||||
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
|
||||
@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
|
||||
@JoinTable(
|
||||
name = "eventgroup_teams",
|
||||
joinColumns = @JoinColumn(name = "group_id"),
|
||||
inverseJoinColumns = @JoinColumn(name = "teams_id")
|
||||
)
|
||||
private List<Team> teams;
|
||||
|
||||
}
|
||||
|
||||
@@ -37,4 +37,6 @@ public class Round extends AbstractEntity {
|
||||
@ManyToOne
|
||||
private Team drawnOut;
|
||||
|
||||
private Boolean isFinalsRound = Boolean.FALSE;
|
||||
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package nl.connectedit.swiss.domain.entity;
|
||||
|
||||
import jakarta.annotation.Nullable;
|
||||
import jakarta.persistence.*;
|
||||
import java.util.List;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.Setter;
|
||||
@@ -17,8 +18,8 @@ public class Team extends AbstractEntity {
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Long id;
|
||||
|
||||
@ManyToOne
|
||||
private Group group;
|
||||
@ManyToMany(mappedBy = "teams", fetch = FetchType.LAZY)
|
||||
private List<Group> groups;
|
||||
|
||||
@ManyToOne
|
||||
private Player player1;
|
||||
|
||||
@@ -32,4 +32,9 @@ public class TournamentPlayer extends AbstractEntity {
|
||||
private boolean counting;
|
||||
|
||||
private Long counts;
|
||||
|
||||
public void incrementCounts() {
|
||||
this.counts++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user