Skip to content

Commit

Permalink
add pethash to character
Browse files Browse the repository at this point in the history
  • Loading branch information
Sammers21 committed Jan 21, 2024
1 parent e21e356 commit f8b2c32
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ indent_size = 4

[*.java]
indent_style = space
indent_size = 2
indent_size = 4
5 changes: 2 additions & 3 deletions src/io/github/sammers/pla/blizzard/PvpLeaderBoard.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@

import io.github.sammers.pla.db.Character;
import io.github.sammers.pla.http.JsonConvertable;
import io.github.sammers.pla.logic.Ladder;
import io.vertx.core.json.JsonArray;
import io.vertx.core.json.JsonObject;

import java.util.*;
import java.util.concurrent.atomic.AtomicLong;
import java.util.stream.Collectors;
import java.util.stream.Stream;

Expand Down Expand Up @@ -95,7 +93,8 @@ public Set<Character> toCharacters(Map<String, WowAPICharacter> characterCache,
wowAPICharacter.race(),
realm,
won,
lost
lost,
Optional.of(wowAPICharacter.petHash())
));
}
})
Expand Down
40 changes: 22 additions & 18 deletions src/io/github/sammers/pla/db/Character.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,24 @@
import io.github.sammers.pla.http.JsonConvertable;
import io.vertx.core.json.JsonObject;

import java.util.Optional;

import static io.github.sammers.pla.db.Spec.HEAL_SPECS;
import static io.github.sammers.pla.logic.Conts.*;
import static io.github.sammers.pla.logic.Conts.SPACE;
import static io.github.sammers.pla.logic.Conts.TIRE;

public record Character(Long pos, Long rating, boolean inCutoff, String name, String clazz, String fullSpec,
String fraction,
String gender, String race,
String realm, Long wins, Long losses) implements JsonConvertable {
String realm, Long wins, Long losses, Optional<Integer> pethash) implements JsonConvertable {

public static Character emptyFromFullNickname(String fullNickname) {
String[] split = fullNickname.split("-");
return new Character(-1L, -1L, false, split[0], "", "", "", "", "", split[1], -1L, -1L);
return new Character(-1L, -1L, false, split[0], "", "", "", "", "", split[1], -1L, -1L, Optional.empty());
}

public Character changeCutoff(boolean inCutoff) {
return new Character(pos, rating, inCutoff, name, clazz, fullSpec, fraction, gender, race, realm, wins, losses);
return new Character(pos, rating, inCutoff, name, clazz, fullSpec, fraction, gender, race, realm, wins, losses, pethash);
}

public String fullSpec() {
Expand Down Expand Up @@ -73,7 +76,7 @@ public boolean isDpsSpec() {
public static Character withWinsAndLossesAndPosAndRating(Character character, Long wins, Long losses, Long pos, Long rating) {
return new Character(pos, rating, character.inCutoff(), character.name(), character.clazz(), character.fullSpec(), character.fraction(),
character.gender(), character.race(),
character.realm(), wins, losses);
character.realm(), wins, losses, character.pethash());
}

public static Character fromJson(JsonObject entries) {
Expand All @@ -91,22 +94,23 @@ public static Character fromJson(JsonObject entries) {
}
return new Character(entries.getLong("pos"), entries.getLong("rating"), inCutoff, entries.getString("name"),
entries.getString("class"), entries.getString("full_spec"), entries.getString("fraction"), gender, race,
entries.getString("realm"), entries.getLong("wins"), entries.getLong("losses"));
entries.getString("realm"), entries.getLong("wins"), entries.getLong("losses"), Optional.empty());
}

public Character changeRealmName(String newRealm) {
return new Character(
pos,
rating,
inCutoff,
name,
clazz,
fullSpec,
fraction,
gender,
race,
newRealm,
wins,
losses);
pos,
rating,
inCutoff,
name,
clazz,
fullSpec,
fraction,
gender,
race,
newRealm,
wins,
losses,
pethash);
}
}
3 changes: 3 additions & 0 deletions src/io/github/sammers/pla/logic/Calculator.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ public class Calculator {
private static final Logger log = LoggerFactory.getLogger(Calculator.class);

public static Multiclassers calculateMulticlassers(Snapshot shuffleSnapshot, CharacterCache cache) {
if (shuffleSnapshot == null) {
return new Multiclassers(List.of());
}
Map<Integer, List<Character>> charsGrpd = new HashMap<>();
for (Character character : shuffleSnapshot.characters()) {
WowAPICharacter wowAPICharacter = cache.getByFullName(character.fullName());
Expand Down
13 changes: 7 additions & 6 deletions src/io/github/sammers/pla/logic/Ladder.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
import io.github.sammers.pla.db.DB;
import io.github.sammers.pla.db.Meta;
import io.github.sammers.pla.db.Snapshot;
import io.reactivex.*;
import io.reactivex.Completable;
import io.reactivex.Maybe;
import io.reactivex.Observable;
import io.reactivex.Single;
import io.vertx.reactivex.core.buffer.Buffer;
import io.vertx.reactivex.ext.web.client.HttpRequest;
import io.vertx.reactivex.ext.web.client.WebClient;
import org.javatuples.Pair;
import org.javatuples.Triplet;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
Expand Down Expand Up @@ -369,7 +369,7 @@ public Single<List<Character>> ladderShuffle(String bracket, Integer page, Strin
String realm = Calculator.realmCalc(nodeList.get(6).attr("data-value"));
Long wins = Long.parseLong(nodeList.get(7).attr("data-value"));
Long losses = Long.parseLong(nodeList.get(8).attr("data-value"));
return enrichWithSpecialData(new Character(pos, rating, false, name, clazz, fullSpec, fraction, "", "", realm, wins, losses), bracket, region);
return enrichWithSpecialData(new Character(pos, rating, false, name, clazz, fullSpec, fraction, "", "", realm, wins, losses, Optional.empty()), bracket, region);
}).toList();
return characters;
}
Expand Down Expand Up @@ -417,7 +417,8 @@ private Character enrichWithSpecialData(Character character, String region, Stri
race,
character.realm(),
character.wins(),
character.losses()
character.losses(),
apiCharacter.map(WowAPICharacter::petHash)
);
}

Expand Down Expand Up @@ -452,7 +453,7 @@ public Single<List<Character>> ladderTraditional(String bracket, Integer page, S
String realm = Calculator.realmCalc(nodeList.get(5).attr("data-value"));
Long wins = Long.parseLong(nodeList.get(6).attr("data-value"));
Long losses = Long.parseLong(nodeList.get(7).attr("data-value"));
return enrichWithSpecialData(new Character(pos, rating, false, name, clazz, fullSpec,fraction,"", "", realm, wins, losses), bracket, region);
return enrichWithSpecialData(new Character(pos, rating, false, name, clazz, fullSpec,fraction,"", "", realm, wins, losses, Optional.empty()), bracket, region);
}).toList();
return characters;
}
Expand Down

0 comments on commit f8b2c32

Please sign in to comment.