Search in sources :

Example 6 with TPSMutator

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

the class LineGraphTest method testLineGraphsForBracketErrors.

@Test
void testLineGraphsForBracketErrors() {
    TPSMutator mutator = new TPSMutator(DATA);
    LineGraph[] graphs = new LineGraph[] { new CPUGraph(mutator, true), new PlayersOnlineGraph(mutator, false), new RamGraph(mutator, true), new TPSGraph(mutator, false), new EntityGraph(mutator, true), new ChunkGraph(mutator, false), new DiskGraph(mutator, false) };
    for (LineGraph graph : graphs) {
        System.out.print("Bracket Test: " + graph.getClass().getSimpleName() + " | ");
        String series = graph.toHighChartsSeries();
        System.out.println(series);
        char[] chars = series.toCharArray();
        assertBracketMatch(chars);
    }
}
Also used : TPSMutator(com.djrapitops.plan.delivery.domain.mutators.TPSMutator) Test(org.junit.jupiter.api.Test)

Example 7 with TPSMutator

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

the class NetworkPerformanceJSONResolver method createNumbersMap.

private Map<String, Object> createNumbersMap(Map<Integer, 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<>();
    List<TPS> tpsDataOfAllServers = new ArrayList<>();
    tpsData.values().forEach(tpsDataOfAllServers::addAll);
    TPSMutator tpsDataMonth = new TPSMutator(tpsDataOfAllServers);
    TPSMutator tpsDataWeek = tpsDataMonth.filterDataBetween(weekAgo, now);
    TPSMutator tpsDataDay = tpsDataWeek.filterDataBetween(dayAgo, now);
    Map<Integer, TPSMutator> mutatorsOfServersMonth = new HashMap<>();
    Map<Integer, TPSMutator> mutatorsOfServersWeek = new HashMap<>();
    Map<Integer, TPSMutator> mutatorsOfServersDay = new HashMap<>();
    for (Map.Entry<Integer, List<TPS>> entry : tpsData.entrySet()) {
        TPSMutator mutator = new TPSMutator(entry.getValue());
        mutatorsOfServersMonth.put(entry.getKey(), mutator);
        mutatorsOfServersWeek.put(entry.getKey(), mutator.filterDataBetween(weekAgo, now));
        mutatorsOfServersDay.put(entry.getKey(), mutator.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));
    long downtimeMonth = getTotalDowntime(mutatorsOfServersMonth);
    long downtimeWeek = getTotalDowntime(mutatorsOfServersWeek);
    long downtimeDay = getTotalDowntime(mutatorsOfServersDay);
    numbers.put("server_downtime_30d", timeAmount.apply(downtimeMonth));
    numbers.put("server_downtime_7d", timeAmount.apply(downtimeWeek));
    numbers.put("server_downtime_24h", timeAmount.apply(downtimeDay));
    if (!tpsData.isEmpty()) {
        numbers.put("avg_server_downtime_30d", timeAmount.apply(downtimeMonth / tpsData.size()));
        numbers.put("avg_server_downtime_7d", timeAmount.apply(downtimeWeek / tpsData.size()));
        numbers.put("avg_server_downtime_24h", timeAmount.apply(downtimeDay / tpsData.size()));
    } else {
        numbers.put("avg_server_downtime_30d", "-");
        numbers.put("avg_server_downtime_7d", "-");
        numbers.put("avg_server_downtime_24h", "-");
    }
    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()));
    return numbers;
}
Also used : TPS(com.djrapitops.plan.gathering.domain.TPS) TPSMutator(com.djrapitops.plan.delivery.domain.mutators.TPSMutator)

Example 8 with TPSMutator

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

the class JSONFactory method serversAsJSONMaps.

