Fixes longest world time calculation #690

This commit is contained in:
Rsl1122 2018-08-20 10:59:14 +03:00
parent 53851bb6da
commit 151d09f284
2 changed files with 12 additions and 5 deletions

View File

@ -154,11 +154,11 @@ public class Session extends DataContainer implements DateHolder {
}
public void setWorldTimes(WorldTimes worldTimes) {
putRawData(SessionKeys.WORLD_TIMES, worldTimes);
this.worldTimes = worldTimes;
}
public void setPlayerKills(List<PlayerKill> playerKills) {
putRawData(SessionKeys.PLAYER_KILLS, playerKills);
this.playerKills = playerKills;
}
public boolean isFetchedFromDB() {
@ -231,7 +231,6 @@ public class Session extends DataContainer implements DateHolder {
}
Map<String, Long> playtimePerAlias = worldTimes.getPlaytimePerAlias();
long total = worldTimes.getTotal();
long longest = 0;
String theWorld = "-";
@ -244,6 +243,11 @@ public class Session extends DataContainer implements DateHolder {
}
}
long total = worldTimes.getTotal();
// Prevent arithmetic error if 0
if (total <= 0) {
total = -1;
}
double quotient = longest * 1.0 / total;
return theWorld + " (" + Formatters.percentage().apply(quotient) + ")";

View File

@ -170,8 +170,11 @@ public class WorldTimes {
}
public Map<String, Long> getPlaytimePerAlias() {
Map<String, Long> playtimePerWorld = getWorldTimes() // WorldTimes Map<String, GMTimes>
.entrySet().stream()
if (times.isEmpty()) {
return new HashMap<>();
}
Map<String, Long> playtimePerWorld = times.entrySet().stream() // WorldTimes Map<String, GMTimes>
.collect(Collectors.toMap(
Map.Entry::getKey,
entry -> entry.getValue().getTotal() // GMTimes.getTotal