From 9e734f878a3dd0ed318bd8ece4b1fe98d8d42c54 Mon Sep 17 00:00:00 2001 From: Sammers21 Date: Wed, 11 Sep 2024 21:41:10 +0300 Subject: [PATCH] releaseb fix the insert issue --- .../sammers/pla/blizzard/BracketType.java | 4 +- .../github/sammers/pla/blizzard/Cutoffs.java | 51 ++++++++-------- src/io/github/sammers/pla/logic/Ladder.java | 61 ++++++++++--------- 3 files changed, 62 insertions(+), 54 deletions(-) diff --git a/src/io/github/sammers/pla/blizzard/BracketType.java b/src/io/github/sammers/pla/blizzard/BracketType.java index 482e5b43..8a086a24 100644 --- a/src/io/github/sammers/pla/blizzard/BracketType.java +++ b/src/io/github/sammers/pla/blizzard/BracketType.java @@ -7,8 +7,8 @@ public enum BracketType { TWO_V_TWO(2, "2v2", "ARENA_2v2"), THREE_V_THREE(3, "3v3", "ARENA_3v3"), RBG(10, "BATTLEGROUNDS", "RBG"), - - SHUFFLE(1, "SHUFFLE"); + SHUFFLE(1, "SHUFFLE"), + BLITZ(1, "BLITZ"); private final List types; private final Integer partySize; diff --git a/src/io/github/sammers/pla/blizzard/Cutoffs.java b/src/io/github/sammers/pla/blizzard/Cutoffs.java index b0a9253e..9f050075 100644 --- a/src/io/github/sammers/pla/blizzard/Cutoffs.java +++ b/src/io/github/sammers/pla/blizzard/Cutoffs.java @@ -3,6 +3,7 @@ import io.github.sammers.pla.http.JsonConvertable; import io.vertx.core.json.JsonArray; import io.vertx.core.json.JsonObject; +import org.slf4j.Logger; import java.util.HashMap; import java.util.Map; @@ -12,6 +13,8 @@ public class Cutoffs implements JsonConvertable { + private static final Logger log = org.slf4j.LoggerFactory.getLogger(Cutoffs.class); + public final String region; public final String season; public final Map cutoffs; @@ -44,11 +47,11 @@ public void setPrediction(String bracket, long rating) { } public void setSpotWithNoAlts(String bracket, long count) { - spotWithNoAlts.put(bracket, (long)count); + spotWithNoAlts.put(bracket, (long) count); } public void setSpotCount(String bracket, int count) { - spotsCounts.put(bracket, (long)count); + spotsCounts.put(bracket, (long) count); } public int spotCount(String bracket) { @@ -66,20 +69,20 @@ public static Cutoffs fromBlizzardJson(String region, JsonObject entries) { cfs.put(bracket, reward.getLong("rating_cutoff")); } else if (bracket.equals("BATTLEGROUNDS")) { cfs.put(bracket + "/" + reward.getJsonObject("faction").getString("name").toLowerCase(), reward.getLong("rating_cutoff")); - } else if (bracket.equals("SHUFFLE")) { + } else if (bracket.equals("SHUFFLE") || bracket.equals("BLITZ")) { String spec = reward.getJsonObject("specialization").getString("name"); Long id = reward.getJsonObject("specialization").getLong("id"); cfs.put(bracket + "/" + specCodeNameById(spec, id), reward.getLong("rating_cutoff")); } else { - System.out.println("Unknown bracket: " + bracket); + log.error("Unknown bracket type: " + bracket); } } long now = System.currentTimeMillis(); return new Cutoffs( - region, - entries.getJsonObject("season").getString("id"), - cfs, - now + region, + entries.getJsonObject("season").getString("id"), + cfs, + now ); } @@ -145,27 +148,27 @@ public Long shuffle(String specialization) { @Override public JsonObject toJson() { return new JsonObject() - .put("region", region) - .put("season", season) - .put("timestamp", timestamp) - .put("rewards", new JsonObject(cutoffs.entrySet().stream().map(x -> Map.entry(x.getKey(), x.getValue())).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)))) - .put("spotCounts", new JsonObject(spotsCounts.entrySet().stream().map(x -> Map.entry(x.getKey(), x.getValue())).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)))) - .put("spotWithNoAlts", new JsonObject(spotWithNoAlts.entrySet().stream().map(x -> Map.entry(x.getKey(), x.getValue())).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)))); + .put("region", region) + .put("season", season) + .put("timestamp", timestamp) + .put("rewards", new JsonObject(cutoffs.entrySet().stream().map(x -> Map.entry(x.getKey(), x.getValue())).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)))) + .put("spotCounts", new JsonObject(spotsCounts.entrySet().stream().map(x -> Map.entry(x.getKey(), x.getValue())).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)))) + .put("spotWithNoAlts", new JsonObject(spotWithNoAlts.entrySet().stream().map(x -> Map.entry(x.getKey(), x.getValue())).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)))); } public JsonObject toJsonWithPredictions() { return toJson() - .put("predictions", new JsonObject(cutoffsPredictions.entrySet().stream().map(x -> Map.entry(x.getKey(), x.getValue())).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)))); + .put("predictions", new JsonObject(cutoffsPredictions.entrySet().stream().map(x -> Map.entry(x.getKey(), x.getValue())).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)))); } public static Cutoffs fromJson(JsonObject json) { return new Cutoffs( - json.getString("region"), - json.getString("season"), - json.getJsonObject("rewards").stream().collect(Collectors.toMap(Map.Entry::getKey, x -> (Long) x.getValue())), - json.getJsonObject("spotCounts").stream().collect(Collectors.toMap(Map.Entry::getKey, x -> (Long) x.getValue())), - json.getJsonObject("spotWithNoAlts").stream().collect(Collectors.toMap(Map.Entry::getKey, x -> (Long) x.getValue())), - json.getLong("timestamp") + json.getString("region"), + json.getString("season"), + json.getJsonObject("rewards").stream().collect(Collectors.toMap(Map.Entry::getKey, x -> (Long) x.getValue())), + json.getJsonObject("spotCounts").stream().collect(Collectors.toMap(Map.Entry::getKey, x -> (Long) x.getValue())), + json.getJsonObject("spotWithNoAlts").stream().collect(Collectors.toMap(Map.Entry::getKey, x -> (Long) x.getValue())), + json.getLong("timestamp") ); } @@ -184,9 +187,9 @@ public Long cutoffByBracketType(String btype) { public boolean equals(Object obj) { if (obj instanceof Cutoffs) { Cutoffs other = (Cutoffs) obj; - return region.equals(other.region) - && season.equals(other.season) - && cutoffs.equals(other.cutoffs); + return region.equals(other.region) + && season.equals(other.season) + && cutoffs.equals(other.cutoffs); } return false; } diff --git a/src/io/github/sammers/pla/logic/Ladder.java b/src/io/github/sammers/pla/logic/Ladder.java index fa8e7a8e..93959220 100644 --- a/src/io/github/sammers/pla/logic/Ladder.java +++ b/src/io/github/sammers/pla/logic/Ladder.java @@ -72,7 +72,7 @@ public void start() { Observable updates; if (updatesEnabled) { updates = Observable.mergeArray(runDataUpdater(EU, 1, MINUTES, new AtomicBoolean(false), new AtomicLong(System.nanoTime()), Observable.defer(() -> { - int initialDelay = Calculator.minutesTillNextMins(euPeriod); + int initialDelay = 0; return Observable.interval(initialDelay, euPeriod, MINUTES); })), runDataUpdater(US, 1, MINUTES, new AtomicBoolean(false), new AtomicLong(System.nanoTime()), Observable.defer(() -> { int initialDelay = Calculator.minutesTillNextMins(usPeriod); @@ -643,34 +643,39 @@ private Completable upsertGamingHistory(String bracket, SnapshotDiff diff) { final AtomicReference> upserted = new AtomicReference<>(); return Completable.create(emitter -> { VTHREAD_SCHEDULER.scheduleDirect(() -> { - log.info("Upserting gaming history for bracket " + bracket); - BracketType bracketType = BracketType.fromType(bracket); - long upsertTotalTick = System.nanoTime(); - if (bracketType.partySize() == 1) { - upserted.set(diff.chars().stream().flatMap(df -> { - try { - return characterCache.upsertDiff(df, bracket).stream(); - } catch (Exception e) { - log.warn("Error upserting diff", e); - return Stream.empty(); - } - }).toList()); - } else { - int partySize = bracketType.partySize(); - long tick = System.nanoTime(); - List> whoWWho = Calculator.whoPlayedWithWho(diff, partySize, characterCache); - log.info("Who played with who for bracket {} partySize={} has been calculated in {} ms, {} groups", bracket, partySize, (System.nanoTime() - tick) / 1000000, whoWWho.size()); - upserted.set(whoWWho.stream().flatMap(list -> { - try { - return characterCache.upsertGroupDiff(list, bracket).stream(); - } catch (Exception e) { - log.warn("Error upserting diff", e); - return Stream.empty(); - } - }).toList()); + try { + log.info("Upserting gaming history for bracket " + bracket); + BracketType bracketType = BracketType.fromType(bracket); + long upsertTotalTick = System.nanoTime(); + if (bracketType.partySize() == 1) { + upserted.set(diff.chars().stream().flatMap(df -> { + try { + return characterCache.upsertDiff(df, bracket).stream(); + } catch (Exception e) { + log.warn("Error upserting diff", e); + return Stream.empty(); + } + }).toList()); + } else { + int partySize = bracketType.partySize(); + long tick = System.nanoTime(); + List> whoWWho = Calculator.whoPlayedWithWho(diff, partySize, characterCache); + log.info("Who played with who for bracket {} partySize={} has been calculated in {} ms, {} groups", bracket, partySize, (System.nanoTime() - tick) / 1000000, whoWWho.size()); + upserted.set(whoWWho.stream().flatMap(list -> { + try { + return characterCache.upsertGroupDiff(list, bracket).stream(); + } catch (Exception e) { + log.warn("Error upserting diff", e); + return Stream.empty(); + } + }).toList()); + } + log.info("Upserting gaming history for bracket {} has been finished in {} ms, upserted {} chars", bracket, (System.nanoTime() - upsertTotalTick) / 1000000, upserted.get().size()); + emitter.onComplete(); + } catch (Exception e) { + log.warn("Error upserting diff", e); + emitter.onError(e); } - log.info("Upserting gaming history for bracket {} has been finished in {} ms, upserted {} chars", bracket, (System.nanoTime() - upsertTotalTick) / 1000000, upserted.get().size()); - emitter.onComplete(); }, 0, SECONDS); }).andThen( Completable.defer(() -> db.bulkUpdateChars(upserted.get())