public Map<String, Object> serversAsJSONMaps() {
    Database db = dbSystem.getDatabase();
    long now = System.currentTimeMillis();
    long weekAgo = now - TimeUnit.DAYS.toMillis(7L);
    Formatter<Long> year = formatters.yearLong();
    Formatter<Double> decimals = formatters.decimals();
    Formatter<Long> timeAmount = formatters.timeAmount();
    Map<ServerUUID, Server> serverInformation = db.query(ServerQueries.fetchPlanServerInformation());
    ServerUUID proxyUUID = serverInformation.values().stream().filter(Server::isProxy).findFirst().map(Server::getUuid).orElse(null);
    Map<ServerUUID, Integer> serverUuidToId = new HashMap<>();
    for (Server server : serverInformation.values()) {
        server.getId().ifPresent(serverId -> serverUuidToId.put(server.getUuid(), serverId));
    }
    Map<Integer, List<TPS>> tpsDataByServerId = db.query(TPSQueries.fetchTPSDataOfAllServersBut(weekAgo, now, proxyUUID));
    Map<ServerUUID, Integer> totalPlayerCounts = db.query(PlayerCountQueries.newPlayerCounts(0, now));
    Map<ServerUUID, Integer> newPlayerCounts = db.query(PlayerCountQueries.newPlayerCounts(weekAgo, now));
    Map<ServerUUID, Integer> uniquePlayerCounts = db.query(PlayerCountQueries.uniquePlayerCounts(weekAgo, now));
    List<Map<String, Object>> servers = new ArrayList<>();
    serverInformation.entrySet().stream().sorted(Comparator.comparing(entry -> entry.getValue().getIdentifiableName().toLowerCase())).filter(entry -> entry.getValue().isNotProxy()).forEach(entry -> {
        ServerUUID serverUUID = entry.getKey();
        Map<String, Object> server = new HashMap<>();
        server.put("name", entry.getValue().getIdentifiableName());
        Optional<DateObj<Integer>> recentPeak = db.query(TPSQueries.fetchPeakPlayerCount(serverUUID, now - TimeUnit.DAYS.toMillis(2L)));
        Optional<DateObj<Integer>> allTimePeak = db.query(TPSQueries.fetchAllTimePeakPlayerCount(serverUUID));
        server.put("last_peak_date", recentPeak.map(DateObj::getDate).map(year).orElse("-"));
        server.put("best_peak_date", allTimePeak.map(DateObj::getDate).map(year).orElse("-"));
        server.put("last_peak_players", recentPeak.map(DateObj::getValue).orElse(0));
        server.put("best_peak_players", allTimePeak.map(DateObj::getValue).orElse(0));
        TPSMutator tpsMonth = new TPSMutator(tpsDataByServerId.getOrDefault(serverUuidToId.get(serverUUID), Collections.emptyList()));
        server.put("playersOnline", tpsMonth.all().stream().map(tps -> new double[] { tps.getDate(), tps.getPlayers() }).toArray(double[][]::new));
        server.put("players", totalPlayerCounts.getOrDefault(serverUUID, 0));
        server.put("new_players", newPlayerCounts.getOrDefault(serverUUID, 0));
        server.put("unique_players", uniquePlayerCounts.getOrDefault(serverUUID, 0));
        TPSMutator tpsWeek = tpsMonth.filterDataBetween(weekAgo, now);
        double averageTPS = tpsWeek.averageTPS();
        server.put("avg_tps", averageTPS != -1 ? decimals.apply(averageTPS) : locale.get(HtmlLang.UNIT_NO_DATA).toString());
        server.put("low_tps_spikes", tpsWeek.lowTpsSpikeCount(config.get(DisplaySettings.GRAPH_TPS_THRESHOLD_MED)));
        server.put("downtime", timeAmount.apply(tpsWeek.serverDownTime()));
        server.put("current_uptime", serverUptimeCalculator.getServerUptimeMillis(serverUUID).map(timeAmount).orElse(locale.getString(GenericLang.UNAVAILABLE)));
        Optional<TPS> online = tpsWeek.getLast();
        server.put("online", online.map(point -> point.getDate() >= now - TimeUnit.MINUTES.toMillis(3L) ? point.getPlayers() : "Possibly offline").orElse(locale.get(HtmlLang.UNIT_NO_DATA).toString()));
        servers.add(server);
    });
    return Collections.singletonMap("servers", servers);
}
Also used : HtmlLang(com.djrapitops.plan.settings.locale.lang.HtmlLang) java.util(java.util) PlanConfig(com.djrapitops.plan.settings.config.PlanConfig) ServerTablePlayersQuery(com.djrapitops.plan.storage.database.queries.objects.playertable.ServerTablePlayersQuery) ServerUUID(com.djrapitops.plan.identification.ServerUUID) TPSMutator(com.djrapitops.plan.delivery.domain.mutators.TPSMutator) Singleton(javax.inject.Singleton) Database(com.djrapitops.plan.storage.database.Database) DBSystem(com.djrapitops.plan.storage.database.DBSystem) Inject(javax.inject.Inject) Graphs(com.djrapitops.plan.delivery.rendering.json.graphs.Graphs) TimeSettings(com.djrapitops.plan.settings.config.paths.TimeSettings) NetworkTablePlayersQuery(com.djrapitops.plan.storage.database.queries.objects.playertable.NetworkTablePlayersQuery) DateObj(com.djrapitops.plan.delivery.domain.DateObj) ServerUptimeCalculator(com.djrapitops.plan.gathering.ServerUptimeCalculator) ServerDto(com.djrapitops.plan.delivery.domain.datatransfer.ServerDto) ExtensionTabData(com.djrapitops.plan.extension.implementation.results.ExtensionTabData) SessionCache(com.djrapitops.plan.gathering.cache.SessionCache) Maps(com.djrapitops.plan.utilities.java.Maps) SessionsMutator(com.djrapitops.plan.delivery.domain.mutators.SessionsMutator) com.djrapitops.plan.gathering.domain(com.djrapitops.plan.gathering.domain) ServerInfo(com.djrapitops.plan.identification.ServerInfo) GenericLang(com.djrapitops.plan.settings.locale.lang.GenericLang) ExtensionServerTableDataQuery(com.djrapitops.plan.extension.implementation.storage.queries.ExtensionServerTableDataQuery) PlayerKillMutator(com.djrapitops.plan.delivery.domain.mutators.PlayerKillMutator) Formatters(com.djrapitops.plan.delivery.formatting.Formatters) SessionStartComparator(com.djrapitops.plan.utilities.comparators.SessionStartComparator) Collectors(java.util.stream.Collectors) TimeUnit(java.util.concurrent.TimeUnit) Server(com.djrapitops.plan.identification.Server) Locale(com.djrapitops.plan.settings.locale.Locale) com.djrapitops.plan.storage.database.queries.objects(com.djrapitops.plan.storage.database.queries.objects) DisplaySettings(com.djrapitops.plan.settings.config.paths.DisplaySettings) Formatter(com.djrapitops.plan.delivery.formatting.Formatter) PlayerCountQueries(com.djrapitops.plan.storage.database.queries.analysis.PlayerCountQueries) Server(com.djrapitops.plan.identification.Server) Database(com.djrapitops.plan.storage.database.Database) ServerUUID(com.djrapitops.plan.identification.ServerUUID) DateObj(com.djrapitops.plan.delivery.domain.DateObj) TPSMutator(com.djrapitops.plan.delivery.domain.mutators.TPSMutator)

