Skip to content

Commit

Permalink
releaseb proper updates of char from prev ssns
Browse files Browse the repository at this point in the history
  • Loading branch information
Sammers21 committed Dec 19, 2023
1 parent bd547de commit b103196
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/io/github/sammers/pla/blizzard/BlizzardAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class BlizzardAPI {

public static final String AUTH_URL = "https://oauth.battle.net/token";
public static String LOCALE = "en_US";
private static final String CURRENT_PVP_SEASON_ID = "36";
public static final Integer CURRENT_PVP_SEASON_ID = 36;
private static final Logger log = LoggerFactory.getLogger(BlizzardAPI.class);
private final String clientSecret;
private final WebClient webClient;
Expand Down Expand Up @@ -188,7 +188,7 @@ public static String oldRegion(String region) {
return oldRegion;
}

public Maybe<PvpLeaderBoard> pvpLeaderboard(String region, String pvpSeasonId, String pvpBracket, String namespace) {
public Maybe<PvpLeaderBoard> pvpLeaderboard(String region, Integer pvpSeasonId, String pvpBracket, String namespace) {
String realRegion;
String realNamespace;
String realPvpBracket;
Expand Down Expand Up @@ -249,7 +249,7 @@ public Single<Cutoffs> cutoffs(String region) {
return cutoffs(region, CURRENT_PVP_SEASON_ID);
}

public Single<Cutoffs> cutoffs(String region, String pvpSsnId) {
public Single<Cutoffs> cutoffs(String region, Integer pvpSsnId) {
String realRegion = realRegion(region);
return token().flatMap(blizzardAuthToken ->
webClient.getAbs("https://" + realRegion + ".api.blizzard.com/data/wow/pvp-season/" + pvpSsnId + "/pvp-reward/index")
Expand Down
11 changes: 10 additions & 1 deletion src/io/github/sammers/pla/blizzard/PvpBracket.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public record PvpBracket(String bracketType,
Boolean isRankOneRange,
GamingHistory gamingHistory
) implements JsonConvertable {
public static PvpBracket parse(JsonObject wowApiBracket, Optional<PvpBracket> prevBracket, Long rank, Long bracketRankOneCutoff) {
public static PvpBracket parse(JsonObject wowApiBracket, Optional<PvpBracket> prevBracket, Long rank, Long bracketRankOneCutoff, boolean thisSsnData) {
String type = wowApiBracket.getJsonObject("bracket").getString("type");
Long rating = wowApiBracket.getLong("rating");
Optional<JsonObject> stats;
Expand Down Expand Up @@ -49,6 +49,15 @@ public static PvpBracket parse(JsonObject wowApiBracket, Optional<PvpBracket> pr
}
Boolean isRankOneRange = rating >= bracketRankOneCutoff;
GamingHistory gamingHistory = prevBracket.map(PvpBracket::gamingHistory).orElse(new GamingHistory(new ArrayList<>()));
if (!thisSsnData) {
rating = 0L;
won = 0L;
lost = 0L;
rank = -1L;
isRankOneRange = false;
seasonMaxRating = 0L;
seasonMaxRatingAchievedTimestamp = System.currentTimeMillis();
}
return new PvpBracket(type, rating, won, lost, rank, seasonMaxRating, seasonMaxRatingAchievedTimestamp, maxRating, maxRatingAchievedTimestamp, isRankOneRange, gamingHistory);
}

Expand Down
7 changes: 4 additions & 3 deletions src/io/github/sammers/pla/blizzard/WowAPICharacter.java
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,8 @@ public static WowAPICharacter parse(
Map<String, PvpBracket> prevBrackets = previous.map(wowAPICharacter -> wowAPICharacter.brackets.stream().collect(Collectors.toMap(PvpBracket::bracketType, Function.identity()))).orElse(Map.of());
String name = entries.getString("name").substring(0, 1).toUpperCase() + entries.getString("name").substring(1);
String realm = Calculator.realmCalc(entries.getJsonObject("realm").getString("name"));
List<PvpBracket> list = brackets.stream().map((JsonObject wowApiBracket) -> {
List<PvpBracket> pvpBrackets = brackets.stream().map((JsonObject wowApiBracket) -> {
boolean thisSsnData = wowApiBracket.getJsonObject("season").getInteger("id").equals(BlizzardAPI.CURRENT_PVP_SEASON_ID);
String btype = wowApiBracket.getJsonObject("bracket").getString("type");
Snapshot latest = refs.snapshotByBracketType(btype, BlizzardAPI.oldRegion(region));
Long rank = Optional.ofNullable(latest).map(s -> s.findChar(Character.fullNameByRealmAndName(name, realm))).map(foundChars -> {
Expand Down Expand Up @@ -215,7 +216,7 @@ public static WowAPICharacter parse(
cutoffByBracketType = cutoffs.map(c -> c.cutoffByBracketType(btype)).orElse(Long.MAX_VALUE);
prevBracket = Optional.ofNullable(prevBrackets.get(btype));
}
return PvpBracket.parse(wowApiBracket, prevBracket, rank, Optional.of(cutoffByBracketType).orElse(-1L));
return PvpBracket.parse(wowApiBracket, prevBracket, rank, Optional.of(cutoffByBracketType).orElse(-1L), thisSsnData);
}).toList();
CharacterMedia media = CharacterMedia.parse(characterMedia);
Long lastUpdatedUTCms = Instant.now().toEpochMilli();
Expand All @@ -233,7 +234,7 @@ public static WowAPICharacter parse(
entries.getJsonObject("character_class").getString("name"),
entries.getInteger("equipped_item_level"),
region,
list,
pvpBrackets,
lastUpdatedUTCms,
parsedAchievements,
pets.getJsonArray("pets").encode().hashCode(),
Expand Down

0 comments on commit b103196

Please sign in to comment.