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