use of com.djrapitops.plan.gathering.domain.TPS in project Plan by plan-player-analytics.
the class TPSQueries method fetchTPSDataOfServer.
public static Query<List<TPS>> fetchTPSDataOfServer(long after, long before, ServerUUID serverUUID) {
String sql = SELECT + "*" + FROM + TABLE_NAME + WHERE + SERVER_ID + "=" + ServerTable.SELECT_SERVER_ID + AND + DATE + ">=?" + AND + DATE + "<=?" + ORDER_BY + DATE;
return new QueryStatement<List<TPS>>(sql, 50000) {
@Override
public void prepare(PreparedStatement statement) throws SQLException {
statement.setString(1, serverUUID.toString());
statement.setLong(2, after);
statement.setLong(3, before);
}
@Override
public List<TPS> processResults(ResultSet set) throws SQLException {
List<TPS> data = new ArrayList<>();
while (set.next()) {
TPS tps = extractTPS(set);
data.add(tps);
}
return data;
}
};
}
use of com.djrapitops.plan.gathering.domain.TPS in project Plan by plan-player-analytics.
the class ImportBuilderTest method serverDataBuilderConstructsCorrectItem.
@Test
void serverDataBuilderConstructsCorrectItem() {
ServerImportData.ServerImportDataBuilder builder = ServerImportData.builder();
TPS tps = new TPS(randomInt, randomInt, randomInt, randomInt, randomInt, randomInt, randomInt, randomInt);
ServerImportData data = builder.tpsData(tps).tpsData(tps).tpsData(tps).tpsData(tps, tps, tps).tpsData(Collections.emptyList()).tpsData(randomInt, randomInt, randomInt, randomInt, randomInt, randomInt, randomInt).tpsData(Collections.singletonList(tps)).tpsData(Arrays.asList(tps, tps)).build();
assertEquals(10, data.getTpsData().size());
assertEquals(randomInt, data.getTpsData().get(0).getDate());
}
use of com.djrapitops.plan.gathering.domain.TPS 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.gathering.domain.TPS 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.gathering.domain.TPS in project Plan by plan-player-analytics.
the class PerformanceJSONCreator method createJSONAsMap.
@Override
public Map<String, Object> createJSONAsMap(ServerUUID serverUUID) {
Map<String, Object> serverOverview = new HashMap<>();
Database db = dbSystem.getDatabase();
long now = System.currentTimeMillis();
long monthAgo = now - TimeUnit.DAYS.toMillis(30L);
List<TPS> tpsData = db.query(TPSQueries.fetchTPSDataOfServer(monthAgo, now, serverUUID));
serverOverview.put("numbers", createNumbersMap(tpsData));
serverOverview.put("insights", createInsightsMap(tpsData));
return serverOverview;
}
Aggregations