mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-11-01 00:10:12 +01:00
[2.9.0-DEV] Bugfixes
Fix #61 #58 #56 #57 #59 - Fixed GamemodeTimesHandler giving NPE if a gamemode is null. - Fixed ArrayOutOfBounds if sessions is empty. - Fixed randomly caused NPE when transforming sessions to length values (also improved it) Demographics tab not yet finished.
This commit is contained in:
parent
388f669fb1
commit
9e6c342f89
@ -225,6 +225,9 @@ public class UserData {
|
||||
* @param time
|
||||
*/
|
||||
public void setGMTime(GameMode gm, long time) {
|
||||
if (gmTimes == null) {
|
||||
gmTimes = new HashMap<>();
|
||||
}
|
||||
gmTimes.put(gm, time);
|
||||
}
|
||||
|
||||
|
@ -33,7 +33,7 @@ public class GamemodeTimesHandler {
|
||||
* @param data UserData matching the Player
|
||||
*/
|
||||
public void handleLogin(GameMode gm, UserData data) {
|
||||
data.setLastGamemode(gm);
|
||||
handleChangeEvent(gm, data);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -45,15 +45,19 @@ public class GamemodeTimesHandler {
|
||||
* @param data UserData matching the Player
|
||||
*/
|
||||
public void handleChangeEvent(GameMode newGM, UserData data) {
|
||||
if (newGM == null) {
|
||||
return;
|
||||
}
|
||||
if (data.getLastGamemode() == null) {
|
||||
data.setLastGamemode(GameMode.SURVIVAL);
|
||||
}
|
||||
GameMode oldGM = data.getLastGamemode();
|
||||
HashMap<GameMode, Long> times = data.getGmTimes();
|
||||
Long currentGMTime = times.get(oldGM);
|
||||
handler.getActivityHandler().saveToCache(data);
|
||||
|
||||
long lastSwap = data.getLastGmSwapTime();
|
||||
long playTime = data.getPlayTime();
|
||||
GameMode oldGM = data.getLastGamemode();
|
||||
if (oldGM != null) {
|
||||
data.setGMTime(oldGM, times.get(oldGM) + (playTime - lastSwap));
|
||||
}
|
||||
data.setGMTime(oldGM, currentGMTime + (playTime - lastSwap));
|
||||
data.setLastGamemode(newGM);
|
||||
data.setLastGmSwapTime(playTime);
|
||||
}
|
||||
@ -65,13 +69,14 @@ public class GamemodeTimesHandler {
|
||||
* @param data UserData matching the Player
|
||||
*/
|
||||
public void saveToCache(GameMode currentGM, UserData data) {
|
||||
if (currentGM == null) {
|
||||
return;
|
||||
}
|
||||
HashMap<GameMode, Long> times = data.getGmTimes();
|
||||
handler.getActivityHandler().saveToCache(data);
|
||||
|
||||
long lastSwap = data.getLastGmSwapTime();
|
||||
long playtime = data.getPlayTime();
|
||||
data.setGMTime(currentGM, times.get(currentGM) + (playtime - lastSwap));
|
||||
|
||||
data.setLastGmSwapTime(playtime);
|
||||
}
|
||||
|
||||
|
@ -176,7 +176,10 @@ public class Analysis {
|
||||
sorted.addTotalKills(uData.getPlayerKills().size());
|
||||
sorted.addTotalMobKills(uData.getMobKills());
|
||||
sorted.addTotalDeaths(uData.getDeaths());
|
||||
sorted.getSessiondata().addAll(uData.getSessions());
|
||||
List<SessionData> sessions = uData.getSessions();
|
||||
if (!sessions.isEmpty()) {
|
||||
sorted.getSessiondata().addAll(sessions);
|
||||
}
|
||||
sorted.getRegistered().add(uData.getRegistered());
|
||||
sorted.addGeoloc(uData.getDemData().getGeoLocation());
|
||||
uData.stopAccessing();
|
||||
|
@ -5,6 +5,7 @@ import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import main.java.com.djrapitops.plan.Settings;
|
||||
import main.java.com.djrapitops.plan.data.SessionData;
|
||||
import main.java.com.djrapitops.plan.data.UserData;
|
||||
@ -43,33 +44,33 @@ public class AnalysisUtils {
|
||||
static String createTableOutOfHashMap(HashMap<String, Integer> commandUse) {
|
||||
return SortableCommandUseTableCreator.createSortedCommandUseTable(commandUse);
|
||||
}
|
||||
|
||||
|
||||
static String createSortablePlayersTable(Collection<UserData> data) {
|
||||
return SortablePlayersTableCreator.createSortablePlayersTable(data);
|
||||
}
|
||||
|
||||
public static int getNewPlayers(List<Long> registered, long scale, long now) {
|
||||
public static int getNewPlayers(List<Long> registered, long scale, long now) {
|
||||
int newPlayers = 0;
|
||||
if (!registered.isEmpty()) {
|
||||
newPlayers = registered.stream()
|
||||
.filter((reg) -> (reg != null))
|
||||
.filter((reg) -> (reg > now - scale))
|
||||
.map((_item) -> 1).reduce(newPlayers, Integer::sum);
|
||||
newPlayers = registered.stream()
|
||||
.filter((reg) -> (reg != null))
|
||||
.filter((reg) -> (reg > now - scale))
|
||||
.map((_item) -> 1).reduce(newPlayers, Integer::sum);
|
||||
}
|
||||
// Filters out register dates before scale
|
||||
|
||||
|
||||
return newPlayers;
|
||||
}
|
||||
|
||||
|
||||
public static List<Long> transformSessionDataToLengths(Collection<SessionData> data) {
|
||||
List<SessionData> d = new ArrayList<>(data);
|
||||
List<Long> list = new ArrayList<>();
|
||||
d.stream().forEach((sData) -> {
|
||||
list.add(sData.getSessionEnd()-sData.getSessionStart());
|
||||
});
|
||||
List<Long> list = data.stream()
|
||||
.filter(session -> session != null)
|
||||
.filter(session -> session.getSessionEnd() > session.getSessionStart())
|
||||
.map(session -> session.getSessionEnd() - session.getSessionStart())
|
||||
.collect(Collectors.toList());
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
public static long average(Collection<Long> list) {
|
||||
if (list.isEmpty()) {
|
||||
return 0;
|
||||
|
Loading…
Reference in New Issue
Block a user