add scores over pp threshold
All checks were successful
Deploy to Dokku / docker (ubuntu-latest) (push) Successful in 1m18s
All checks were successful
Deploy to Dokku / docker (ubuntu-latest) (push) Successful in 1m18s
This commit is contained in:
parent
95a5cab1fc
commit
260fcb94a8
@ -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)));
|
||||
}
|
||||
}
|
||||
|
@ -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<Integer, Integer> 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);
|
||||
}
|
||||
}
|
@ -8,7 +8,7 @@ import lombok.Getter;
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
@Getter
|
||||
public class TotalScoresMetric {
|
||||
public class TotalScoresResponse {
|
||||
/**
|
||||
* The total number of scores
|
||||
*/
|
@ -2,7 +2,6 @@ package cc.fascinated.model.score;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Id;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
|
@ -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())
|
||||
|
@ -41,4 +41,13 @@ public interface TrackedScoreRepository extends CrudRepository<TrackedScore, Str
|
||||
*/
|
||||
@Query(value = "SELECT COUNT(*) FROM score WHERE platform = :platform AND pp > 0", nativeQuery = true)
|
||||
int countTotalRankedScores(@Param("platform") String platform);
|
||||
|
||||
/**
|
||||
* Gets all scores for a platform.
|
||||
*
|
||||
* @param platform the platform to get the scores from
|
||||
* @return the scores
|
||||
*/
|
||||
@Query(value = "SELECT COUNT(*) FROM score WHERE platform = :platform AND pp > :pp", nativeQuery = true)
|
||||
int getScoreCountOverPpThreshold(@Param("platform") String platform, @Param("pp") double pp);
|
||||
}
|
@ -1,7 +1,8 @@
|
||||
package cc.fascinated.services;
|
||||
|
||||
import cc.fascinated.exception.impl.BadRequestException;
|
||||
import cc.fascinated.model.score.TotalScoresMetric;
|
||||
import cc.fascinated.model.score.ScoresOverResponse;
|
||||
import cc.fascinated.model.score.TotalScoresResponse;
|
||||
import cc.fascinated.model.score.TrackedScore;
|
||||
import cc.fascinated.model.score.TrackedScoreDTO;
|
||||
import cc.fascinated.platform.Platform;
|
||||
@ -17,6 +18,11 @@ import java.util.List;
|
||||
*/
|
||||
@Service
|
||||
public class TrackedScoreService {
|
||||
/**
|
||||
* The scores over thresholds.
|
||||
*/
|
||||
private static final int[] SCORES_OVER = {1000, 900, 800, 700, 600, 500, 400, 300, 200, 100};
|
||||
|
||||
/**
|
||||
* The tracked score repository to use.
|
||||
*/
|
||||
@ -43,6 +49,21 @@ public class TrackedScoreService {
|
||||
return scores.stream().map(TrackedScore::getAsDTO).toList();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the amount of scores over pp thresholds.
|
||||
*
|
||||
* @param platform the platform to get the scores from
|
||||
* @return the scores over pp thresholds
|
||||
*/
|
||||
public ScoresOverResponse getScoresOver(Platform.Platforms platform) {
|
||||
ScoresOverResponse scoresOverResponse = new ScoresOverResponse();
|
||||
|
||||
for (int i : SCORES_OVER) {
|
||||
scoresOverResponse.addScores(i, trackedScoreRepository.getScoreCountOverPpThreshold(platform.getPlatformName(), i));
|
||||
}
|
||||
return scoresOverResponse;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the total amount of scores
|
||||
* for a platform.
|
||||
@ -50,8 +71,8 @@ public class TrackedScoreService {
|
||||
* @param platform the platform to get the scores from
|
||||
* @return the total amount of scores for the platform
|
||||
*/
|
||||
public TotalScoresMetric getTotalScores(Platform.Platforms platform) {
|
||||
return new TotalScoresMetric(
|
||||
public TotalScoresResponse getTotalScores(Platform.Platforms platform) {
|
||||
return new TotalScoresResponse(
|
||||
trackedScoreRepository.countTotalScores(platform.getPlatformName()),
|
||||
trackedScoreRepository.countTotalRankedScores(platform.getPlatformName())
|
||||
);
|
||||
|
Reference in New Issue
Block a user