Skip to content

Commit

Permalink
Add ratingCycle tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
ALEEF02 committed Nov 14, 2022
1 parent 98861df commit f42bc40
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
10 changes: 5 additions & 5 deletions MavenBack/src/main/java/ppp/db/controllers/CGames.java
Original file line number Diff line number Diff line change
Expand Up @@ -521,9 +521,9 @@ public static void insert(OGame rec) {
rec.date = new Timestamp(System.currentTimeMillis());
}
rec.id = WebDb.get().insert(
"INSERT INTO games(date, status, sender, receiver, winner, winner_score, loser_score) " +
"VALUES (?,?,?,?,?,?,?)",
rec.date, rec.status.getNum(), rec.sender, rec.receiver, rec.winner, rec.winnerScore, rec.loserScore);
"INSERT INTO games(date, status, sender, receiver, winner, winner_score, loser_score, rating_cycle) " +
"VALUES (?,?,?,?,?,?,?,?)",
rec.date, rec.status.getNum(), rec.sender, rec.receiver, rec.winner, rec.winnerScore, rec.loserScore, rec.ratingCycle);
} catch (Exception e) {
e.printStackTrace();
}
Expand All @@ -533,8 +533,8 @@ public static void insert(OGame rec) {
public static void update(OGame record) {
try {
WebDb.get().query(
"UPDATE games SET date = ?, status = ?, sender = ?, receiver = ?, winner = ?, winner_score = ?, loser_score = ? WHERE id = ?",
record.date, record.status.getNum(), record.sender, record.receiver, record.winner, record.winnerScore, record.loserScore, record.id);
"UPDATE games SET date = ?, status = ?, sender = ?, receiver = ?, winner = ?, winner_score = ?, loser_score = ?, rating_cycle = ? WHERE id = ?",
record.date, record.status.getNum(), record.sender, record.receiver, record.winner, record.winnerScore, record.loserScore, record.ratingCycle, record.id);
} catch (Exception e) {
e.printStackTrace();
}
Expand Down
4 changes: 4 additions & 0 deletions MavenBack/src/main/java/ppp/db/model/OGame.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@

import java.sql.Timestamp;

/**
* A game object.
*/
public class OGame extends AbstractModel {
public int id = 0;
public Timestamp date = null;
Expand All @@ -18,6 +21,7 @@ public class OGame extends AbstractModel {
public int winner = 0;
public int winnerScore = 0;
public int loserScore = 0;
public int ratingCycle = 0;

private OUser senderUser = new OUser();
private OUser receiverUser = new OUser();
Expand Down
5 changes: 4 additions & 1 deletion MavenBack/src/main/java/ppp/meta/GlickoTwo.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@ public class GlickoTwo {
public static void run() {
List<OUser> players = CUser.getAllNotBannedUsers();
List<OGame> games = CGames.getLatestGamesByStatus(StatusEnum.Status.ACCEPTED, RATING_PERIOD + 1);
List<OGame> lastCalculatedGame = CGames.getLatestGamesByStatus(StatusEnum.Status.CALCULATED, 1);
int ratingCycle = lastCalculatedGame.isEmpty() ? 1 : lastCalculatedGame.get(0).ratingCycle + 1;
List<OUser> updatedPlayers = new ArrayList<>();
System.out.println("Running Glicko2 Period...");
System.out.println("Running Glicko2 Period... [" + ratingCycle + "]");

for (OUser me : players) {
System.out.println("--------------------------------\nProcessing for " + me.username);
Expand Down Expand Up @@ -154,6 +156,7 @@ public static void run() {
// Now that we've processed the games for all players, let's mark them as CALCULATED
for (OGame game : games) {
game.status = StatusEnum.Status.CALCULATED;
game.ratingCycle = ratingCycle;
CGames.update(game);
}

Expand Down

0 comments on commit f42bc40

Please sign in to comment.