Search in sources :

Example 1 with TPSMutator

use of com.djrapitops.plan.delivery.domain.mutators.TPSMutator in project Plan by plan-player-analytics.

the class PerformanceJSONCreator method createNumbersMap.

private Map<String, Object> createNumbersMap(List<TPS> tpsData) {
    long now = System.currentTimeMillis();
    long dayAgo = now - TimeUnit.DAYS.toMillis(1L);
    long weekAgo = now - TimeUnit.DAYS.toMillis(7L);
    Map<String, Object> numbers = new HashMap<>();
    TPSMutator tpsDataMonth = new TPSMutator(tpsData);
    TPSMutator tpsDataWeek = tpsDataMonth.filterDataBetween(weekAgo, now);
    TPSMutator tpsDataDay = tpsDataWeek.filterDataBetween(dayAgo, now);
    Double tpsThreshold = config.get(DisplaySettings.GRAPH_TPS_THRESHOLD_MED);
    numbers.put("low_tps_spikes_30d", tpsDataMonth.lowTpsSpikeCount(tpsThreshold));
    numbers.put("low_tps_spikes_7d", tpsDataWeek.lowTpsSpikeCount(tpsThreshold));
    numbers.put("low_tps_spikes_24h", tpsDataDay.lowTpsSpikeCount(tpsThreshold));
    numbers.put("server_downtime_30d", timeAmount.apply(tpsDataMonth.serverDownTime()));
    numbers.put("server_downtime_7d", timeAmount.apply(tpsDataWeek.serverDownTime()));
    numbers.put("server_downtime_24h", timeAmount.apply(tpsDataDay.serverDownTime()));
    numbers.put("tps_30d", format(tpsDataMonth.averageTPS()));
    numbers.put("tps_7d", format(tpsDataWeek.averageTPS()));
    numbers.put("tps_24h", format(tpsDataDay.averageTPS()));
    numbers.put("cpu_30d", formatPercentage(tpsDataMonth.averageCPU()));
    numbers.put("cpu_7d", formatPercentage(tpsDataWeek.averageCPU()));
    numbers.put("cpu_24h", formatPercentage(tpsDataDay.averageCPU()));
    numbers.put("ram_30d", formatBytes(tpsDataMonth.averageRAM()));
    numbers.put("ram_7d", formatBytes(tpsDataWeek.averageRAM()));
    numbers.put("ram_24h", formatBytes(tpsDataDay.averageRAM()));
    numbers.put("entities_30d", format((int) tpsDataMonth.averageEntities()));
    numbers.put("entities_7d", format((int) tpsDataWeek.averageEntities()));
    numbers.put("entities_24h", format((int) tpsDataDay.averageEntities()));
    numbers.put("chunks_30d", format((int) tpsDataMonth.averageChunks()));
    numbers.put("chunks_7d", format((int) tpsDataWeek.averageChunks()));
    numbers.put("chunks_24h", format((int) tpsDataDay.averageChunks()));
    numbers.put("max_disk_30d", formatBytes(tpsDataMonth.maxFreeDisk()));
    numbers.put("max_disk_7d", formatBytes(tpsDataWeek.maxFreeDisk()));
    numbers.put("max_disk_24h", formatBytes(tpsDataDay.maxFreeDisk()));
    numbers.put("min_disk_30d", formatBytes(tpsDataMonth.minFreeDisk()));
    numbers.put("min_disk_7d", formatBytes(tpsDataWeek.minFreeDisk()));
    numbers.put("min_disk_24h", formatBytes(tpsDataDay.minFreeDisk()));
    return numbers;
}
Also used : HashMap(java.util.HashMap) TPSMutator(com.djrapitops.plan.delivery.domain.mutators.TPSMutator)

Example 2 with TPSMutator

use of com.djrapitops.plan.delivery.domain.mutators.TPSMutator in project Plan by plan-player-analytics.

the class ServerOverviewJSONCreator method createLast7DaysMap.

