Search in sources :

Example 1 with FinishedSession

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

the class PerServerContainerQuery method executeQuery.

@Override
public PerServerContainer executeQuery(SQLDB db) {
    PerServerContainer perServerContainer = new PerServerContainer();
    userInformation(db, perServerContainer);
    lastSeen(db, perServerContainer);
    playerKillCount(db, perServerContainer);
    mobKillCount(db, perServerContainer);
    totalDeathCount(db, perServerContainer);
    worldTimes(db, perServerContainer);
    Map<ServerUUID, List<FinishedSession>> sessions = db.query(SessionQueries.fetchSessionsOfPlayer(playerUUID));
    for (Map.Entry<ServerUUID, List<FinishedSession>> entry : sessions.entrySet()) {
        ServerUUID serverUUID = entry.getKey();
        List<FinishedSession> serverSessions = entry.getValue();
        DataContainer serverContainer = perServerContainer.getOrDefault(serverUUID, new SupplierDataContainer());
        serverContainer.putRawData(PerServerKeys.SESSIONS, serverSessions);
        perServerContainer.put(serverUUID, serverContainer);
    }
    return perServerContainer;
}
Also used : PerServerContainer(com.djrapitops.plan.delivery.domain.container.PerServerContainer) ServerUUID(com.djrapitops.plan.identification.ServerUUID) DataContainer(com.djrapitops.plan.delivery.domain.container.DataContainer) SupplierDataContainer(com.djrapitops.plan.delivery.domain.container.SupplierDataContainer) FinishedSession(com.djrapitops.plan.gathering.domain.FinishedSession) List(java.util.List) Map(java.util.Map) SupplierDataContainer(com.djrapitops.plan.delivery.domain.container.SupplierDataContainer)

Example 2 with FinishedSession

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

the class SessionQueriesTest method serverPreferencePieValuesAreCorrect.

@Test
default void serverPreferencePieValuesAreCorrect() {
    prepareForSessionSave();
    List<FinishedSession> server1Sessions = RandomData.randomSessions(serverUUID(), worlds, playerUUID, player2UUID);
    server1Sessions.forEach(session -> execute(DataStoreQueries.storeSession(session)));
    ServerUUID serverTwoUuid = TestConstants.SERVER_TWO_UUID;
    executeTransactions(new StoreServerInformationTransaction(new Server(serverTwoUuid, TestConstants.SERVER_TWO_NAME, "")));
    db().executeTransaction(new WorldNameStoreTransaction(serverTwoUuid, worlds[0]));
    db().executeTransaction(new WorldNameStoreTransaction(serverTwoUuid, worlds[1]));
    List<FinishedSession> server2Sessions = RandomData.randomSessions(serverTwoUuid, worlds, playerUUID, player2UUID);
    server2Sessions.forEach(session -> execute(DataStoreQueries.storeSession(session)));
    Map<String, Long> expected = Maps.builder(String.class, Long.class).put(TestConstants.SERVER_NAME, new SessionsMutator(server1Sessions).toPlaytime()).put(TestConstants.SERVER_TWO_NAME, new SessionsMutator(server2Sessions).toPlaytime()).build();
    Map<String, Long> results = db().query(SessionQueries.playtimePerServer(Long.MIN_VALUE, Long.MAX_VALUE));
    assertEquals(expected, results);
}
Also used : ServerUUID(com.djrapitops.plan.identification.ServerUUID) Server(com.djrapitops.plan.identification.Server) FinishedSession(com.djrapitops.plan.gathering.domain.FinishedSession) StoreServerInformationTransaction(com.djrapitops.plan.storage.database.transactions.StoreServerInformationTransaction) WorldNameStoreTransaction(com.djrapitops.plan.storage.database.transactions.events.WorldNameStoreTransaction) SessionsMutator(com.djrapitops.plan.delivery.domain.mutators.SessionsMutator) RepeatedTest(org.junit.jupiter.api.RepeatedTest) Test(org.junit.jupiter.api.Test)

Example 3 with FinishedSession

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

the class SessionQueriesTest method playersTableAndPlayerPageActivityIndexMatches.

