add missing leaderboards
All checks were successful
Deploy to Dokku / docker (ubuntu-latest) (push) Successful in 37s
All checks were successful
Deploy to Dokku / docker (ubuntu-latest) (push) Successful in 37s
This commit is contained in:
parent
4e828f2c2b
commit
58bdc6f414
@ -33,7 +33,7 @@ public class ScoreSaberPlatform extends Platform {
|
|||||||
/**
|
/**
|
||||||
* Delay in ms for requests per minute.
|
* Delay in ms for requests per minute.
|
||||||
*/
|
*/
|
||||||
private static final long UPDATE_DELAY = 1000L / 150L; // 150 requests per minute
|
private static final long UPDATE_DELAY = 1000L / 250L; // 150 requests per minute
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The base multiplier for stars.
|
* The base multiplier for stars.
|
||||||
@ -192,21 +192,31 @@ public class ScoreSaberPlatform extends Platform {
|
|||||||
public void updateLeaderboards() {
|
public void updateLeaderboards() {
|
||||||
// TODO: PUSH THIS
|
// TODO: PUSH THIS
|
||||||
List<TrackedScore> scores = this.trackedScoreService.getTrackedScores(this.getPlatform(), true);
|
List<TrackedScore> scores = this.trackedScoreService.getTrackedScores(this.getPlatform(), true);
|
||||||
Map<String, ScoreSaberLeaderboardToken> rankedLeaderboards = new HashMap<>();
|
Map<String, ScoreSaberLeaderboardToken> leaderboards = new HashMap<>();
|
||||||
for (ScoreSaberLeaderboardPageToken rankedLeaderboard : this.scoreSaberService.getRankedLeaderboards()) {
|
for (ScoreSaberLeaderboardPageToken rankedLeaderboard : this.scoreSaberService.getRankedLeaderboards()) {
|
||||||
for (ScoreSaberLeaderboardToken leaderboard : rankedLeaderboard.getLeaderboards()) {
|
for (ScoreSaberLeaderboardToken leaderboard : rankedLeaderboard.getLeaderboards()) {
|
||||||
rankedLeaderboards.put(leaderboard.getId(), leaderboard);
|
leaderboards.put(leaderboard.getId(), leaderboard);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add any missing leaderboards
|
||||||
|
for (TrackedScore score : scores) {
|
||||||
|
if (leaderboards.containsKey(score.getLeaderboardId())) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
ScoreSaberLeaderboardToken leaderboard = this.scoreSaberService.getLeaderboard(score.getLeaderboardId(), true);
|
||||||
|
leaderboards.put(leaderboard.getId(), leaderboard);
|
||||||
|
}
|
||||||
|
|
||||||
log.info("Updating {} leaderboards for platform '{}'",
|
log.info("Updating {} leaderboards for platform '{}'",
|
||||||
rankedLeaderboards.size(),
|
leaderboards.size(),
|
||||||
this.getPlatform().getPlatformName()
|
this.getPlatform().getPlatformName()
|
||||||
);
|
);
|
||||||
|
|
||||||
// Update the leaderboards
|
// Update the leaderboards
|
||||||
int finished = 0;
|
int finished = 0;
|
||||||
|
for (Map.Entry<String, ScoreSaberLeaderboardToken> leaderboardEntry : leaderboards.entrySet()) {
|
||||||
for (Map.Entry<String, ScoreSaberLeaderboardToken> leaderboardEntry : rankedLeaderboards.entrySet()) {
|
|
||||||
String id = leaderboardEntry.getKey();
|
String id = leaderboardEntry.getKey();
|
||||||
ScoreSaberLeaderboardToken leaderboard = leaderboardEntry.getValue();
|
ScoreSaberLeaderboardToken leaderboard = leaderboardEntry.getValue();
|
||||||
|
|
||||||
@ -220,11 +230,6 @@ public class ScoreSaberPlatform extends Platform {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (leaderboard == null) {
|
|
||||||
log.warn("Failed to update leaderboard '{}' for platform '{}'", id, this.getPlatform().getPlatformName());
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
List<TrackedScore> toUpdate = scores.stream().filter(score -> {
|
List<TrackedScore> toUpdate = scores.stream().filter(score -> {
|
||||||
if (!score.getLeaderboardId().equals(id)) { // Check if the leaderboard ID matches
|
if (!score.getLeaderboardId().equals(id)) { // Check if the leaderboard ID matches
|
||||||
return false;
|
return false;
|
||||||
@ -246,14 +251,13 @@ public class ScoreSaberPlatform extends Platform {
|
|||||||
}
|
}
|
||||||
finished++;
|
finished++;
|
||||||
|
|
||||||
log.info("Updated leaderboard '{}' for platform '{}', changed {} scores. ({}/{})",
|
if (finished % 100 == 0) {
|
||||||
leaderboard.getSongName(),
|
log.info("Updated {}/{} leaderboards for platform '{}'",
|
||||||
this.getPlatform().getPlatformName(),
|
|
||||||
toUpdate.size(),
|
|
||||||
|
|
||||||
finished,
|
finished,
|
||||||
rankedLeaderboards.size()
|
leaderboards.size(),
|
||||||
|
this.getPlatform().getPlatformName()
|
||||||
);
|
);
|
||||||
|
}
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
log.error("An error occurred while updating leaderboard '{}'", id, ex);
|
log.error("An error occurred while updating leaderboard '{}'", id, ex);
|
||||||
}
|
}
|
||||||
|
@ -30,16 +30,8 @@ public class PlatformService {
|
|||||||
*/
|
*/
|
||||||
private final List<Platform> platforms = new ArrayList<>();
|
private final List<Platform> platforms = new ArrayList<>();
|
||||||
|
|
||||||
/**
|
|
||||||
* The tracked score repository to use.
|
|
||||||
*/
|
|
||||||
@NonNull
|
|
||||||
private final TrackedScoreRepository trackedScoreRepository;
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public PlatformService(@NonNull ApplicationContext context, @NonNull TrackedScoreRepository trackedScoreRepository) {
|
public PlatformService(@NonNull ApplicationContext context) {
|
||||||
this.trackedScoreRepository = trackedScoreRepository;
|
|
||||||
|
|
||||||
log.info("Registering platforms...");
|
log.info("Registering platforms...");
|
||||||
registerPlatform(context.getBean(ScoreSaberPlatform.class));
|
registerPlatform(context.getBean(ScoreSaberPlatform.class));
|
||||||
log.info("Loaded %s platforms.".formatted(this.platforms.size()));
|
log.info("Loaded %s platforms.".formatted(this.platforms.size()));
|
||||||
@ -123,16 +115,23 @@ public class PlatformService {
|
|||||||
Document finalDocument = document;
|
Document finalDocument = document;
|
||||||
EXECUTOR_SERVICE.execute(() -> {
|
EXECUTOR_SERVICE.execute(() -> {
|
||||||
platform.updateLeaderboards();
|
platform.updateLeaderboards();
|
||||||
// Update the document
|
this.savePlatform(platform, finalDocument);
|
||||||
finalDocument.put("currentCurveVersion", platform.getCurrentCurveVersion());
|
|
||||||
MongoService.INSTANCE.getPlatformsCollection().replaceOne(Filters.eq("_id", platform.getPlatform().getPlatformName()), finalDocument);
|
|
||||||
}); // Update the leaderboards
|
}); // Update the leaderboards
|
||||||
} else {
|
} else {
|
||||||
// Update the document
|
this.savePlatform(platform, document);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Saves the platform.
|
||||||
|
*
|
||||||
|
* @param platform the platform to save
|
||||||
|
* @param document the document to save
|
||||||
|
*/
|
||||||
|
public void savePlatform(Platform platform, Document document) {
|
||||||
document.put("currentCurveVersion", platform.getCurrentCurveVersion());
|
document.put("currentCurveVersion", platform.getCurrentCurveVersion());
|
||||||
MongoService.INSTANCE.getPlatformsCollection().replaceOne(Filters.eq("_id", platform.getPlatform().getPlatformName()), document);
|
MongoService.INSTANCE.getPlatformsCollection().replaceOne(Filters.eq("_id", platform.getPlatform().getPlatformName()), document);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the ScoreSaber platform.
|
* Gets the ScoreSaber platform.
|
||||||
|
Reference in New Issue
Block a user