rename statistics to histories
Some checks failed
Deploy API / docker (17, 3.8.5) (push) Failing after 34s

This commit is contained in:
Lee 2024-08-04 04:25:51 +01:00
parent 8c354b1be1
commit 29f5d5983a
2 changed files with 19 additions and 18 deletions

@ -67,35 +67,35 @@ public class User {
/**
* The user's statistic history.
*/
public Map<Platform.Platforms, Map<String, Statistic>> statistics;
public Map<Platform.Platforms, Map<String, Statistic>> histories;
/**
* The user's statistic history.
* The user's history points history.
*/
@JsonIgnore
public Map<Platform.Platforms, Map<Date, Statistic>> getStatistics() {
if (this.statistics == null) {
this.statistics = new HashMap<>();
public Map<Platform.Platforms, Map<Date, Statistic>> getHistories() {
if (this.histories == null) {
this.histories = new HashMap<>();
}
Map<Platform.Platforms, Map<Date, Statistic>> toReturn = new HashMap<>();
for (Platform.Platforms platform : statistics.keySet()) {
toReturn.put(platform, getStatistic(platform));
for (Platform.Platforms platform : histories.keySet()) {
toReturn.put(platform, getHistory(platform));
}
return toReturn;
}
/**
* Gets the statistics for a platform.
* Gets the history points for a platform.
*
* @param platform the platform to get the statistics for
* @return the statistics
*/
@SneakyThrows
public Map<Date, Statistic> getStatistic(@NonNull Platform.Platforms platform) {
if (this.statistics == null) {
this.statistics = new HashMap<>();
public Map<Date, Statistic> getHistory(@NonNull Platform.Platforms platform) {
if (this.histories == null) {
this.histories = new HashMap<>();
}
Map<String, Statistic> statisticMap = this.statistics.computeIfAbsent(platform, k -> new HashMap<>());
Map<String, Statistic> statisticMap = this.histories.computeIfAbsent(platform, k -> new HashMap<>());
Map<Date, Statistic> statistics = new HashMap<>();
for (Map.Entry<String, Statistic> entry : statisticMap.entrySet()) {
statistics.put(DATE_FORMAT.parse(entry.getKey()), entry.getValue());
@ -104,17 +104,17 @@ public class User {
}
/**
* Adds a statistic to the user's history.
* Adds a history point to the user's history.
*
* @param platform the platform to add the statistic for
* @param date the date of the statistic
* @param statistic the statistic to add
*/
public void addStatistic(@NonNull Platform.Platforms platform, @NonNull Date date, @NonNull Statistic statistic) {
if (this.statistics == null) {
this.statistics = new HashMap<>();
public void addHistory(@NonNull Platform.Platforms platform, @NonNull Date date, @NonNull Statistic statistic) {
if (this.histories == null) {
this.histories = new HashMap<>();
}
Map<String, Statistic> statisticMap = this.statistics.computeIfAbsent(platform, k -> new HashMap<>());
Map<String, Statistic> statisticMap = this.histories.computeIfAbsent(platform, k -> new HashMap<>());
statisticMap.put(String.valueOf(date.toString()), statistic);
}

@ -138,12 +138,13 @@ public class ScoreSaberPlatform extends Platform {
@Override
public void updatePlayers() {
Date date = DateUtils.alignToCurrentHour(new Date());
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
user.addStatistic(this.getPlatform(), DateUtils.alignToCurrentHour(new Date()), new ScoreSaberStatistic(
user.addHistory(this.getPlatform(), date, new ScoreSaberStatistic(
account.getRank(),
account.getCountryRank(),
account.getScoreStats().getTotalScore(),