Search in sources :

Example 16 with WorldTimes

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;
}
Also used : PerServerContainer(com.djrapitops.plan.delivery.domain.container.PerServerContainer) PlayerContainer(com.djrapitops.plan.delivery.domain.container.PlayerContainer) BaseUser(com.djrapitops.plan.gathering.domain.BaseUser) FinishedSession(com.djrapitops.plan.gathering.domain.FinishedSession) PerServerMutator(com.djrapitops.plan.delivery.domain.mutators.PerServerMutator) Collection(java.util.Collection) WorldTimes(com.djrapitops.plan.gathering.domain.WorldTimes) Key(com.djrapitops.plan.delivery.domain.keys.Key)

Example 17 with WorldTimes

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);
}
Also used : ServerUUID(com.djrapitops.plan.identification.ServerUUID) PlayerServerRegisterTransaction(com.djrapitops.plan.storage.database.transactions.events.PlayerServerRegisterTransaction) Transaction(com.djrapitops.plan.storage.database.transactions.Transaction) RemoveEverythingTransaction(com.djrapitops.plan.storage.database.transactions.commands.RemoveEverythingTransaction) StoreServerInformationTransaction(com.djrapitops.plan.storage.database.transactions.StoreServerInformationTransaction) WorldNameStoreTransaction(com.djrapitops.plan.storage.database.transactions.events.WorldNameStoreTransaction) FinishedSession(com.djrapitops.plan.gathering.domain.FinishedSession) WorldTimes(com.djrapitops.plan.gathering.domain.WorldTimes) RepeatedTest(org.junit.jupiter.api.RepeatedTest) Test(org.junit.jupiter.api.Test)

Example 18 with WorldTimes

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

Example 19 with WorldTimes

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

Example 20 with WorldTimes

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

Aggregations

WorldTimes (com.djrapitops.plan.gathering.domain.WorldTimes)20 FinishedSession (com.djrapitops.plan.gathering.domain.FinishedSession)8 ServerUUID (com.djrapitops.plan.identification.ServerUUID)8 RepeatedTest (org.junit.jupiter.api.RepeatedTest)7 Test (org.junit.jupiter.api.Test)7 GMTimes (com.djrapitops.plan.gathering.domain.GMTimes)5 PreparedStatement (java.sql.PreparedStatement)4 DataContainer (com.djrapitops.plan.delivery.domain.container.DataContainer)3 WorldPie (com.djrapitops.plan.delivery.rendering.json.graphs.pie.WorldPie)3 QueryStatement (com.djrapitops.plan.storage.database.queries.QueryStatement)3 StoreServerInformationTransaction (com.djrapitops.plan.storage.database.transactions.StoreServerInformationTransaction)3 Transaction (com.djrapitops.plan.storage.database.transactions.Transaction)3 RemoveEverythingTransaction (com.djrapitops.plan.storage.database.transactions.commands.RemoveEverythingTransaction)3 PlayerServerRegisterTransaction (com.djrapitops.plan.storage.database.transactions.events.PlayerServerRegisterTransaction)3 WorldNameStoreTransaction (com.djrapitops.plan.storage.database.transactions.events.WorldNameStoreTransaction)3 ResultSet (java.sql.ResultSet)3 Map (java.util.Map)3 PlayerContainer (com.djrapitops.plan.delivery.domain.container.PlayerContainer)2 Database (com.djrapitops.plan.storage.database.Database)2 ArrayList (java.util.ArrayList)2