From b103196213516021c1cc92bfc87c231dcf927ac4 Mon Sep 17 00:00:00 2001 From: Sammers21 Date: Tue, 19 Dec 2023 12:26:02 +0300 Subject: [PATCH] releaseb proper updates of char from prev ssns --- src/io/github/sammers/pla/blizzard/BlizzardAPI.java | 6 +++--- src/io/github/sammers/pla/blizzard/PvpBracket.java | 11 ++++++++++- .../github/sammers/pla/blizzard/WowAPICharacter.java | 7 ++++--- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/io/github/sammers/pla/blizzard/BlizzardAPI.java b/src/io/github/sammers/pla/blizzard/BlizzardAPI.java index 1fd671d9..b248f84a 100644 --- a/src/io/github/sammers/pla/blizzard/BlizzardAPI.java +++ b/src/io/github/sammers/pla/blizzard/BlizzardAPI.java @@ -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; @@ -188,7 +188,7 @@ public static String oldRegion(String region) { return oldRegion; } - public Maybe pvpLeaderboard(String region, String pvpSeasonId, String pvpBracket, String namespace) { + public Maybe pvpLeaderboard(String region, Integer pvpSeasonId, String pvpBracket, String namespace) { String realRegion; String realNamespace; String realPvpBracket; @@ -249,7 +249,7 @@ public Single cutoffs(String region) { return cutoffs(region, CURRENT_PVP_SEASON_ID); } - public Single cutoffs(String region, String pvpSsnId) { + public Single 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") diff --git a/src/io/github/sammers/pla/blizzard/PvpBracket.java b/src/io/github/sammers/pla/blizzard/PvpBracket.java index aee9f9de..6bd8b535 100644 --- a/src/io/github/sammers/pla/blizzard/PvpBracket.java +++ b/src/io/github/sammers/pla/blizzard/PvpBracket.java @@ -21,7 +21,7 @@ public record PvpBracket(String bracketType, Boolean isRankOneRange, GamingHistory gamingHistory ) implements JsonConvertable { - public static PvpBracket parse(JsonObject wowApiBracket, Optional prevBracket, Long rank, Long bracketRankOneCutoff) { + public static PvpBracket parse(JsonObject wowApiBracket, Optional prevBracket, Long rank, Long bracketRankOneCutoff, boolean thisSsnData) { String type = wowApiBracket.getJsonObject("bracket").getString("type"); Long rating = wowApiBracket.getLong("rating"); Optional stats; @@ -49,6 +49,15 @@ public static PvpBracket parse(JsonObject wowApiBracket, Optional 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); } diff --git a/src/io/github/sammers/pla/blizzard/WowAPICharacter.java b/src/io/github/sammers/pla/blizzard/WowAPICharacter.java index cbfb90cc..c1af124b 100644 --- a/src/io/github/sammers/pla/blizzard/WowAPICharacter.java +++ b/src/io/github/sammers/pla/blizzard/WowAPICharacter.java @@ -186,7 +186,8 @@ public static WowAPICharacter parse( Map 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 list = brackets.stream().map((JsonObject wowApiBracket) -> { + List 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 -> { @@ -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(); @@ -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(),