Search in sources :

Example 1 with WorldTimes

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

the class WorldAliasSettings method getLongestWorldPlayed.

public String getLongestWorldPlayed(ActiveSession session) {
    Optional<WorldTimes> foundWorldTimes = session.getExtraData(WorldTimes.class);
    if (!foundWorldTimes.isPresent()) {
        return locale.get().getString(HtmlLang.UNIT_NO_DATA);
    }
    WorldTimes worldTimes = foundWorldTimes.orElseGet(WorldTimes::new);
    return worldTimes.getCurrentWorld().map(currentWorld -> "Current: " + getAlias(currentWorld).orElse(currentWorld)).orElse("Current: " + locale.get().getString(GenericLang.UNAVAILABLE));
}
Also used : HtmlLang(com.djrapitops.plan.settings.locale.lang.HtmlLang) java.util(java.util) FinishedSession(com.djrapitops.plan.gathering.domain.FinishedSession) WorldTimes(com.djrapitops.plan.gathering.domain.WorldTimes) GenericLang(com.djrapitops.plan.settings.locale.lang.GenericLang) Formatters(com.djrapitops.plan.delivery.formatting.Formatters) IOException(java.io.IOException) Singleton(javax.inject.Singleton) Lazy(dagger.Lazy) StringUtils(org.apache.commons.lang3.StringUtils) Supplier(java.util.function.Supplier) Collectors(java.util.stream.Collectors) Inject(javax.inject.Inject) GMTimes(com.djrapitops.plan.gathering.domain.GMTimes) ErrorLogger(com.djrapitops.plan.utilities.logging.ErrorLogger) Locale(com.djrapitops.plan.settings.locale.Locale) ActiveSession(com.djrapitops.plan.gathering.domain.ActiveSession) ErrorContext(com.djrapitops.plan.utilities.logging.ErrorContext) Processing(com.djrapitops.plan.processing.Processing) DisplaySettings(com.djrapitops.plan.settings.config.paths.DisplaySettings) Formatter(com.djrapitops.plan.delivery.formatting.Formatter) WorldTimes(com.djrapitops.plan.gathering.domain.WorldTimes)

Example 2 with WorldTimes

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

the class SessionQueriesTest method worldTimesAreSavedWithSessionWithoutWorlds.

@Test
default void worldTimesAreSavedWithSessionWithoutWorlds() {
    prepareForSessionSave();
    // Remove the worlds from the database so that they need to also be saved.
    execute(new ExecStatement("DELETE FROM " + WorldTable.TABLE_NAME) {

        @Override
        public void prepare(PreparedStatement statement) {
        // Nothing needed
        }
    });
    WorldTimes worldTimes = RandomData.randomWorldTimes(worlds);
    FinishedSession session = RandomData.randomSession(serverUUID(), worlds, playerUUID);
    session.getExtraData().put(WorldTimes.class, worldTimes);
    List<FinishedSession> sessions = new ArrayList<>();
    sessions.add(session);
    db().executeTransaction(new Transaction() {

        @Override
        protected void performOperations() {
            execute(LargeStoreQueries.storeAllSessionsWithKillAndWorldData(sessions));
        }
    });
    List<FinishedSession> allSessions = db().query(SessionQueries.fetchAllSessions());
    assertEquals(worldTimes, allSessions.get(0).getExtraData(WorldTimes.class).get());
}
Also used : 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) PreparedStatement(java.sql.PreparedStatement) WorldTimes(com.djrapitops.plan.gathering.domain.WorldTimes) ExecStatement(com.djrapitops.plan.storage.database.transactions.ExecStatement) RepeatedTest(org.junit.jupiter.api.RepeatedTest) Test(org.junit.jupiter.api.Test)

Example 3 with WorldTimes

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

the class SessionQueriesTest method serverWorldTimesMatchTotal.

@Test
default void serverWorldTimesMatchTotal() {
    worldTimesAreSavedWithSession();
    FinishedSession session = db().query(SessionQueries.fetchSessionsOfPlayer(playerUUID)).get(serverUUID()).get(0);
    WorldTimes expected = session.getExtraData(WorldTimes.class).orElseThrow(AssertionError::new);
    WorldTimes worldTimesOfServer = db().query(WorldTimesQueries.fetchServerTotalWorldTimes(serverUUID()));
    assertEquals(expected, worldTimesOfServer);
}
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 4 with WorldTimes

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

the class SessionQueriesTest method worldTimesAreSavedWithSession.

@Test
default void worldTimesAreSavedWithSession() {
    prepareForSessionSave();
    WorldTimes worldTimes = RandomData.randomWorldTimes(worlds);
    FinishedSession session = RandomData.randomSession(serverUUID(), worlds, playerUUID);
    session.getExtraData().put(WorldTimes.class, worldTimes);
    List<FinishedSession> sessions = new ArrayList<>();
    sessions.add(session);
    db().executeTransaction(new Transaction() {

        @Override
        protected void performOperations() {
            execute(LargeStoreQueries.storeAllSessionsWithKillAndWorldData(sessions));
        }
    });
    List<FinishedSession> allSessions = db().query(SessionQueries.fetchAllSessions());
    assertEquals(worldTimes, allSessions.get(0).getExtraData(WorldTimes.class).get());
}
Also used : 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 5 with WorldTimes

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

the class PerServerMutator method flatMapWorldTimes.

public WorldTimes flatMapWorldTimes() {
    WorldTimes total = new WorldTimes();
    for (DataContainer container : data.values()) {
        if (container.supports(PerServerKeys.WORLD_TIMES)) {
            WorldTimes worldTimes = container.getUnsafe(PerServerKeys.WORLD_TIMES);
            total.add(worldTimes);
        }
    }
    return total;
}
Also used : DataContainer(com.djrapitops.plan.delivery.domain.container.DataContainer) WorldTimes(com.djrapitops.plan.gathering.domain.WorldTimes)

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