@RepeatedTest(value = 3, name = "Players table and player page Activity Index calculations match {currentRepetition}/{totalRepetitions}")
default void playersTableAndPlayerPageActivityIndexMatches() {
    prepareForSessionSave();
    List<FinishedSession> player1Sessions = RandomData.randomSessions(serverUUID(), worlds, playerUUID, player2UUID);
    List<FinishedSession> player2Sessions = RandomData.randomSessions(serverUUID(), worlds, player2UUID, playerUUID);
    player1Sessions.forEach(session -> execute(DataStoreQueries.storeSession(session)));
    player2Sessions.forEach(session -> execute(DataStoreQueries.storeSession(session)));
    long time = System.currentTimeMillis();
    long playtimeThreshold = RandomData.randomLong(TimeUnit.HOURS.toMillis(1L), TimeUnit.DAYS.toMillis(2L));
    PlayerContainer playerContainer = db().query(new PlayerContainerQuery(playerUUID));
    TablePlayer tablePlayer = db().query(new ServerTablePlayersQuery(serverUUID(), time, playtimeThreshold, 5)).stream().filter(player -> playerUUID.equals(player.getPlayerUUID())).findAny().orElseThrow(AssertionError::new);
    SessionsMutator sessionsMutator = SessionsMutator.forContainer(playerContainer);
    long week = TimeAmount.WEEK.toMillis(1L);
    long weekAgo = time - week;
    long twoWeeksAgo = time - 2L * week;
    long threeWeeksAgo = time - 3L * week;
    SessionsMutator weekOne = sessionsMutator.filterSessionsBetween(weekAgo, time);
    SessionsMutator weekTwo = sessionsMutator.filterSessionsBetween(twoWeeksAgo, weekAgo);
    SessionsMutator weekThree = sessionsMutator.filterSessionsBetween(threeWeeksAgo, twoWeeksAgo);
    long playtime1 = weekOne.toActivePlaytime();
    long playtime2 = weekTwo.toActivePlaytime();
    long playtime3 = weekThree.toActivePlaytime();
    double expected = playerContainer.getActivityIndex(time, playtimeThreshold).getValue();
    double got = tablePlayer.getCurrentActivityIndex().orElseThrow(AssertionError::new).getValue();
    assertEquals(expected, got, 0.001, () -> "Activity Indexes between queries differed, expected: <" + expected + "> but was: <" + got + ">" + ". Playtime for reference container: <w1:" + playtime1 + ", w2:" + playtime2 + ", w3:" + playtime3 + ">");
}
Also used : ServerTablePlayersQuery(com.djrapitops.plan.storage.database.queries.objects.playertable.ServerTablePlayersQuery) PlayerContainer(com.djrapitops.plan.delivery.domain.container.PlayerContainer) PlayerContainerQuery(com.djrapitops.plan.storage.database.queries.containers.PlayerContainerQuery) FinishedSession(com.djrapitops.plan.gathering.domain.FinishedSession) TablePlayer(com.djrapitops.plan.delivery.domain.TablePlayer) SessionsMutator(com.djrapitops.plan.delivery.domain.mutators.SessionsMutator) RepeatedTest(org.junit.jupiter.api.RepeatedTest)

Example 4 with FinishedSession

use of com.djrapitops.plan.gathering.domain.FinishedSession 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 5 with FinishedSession

use of com.djrapitops.plan.gathering.domain.FinishedSession 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)

Aggregations

FinishedSession (com.djrapitops.plan.gathering.domain.FinishedSession)33 Test (org.junit.jupiter.api.Test)23 RepeatedTest (org.junit.jupiter.api.RepeatedTest)18 ServerUUID (com.djrapitops.plan.identification.ServerUUID)16 WorldNameStoreTransaction (com.djrapitops.plan.storage.database.transactions.events.WorldNameStoreTransaction)10 TablePlayer (com.djrapitops.plan.delivery.domain.TablePlayer)7 WorldTimes (com.djrapitops.plan.gathering.domain.WorldTimes)7 ServerTablePlayersQuery (com.djrapitops.plan.storage.database.queries.objects.playertable.ServerTablePlayersQuery)7 PlayerServerRegisterTransaction (com.djrapitops.plan.storage.database.transactions.events.PlayerServerRegisterTransaction)7 SessionsMutator (com.djrapitops.plan.delivery.domain.mutators.SessionsMutator)6 ActiveSession (com.djrapitops.plan.gathering.domain.ActiveSession)6 PlayerContainer (com.djrapitops.plan.delivery.domain.container.PlayerContainer)5 Transaction (com.djrapitops.plan.storage.database.transactions.Transaction)5 List (java.util.List)5 NetworkTablePlayersQuery (com.djrapitops.plan.storage.database.queries.objects.playertable.NetworkTablePlayersQuery)4 Sql (com.djrapitops.plan.storage.database.sql.building.Sql)4 ResultSet (java.sql.ResultSet)4 SQLException (java.sql.SQLException)4 Collection (java.util.Collection)4 TimeUnit (java.util.concurrent.TimeUnit)4