Search in sources :

Example 11 with TPS

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;
        }
    };
}
Also used : TPS(com.djrapitops.plan.gathering.domain.TPS) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) QueryStatement(com.djrapitops.plan.storage.database.queries.QueryStatement)

Example 12 with TPS

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());
}
Also used : TPS(com.djrapitops.plan.gathering.domain.TPS) Test(org.junit.jupiter.api.Test)

Example 13 with TPS

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;
}
Also used : TPS(com.djrapitops.plan.gathering.domain.TPS) TPSMutator(com.djrapitops.plan.delivery.domain.mutators.TPSMutator)

Example 14 with TPS

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;
}
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 15 with TPS

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;
}
Also used : HashMap(java.util.HashMap) TPS(com.djrapitops.plan.gathering.domain.TPS) Database(com.djrapitops.plan.storage.database.Database)

Aggregations

TPS (com.djrapitops.plan.gathering.domain.TPS)19 Test (org.junit.jupiter.api.Test)7 Database (com.djrapitops.plan.storage.database.Database)5 TPSMutator (com.djrapitops.plan.delivery.domain.mutators.TPSMutator)3 ServerUUID (com.djrapitops.plan.identification.ServerUUID)3 TPSStoreTransaction (com.djrapitops.plan.storage.database.transactions.events.TPSStoreTransaction)3 TPSComparator (com.djrapitops.plan.utilities.comparators.TPSComparator)3 ResultSet (java.sql.ResultSet)3 HashMap (java.util.HashMap)3 Point (com.djrapitops.plan.delivery.rendering.json.graphs.line.Point)2 QueryStatement (com.djrapitops.plan.storage.database.queries.QueryStatement)2 Lists (com.djrapitops.plan.utilities.java.Lists)2 PreparedStatement (java.sql.PreparedStatement)2 List (java.util.List)2 DateObj (com.djrapitops.plan.delivery.domain.DateObj)1 User (com.djrapitops.plan.delivery.domain.auth.User)1 PlayersOnlineResolver (com.djrapitops.plan.delivery.domain.mutators.PlayersOnlineResolver)1 SessionsMutator (com.djrapitops.plan.delivery.domain.mutators.SessionsMutator)1 FinishedSession (com.djrapitops.plan.gathering.domain.FinishedSession)1 GMTimes (com.djrapitops.plan.gathering.domain.GMTimes)1