use of com.djrapitops.plan.storage.database.Database in project Plan by plan-player-analytics.
the class GraphJSONCreator method pingGraphsJSON.
public String pingGraphsJSON(ServerUUID serverUUID) {
Database db = dbSystem.getDatabase();
long now = System.currentTimeMillis();
List<Ping> pings = db.query(PingQueries.fetchPingDataOfServer(now - TimeUnit.DAYS.toMillis(180L), now, serverUUID));
// TODO Optimize in query
PingGraph pingGraph = graphs.line().pingGraph(new PingMutator(pings).mutateToByMinutePings().all());
return "{\"min_ping_series\":" + pingGraph.getMinGraph().toHighChartsSeries() + ",\"avg_ping_series\":" + pingGraph.getAvgGraph().toHighChartsSeries() + ",\"max_ping_series\":" + pingGraph.getMaxGraph().toHighChartsSeries() + ",\"colors\":{" + "\"min\":\"" + theme.getValue(ThemeVal.GRAPH_MIN_PING) + "\"," + "\"avg\":\"" + theme.getValue(ThemeVal.GRAPH_AVG_PING) + "\"," + "\"max\":\"" + theme.getValue(ThemeVal.GRAPH_MAX_PING) + "\"" + "}}";
}
use of com.djrapitops.plan.storage.database.Database in project Plan by plan-player-analytics.
the class GraphJSONCreator method performanceGraphJSON.
public String performanceGraphJSON(ServerUUID serverUUID) {
long now = System.currentTimeMillis();
Database db = dbSystem.getDatabase();
LineGraphFactory lineGraphs = graphs.line();
long halfYearAgo = now - TimeUnit.DAYS.toMillis(180);
TPSMutator tpsMutator = new TPSMutator(db.query(TPSQueries.fetchTPSDataOfServer(halfYearAgo, now, serverUUID)));
return '{' + "\"playersOnline\":" + lineGraphs.playersOnlineGraph(tpsMutator).toHighChartsSeries() + ",\"tps\":" + lineGraphs.tpsGraph(tpsMutator).toHighChartsSeries() + ",\"cpu\":" + lineGraphs.cpuGraph(tpsMutator).toHighChartsSeries() + ",\"ram\":" + lineGraphs.ramGraph(tpsMutator).toHighChartsSeries() + ",\"entities\":" + lineGraphs.entityGraph(tpsMutator).toHighChartsSeries() + ",\"chunks\":" + lineGraphs.chunkGraph(tpsMutator).toHighChartsSeries() + ",\"disk\":" + lineGraphs.diskGraph(tpsMutator).toHighChartsSeries() + ",\"colors\":{" + "\"playersOnline\":\"" + theme.getValue(ThemeVal.GRAPH_PLAYERS_ONLINE) + "\"," + "\"cpu\":\"" + theme.getValue(ThemeVal.GRAPH_CPU) + "\"," + "\"ram\":\"" + theme.getValue(ThemeVal.GRAPH_RAM) + "\"," + "\"entities\":\"" + theme.getValue(ThemeVal.GRAPH_ENTITIES) + "\"," + "\"chunks\":\"" + theme.getValue(ThemeVal.GRAPH_CHUNKS) + "\"," + "\"low\":\"" + theme.getValue(ThemeVal.GRAPH_TPS_LOW) + "\"," + "\"med\":\"" + theme.getValue(ThemeVal.GRAPH_TPS_MED) + "\"," + "\"high\":\"" + theme.getValue(ThemeVal.GRAPH_TPS_HIGH) + "\"}" + ",\"zones\":{" + "\"tpsThresholdMed\":" + config.get(DisplaySettings.GRAPH_TPS_THRESHOLD_MED) + ',' + "\"tpsThresholdHigh\":" + config.get(DisplaySettings.GRAPH_TPS_THRESHOLD_HIGH) + ',' + "\"diskThresholdMed\":" + config.get(DisplaySettings.GRAPH_DISK_THRESHOLD_MED) + ',' + "\"diskThresholdHigh\":" + config.get(DisplaySettings.GRAPH_DISK_THRESHOLD_HIGH) + "}}";
}
use of com.djrapitops.plan.storage.database.Database in project Plan by plan-player-analytics.
the class GraphJSONCreator method optimizedPerformanceGraphJSON.
public Map<String, Object> optimizedPerformanceGraphJSON(ServerUUID serverUUID, URIQuery query) {
// TODO Implement if performance issues become apparent.
long after = getAfter(query);
long now = System.currentTimeMillis();
long twoMonthsAgo = now - TimeUnit.DAYS.toMillis(60);
long monthAgo = now - TimeUnit.DAYS.toMillis(30);
long lowestResolution = TimeUnit.MINUTES.toMillis(20);
long lowResolution = TimeUnit.MINUTES.toMillis(5);
Database db = dbSystem.getDatabase();
TPSMutator lowestResolutionData = new TPSMutator(db.query(TPSQueries.fetchTPSDataOfServerInResolution(0, twoMonthsAgo, lowestResolution, serverUUID)));
TPSMutator lowResolutionData = new TPSMutator(db.query(TPSQueries.fetchTPSDataOfServerInResolution(twoMonthsAgo, monthAgo, lowResolution, serverUUID)));
TPSMutator highResolutionData = new TPSMutator(db.query(TPSQueries.fetchTPSDataOfServer(monthAgo, now, serverUUID)));
String serverName = db.query(ServerQueries.fetchServerMatchingIdentifier(serverUUID)).map(Server::getIdentifiableName).orElse(serverUUID.toString());
List<Number[]> values = lowestResolutionData.toArrays(new LineGraph.GapStrategy(config.isTrue(DisplaySettings.GAPS_IN_GRAPH_DATA), lowestResolution + TimeUnit.MINUTES.toMillis(1), TimeUnit.MINUTES.toMillis(1), TimeUnit.MINUTES.toMillis(30), null));
values.addAll(lowResolutionData.toArrays(new LineGraph.GapStrategy(config.isTrue(DisplaySettings.GAPS_IN_GRAPH_DATA), lowResolution + TimeUnit.MINUTES.toMillis(1), TimeUnit.MINUTES.toMillis(1), TimeUnit.MINUTES.toMillis(30), null)));
values.addAll(highResolutionData.toArrays(new LineGraph.GapStrategy(config.isTrue(DisplaySettings.GAPS_IN_GRAPH_DATA), TimeUnit.MINUTES.toMillis(3), TimeUnit.MINUTES.toMillis(1), TimeUnit.MINUTES.toMillis(30), null)));
return Maps.builder(String.class, Object.class).put("keys", new String[] { "date", "playersOnline", "tps", "cpu", "ram", "entities", "chunks", "disk" }).put("values", values).put("colors", Maps.builder(String.class, Object.class).put("playersOnline", theme.getValue(ThemeVal.GRAPH_PLAYERS_ONLINE)).put("cpu", theme.getValue(ThemeVal.GRAPH_CPU)).put("ram", theme.getValue(ThemeVal.GRAPH_RAM)).put("entities", theme.getValue(ThemeVal.GRAPH_ENTITIES)).put("chunks", theme.getValue(ThemeVal.GRAPH_CHUNKS)).put("low", theme.getValue(ThemeVal.GRAPH_TPS_LOW)).put("med", theme.getValue(ThemeVal.GRAPH_TPS_MED)).put("high", theme.getValue(ThemeVal.GRAPH_TPS_HIGH)).build()).put("zones", Maps.builder(String.class, Object.class).put("tpsThresholdMed", config.get(DisplaySettings.GRAPH_TPS_THRESHOLD_MED)).put("tpsThresholdHigh", config.get(DisplaySettings.GRAPH_TPS_THRESHOLD_HIGH)).put("diskThresholdMed", config.get(DisplaySettings.GRAPH_DISK_THRESHOLD_MED)).put("diskThresholdHigh", config.get(DisplaySettings.GRAPH_DISK_THRESHOLD_HIGH)).build()).put("serverName", serverName).put("serverUUID", serverUUID).build();
}
use of com.djrapitops.plan.storage.database.Database in project Plan by plan-player-analytics.
the class ExportScheduler method scheduleExport.
private void scheduleExport() {
Database database = dbSystem.getDatabase();
boolean hasProxy = database.query(ServerQueries.fetchProxyServerInformation()).isPresent();
if (serverInfo.getServer().isNotProxy() && hasProxy) {
return;
}
scheduleServerPageExport();
schedulePlayersPageExport();
}
use of com.djrapitops.plan.storage.database.Database in project Plan by plan-player-analytics.
the class OnlineActivityOverviewJSONCreator method createNumbersMap.
private Map<String, Object> createNumbersMap(ServerUUID serverUUID) {
Database db = dbSystem.getDatabase();
long now = System.currentTimeMillis();
long dayAgo = now - TimeUnit.DAYS.toMillis(1L);
long weekAgo = now - TimeUnit.DAYS.toMillis(7L);
long halfMonthAgo = now - TimeUnit.DAYS.toMillis(15L);
long monthAgo = now - TimeUnit.DAYS.toMillis(30L);
int timeZoneOffset = config.getTimeZone().getOffset(now);
Long playThreshold = config.get(TimeSettings.ACTIVE_PLAY_THRESHOLD);
Map<String, Object> numbers = new HashMap<>();
numbers.put("unique_players_30d", db.query(PlayerCountQueries.uniquePlayerCount(monthAgo, now, serverUUID)));
numbers.put("unique_players_30d_trend", new Trend(db.query(PlayerCountQueries.uniquePlayerCount(monthAgo, halfMonthAgo, serverUUID)), db.query(PlayerCountQueries.uniquePlayerCount(halfMonthAgo, now, serverUUID)), false));
numbers.put("unique_players_7d", db.query(PlayerCountQueries.uniquePlayerCount(weekAgo, now, serverUUID)));
numbers.put("unique_players_24h", db.query(PlayerCountQueries.uniquePlayerCount(dayAgo, now, serverUUID)));
numbers.put("unique_players_30d_avg", db.query(PlayerCountQueries.averageUniquePlayerCount(monthAgo, now, timeZoneOffset, serverUUID)));
numbers.put("unique_players_30d_avg_trend", new Trend(db.query(PlayerCountQueries.averageUniquePlayerCount(monthAgo, halfMonthAgo, timeZoneOffset, serverUUID)), db.query(PlayerCountQueries.averageUniquePlayerCount(halfMonthAgo, now, timeZoneOffset, serverUUID)), false));
numbers.put("unique_players_7d_avg", db.query(PlayerCountQueries.averageUniquePlayerCount(weekAgo, now, timeZoneOffset, serverUUID)));
numbers.put("unique_players_24h_avg", db.query(PlayerCountQueries.averageUniquePlayerCount(dayAgo, now, timeZoneOffset, serverUUID)));
Integer new30d = db.query(PlayerCountQueries.newPlayerCount(monthAgo, now, serverUUID));
Integer new7d = db.query(PlayerCountQueries.newPlayerCount(weekAgo, now, serverUUID));
Integer new1d = db.query(PlayerCountQueries.newPlayerCount(dayAgo, now, serverUUID));
numbers.put("new_players_30d", new30d);
numbers.put("new_players_30d_trend", new Trend(db.query(PlayerCountQueries.newPlayerCount(monthAgo, halfMonthAgo, serverUUID)), db.query(PlayerCountQueries.newPlayerCount(halfMonthAgo, now, serverUUID)), false));
numbers.put("new_players_7d", new7d);
numbers.put("new_players_24h", new1d);
numbers.put("new_players_30d_avg", db.query(PlayerCountQueries.averageNewPlayerCount(monthAgo, now, timeZoneOffset, serverUUID)));
numbers.put("new_players_30d_avg_trend", new Trend(db.query(PlayerCountQueries.averageNewPlayerCount(monthAgo, halfMonthAgo, timeZoneOffset, serverUUID)), db.query(PlayerCountQueries.averageNewPlayerCount(halfMonthAgo, now, timeZoneOffset, serverUUID)), false));
numbers.put("new_players_7d_avg", db.query(PlayerCountQueries.averageNewPlayerCount(weekAgo, now, timeZoneOffset, serverUUID)));
numbers.put("new_players_24h_avg", db.query(PlayerCountQueries.averageNewPlayerCount(dayAgo, now, timeZoneOffset, serverUUID)));
int retained30d = db.query(PlayerCountQueries.retainedPlayerCount(monthAgo, now, serverUUID));
int retained7d = db.query(PlayerCountQueries.retainedPlayerCount(weekAgo, now, serverUUID));
double retentionPercentage30d = Percentage.calculate(retained30d, new30d, -1);
double retentionPercentage7d = Percentage.calculate(retained7d, new7d, -1);
numbers.put("new_players_retention_30d", retained30d);
numbers.put("new_players_retention_30d_perc", percentageFormatter.apply(retentionPercentage30d));
numbers.put("new_players_retention_7d", retained7d);
numbers.put("new_players_retention_7d_perc", percentageFormatter.apply(retentionPercentage7d));
int prediction1d = RetentionData.countRetentionPrediction(db.query(ActivityIndexQueries.activityIndexForNewPlayers(dayAgo, now, serverUUID, playThreshold)), db.query(ActivityIndexQueries.averageActivityIndexForRetainedPlayers(monthAgo, now, serverUUID, playThreshold)), db.query(ActivityIndexQueries.averageActivityIndexForNonRetainedPlayers(monthAgo, now, serverUUID, playThreshold)));
double retentionPercentage1d = Percentage.calculate(prediction1d, new1d, -1);
numbers.put("new_players_retention_24h", prediction1d);
numbers.put("new_players_retention_24h_perc", percentageFormatter.apply(retentionPercentage1d));
Long playtimeMonth = db.query(SessionQueries.playtime(monthAgo, now, serverUUID));
Long playtimeWeek = db.query(SessionQueries.playtime(weekAgo, now, serverUUID));
Long playtimeDay = db.query(SessionQueries.playtime(dayAgo, now, serverUUID));
Long playtimeBefore = db.query(SessionQueries.playtime(monthAgo, halfMonthAgo, serverUUID));
Long playtimeAfter = db.query(SessionQueries.playtime(halfMonthAgo, now, serverUUID));
numbers.put("playtime_30d", timeAmountFormatter.apply(playtimeMonth));
numbers.put("playtime_30d_trend", new Trend(playtimeBefore, playtimeAfter, false, timeAmountFormatter));
numbers.put("playtime_7d", timeAmountFormatter.apply(playtimeWeek));
numbers.put("playtime_24h", timeAmountFormatter.apply(playtimeDay));
numbers.put("playtime_30d_avg", timeAmountFormatter.apply(db.query(SessionQueries.averagePlaytimePerDay(monthAgo, now, timeZoneOffset, serverUUID))));
numbers.put("playtime_30d_avg_trend", new Trend(db.query(SessionQueries.averagePlaytimePerDay(monthAgo, halfMonthAgo, timeZoneOffset, serverUUID)), db.query(SessionQueries.averagePlaytimePerDay(halfMonthAgo, now, timeZoneOffset, serverUUID)), false, timeAmountFormatter));
numbers.put("playtime_7d_avg", timeAmountFormatter.apply(db.query(SessionQueries.averagePlaytimePerDay(weekAgo, now, timeZoneOffset, serverUUID))));
numbers.put("playtime_24h_avg", timeAmountFormatter.apply(db.query(SessionQueries.playtime(dayAgo, now, serverUUID))));
Long sessionsMonth = db.query(SessionQueries.sessionCount(monthAgo, now, serverUUID));
Long sessionsWeek = db.query(SessionQueries.sessionCount(weekAgo, now, serverUUID));
Long sessionsDay = db.query(SessionQueries.sessionCount(dayAgo, now, serverUUID));
Long sessionsBefore = db.query(SessionQueries.sessionCount(monthAgo, halfMonthAgo, serverUUID));
Long sessionsAfter = db.query(SessionQueries.sessionCount(halfMonthAgo, now, serverUUID));
numbers.put("sessions_30d", sessionsMonth);
numbers.put("sessions_30d_trend", new Trend(sessionsBefore, sessionsAfter, false));
numbers.put("sessions_7d", sessionsWeek);
numbers.put("sessions_24h", sessionsDay);
Long sessionLengthAvgMonth = sessionsMonth != 0 ? playtimeMonth / sessionsMonth : 0;
Long sessionLengthAvgWeek = sessionsWeek != 0 ? playtimeWeek / sessionsWeek : 0;
Long sessionLengthAvgDay = sessionsDay != 0 ? playtimeDay / sessionsDay : 0;
numbers.put("session_length_30d_avg", timeAmountFormatter.apply(sessionLengthAvgMonth));
numbers.put("session_length_30d_trend", new Trend(sessionsBefore != 0 ? playtimeBefore / sessionsBefore : 0, sessionsAfter != 0 ? playtimeAfter / sessionsAfter : 0, false, timeAmountFormatter));
numbers.put("session_length_7d_avg", timeAmountFormatter.apply(sessionLengthAvgWeek));
numbers.put("session_length_24h_avg", timeAmountFormatter.apply(sessionLengthAvgDay));
TPSMutator tpsMutator = new TPSMutator(db.query(TPSQueries.fetchTPSDataOfServer(monthAgo, now, serverUUID)));
numbers.put("average_tps", decimalFormatter.apply(tpsMutator.averageTPS()));
numbers.put("low_tps_spikes", tpsMutator.lowTpsSpikeCount(config.get(DisplaySettings.GRAPH_TPS_THRESHOLD_MED)));
numbers.put("downtime", timeAmountFormatter.apply(tpsMutator.serverDownTime()));
return numbers;
}
Aggregations