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);
}
}
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;
}
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);
}
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;
}
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;
}
Aggregations