use of com.djrapitops.plan.gathering.domain.WorldTimes 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.WorldTimes in project Plan by plan-player-analytics.
the class SessionQueriesTest method worldTimesAreSavedWithAllSessionSave.
@Test
default void worldTimesAreSavedWithAllSessionSave() {
prepareForSessionSave();
WorldTimes worldTimes = RandomData.randomWorldTimes(worlds);
FinishedSession session = RandomData.randomSession(serverUUID(), worlds, playerUUID);
session.getExtraData().put(WorldTimes.class, worldTimes);
List<FinishedSession> sessions = Collections.singletonList(session);
db().executeTransaction(new Transaction() {
@Override
protected void performOperations() {
execute(LargeStoreQueries.storeAllSessionsWithKillAndWorldData(sessions));
}
});
Map<ServerUUID, WorldTimes> saved = db().query(WorldTimesQueries.fetchPlayerWorldTimesOnServers(playerUUID));
WorldTimes savedWorldTimes = saved.get(serverUUID());
assertEquals(worldTimes, savedWorldTimes);
}
use of com.djrapitops.plan.gathering.domain.WorldTimes in project Plan by plan-player-analytics.
the class SessionQueriesTest method emptyServerWorldTimesIsEmpty.
@Test
default void emptyServerWorldTimesIsEmpty() {
WorldTimes worldTimesOfServer = db().query(WorldTimesQueries.fetchServerTotalWorldTimes(serverUUID()));
assertEquals(new WorldTimes(), worldTimesOfServer);
}
use of com.djrapitops.plan.gathering.domain.WorldTimes in project Plan by plan-player-analytics.
the class SessionQueriesTest method playersWorldTimesMatchTotal.
@Test
default void playersWorldTimesMatchTotal() {
worldTimesAreSavedWithSession();
FinishedSession session = db().query(SessionQueries.fetchSessionsOfPlayer(playerUUID)).get(serverUUID()).get(0);
WorldTimes expected = session.getExtraData(WorldTimes.class).orElseThrow(AssertionError::new);
WorldTimes worldTimesOfUser = db().query(WorldTimesQueries.fetchPlayerTotalWorldTimes(playerUUID));
assertEquals(expected, worldTimesOfUser);
}
use of com.djrapitops.plan.gathering.domain.WorldTimes in project Plan by plan-player-analytics.
the class SessionQueriesTest method sessionWorldTimesAreFetchedCorrectly.
@Test
default void sessionWorldTimesAreFetchedCorrectly() {
prepareForSessionSave();
FinishedSession session = RandomData.randomSession(serverUUID(), worlds, playerUUID, player2UUID);
WorldTimes expected = session.getExtraData(WorldTimes.class).orElseThrow(AssertionError::new);
execute(DataStoreQueries.storeSession(session));
// Fetch the session
Map<ServerUUID, List<FinishedSession>> sessions = db().query(SessionQueries.fetchSessionsOfPlayer(playerUUID));
List<FinishedSession> serverSessions = sessions.get(serverUUID());
assertNotNull(serverSessions);
assertFalse(serverSessions.isEmpty());
WorldTimes got = serverSessions.get(0).getExtraData(WorldTimes.class).orElseThrow(AssertionError::new);
assertEquals(expected, got);
}
Aggregations