Search in sources :

Example 16 with TPS

use of com.djrapitops.plan.gathering.domain.TPS in project Plan by plan-player-analytics.

the class TPSMutator method serverOccupiedTime.

public long serverOccupiedTime() {
    long lastDate = -1;
    long activeTime = 0;
    tpsData.sort(new TPSComparator());
    for (TPS tps : tpsData) {
        long date = tps.getDate();
        if (lastDate == -1) {
            lastDate = date;
            continue;
        }
        int players = tps.getPlayers();
        long diff = date - lastDate;
        if (players > 0 && diff <= TimeUnit.MINUTES.toMillis(3L)) {
            activeTime += diff;
        }
        lastDate = date;
    }
    return activeTime;
}
Also used : TPS(com.djrapitops.plan.gathering.domain.TPS) TPSComparator(com.djrapitops.plan.utilities.comparators.TPSComparator) Point(com.djrapitops.plan.delivery.rendering.json.graphs.line.Point)

Example 17 with TPS

use of com.djrapitops.plan.gathering.domain.TPS in project Plan by plan-player-analytics.

the class TPSQueriesTest method tpsIsStored.

@Test
default void tpsIsStored() {
    List<TPS> expected = RandomData.randomTPS();
    for (TPS tps : expected) {
        execute(DataStoreQueries.storeTPS(serverUUID(), tps));
    }
    forcePersistenceCheck();
    expected.sort(new TPSComparator());
    assertEquals(expected, db().query(TPSQueries.fetchTPSDataOfServer(Long.MIN_VALUE, Long.MAX_VALUE, serverUUID())));
}
Also used : TPS(com.djrapitops.plan.gathering.domain.TPS) TPSComparator(com.djrapitops.plan.utilities.comparators.TPSComparator) Test(org.junit.jupiter.api.Test)

Example 18 with TPS

use of com.djrapitops.plan.gathering.domain.TPS in project Plan by plan-player-analytics.

the class TPSQueriesTest method serverStartDateIsCorrect.

@Test
default void serverStartDateIsCorrect() {
    List<TPS> tpsData = RandomData.randomTPS();
    TPS stored = tpsData.get(0);
    TPS stored2 = TPSBuilder.get().date(stored.getDate() + TimeUnit.MINUTES.toMillis(4L)).toTPS();
    TPS stored3 = TPSBuilder.get().date(stored.getDate() + TimeUnit.MINUTES.toMillis(5L)).toTPS();
    db().executeTransaction(new TPSStoreTransaction(serverUUID(), stored));
    db().executeTransaction(new TPSStoreTransaction(serverUUID(), stored2));
    db().executeTransaction(new TPSStoreTransaction(serverUUID(), stored3));
    Optional<Long> result = db().query(TPSQueries.fetchLatestServerStartTime(serverUUID(), TimeUnit.MINUTES.toMillis(3)));
    assertTrue(result.isPresent());
    assertEquals(stored2.getDate(), result.get());
}
Also used : TPS(com.djrapitops.plan.gathering.domain.TPS) TPSStoreTransaction(com.djrapitops.plan.storage.database.transactions.events.TPSStoreTransaction) Test(org.junit.jupiter.api.Test)

Example 19 with TPS

use of com.djrapitops.plan.gathering.domain.TPS in project Plan by plan-player-analytics.

the class SessionsOverviewJSONCreator method createInsightsMap.

private Map<String, Object> createInsightsMap(ServerUUID serverUUID) {
    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));
    TPSMutator tpsMutator = new TPSMutator(tpsData);
    Map<String, Object> insights = new HashMap<>();
    long uptime = TimeUnit.DAYS.toMillis(30L) - tpsMutator.serverDownTime();
    long occupied = tpsMutator.serverOccupiedTime();
    insights.put("server_occupied", timeAmount.apply(occupied));
    insights.put("server_occupied_perc", percentage.apply(Percentage.calculate(occupied, uptime, -1)));
    Long playtime = db.query(SessionQueries.playtime(monthAgo, now, serverUUID));
    Long afkTime = db.query(SessionQueries.afkTime(monthAgo, now, serverUUID));
    insights.put("total_playtime", timeAmount.apply(playtime));
    insights.put("afk_time", timeAmount.apply(afkTime));
    insights.put("afk_time_perc", percentage.apply(Percentage.calculate(afkTime, playtime, -1)));
    GMTimes gmTimes = db.query(WorldTimesQueries.fetchGMTimes(monthAgo, now, serverUUID));
    Optional<String> mostUsedGameMode = gmTimes.getMostUsedGameMode();
    Long longestGMTime = mostUsedGameMode.map(gmTimes::getTime).orElse(-1L);
    insights.put("most_active_gamemode", mostUsedGameMode.map(WordUtils::capitalizeFully).orElse("Not Known"));
    insights.put("most_active_gamemode_perc", percentage.apply(Percentage.calculate(longestGMTime, playtime, -1)));
    return insights;
}
Also used : GMTimes(com.djrapitops.plan.gathering.domain.GMTimes) WordUtils(org.apache.commons.text.WordUtils) TPS(com.djrapitops.plan.gathering.domain.TPS) Database(com.djrapitops.plan.storage.database.Database) TPSMutator(com.djrapitops.plan.delivery.domain.mutators.TPSMutator)

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