Skip to content

Commit

Permalink
releaseb enable updates again
Browse files Browse the repository at this point in the history
  • Loading branch information
Sammers21 committed Sep 24, 2023
1 parent 8bd74dc commit 5b0387a
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 34 deletions.
54 changes: 37 additions & 17 deletions src/io/github/sammers/pla/logic/Calculator.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.time.Duration;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Function;
Expand Down Expand Up @@ -64,6 +67,7 @@ public static Maybe<SnapshotDiff> calcDiffAndCombine(String bracket, String regi
}
});
}

public static SnapshotDiff calculateDiff(Snapshot oldChars, Snapshot newChars, String bracket) {
return calculateDiff(oldChars, newChars, bracket, true);
}
Expand All @@ -83,7 +87,7 @@ public static SnapshotDiff calculateDiff(Snapshot oldChars, Snapshot newChars, S
}
CharAndDiff e;
if (oldChar == null) {
if(newIsZero) {
if (newIsZero) {
e = new CharAndDiff(newChar, new Diff(0L, 0L, 0L, 0L, newChars.timestamp()));
} else {
e = new CharAndDiff(newChar,
Expand Down Expand Up @@ -157,7 +161,7 @@ public static double pPresence(List<CharAndDiff> chars, int total) {

public static Meta calculateMeta(SnapshotDiff snapshot, String role, String bracket, double... ratios) {
Set<String> acceptedSpecs;
if (role.equals("all")){
if (role.equals("all")) {
acceptedSpecs = Spec.ALL_SPECS;
} else if (role.equals("dps")) {
acceptedSpecs = Spec.DPS_SPECS;
Expand All @@ -177,9 +181,9 @@ public static Meta calculateMeta(SnapshotDiff snapshot, String role, String brac
.sorted(Comparator.comparing((CharAndDiff o) -> o.character().rating()).reversed()).toList();
if (bracket.equals("shuffle")) {
int maxMinRating = totalSortedRoleList.stream().collect(Collectors.groupingBy(character -> character.character().fullSpec(), Collectors.toList()))
.entrySet().stream()
.collect(Collectors.toMap(Map.Entry::getKey, entry -> entry.getValue().stream().mapToLong(c -> c.character().rating()).min().orElse(0)))
.values().stream().mapToInt(Long::intValue).max().orElse(0);
.entrySet().stream()
.collect(Collectors.toMap(Map.Entry::getKey, entry -> entry.getValue().stream().mapToLong(c -> c.character().rating()).min().orElse(0)))
.values().stream().mapToInt(Long::intValue).max().orElse(0);
totalSortedRoleList = totalSortedRoleList.stream().filter(c -> c.character().rating() >= maxMinRating).toList();
}
LinkedList<CharAndDiff> fsrtList = new LinkedList<>(totalSortedRoleList);
Expand Down Expand Up @@ -217,20 +221,20 @@ public static Meta calculateMeta(SnapshotDiff snapshot, String role, String brac
}
List<Spec> specs = diviedLists.stream().flatMap(List::stream).collect(Collectors.groupingBy(Spec::specName, Collectors.toList()))
.entrySet().stream().map(entry -> {
Map<String, Double> res = new HashMap<>();
for(Spec spec : entry.getValue()) {
res.putAll(spec.winRates());
}
for (Double ratio: ratios) {
if(!res.containsKey(String.format("%.3f_win_rate", ratio))) {
res.put(String.format("%.3f_win_rate", ratio), 0.0);
Map<String, Double> res = new HashMap<>();
for (Spec spec : entry.getValue()) {
res.putAll(spec.winRates());
}
if(!res.containsKey(String.format("%.3f_presence", ratio))) {
res.put(String.format("%.3f_presence", ratio), 0.0);
for (Double ratio : ratios) {
if (!res.containsKey(String.format("%.3f_win_rate", ratio))) {
res.put(String.format("%.3f_win_rate", ratio), 0.0);
}
if (!res.containsKey(String.format("%.3f_presence", ratio))) {
res.put(String.format("%.3f_presence", ratio), 0.0);
}
}
}
return new Spec(entry.getKey(), res);
}).toList();
}).toList();
return new Meta(Map.of(), sizing, specs);
}

Expand All @@ -248,7 +252,7 @@ public static void indexCharAlts(Map<Integer, Set<WowAPICharacter>> alts, WowAPI
if (key == -1) {
return null;
}
if (value == null) {
if (value == null) {
value = new TreeSet<>(Comparator.comparing(WowAPICharacter::id));
}
value.add(character);
Expand All @@ -270,4 +274,20 @@ public static String realmCalc(String realm) {
String withCapFirst = realm.substring(0, 1).toUpperCase() + realm.substring(1).toLowerCase();
return withCapFirst.replace(" ", "-");
}

public static int minutesTillNextHour() {
ZoneId zone = ZoneId.systemDefault();
ZonedDateTime now = ZonedDateTime.now(zone);
ZonedDateTime nextHour = now.withMinute(0).withSecond(0).withNano(0).plusHours(1).plusMinutes(1);
Duration duration = Duration.between(now, nextHour);
return (int) duration.toMinutes();
}

public static int minutesTill5am() {
ZoneId zone = ZoneId.systemDefault();
ZonedDateTime now = ZonedDateTime.now(zone);
ZonedDateTime nextHour = now.withMinute(0).withSecond(0).withHour(5).plusDays(1);
Duration duration = Duration.between(now, nextHour);
return (int) duration.toMinutes();
}
}
13 changes: 7 additions & 6 deletions src/io/github/sammers/pla/logic/CharUpdater.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,12 @@ public Completable updateChars(List<String> nickNames, String region) {
}

public Completable updateChar(String region, String nickName) {
return api.character(region, nickName).flatMapCompletable(wowAPICharacter -> {
Calculator.indexCharAlts(altsCache, wowAPICharacter);
characterCache.put(nickName, wowAPICharacter);
charSearchIndex.insertNickNames(new SearchResult(nickName, region, wowAPICharacter.clazz()));
return db.upsertCharacter(wowAPICharacter).ignoreElement();
}).onErrorComplete();
return Completable.defer(() -> api.character(region, nickName).flatMapCompletable(wowAPICharacter -> {
Calculator.indexCharAlts(altsCache, wowAPICharacter);
characterCache.put(nickName, wowAPICharacter);
charSearchIndex.insertNickNames(new SearchResult(nickName, region, wowAPICharacter.clazz()));
return db.upsertCharacter(wowAPICharacter).ignoreElement();
}).onErrorComplete()
);
}
}
16 changes: 5 additions & 11 deletions src/io/github/sammers/pla/logic/Ladder.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@

import static io.github.sammers.pla.Main.VTHREAD_SCHEDULER;
import static io.github.sammers.pla.blizzard.BlizzardAPI.realRegion;
import static io.github.sammers.pla.logic.Calculator.minutesTill5am;
import static io.github.sammers.pla.logic.Calculator.minutesTillNextHour;

public class Ladder {

Expand Down Expand Up @@ -161,7 +163,7 @@ public void start() {
runDataUpdater(US,
runDataUpdater(EU,
Observable.defer(() -> {
int initialDelay = minutesTillNextHour();
int initialDelay = Calculator.minutesTillNextHour();
return Observable.interval(initialDelay, 60, TimeUnit.MINUTES)
.observeOn(VTHREAD_SCHEDULER)
.subscribeOn(VTHREAD_SCHEDULER);
Expand All @@ -184,8 +186,8 @@ private <R> Observable<Snapshot> runDataUpdater(String region, Observable<R> tic
.flatMapSingle(tick -> twoVTwo(region))
.flatMapSingle(tick -> battlegrounds(region))
.flatMapSingle(tick -> shuffle(region))
.flatMapSingle(tick -> calculateMeta(region).andThen(Single.just(tick)))
.flatMapSingle(tick -> loadCutoffs(region).andThen(Single.just(tick)))
.flatMapSingle(tick -> calculateMeta(region).andThen(Single.just(tick)))
.flatMapSingle(tick -> {
log.info("Data updater for " + region + " has been finished");
return Single.just(tick);
Expand Down Expand Up @@ -587,7 +589,7 @@ public Completable loadWowCharApiData(String region) {
List<SearchResult> list = characters.stream().map(charz -> new SearchResult(charz.fullName(), charz.region(), charz.clazz())).toList();
charSearchIndex.insertNickNames(list);
log.info("Character data size={} for region={} has been loaded to cache in {} ms", characters.size(), region, (System.nanoTime() - tick) / 1000000);
// VTHREAD_SCHEDULER.schedulePeriodicallyDirect(() -> charUpdater.updateCharsInfinite(region).subscribe(), 0, 24, TimeUnit.HOURS);
VTHREAD_SCHEDULER.schedulePeriodicallyDirect(() -> charUpdater.updateCharsInfinite(region).subscribe(), minutesTill5am(), 24 * 60, TimeUnit.MINUTES);
emitter.onComplete();
});
}));
Expand Down Expand Up @@ -778,12 +780,4 @@ public Completable newDataOnBracket(String bracket, String region, Snapshot newC
return Completable.complete();
}
}

public static int minutesTillNextHour() {
ZoneId zone = ZoneId.systemDefault();
ZonedDateTime now = ZonedDateTime.now(zone);
ZonedDateTime nextHour = now.withMinute(0).withSecond(0).withNano(0).plusHours(1).plusMinutes(1);
Duration duration = Duration.between(now, nextHour);
return (int) duration.toMinutes();
}
}

0 comments on commit 5b0387a

Please sign in to comment.