From 49f8cedb3de16b2a7bb730e90525de4cbfc2d120 Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Fri, 26 Jul 2019 21:33:54 +0300 Subject: [PATCH] Serveral things to server overview: - Fixed unique player query - Week timeframes added - Average Playtime / Player sorted out --- .../queries/analysis/PlayerCountQueries.java | 9 +--- .../system/json/ServerOverviewJSONParser.java | 54 +++++++++++-------- .../assets/plan/web/js/server-values.js | 11 ++-- .../resources/assets/plan/web/server.html | 19 ++++--- 4 files changed, 53 insertions(+), 40 deletions(-) diff --git a/Plan/common/src/main/java/com/djrapitops/plan/db/access/queries/analysis/PlayerCountQueries.java b/Plan/common/src/main/java/com/djrapitops/plan/db/access/queries/analysis/PlayerCountQueries.java index 3ceb16124..a055dfce3 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/db/access/queries/analysis/PlayerCountQueries.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/db/access/queries/analysis/PlayerCountQueries.java @@ -56,20 +56,15 @@ public class PlayerCountQueries { } public static Query uniquePlayerCount(long after, long before, UUID serverUUID) { - String sql = SELECT + "COUNT(" + SessionsTable.USER_UUID + ") as player_count" + + String sql = SELECT + "COUNT(DISTINCT " + SessionsTable.USER_UUID + ") as player_count" + FROM + SessionsTable.TABLE_NAME + WHERE + SessionsTable.SESSION_END + "<=?" + AND + SessionsTable.SESSION_START + ">=?" + - AND + SessionsTable.SERVER_UUID + "=?" + - GROUP_BY + SessionsTable.USER_UUID; + AND + SessionsTable.SERVER_UUID + "=?"; return queryPlayerCount(sql, after, before, serverUUID); } - public static Query uniquePlayerCountPerDay(long after, long before, UUID serverUUID) { - return db -> 0; // TODO - } - public static Query newPlayerCount(long after, long before, UUID serverUUID) { String sql = SELECT + "COUNT(" + UserInfoTable.USER_UUID + ") as player_count" + FROM + UserInfoTable.TABLE_NAME + diff --git a/Plan/common/src/main/java/com/djrapitops/plan/system/json/ServerOverviewJSONParser.java b/Plan/common/src/main/java/com/djrapitops/plan/system/json/ServerOverviewJSONParser.java index 8418f05f8..f070055b2 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/system/json/ServerOverviewJSONParser.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/system/json/ServerOverviewJSONParser.java @@ -51,14 +51,15 @@ import java.util.concurrent.TimeUnit; @Singleton public class ServerOverviewJSONParser implements TabJSONParser> { + private final Formatter day; private PlanConfig config; private DBSystem dbSystem; private ServerInfo serverInfo; - private Formatter timeAmountFormatter; - private Formatter decimalFormatter; - private Formatter percentageFormatter; - private Formatter dateFormatter; + private Formatter timeAmount; + private Formatter decimals; + private Formatter percentage; + private Formatter year; @Inject public ServerOverviewJSONParser( @@ -71,10 +72,11 @@ public class ServerOverviewJSONParser implements TabJSONParser createJSONAsMap(UUID serverUUID) { @@ -93,14 +95,14 @@ public class ServerOverviewJSONParser implements TabJSONParser sevenDays = new HashMap<>(); sevenDays.put("unique_players", db.query(PlayerCountQueries.uniquePlayerCount(sevenDaysAgo, now, serverUUID))); - sevenDays.put("unique_players_day", db.query(PlayerCountQueries.uniquePlayerCountPerDay(sevenDaysAgo, now, serverUUID))); // TODO + sevenDays.put("unique_players_day", "!"); // TODO sevenDays.put("new_players", db.query(PlayerCountQueries.newPlayerCount(sevenDaysAgo, now, serverUUID))); - sevenDays.put("new_players_retention", 0); // TODO - sevenDays.put("new_players_retention_perc", percentageFormatter.apply(-1.0)); // TODO + sevenDays.put("new_players_retention", "!"); // TODO + sevenDays.put("new_players_retention_perc", "!"); // TODO TPSMutator tpsMutator = new TPSMutator(db.query(TPSQueries.fetchTPSDataOfServer(sevenDaysAgo, now, serverUUID))); - sevenDays.put("average_tps", decimalFormatter.apply(tpsMutator.averageTPS())); + sevenDays.put("average_tps", decimals.apply(tpsMutator.averageTPS())); sevenDays.put("low_tps_spikes", tpsMutator.lowTpsSpikeCount(config.getNumber(DisplaySettings.GRAPH_TPS_THRESHOLD_MED))); - sevenDays.put("downtime", timeAmountFormatter.apply(tpsMutator.serverDownTime())); + sevenDays.put("downtime", timeAmount.apply(tpsMutator.serverDownTime())); return sevenDays; } @@ -113,17 +115,19 @@ public class ServerOverviewJSONParser implements TabJSONParser numbers = new HashMap<>(); - numbers.put("total_players", db.query(ServerAggregateQueries.serverUserCount(serverUUID))); + Integer userCount = db.query(ServerAggregateQueries.serverUserCount(serverUUID)); + numbers.put("total_players", userCount); numbers.put("regular_players", db.query(ActivityIndexQueries.fetchRegularPlayerCount(now, serverUUID, playtimeThreshold))); numbers.put("online_players", getOnlinePlayers(serverUUID, db)); Optional> lastPeak = db.query(TPSQueries.fetchPeakPlayerCount(serverUUID, twoDaysAgo)); Optional> allTimePeak = db.query(TPSQueries.fetchAllTimePeakPlayerCount(serverUUID)); - numbers.put("last_peak_date", lastPeak.map(dateFormatter).orElse("-")); + numbers.put("last_peak_date", lastPeak.map(year).orElse("-")); numbers.put("last_peak_players", lastPeak.map(dateObj -> dateObj.getValue().toString()).orElse("-")); - numbers.put("best_peak_date", allTimePeak.map(dateFormatter).orElse("-")); + numbers.put("best_peak_date", allTimePeak.map(year).orElse("-")); numbers.put("best_peak_players", allTimePeak.map(dateObj -> dateObj.getValue().toString()).orElse("-")); - numbers.put("playtime", timeAmountFormatter.apply(db.query(SessionQueries.playtime(0L, now, serverUUID)))); - numbers.put("player_playtime", "-"); // TODO + Long totalPlaytime = db.query(SessionQueries.playtime(0L, now, serverUUID)); + numbers.put("playtime", timeAmount.apply(totalPlaytime)); + numbers.put("player_playtime", userCount != 0 ? timeAmount.apply(totalPlaytime / userCount) : "-"); numbers.put("sessions", db.query(SessionQueries.sessionCount(0L, now, serverUUID))); numbers.put("player_kills", db.query(KillQueries.playerKillCount(0L, now, serverUUID))); numbers.put("mob_kills", db.query(KillQueries.mobKillCount(0L, now, serverUUID))); @@ -149,6 +153,10 @@ public class ServerOverviewJSONParser implements TabJSONParser weeks = new HashMap<>(); + weeks.put("start", day.apply(twoWeeksAgo)); + weeks.put("midpoint", day.apply(oneWeekAgo)); + weeks.put("end", day.apply(now)); + Integer uniqueBefore = db.query(PlayerCountQueries.uniquePlayerCount(twoWeeksAgo, oneWeekAgo, serverUUID)); Integer uniqueAfter = db.query(PlayerCountQueries.uniquePlayerCount(oneWeekAgo, now, serverUUID)); Trend uniqueTrend = new Trend(uniqueBefore, uniqueAfter, false); @@ -171,10 +179,12 @@ public class ServerOverviewJSONParser implements TabJSONParser Week Comparison - +
- - + + - + @@ -284,9 +287,9 @@ - - - + + + @@ -1534,7 +1537,7 @@ }); jsonRequest("../v1/graph?type=worldPie&server=${serverName}", function (json, error) { - if (data) { + if (json) { var worldSeries = {name: 'World Playtime', colorByPoint: true, data: json.world_series}; var gmSeries = json.gm_series; worldPie("worldPie", worldSeries, gmSeries);
Comparing 7 days 7 days before (22.1. - 29.1.)Last 7 days (29.1. - 5.2.)7 days before ( - ) + Last 7 days ( - ) + Trend
Unique Players Average Playtime / Player
Sessions