Serveral things to server overview:

- Fixed unique player query
- Week timeframes added
- Average Playtime / Player sorted out
This commit is contained in:
Rsl1122 2019-07-26 21:33:54 +03:00
parent eb9a6e3134
commit 49f8cedb3d
4 changed files with 53 additions and 40 deletions

View File

@ -56,20 +56,15 @@ public class PlayerCountQueries {
}
public static Query<Integer> 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<Integer> uniquePlayerCountPerDay(long after, long before, UUID serverUUID) {
return db -> 0; // TODO
}
public static Query<Integer> newPlayerCount(long after, long before, UUID serverUUID) {
String sql = SELECT + "COUNT(" + UserInfoTable.USER_UUID + ") as player_count" +
FROM + UserInfoTable.TABLE_NAME +

View File

@ -51,14 +51,15 @@ import java.util.concurrent.TimeUnit;
@Singleton
public class ServerOverviewJSONParser implements TabJSONParser<Map<String, Object>> {
private final Formatter<Long> day;
private PlanConfig config;
private DBSystem dbSystem;
private ServerInfo serverInfo;
private Formatter<Long> timeAmountFormatter;
private Formatter<Double> decimalFormatter;
private Formatter<Double> percentageFormatter;
private Formatter<DateHolder> dateFormatter;
private Formatter<Long> timeAmount;
private Formatter<Double> decimals;
private Formatter<Double> percentage;
private Formatter<DateHolder> year;
@Inject
public ServerOverviewJSONParser(
@ -71,10 +72,11 @@ public class ServerOverviewJSONParser implements TabJSONParser<Map<String, Objec
this.dbSystem = dbSystem;
this.serverInfo = serverInfo;
dateFormatter = formatters.year();
timeAmountFormatter = formatters.timeAmount();
decimalFormatter = formatters.decimals();
percentageFormatter = formatters.percentage();
year = formatters.year();
day = formatters.dayLong();
timeAmount = formatters.timeAmount();
decimals = formatters.decimals();
percentage = formatters.percentage();
}
public Map<String, Object> createJSONAsMap(UUID serverUUID) {
@ -93,14 +95,14 @@ public class ServerOverviewJSONParser implements TabJSONParser<Map<String, Objec
Map<String, Object> 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<Map<String, Objec
Map<String, Object> 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<DateObj<Integer>> lastPeak = db.query(TPSQueries.fetchPeakPlayerCount(serverUUID, twoDaysAgo));
Optional<DateObj<Integer>> 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<Map<String, Objec
Map<String, Object> 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<Map<String, Objec
Long playtimeBefore = db.query(SessionQueries.playtime(twoWeeksAgo, oneWeekAgo, serverUUID));
Long playtimeAfter = db.query(SessionQueries.playtime(oneWeekAgo, now, serverUUID));
Trend playtimeTrend = new Trend(playtimeBefore, playtimeAfter, false, timeAmountFormatter);
weeks.put("playtime_before", timeAmountFormatter.apply(playtimeBefore));
weeks.put("playtime_after", timeAmountFormatter.apply(playtimeAfter));
weeks.put("playtime_trend", playtimeTrend);
long avgPlaytimeBefore = uniqueBefore != 0 ? playtimeBefore / uniqueBefore : 0L;
long avgPlaytimeAfter = uniqueAfter != 0 ? playtimeAfter / uniqueAfter : 0L;
Trend avgPlaytimeTrend = new Trend(avgPlaytimeBefore, avgPlaytimeAfter, false, timeAmount);
weeks.put("average_playtime_before", timeAmount.apply(avgPlaytimeBefore));
weeks.put("average_playtime_after", timeAmount.apply(avgPlaytimeAfter));
weeks.put("average_playtime_trend", avgPlaytimeTrend);
Long sessionsBefore = db.query(SessionQueries.sessionCount(twoWeeksAgo, oneWeekAgo, serverUUID));
Long sessionsAfter = db.query(SessionQueries.sessionCount(oneWeekAgo, now, serverUUID));

View File

@ -84,6 +84,11 @@ function loadServerOverviewValues(json, error) {
data = json.weeks;
element = $(tab).find('#data_weeks');
$(element).find('#data_start').text(data.start);
$(element).find('#data_midpoint').text(data.midpoint);
$(element).find('#data_midpoint2').text(data.midpoint);
$(element).find('#data_end').text(data.end);
$(element).find('#data_unique_before').text(data.unique_before);
$(element).find('#data_unique_after').text(data.unique_after);
$(element).find('#data_unique_trend').replaceWith(trend(data.unique_trend));
@ -94,9 +99,9 @@ function loadServerOverviewValues(json, error) {
$(element).find('#data_regular_after').text(data.regular_after);
$(element).find('#data_regular_trend').replaceWith(trend(data.regular_trend));
$(element).find('#data_playtime_before').text(data.playtime_before);
$(element).find('#data_playtime_after').text(data.playtime_after);
$(element).find('#data_playtime_trend').replaceWith(trend(data.playtime_trend));
$(element).find('#data_average_playtime_before').text(data.average_playtime_before);
$(element).find('#data_average_playtime_after').text(data.average_playtime_after);
$(element).find('#data_average_playtime_trend').replaceWith(trend(data.average_playtime_trend));
$(element).find('#data_sessions_before').text(data.sessions_before);
$(element).find('#data_sessions_after').text(data.sessions_after);
$(element).find('#data_sessions_trend').replaceWith(trend(data.sessions_trend));

View File

@ -249,19 +249,22 @@
class="fa fa-fw fa-exchange-alt"></i>
Week Comparison</h6>
</div>
<table class="table mb-0">
<table class="table mb-0" id="data_weeks">
<thead>
<tr>
<th><i class="text-success fa fa-caret-up"></i><i
class="text-danger fa fa-caret-down"></i>
<small>Comparing 7 days</small>
</th>
<th>7 days before (22.1. - 29.1.)</th>
<th>Last 7 days (29.1. - 5.2.)</th>
<th>7 days before (<span id="data_start"></span> - <span
id="data_midpoint"></span>)
</th>
<th>Last 7 days (<span id="data_midpoint2"></span> - <span id="data_end"></span>)
</th>
<th>Trend</th>
</tr>
</thead>
<tbody id="data_weeks">
<tbody>
<tr>
<td><i class="col-blue fa fa-fw fa-users"></i> Unique Players</td>
<td id="data_unique_before"></td>
@ -284,9 +287,9 @@
<td><i class="col-green far fa-fw fa-clock"></i> Average Playtime /
Player
</td>
<td id="data_playtime_before"></td>
<td id="data_playtime_after"></td>
<td><span id="data_playtime_trend"></span></td>
<td id="data_average_playtime_before"></td>
<td id="data_average_playtime_after"></td>
<td><span id="data_average_playtime_trend"></span></td>
</tr>
<tr>
<td><i class="col-teal far fa-fw fa-calendar-check"></i> Sessions</td>
@ -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);