From 70130f962974599b7400ec92e641cc81eed2cc93 Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Fri, 2 Feb 2018 13:20:50 +0200 Subject: [PATCH] Fixes Network page displaying odd Unique player numbers (#518) --- .../webserver/pages/parsing/NetworkPage.java | 6 +++--- .../plan/utilities/analysis/AnalysisUtils.java | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/Plan/src/main/java/com/djrapitops/plan/system/webserver/pages/parsing/NetworkPage.java b/Plan/src/main/java/com/djrapitops/plan/system/webserver/pages/parsing/NetworkPage.java index b21ecad3b..6e1704ddd 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/webserver/pages/parsing/NetworkPage.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/webserver/pages/parsing/NetworkPage.java @@ -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 { diff --git a/Plan/src/main/java/com/djrapitops/plan/utilities/analysis/AnalysisUtils.java b/Plan/src/main/java/com/djrapitops/plan/utilities/analysis/AnalysisUtils.java index 5369a7478..4f83c777f 100644 --- a/Plan/src/main/java/com/djrapitops/plan/utilities/analysis/AnalysisUtils.java +++ b/Plan/src/main/java/com/djrapitops/plan/utilities/analysis/AnalysisUtils.java @@ -33,6 +33,24 @@ public class AnalysisUtils { return newPlayers; } + public static int getUniquePlayers(Map> sessions, long after) { + Set uuids = new HashSet<>(); + + for (Map.Entry> 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> sessions, long after) { Map> uniqueJoins = new HashMap<>();