From 260fcb94a883104e08f9164f8c2b870ce9718ade Mon Sep 17 00:00:00 2001 From: Liam Date: Wed, 24 Jul 2024 12:41:57 +0100 Subject: [PATCH] add scores over pp threshold --- .../controller/ScoresController.java | 16 ++++++++++- .../model/score/ScoresOverResponse.java | 24 +++++++++++++++++ ...esMetric.java => TotalScoresResponse.java} | 2 +- .../fascinated/model/score/TrackedScore.java | 1 - .../platform/impl/ScoreSaberPlatform.java | 5 ++-- .../couchdb/TrackedScoreRepository.java | 9 +++++++ .../services/TrackedScoreService.java | 27 ++++++++++++++++--- 7 files changed, 75 insertions(+), 9 deletions(-) create mode 100644 src/main/java/cc/fascinated/model/score/ScoresOverResponse.java rename src/main/java/cc/fascinated/model/score/{TotalScoresMetric.java => TotalScoresResponse.java} (90%) diff --git a/src/main/java/cc/fascinated/controller/ScoresController.java b/src/main/java/cc/fascinated/controller/ScoresController.java index b813f53..caec388 100644 --- a/src/main/java/cc/fascinated/controller/ScoresController.java +++ b/src/main/java/cc/fascinated/controller/ScoresController.java @@ -47,7 +47,7 @@ public class ScoresController { * amount of scores for a platform * * @param platform the platform to get the scores from - * @return the amount scores + * @return the amount of scores * @throws BadRequestException if there were no scores found */ @ResponseBody @@ -55,4 +55,18 @@ public class ScoresController { public ResponseEntity getScoresCount(@PathVariable String platform) { return ResponseEntity.ok(trackedScoreService.getTotalScores(Platform.Platforms.getPlatform(platform))); } + + /** + * A GET mapping to retrieve the total + * amount of scores over pp thresholds + * + * @param platform the platform to get the scores from + * @return the amount of scores + * @throws BadRequestException if there were no scores found + */ + @ResponseBody + @GetMapping(value = "/ppthresholds/{platform}") + public ResponseEntity getScoresOver(@PathVariable String platform) { + return ResponseEntity.ok(trackedScoreService.getScoresOver(Platform.Platforms.getPlatform(platform))); + } } diff --git a/src/main/java/cc/fascinated/model/score/ScoresOverResponse.java b/src/main/java/cc/fascinated/model/score/ScoresOverResponse.java new file mode 100644 index 0000000..8db77d0 --- /dev/null +++ b/src/main/java/cc/fascinated/model/score/ScoresOverResponse.java @@ -0,0 +1,24 @@ +package cc.fascinated.model.score; + +import java.util.HashMap; +import java.util.Map; + +/** + * @author Fascinated (fascinated7) + */ +public class ScoresOverResponse { + /** + * Scores over a certain pp threshold. + */ + public Map scoresOver = new HashMap<>(); + + /** + * Adds scores over a certain pp threshold. + * + * @param pp the pp threshold + * @param scoreAmount the amount of scores over the pp threshold + */ + public void addScores(int pp, int scoreAmount) { + scoresOver.put(pp, scoreAmount); + } +} diff --git a/src/main/java/cc/fascinated/model/score/TotalScoresMetric.java b/src/main/java/cc/fascinated/model/score/TotalScoresResponse.java similarity index 90% rename from src/main/java/cc/fascinated/model/score/TotalScoresMetric.java rename to src/main/java/cc/fascinated/model/score/TotalScoresResponse.java index 6ef4412..cd03aeb 100644 --- a/src/main/java/cc/fascinated/model/score/TotalScoresMetric.java +++ b/src/main/java/cc/fascinated/model/score/TotalScoresResponse.java @@ -8,7 +8,7 @@ import lombok.Getter; */ @AllArgsConstructor @Getter -public class TotalScoresMetric { +public class TotalScoresResponse { /** * The total number of scores */ diff --git a/src/main/java/cc/fascinated/model/score/TrackedScore.java b/src/main/java/cc/fascinated/model/score/TrackedScore.java index 4f89602..9a223df 100644 --- a/src/main/java/cc/fascinated/model/score/TrackedScore.java +++ b/src/main/java/cc/fascinated/model/score/TrackedScore.java @@ -2,7 +2,6 @@ package cc.fascinated.model.score; import jakarta.persistence.Entity; import jakarta.persistence.Id; -import lombok.AllArgsConstructor; import lombok.Getter; /** diff --git a/src/main/java/cc/fascinated/platform/impl/ScoreSaberPlatform.java b/src/main/java/cc/fascinated/platform/impl/ScoreSaberPlatform.java index 53eb961..9070fbf 100644 --- a/src/main/java/cc/fascinated/platform/impl/ScoreSaberPlatform.java +++ b/src/main/java/cc/fascinated/platform/impl/ScoreSaberPlatform.java @@ -1,7 +1,6 @@ package cc.fascinated.platform.impl; -import cc.fascinated.model.score.TotalScoresMetric; -import cc.fascinated.model.score.TrackedScore; +import cc.fascinated.model.score.TotalScoresResponse; import cc.fascinated.model.token.ScoreSaberAccountToken; import cc.fascinated.model.user.User; import cc.fascinated.platform.Platform; @@ -82,7 +81,7 @@ public class ScoreSaberPlatform extends Platform { @Override public void updateMetrics() { try (Sender sender = questDBService.getSender()) { - TotalScoresMetric totalScores = trackedScoreService.getTotalScores(this.getPlatform()); + TotalScoresResponse totalScores = trackedScoreService.getTotalScores(this.getPlatform()); sender.table("metrics") .symbol("platform", this.getPlatform().getPlatformName()) .longColumn("total_scores", totalScores.getTotalScores()) diff --git a/src/main/java/cc/fascinated/repository/couchdb/TrackedScoreRepository.java b/src/main/java/cc/fascinated/repository/couchdb/TrackedScoreRepository.java index 9068cb0..4153d36 100644 --- a/src/main/java/cc/fascinated/repository/couchdb/TrackedScoreRepository.java +++ b/src/main/java/cc/fascinated/repository/couchdb/TrackedScoreRepository.java @@ -41,4 +41,13 @@ public interface TrackedScoreRepository extends CrudRepository