api: track player histories more often to keep them more up to date
Some checks failed
Deploy API / docker (17, 3.8.5) (push) Failing after 1m4s
Some checks failed
Deploy API / docker (17, 3.8.5) (push) Failing after 1m4s
This commit is contained in:
parent
131a5c2efe
commit
bd31254990
@ -20,6 +20,9 @@ public class RootController {
|
|||||||
@ResponseBody
|
@ResponseBody
|
||||||
@GetMapping(value = "/")
|
@GetMapping(value = "/")
|
||||||
public ResponseEntity<?> getWelcome() {
|
public ResponseEntity<?> getWelcome() {
|
||||||
return ResponseEntity.ok(Map.of("message", "Hello!"));
|
return ResponseEntity.ok(Map.of(
|
||||||
|
"message", "Hello!",
|
||||||
|
"url", "https://git.fascinated.cc/Fascinated/beatsaber-scoretracker"
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
package cc.fascinated.model.user;
|
package cc.fascinated.model.user;
|
||||||
|
|
||||||
import cc.fascinated.model.user.history.History;
|
import cc.fascinated.model.user.history.History;
|
||||||
|
import cc.fascinated.model.user.history.HistoryPoint;
|
||||||
|
import cc.fascinated.platform.Platform;
|
||||||
|
import cc.fascinated.services.ScoreService;
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
@ -77,6 +80,25 @@ public class User {
|
|||||||
return this.history;
|
return this.history;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the user's today history.
|
||||||
|
*
|
||||||
|
* @return the user's today history
|
||||||
|
*/
|
||||||
|
public HistoryPoint getTodayHistory() {
|
||||||
|
HistoryPoint todayHistory = this.getHistory().getTodayHistory();
|
||||||
|
if (todayHistory.getTotalPlayCount() == null) {
|
||||||
|
todayHistory.setTotalPlayCount(ScoreService.INSTANCE.getTotalScores(Platform.Platforms.SCORESABER, this));
|
||||||
|
}
|
||||||
|
if (todayHistory.getTotalRankedPlayCount() == null) {
|
||||||
|
todayHistory.setTotalRankedPlayCount(ScoreService.INSTANCE.getTotalRankedScores(Platform.Platforms.SCORESABER, this));
|
||||||
|
}
|
||||||
|
if (todayHistory.getTotalUnrankedPlayCount() == null) {
|
||||||
|
todayHistory.setTotalUnrankedPlayCount(ScoreService.INSTANCE.getTotalUnrankedScores(Platform.Platforms.SCORESABER, this));
|
||||||
|
}
|
||||||
|
return todayHistory;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the user as a DTO.
|
* Gets the user as a DTO.
|
||||||
*
|
*
|
||||||
|
@ -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 23:59.
|
* This method is scheduled to run every hour.
|
||||||
* </p>
|
* </p>
|
||||||
*/
|
*/
|
||||||
@Scheduled(cron = "0 59 23 * * *")
|
@Scheduled(cron = "0 0 * * * *")
|
||||||
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) {
|
||||||
|
@ -193,7 +193,7 @@ public class ScoreService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ScoreSaberScore scoreSaberScore = new ScoreSaberScore(
|
ScoreSaberScore scoreSaberScore = new ScoreSaberScore(
|
||||||
counterService.getNext(CounterService.CounterType.SCORE),
|
this.counterService.getNext(CounterService.CounterType.SCORE),
|
||||||
user.getSteamId(),
|
user.getSteamId(),
|
||||||
Platform.Platforms.SCORESABER,
|
Platform.Platforms.SCORESABER,
|
||||||
score.getId(),
|
score.getId(),
|
||||||
@ -245,7 +245,7 @@ public class ScoreService {
|
|||||||
* @param score The score to save.
|
* @param score The score to save.
|
||||||
*/
|
*/
|
||||||
public void saveScore(User user, Score score) {
|
public void saveScore(User user, Score score) {
|
||||||
HistoryPoint todayHistory = user.getHistory().getTodayHistory();
|
HistoryPoint todayHistory = user.getTodayHistory();
|
||||||
if (score.isRanked()) {
|
if (score.isRanked()) {
|
||||||
todayHistory.incrementRankedPlayCount();
|
todayHistory.incrementRankedPlayCount();
|
||||||
} else {
|
} else {
|
||||||
|
@ -94,7 +94,7 @@ public class UserService {
|
|||||||
user.setScoresaberAccount(ScoreSaberAccount.getFromToken(accountToken)); // Update the ScoreSaber account
|
user.setScoresaberAccount(ScoreSaberAccount.getFromToken(accountToken)); // Update the ScoreSaber account
|
||||||
user.setUsername(accountToken.getName()); // Update the username
|
user.setUsername(accountToken.getName()); // Update the username
|
||||||
|
|
||||||
HistoryPoint historyToday = user.getHistory().getTodayHistory();
|
HistoryPoint historyToday = user.getTodayHistory();
|
||||||
historyToday.setRank(accountToken.getRank());
|
historyToday.setRank(accountToken.getRank());
|
||||||
historyToday.setCountryRank(accountToken.getCountryRank());
|
historyToday.setCountryRank(accountToken.getCountryRank());
|
||||||
historyToday.setPp(accountToken.getPp());
|
historyToday.setPp(accountToken.getPp());
|
||||||
|
Reference in New Issue
Block a user