Skip to content

Commit

Permalink
releaseb fix the insert issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Sammers21 committed Sep 11, 2024
1 parent 33f7663 commit 9e734f8
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 54 deletions.
4 changes: 2 additions & 2 deletions src/io/github/sammers/pla/blizzard/BracketType.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> types;
private final Integer partySize;
Expand Down
51 changes: 27 additions & 24 deletions src/io/github/sammers/pla/blizzard/Cutoffs.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<String, Long> cutoffs;
Expand Down Expand Up @@ -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) {
Expand All @@ -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
);
}

Expand Down Expand Up @@ -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")
);
}

Expand All @@ -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;
}
Expand Down
61 changes: 33 additions & 28 deletions src/io/github/sammers/pla/logic/Ladder.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public void start() {
Observable<Long> 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);
Expand Down Expand Up @@ -643,34 +643,39 @@ private Completable upsertGamingHistory(String bracket, SnapshotDiff diff) {
final AtomicReference<List<WowAPICharacter>> 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<List<CharAndDiff>> 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<List<CharAndDiff>> 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())
Expand Down

0 comments on commit 9e734f8

Please sign in to comment.