Example 9 with TPSMutator

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

the class OnlineActivityOverviewJSONCreator method createInsightsMap.

private Map<String, Object> createInsightsMap(ServerUUID serverUUID) {
    Database db = dbSystem.getDatabase();
    long now = System.currentTimeMillis();
    long halfMonthAgo = now - TimeUnit.DAYS.toMillis(15L);
    long monthAgo = now - TimeUnit.DAYS.toMillis(30L);
    Map<String, Object> insights = new HashMap<>();
    SessionsMutator sessions = new SessionsMutator(db.query(SessionQueries.fetchServerSessionsWithoutKillOrWorldData(monthAgo, now, serverUUID)));
    List<TPS> tpsData = db.query(TPSQueries.fetchTPSDataOfServer(monthAgo, now, serverUUID));
    Map<UUID, Long> registerDates = db.query(UserInfoQueries.fetchRegisterDates(monthAgo, now, serverUUID));
    PlayersOnlineResolver playersOnlineResolver = new PlayersOnlineResolver(new TPSMutator(tpsData));
    SessionsMutator firstSessions = sessions.filterBy(session -> {
        long registered = registerDates.getOrDefault(session.getPlayerUUID(), -501L);
        long start = session.getDate();
        return Math.abs(registered - start) < 500L;
    });
    SessionsMutator firstSessionsBefore = firstSessions.filterSessionsBetween(monthAgo, halfMonthAgo);
    SessionsMutator firstSessionsAfter = firstSessions.filterSessionsBetween(halfMonthAgo, now);
    long avgFirstSessionLength = firstSessions.toAverageSessionLength();
    long avgFirstSessionLengthBefore = firstSessionsBefore.toAverageSessionLength();
    long avgFirstSessionLengthAfter = firstSessionsAfter.toAverageSessionLength();
    insights.put("first_session_length_avg", timeAmountFormatter.apply(avgFirstSessionLength));
    insights.put("first_session_length_trend", new Trend(avgFirstSessionLengthBefore, avgFirstSessionLengthAfter, false, timeAmountFormatter));
    long medianFirstSessionLength = firstSessions.toMedianSessionLength();
    long medianFirstSessionLengthBefore = firstSessionsBefore.toMedianSessionLength();
    long medianFirstSessionLengthAfter = firstSessionsAfter.toMedianSessionLength();
    insights.put("first_session_length_median", timeAmountFormatter.apply(medianFirstSessionLength));
    insights.put("first_session_length_median_trend", new Trend(medianFirstSessionLengthBefore, medianFirstSessionLengthAfter, false, timeAmountFormatter));
    int lonelyJoins = playersOnlineResolver.findLonelyJoins(sessions.toSessionStarts());
    int loneJoinsBefore = playersOnlineResolver.findLonelyJoins(sessions.filterSessionsBetween(monthAgo, halfMonthAgo).toSessionStarts());
    int loneJoinsAfter = playersOnlineResolver.findLonelyJoins(sessions.filterSessionsBetween(halfMonthAgo, now).toSessionStarts());
    insights.put("lone_joins", lonelyJoins);
    insights.put("lone_joins_trend", new Trend(loneJoinsBefore, loneJoinsAfter, true));
    int newLonelyJoins = playersOnlineResolver.findLonelyJoins(firstSessions.toSessionStarts());
    int newLoneJoinsBefore = playersOnlineResolver.findLonelyJoins(firstSessionsBefore.toSessionStarts());
    int newLoneJoinsAfter = playersOnlineResolver.findLonelyJoins(firstSessionsAfter.toSessionStarts());
    insights.put("lone_new_joins", newLonelyJoins);
    insights.put("lone_new_joins_trend", new Trend(newLoneJoinsBefore, newLoneJoinsAfter, true));
    double playersOnlineOnRegister = firstSessions.toAveragePlayersOnline(playersOnlineResolver);
    double playersOnlineOnRegisterBefore = firstSessionsBefore.toAveragePlayersOnline(playersOnlineResolver);
    double playersOnlineOnRegisterAfter = firstSessionsAfter.toAveragePlayersOnline(playersOnlineResolver);
    insights.put("players_first_join_avg", decimalFormatter.apply(playersOnlineOnRegister));
    insights.put("players_first_join_trend", new Trend(playersOnlineOnRegisterBefore, playersOnlineOnRegisterAfter, false, decimalFormatter));
    return insights;
}
Also used : HashMap(java.util.HashMap) PlayersOnlineResolver(com.djrapitops.plan.delivery.domain.mutators.PlayersOnlineResolver) TPS(com.djrapitops.plan.gathering.domain.TPS) Database(com.djrapitops.plan.storage.database.Database) ServerUUID(com.djrapitops.plan.identification.ServerUUID) UUID(java.util.UUID) SessionsMutator(com.djrapitops.plan.delivery.domain.mutators.SessionsMutator) TPSMutator(com.djrapitops.plan.delivery.domain.mutators.TPSMutator)

