use of com.djrapitops.plan.gathering.domain.FinishedSession in project Plan by plan-player-analytics.
the class JSErrorRegressionTest method savePlayerData.
private static void savePlayerData() {
DBSystem dbSystem = planSystem.getDatabaseSystem();
Database database = dbSystem.getDatabase();
UUID uuid = TestConstants.PLAYER_ONE_UUID;
database.executeTransaction(new PlayerRegisterTransaction(uuid, RandomData::randomTime, TestConstants.PLAYER_ONE_NAME));
FinishedSession session = new FinishedSession(uuid, serverUUID, 1000L, 11000L, 500L, new DataMap());
database.executeTransaction(new WorldNameStoreTransaction(serverUUID, "world"));
database.executeTransaction(new StoreSessionTransaction(session));
}
use of com.djrapitops.plan.gathering.domain.FinishedSession in project Plan by plan-player-analytics.
the class ShutdownSaveTest method endedSessionsHaveSameEndTime.
@Test
void endedSessionsHaveSameEndTime() {
for (int i = 0; i < 100; i++) {
UUID playerUUID = UUID.randomUUID();
ActiveSession session = RandomData.randomUnfinishedSession(TestConstants.SERVER_UUID, new String[] { "w1", "w2" }, playerUUID);
sessionCache.cacheSession(playerUUID, session);
}
long endTime = System.currentTimeMillis();
Collection<ActiveSession> activeSessions = SessionCache.getActiveSessions();
for (FinishedSession session : underTest.finishSessions(activeSessions, endTime)) {
assertEquals(endTime, session.getEnd(), "One of the sessions had differing end time");
}
}
use of com.djrapitops.plan.gathering.domain.FinishedSession in project Plan by plan-player-analytics.
the class SessionCacheTest method sessionsAreRemovedFromCacheOnEnd.
@Test
void sessionsAreRemovedFromCacheOnEnd() {
Optional<FinishedSession> ended = new SessionCache().endSession(uuid, System.currentTimeMillis());
assertTrue(ended.isPresent());
for (ActiveSession session : SessionCache.getActiveSessions()) {
fail("Session was still in cache: " + session);
}
}
use of com.djrapitops.plan.gathering.domain.FinishedSession in project Plan by plan-player-analytics.
the class PlayerContainerQuery method executeQuery.
@Override
public PlayerContainer executeQuery(SQLDB db) {
PlayerContainer container = new PlayerContainer();
container.putRawData(PlayerKeys.UUID, uuid);
Key<BaseUser> baseUserKey = new Key<>(BaseUser.class, "BASE_USER");
container.putSupplier(baseUserKey, () -> db.query(BaseUserQueries.fetchBaseUserOfPlayer(uuid)).orElse(null));
container.putSupplier(PlayerKeys.REGISTERED, () -> container.getValue(baseUserKey).map(BaseUser::getRegistered).orElse(null));
container.putSupplier(PlayerKeys.NAME, () -> container.getValue(baseUserKey).map(BaseUser::getName).orElse(null));
container.putSupplier(PlayerKeys.KICK_COUNT, () -> container.getValue(baseUserKey).map(BaseUser::getTimesKicked).orElse(null));
container.putCachingSupplier(PlayerKeys.GEO_INFO, () -> db.query(GeoInfoQueries.fetchPlayerGeoInformation(uuid)));
container.putCachingSupplier(PlayerKeys.PING, () -> db.query(PingQueries.fetchPingDataOfPlayer(uuid)));
container.putCachingSupplier(PlayerKeys.NICKNAMES, () -> db.query(NicknameQueries.fetchNicknameDataOfPlayer(uuid)));
container.putCachingSupplier(PlayerKeys.PER_SERVER, () -> db.query(new PerServerContainerQuery(uuid)));
container.putSupplier(PlayerKeys.BANNED, () -> new PerServerMutator(container.getValue(PlayerKeys.PER_SERVER).orElse(new PerServerContainer())).isBanned());
container.putSupplier(PlayerKeys.OPERATOR, () -> new PerServerMutator(container.getValue(PlayerKeys.PER_SERVER).orElse(new PerServerContainer())).isOperator());
container.putCachingSupplier(PlayerKeys.SESSIONS, () -> {
List<FinishedSession> sessions = new PerServerMutator(container.getValue(PlayerKeys.PER_SERVER).orElse(new PerServerContainer())).flatMapSessions();
container.getValue(PlayerKeys.ACTIVE_SESSION).map(ActiveSession::toFinishedSessionFromStillActive).ifPresent(sessions::add);
return sessions;
});
container.putCachingSupplier(PlayerKeys.WORLD_TIMES, () -> {
WorldTimes worldTimes = db.query(WorldTimesQueries.fetchPlayerTotalWorldTimes(uuid));
container.getValue(PlayerKeys.ACTIVE_SESSION).ifPresent(session -> worldTimes.add(session.getExtraData(WorldTimes.class).orElseGet(WorldTimes::new)));
return worldTimes;
});
container.putSupplier(PlayerKeys.LAST_SEEN, () -> SessionsMutator.forContainer(container).toLastSeen());
container.putSupplier(PlayerKeys.PLAYER_KILLS, () -> db.query(KillQueries.fetchPlayerKillsOfPlayer(uuid)));
container.putSupplier(PlayerKeys.PLAYER_DEATHS_KILLS, () -> db.query(KillQueries.fetchPlayerDeathsOfPlayer(uuid)));
container.putSupplier(PlayerKeys.PLAYER_KILL_COUNT, () -> container.getValue(PlayerKeys.PLAYER_KILLS).map(Collection::size).orElse(0));
container.putSupplier(PlayerKeys.MOB_KILL_COUNT, () -> SessionsMutator.forContainer(container).toMobKillCount());
container.putSupplier(PlayerKeys.DEATH_COUNT, () -> SessionsMutator.forContainer(container).toDeathCount());
SessionCache.getCachedSession(uuid).ifPresent(session -> container.putRawData(PlayerKeys.ACTIVE_SESSION, session));
return container;
}
use of com.djrapitops.plan.gathering.domain.FinishedSession in project Plan by plan-player-analytics.
the class ActivityIndexQueriesTest method activityIndexCalculationsMatch.
// @Test
// default void activityIndexCoalesceSanityCheck() {
// storeSessions();
// Map<String, Integer> groupings = db().query(
// ActivityIndexQueries.fetchActivityIndexGroupingsOn(System.currentTimeMillis(), serverUUID(), TimeUnit.HOURS.toMillis(2L))
// );
// Map<String, Integer> expected = Collections.singletonMap(ActivityIndex.getDefaultGroups()[4], 1); // Inactive
// assertEquals(expected, groupings);
// }
@RepeatedTest(value = 3, name = "Activity Index calculations match {currentRepetition}/{totalRepetitions}")
default void activityIndexCalculationsMatch() {
storeSessions(session -> true);
long date = System.currentTimeMillis();
long playtimeThreshold = TimeUnit.HOURS.toMillis(5L);
List<FinishedSession> sessions = db().query(SessionQueries.fetchSessionsOfPlayer(playerUUID)).values().stream().flatMap(Collection::stream).collect(Collectors.toList());
ActivityIndex javaCalculation = new ActivityIndex(sessions, date, playtimeThreshold);
List<TablePlayer> players = db().query(new ServerTablePlayersQuery(serverUUID(), date, playtimeThreshold, 5));
Optional<TablePlayer> found = players.stream().filter(tp -> playerUUID.equals(tp.getPlayerUUID())).findFirst();
assertTrue(found.isPresent());
Optional<ActivityIndex> currentActivityIndex = found.get().getCurrentActivityIndex();
assertTrue(currentActivityIndex.isPresent());
assertEquals(javaCalculation.getValue(), currentActivityIndex.get().getValue(), 0.001, () -> {
StringBuilder errorMsg = new StringBuilder("Activity indexes did not match\n");
long week = TimeUnit.DAYS.toMillis(7L);
long weekAgo = date - week;
long twoWeeksAgo = date - 2L * week;
long threeWeeksAgo = date - 3L * week;
SessionsMutator mutator = new SessionsMutator(sessions);
SessionsMutator w1 = mutator.filterSessionsBetween(weekAgo, date);
SessionsMutator w2 = mutator.filterSessionsBetween(twoWeeksAgo, weekAgo);
SessionsMutator w3 = mutator.filterSessionsBetween(threeWeeksAgo, twoWeeksAgo);
Long dbW1 = db().query(SessionQueries.activePlaytime(weekAgo, date, serverUUID()));
Long dbW2 = db().query(SessionQueries.activePlaytime(twoWeeksAgo, weekAgo, serverUUID()));
Long dbW3 = db().query(SessionQueries.activePlaytime(threeWeeksAgo, twoWeeksAgo, serverUUID()));
errorMsg.append("Java calculation playtimes: ").append(w1.toActivePlaytime()).append("ms,").append(w2.toActivePlaytime()).append("ms,").append(w3.toActivePlaytime()).append("ms\n").append("DB calculation playtimes: ").append(dbW1).append("ms,").append(dbW2).append("ms,").append(dbW3).append("ms");
return errorMsg.toString();
});
}
Aggregations