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. * 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 @JsonIgnore
public Map<Platform.Platforms, Map<Date, Statistic>> getStatistics() { public Map<Platform.Platforms, Map<Date, Statistic>> getHistories() {
if (this.statistics == null) { if (this.histories == null) {
this.statistics = new HashMap<>(); this.histories = new HashMap<>();
} }
Map<Platform.Platforms, Map<Date, Statistic>> toReturn = new HashMap<>(); Map<Platform.Platforms, Map<Date, Statistic>> toReturn = new HashMap<>();
for (Platform.Platforms platform : statistics.keySet()) { for (Platform.Platforms platform : histories.keySet()) {
toReturn.put(platform, getStatistic(platform)); toReturn.put(platform, getHistory(platform));
} }
return toReturn; return toReturn;
} }
/** /**
* Gets the statistics for a platform. * Gets the history points for a platform.
* *
* @param platform the platform to get the statistics for * @param platform the platform to get the statistics for
* @return the statistics * @return the statistics
*/ */
@SneakyThrows @SneakyThrows
public Map<Date, Statistic> getStatistic(@NonNull Platform.Platforms platform) { public Map<Date, Statistic> getHistory(@NonNull Platform.Platforms platform) {
if (this.statistics == null) { if (this.histories == null) {
this.statistics = new HashMap<>(); 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<>(); Map<Date, Statistic> statistics = new HashMap<>();
for (Map.Entry<String, Statistic> entry : statisticMap.entrySet()) { for (Map.Entry<String, Statistic> entry : statisticMap.entrySet()) {
statistics.put(DATE_FORMAT.parse(entry.getKey()), entry.getValue()); 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 platform the platform to add the statistic for
* @param date the date of the statistic * @param date the date of the statistic
* @param statistic the statistic to add * @param statistic the statistic to add
*/ */
public void addStatistic(@NonNull Platform.Platforms platform, @NonNull Date date, @NonNull Statistic statistic) { public void addHistory(@NonNull Platform.Platforms platform, @NonNull Date date, @NonNull Statistic statistic) {
if (this.statistics == null) { if (this.histories == null) {
this.statistics = new HashMap<>(); 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); statisticMap.put(String.valueOf(date.toString()), statistic);
} }

@ -138,12 +138,13 @@ public class ScoreSaberPlatform extends Platform {
@Override @Override
public void updatePlayers() { public void updatePlayers() {
Date date = DateUtils.alignToCurrentHour(new Date());
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 if (!user.isLinkedAccount()) { // Check if the user has linked their account
continue; continue;
} }
ScoreSaberAccountToken account = scoreSaberService.getAccount(user); // Get the account from the ScoreSaber API 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.getRank(),
account.getCountryRank(), account.getCountryRank(),
account.getScoreStats().getTotalScore(), account.getScoreStats().getTotalScore(),