Fixes Network page displaying odd Unique player numbers (#518)

This commit is contained in:
Rsl1122 2018-02-02 13:20:50 +02:00
parent 13e948c1b4
commit 70130f9629
2 changed files with 21 additions and 3 deletions

View File

@ -81,9 +81,9 @@ public class NetworkPage extends Page {
long weekAgo = now - TimeAmount.WEEK.ms();
long monthAgo = now - TimeAmount.MONTH.ms();
addValue("playersUniqueDay", AnalysisUtils.getUniqueJoinsPerDay(userSessions, dayAgo));
addValue("playersUniqueWeek", AnalysisUtils.getUniqueJoinsPerDay(userSessions, weekAgo));
addValue("playersUniqueMonth", AnalysisUtils.getUniqueJoinsPerDay(userSessions, monthAgo));
addValue("playersUniqueDay", AnalysisUtils.getUniquePlayers(userSessions, dayAgo));
addValue("playersUniqueWeek", AnalysisUtils.getUniquePlayers(userSessions, weekAgo));
addValue("playersUniqueMonth", AnalysisUtils.getUniquePlayers(userSessions, monthAgo));
}
private void peakTimes(UUID serverUUID, long now, Database db) throws DBException {

View File

@ -33,6 +33,24 @@ public class AnalysisUtils {
return newPlayers;
}
public static int getUniquePlayers(Map<UUID, List<Session>> sessions, long after) {
Set<UUID> uuids = new HashSet<>();
for (Map.Entry<UUID, List<Session>> entry : sessions.entrySet()) {
UUID uuid = entry.getKey();
for (Session session : entry.getValue()) {
if (session.getSessionStart() < after) {
continue;
} else {
uuids.add(uuid);
break;
}
}
}
return uuids.size();
}
public static int getUniqueJoinsPerDay(Map<UUID, List<Session>> sessions, long after) {
Map<Integer, Set<UUID>> uniqueJoins = new HashMap<>();