private Map<String, Object> createLast7DaysMap(ServerUUID serverUUID) {
    Database db = dbSystem.getDatabase();
    long now = System.currentTimeMillis();
    long weekAgo = now - TimeUnit.DAYS.toMillis(7L);
    Map<String, Object> sevenDays = new HashMap<>();
    sevenDays.put("unique_players", db.query(PlayerCountQueries.uniquePlayerCount(weekAgo, now, serverUUID)));
    sevenDays.put("unique_players_day", db.query(PlayerCountQueries.averageUniquePlayerCount(weekAgo, now, config.getTimeZone().getOffset(now), serverUUID)));
    int new7d = db.query(PlayerCountQueries.newPlayerCount(weekAgo, now, serverUUID));
    int retained7d = db.query(PlayerCountQueries.retainedPlayerCount(weekAgo, now, serverUUID));
    double retentionPercentage7d = Percentage.calculate(retained7d, new7d, -1);
    sevenDays.put("new_players", new7d);
    sevenDays.put("new_players_retention", retained7d);
    sevenDays.put("new_players_retention_perc", percentage.apply(retentionPercentage7d));
    TPSMutator tpsMutator = new TPSMutator(db.query(TPSQueries.fetchTPSDataOfServer(weekAgo, now, serverUUID)));
    double averageTPS = tpsMutator.averageTPS();
    sevenDays.put("average_tps", averageTPS != -1 ? decimals.apply(averageTPS) : locale.get(GenericLang.UNAVAILABLE).toString());
    sevenDays.put("low_tps_spikes", tpsMutator.lowTpsSpikeCount(config.get(DisplaySettings.GRAPH_TPS_THRESHOLD_MED)));
    sevenDays.put("downtime", timeAmount.apply(tpsMutator.serverDownTime()));
    return sevenDays;
}
Also used : HashMap(java.util.HashMap) Database(com.djrapitops.plan.storage.database.Database) TPSMutator(com.djrapitops.plan.delivery.domain.mutators.TPSMutator)

Example 3 with TPSMutator

use of com.djrapitops.plan.delivery.domain.mutators.TPSMutator 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) + "}}";
}
Also used : Database(com.djrapitops.plan.storage.database.Database) LineGraphFactory(com.djrapitops.plan.delivery.rendering.json.graphs.line.LineGraphFactory) TPSMutator(com.djrapitops.plan.delivery.domain.mutators.TPSMutator)

Example 4 with TPSMutator

use of com.djrapitops.plan.delivery.domain.mutators.TPSMutator 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();
}
Also used : Database(com.djrapitops.plan.storage.database.Database) LineGraph(com.djrapitops.plan.delivery.rendering.json.graphs.line.LineGraph) TPSMutator(com.djrapitops.plan.delivery.domain.mutators.TPSMutator)

Example 5 with TPSMutator

use of com.djrapitops.plan.delivery.domain.mutators.TPSMutator 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;
}
Also used : HashMap(java.util.HashMap) Database(com.djrapitops.plan.storage.database.Database) TPSMutator(com.djrapitops.plan.delivery.domain.mutators.TPSMutator)

Aggregations

TPSMutator (com.djrapitops.plan.delivery.domain.mutators.TPSMutator)11 Database (com.djrapitops.plan.storage.database.Database)7 HashMap (java.util.HashMap)5 TPS (com.djrapitops.plan.gathering.domain.TPS)3 SessionsMutator (com.djrapitops.plan.delivery.domain.mutators.SessionsMutator)2 ServerUUID (com.djrapitops.plan.identification.ServerUUID)2 DateObj (com.djrapitops.plan.delivery.domain.DateObj)1 ServerDto (com.djrapitops.plan.delivery.domain.datatransfer.ServerDto)1 PlayerKillMutator (com.djrapitops.plan.delivery.domain.mutators.PlayerKillMutator)1 PlayersOnlineResolver (com.djrapitops.plan.delivery.domain.mutators.PlayersOnlineResolver)1 Formatter (com.djrapitops.plan.delivery.formatting.Formatter)1 Formatters (com.djrapitops.plan.delivery.formatting.Formatters)1 Graphs (com.djrapitops.plan.delivery.rendering.json.graphs.Graphs)1 LineGraph (com.djrapitops.plan.delivery.rendering.json.graphs.line.LineGraph)1 LineGraphFactory (com.djrapitops.plan.delivery.rendering.json.graphs.line.LineGraphFactory)1 ExtensionTabData (com.djrapitops.plan.extension.implementation.results.ExtensionTabData)1 ExtensionServerTableDataQuery (com.djrapitops.plan.extension.implementation.storage.queries.ExtensionServerTableDataQuery)1 ServerUptimeCalculator (com.djrapitops.plan.gathering.ServerUptimeCalculator)1 SessionCache (com.djrapitops.plan.gathering.cache.SessionCache)1 com.djrapitops.plan.gathering.domain (com.djrapitops.plan.gathering.domain)1