Example 10 with TPSMutator

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

the class PerformanceJSONCreator method createInsightsMap.

private Map<String, Object> createInsightsMap(List<TPS> tpsData) {
    TPSMutator tpsMutator = new TPSMutator(tpsData);
    Double tpsThreshold = config.get(DisplaySettings.GRAPH_TPS_THRESHOLD_MED);
    TPSMutator lowTPS = tpsMutator.filterTPSBetween(-1, tpsThreshold);
    Map<String, Object> insights = new HashMap<>();
    double averageTPS = lowTPS.averageTPS();
    double avgPlayersOnline = lowTPS.averagePlayersOnline();
    double averageCPU = lowTPS.averageCPU();
    double averageEntities = lowTPS.averageEntities();
    double averageChunks = lowTPS.averageChunks();
    insights.put("low_tps_players", avgPlayersOnline != -1 ? decimals.apply(avgPlayersOnline) : locale.get(HtmlLang.TEXT_NO_LOW_TPS).toString());
    insights.put("low_tps_tps", averageTPS != -1 ? decimals.apply(averageTPS) : "-");
    insights.put("low_tps_cpu", averageCPU != -1 ? decimals.apply(averageCPU) : "-");
    insights.put("low_tps_entities", averageEntities != -1 ? decimals.apply(averageEntities) : "-");
    insights.put("low_tps_chunks", averageChunks != -1 ? decimals.apply(averageChunks) : "-");
    return insights;
}
Also used : HashMap(java.util.HashMap) 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