From bd3125499067cc061d1da1ab4ebb083a8f9cffeb Mon Sep 17 00:00:00 2001 From: Liam Date: Tue, 6 Aug 2024 21:12:59 +0100 Subject: [PATCH] api: track player histories more often to keep them more up to date --- .../fascinated/controller/RootController.java | 5 ++++- .../java/cc/fascinated/model/user/User.java | 22 +++++++++++++++++++ .../fascinated/services/PlatformService.java | 4 ++-- .../cc/fascinated/services/ScoreService.java | 4 ++-- .../cc/fascinated/services/UserService.java | 2 +- 5 files changed, 31 insertions(+), 6 deletions(-) diff --git a/API/src/main/java/cc/fascinated/controller/RootController.java b/API/src/main/java/cc/fascinated/controller/RootController.java index 027c574..aab6a28 100644 --- a/API/src/main/java/cc/fascinated/controller/RootController.java +++ b/API/src/main/java/cc/fascinated/controller/RootController.java @@ -20,6 +20,9 @@ public class RootController { @ResponseBody @GetMapping(value = "/") public ResponseEntity getWelcome() { - return ResponseEntity.ok(Map.of("message", "Hello!")); + return ResponseEntity.ok(Map.of( + "message", "Hello!", + "url", "https://git.fascinated.cc/Fascinated/beatsaber-scoretracker" + )); } } diff --git a/API/src/main/java/cc/fascinated/model/user/User.java b/API/src/main/java/cc/fascinated/model/user/User.java index 63e08bf..e2248a3 100644 --- a/API/src/main/java/cc/fascinated/model/user/User.java +++ b/API/src/main/java/cc/fascinated/model/user/User.java @@ -1,6 +1,9 @@ package cc.fascinated.model.user; import cc.fascinated.model.user.history.History; +import cc.fascinated.model.user.history.HistoryPoint; +import cc.fascinated.platform.Platform; +import cc.fascinated.services.ScoreService; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Getter; @@ -77,6 +80,25 @@ public class User { return this.history; } + /** + * Gets the user's today history. + * + * @return the user's today history + */ + public HistoryPoint getTodayHistory() { + HistoryPoint todayHistory = this.getHistory().getTodayHistory(); + if (todayHistory.getTotalPlayCount() == null) { + todayHistory.setTotalPlayCount(ScoreService.INSTANCE.getTotalScores(Platform.Platforms.SCORESABER, this)); + } + if (todayHistory.getTotalRankedPlayCount() == null) { + todayHistory.setTotalRankedPlayCount(ScoreService.INSTANCE.getTotalRankedScores(Platform.Platforms.SCORESABER, this)); + } + if (todayHistory.getTotalUnrankedPlayCount() == null) { + todayHistory.setTotalUnrankedPlayCount(ScoreService.INSTANCE.getTotalUnrankedScores(Platform.Platforms.SCORESABER, this)); + } + return todayHistory; + } + /** * Gets the user as a DTO. * diff --git a/API/src/main/java/cc/fascinated/services/PlatformService.java b/API/src/main/java/cc/fascinated/services/PlatformService.java index 321ff3f..a1479c2 100644 --- a/API/src/main/java/cc/fascinated/services/PlatformService.java +++ b/API/src/main/java/cc/fascinated/services/PlatformService.java @@ -58,10 +58,10 @@ public class PlatformService { /** * Updates the platform players. *

- * This method is scheduled to run every day at 23:59. + * This method is scheduled to run every hour. *

*/ - @Scheduled(cron = "0 59 23 * * *") + @Scheduled(cron = "0 0 * * * *") public void updatePlayerMetrics() { log.info("Updating %s platform player metrics...".formatted(this.platforms.size())); for (Platform platform : this.platforms) { diff --git a/API/src/main/java/cc/fascinated/services/ScoreService.java b/API/src/main/java/cc/fascinated/services/ScoreService.java index ca22ed4..04a8ac5 100644 --- a/API/src/main/java/cc/fascinated/services/ScoreService.java +++ b/API/src/main/java/cc/fascinated/services/ScoreService.java @@ -193,7 +193,7 @@ public class ScoreService { } ScoreSaberScore scoreSaberScore = new ScoreSaberScore( - counterService.getNext(CounterService.CounterType.SCORE), + this.counterService.getNext(CounterService.CounterType.SCORE), user.getSteamId(), Platform.Platforms.SCORESABER, score.getId(), @@ -245,7 +245,7 @@ public class ScoreService { * @param score The score to save. */ public void saveScore(User user, Score score) { - HistoryPoint todayHistory = user.getHistory().getTodayHistory(); + HistoryPoint todayHistory = user.getTodayHistory(); if (score.isRanked()) { todayHistory.incrementRankedPlayCount(); } else { diff --git a/API/src/main/java/cc/fascinated/services/UserService.java b/API/src/main/java/cc/fascinated/services/UserService.java index c3959ee..af103c9 100644 --- a/API/src/main/java/cc/fascinated/services/UserService.java +++ b/API/src/main/java/cc/fascinated/services/UserService.java @@ -94,7 +94,7 @@ public class UserService { user.setScoresaberAccount(ScoreSaberAccount.getFromToken(accountToken)); // Update the ScoreSaber account user.setUsername(accountToken.getName()); // Update the username - HistoryPoint historyToday = user.getHistory().getTodayHistory(); + HistoryPoint historyToday = user.getTodayHistory(); historyToday.setRank(accountToken.getRank()); historyToday.setCountryRank(accountToken.getCountryRank()); historyToday.setPp(accountToken.getPp());