api: change how some data points are got for histories
Some checks failed
Deploy API / docker (17, 3.8.5) (push) Failing after 31s
Some checks failed
Deploy API / docker (17, 3.8.5) (push) Failing after 31s
This commit is contained in:
parent
7b0c9f54ff
commit
98223a3293
@ -9,6 +9,8 @@ import lombok.Setter;
|
|||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
public class HistoryPoint {
|
public class HistoryPoint {
|
||||||
|
// These are data points that are provided by ScoreSaber, and may not always be here
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The rank of the player.
|
* The rank of the player.
|
||||||
*/
|
*/
|
||||||
@ -24,6 +26,8 @@ public class HistoryPoint {
|
|||||||
*/
|
*/
|
||||||
private Double pp;
|
private Double pp;
|
||||||
|
|
||||||
|
// Below are data points that are provided by us, therefore they will always be here
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Play count of all the player's scores.
|
* Play count of all the player's scores.
|
||||||
*/
|
*/
|
||||||
@ -34,6 +38,11 @@ public class HistoryPoint {
|
|||||||
*/
|
*/
|
||||||
private Integer totalRankedPlayCount;
|
private Integer totalRankedPlayCount;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Play count of all the player's unranked scores.
|
||||||
|
*/
|
||||||
|
private Integer totalUnrankedPlayCount;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Play count for this day's unranked scores.
|
* Play count for this day's unranked scores.
|
||||||
*/
|
*/
|
||||||
|
@ -48,9 +48,14 @@ public class ScoreSaberPlatform extends Platform {
|
|||||||
@NonNull
|
@NonNull
|
||||||
private final UserService userService;
|
private final UserService userService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The score service to use
|
||||||
|
*/
|
||||||
|
@NonNull
|
||||||
|
private final ScoreService scoreService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public ScoreSaberPlatform(@NonNull ScoreSaberService scoreSaberService, @NonNull UserService userService) {
|
public ScoreSaberPlatform(@NonNull ScoreSaberService scoreSaberService, @NonNull UserService userService, @NonNull ScoreService scoreService) {
|
||||||
super(Platforms.SCORESABER, 1, Map.of(
|
super(Platforms.SCORESABER, 1, Map.of(
|
||||||
1, new CurvePoint[]{
|
1, new CurvePoint[]{
|
||||||
new CurvePoint(0, 0),
|
new CurvePoint(0, 0),
|
||||||
@ -94,6 +99,7 @@ public class ScoreSaberPlatform extends Platform {
|
|||||||
));
|
));
|
||||||
this.scoreSaberService = scoreSaberService;
|
this.scoreSaberService = scoreSaberService;
|
||||||
this.userService = userService;
|
this.userService = userService;
|
||||||
|
this.scoreService = scoreService;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -140,16 +146,13 @@ public class ScoreSaberPlatform extends Platform {
|
|||||||
public void trackPlayerMetrics() {
|
public void trackPlayerMetrics() {
|
||||||
Date date = DateUtils.getMidnightToday();
|
Date date = DateUtils.getMidnightToday();
|
||||||
for (User user : this.userService.getUsers(false)) {
|
for (User user : this.userService.getUsers(false)) {
|
||||||
if (!user.isLinkedAccount()) { // Check if the user has linked their account
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
ScoreSaberAccountToken account = scoreSaberService.getAccount(user); // Get the account from the ScoreSaber API
|
|
||||||
HistoryPoint history = user.getHistory().getHistoryForDate(date);
|
HistoryPoint history = user.getHistory().getHistoryForDate(date);
|
||||||
history.setPp(account.getPp());
|
if (user.isLinkedAccount()) { // Check if the user has linked their account
|
||||||
history.setRank(account.getRank());
|
ScoreSaberAccountToken account = scoreSaberService.getAccount(user); // Get the account from the ScoreSaber API
|
||||||
history.setCountryRank(account.getCountryRank());
|
history.setPp(account.getPp());
|
||||||
history.setTotalPlayCount(account.getScoreStats().getTotalPlayCount());
|
history.setRank(account.getRank());
|
||||||
history.setTotalRankedPlayCount((int) account.getScoreStats().getTotalRankedScore());
|
history.setCountryRank(account.getCountryRank());
|
||||||
|
}
|
||||||
this.userService.saveUser(user); // Save the user
|
this.userService.saveUser(user); // Save the user
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -106,7 +106,7 @@ public interface ScoreRepository extends MongoRepository<Score, String> {
|
|||||||
"{ $match: { platform: ?0 } }",
|
"{ $match: { platform: ?0 } }",
|
||||||
"{ $count: 'total' }"
|
"{ $count: 'total' }"
|
||||||
})
|
})
|
||||||
int getTotalScores(@NonNull Platform.Platforms platform);
|
Integer getTotalScores(@NonNull Platform.Platforms platform);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the total ranked scores for the platform.
|
* Gets the total ranked scores for the platform.
|
||||||
@ -118,5 +118,44 @@ public interface ScoreRepository extends MongoRepository<Score, String> {
|
|||||||
"{ $match: { platform: ?0, pp: { $gt: 0 } } }",
|
"{ $match: { platform: ?0, pp: { $gt: 0 } } }",
|
||||||
"{ $count: 'total' }"
|
"{ $count: 'total' }"
|
||||||
})
|
})
|
||||||
int getTotalRankedScores(@NonNull Platform.Platforms platform);
|
Integer getTotalRankedScores(@NonNull Platform.Platforms platform);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the total player scores for the platform.
|
||||||
|
*
|
||||||
|
* @param platform the platform to get the scores from
|
||||||
|
* @param playerId the player id to get the scores from
|
||||||
|
* @return the total player scores
|
||||||
|
*/
|
||||||
|
@Aggregation(pipeline = {
|
||||||
|
"{ $match: { platform: ?0, playerId: ?1 } }",
|
||||||
|
"{ $count: 'total' }"
|
||||||
|
})
|
||||||
|
Integer getTotalPlayerScores(@NonNull Platform.Platforms platform, @NonNull String playerId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the total player ranked scores for the platform.
|
||||||
|
*
|
||||||
|
* @param platform the platform to get the scores from
|
||||||
|
* @param playerId the player id to get the scores from
|
||||||
|
* @return the total player ranked scores
|
||||||
|
*/
|
||||||
|
@Aggregation(pipeline = {
|
||||||
|
"{ $match: { platform: ?0, playerId: ?1, pp: { $gt: 0 } } }",
|
||||||
|
"{ $count: 'total' }"
|
||||||
|
})
|
||||||
|
Integer getTotalPlayerRankedScores(@NonNull Platform.Platforms platform, @NonNull String playerId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the total player unranked scores for the platform.
|
||||||
|
*
|
||||||
|
* @param platform the platform to get the scores from
|
||||||
|
* @param playerId the player id to get the scores from
|
||||||
|
* @return the total player unranked scores
|
||||||
|
*/
|
||||||
|
@Aggregation(pipeline = {
|
||||||
|
"{ $match: { platform: ?0, playerId: ?1, pp: { $eq: null } } }",
|
||||||
|
"{ $count: 'total' }"
|
||||||
|
})
|
||||||
|
Integer getTotalPlayerUnrankedScores(@NonNull Platform.Platforms platform, @NonNull String playerId);
|
||||||
}
|
}
|
||||||
|
@ -58,10 +58,10 @@ public class PlatformService {
|
|||||||
/**
|
/**
|
||||||
* Updates the platform players.
|
* Updates the platform players.
|
||||||
* <p>
|
* <p>
|
||||||
* This method is scheduled to run every day at midnight.
|
* This method is scheduled to run every day at 23:59.
|
||||||
* </p>
|
* </p>
|
||||||
*/
|
*/
|
||||||
@Scheduled(cron = "0 0 0 * * *")
|
@Scheduled(cron = "0 59 23 * * *")
|
||||||
public void updatePlayerMetrics() {
|
public void updatePlayerMetrics() {
|
||||||
log.info("Updating %s platform player metrics...".formatted(this.platforms.size()));
|
log.info("Updating %s platform player metrics...".formatted(this.platforms.size()));
|
||||||
for (Platform platform : this.platforms) {
|
for (Platform platform : this.platforms) {
|
||||||
|
@ -148,6 +148,42 @@ public class ScoreService {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the total scores for the platform and user.
|
||||||
|
*
|
||||||
|
* @param platform The platform to get the scores from.
|
||||||
|
* @param user The user to get the scores from.
|
||||||
|
* @return The total scores.
|
||||||
|
*/
|
||||||
|
public int getTotalScores(@NonNull Platform.Platforms platform, @NonNull User user) {
|
||||||
|
Integer totalPlayerScores = scoreRepository.getTotalPlayerScores(platform, user.getSteamId());
|
||||||
|
return totalPlayerScores == null ? 0 : totalPlayerScores;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the total ranked scores for the platform and user.
|
||||||
|
*
|
||||||
|
* @param platform The platform to get the scores from.
|
||||||
|
* @param user The user to get the scores from.
|
||||||
|
* @return The total ranked scores.
|
||||||
|
*/
|
||||||
|
public int getTotalRankedScores(@NonNull Platform.Platforms platform, @NonNull User user) {
|
||||||
|
Integer totalPlayerRankedScores = scoreRepository.getTotalPlayerRankedScores(platform, user.getSteamId());
|
||||||
|
return totalPlayerRankedScores == null ? 0 : totalPlayerRankedScores;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the total unranked scores for the platform and user.
|
||||||
|
*
|
||||||
|
* @param platform The platform to get the scores from.
|
||||||
|
* @param user The user to get the scores from.
|
||||||
|
* @return The total unranked scores.
|
||||||
|
*/
|
||||||
|
public int getTotalUnrankedScores(@NonNull Platform.Platforms platform, @NonNull User user) {
|
||||||
|
Integer totalPlayerUnrankedScores = scoreRepository.getTotalPlayerUnrankedScores(platform, user.getSteamId());
|
||||||
|
return totalPlayerUnrankedScores == null ? 0 : totalPlayerUnrankedScores;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tracks a ScoreSaber score.
|
* Tracks a ScoreSaber score.
|
||||||
*
|
*
|
||||||
@ -274,6 +310,10 @@ public class ScoreService {
|
|||||||
} else {
|
} else {
|
||||||
todayHistory.incrementUnrankedPlayCount();
|
todayHistory.incrementUnrankedPlayCount();
|
||||||
}
|
}
|
||||||
|
Platform.Platforms platform = score.getPlatform();
|
||||||
|
todayHistory.setTotalPlayCount(this.getTotalScores(platform, user)); // Get the total scores for the platform
|
||||||
|
todayHistory.setTotalRankedPlayCount(this.getTotalRankedScores(platform, user)); // Get the total ranked scores for the platform
|
||||||
|
todayHistory.setTotalUnrankedPlayCount(this.getTotalUnrankedScores(platform, user)); // Get the total unranked scores for the platform
|
||||||
userService.saveUser(user); // Save the user
|
userService.saveUser(user); // Save the user
|
||||||
scoreRepository.save(score); // Save the score
|
scoreRepository.save(score); // Save the score
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user