Search in sources :

Example 26 with FinishedSession

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

the class PlayerCalendar method getSessionsByDay.

private Map<String, List<FinishedSession>> getSessionsByDay() {
    Map<String, List<FinishedSession>> sessionsByDay = new HashMap<>();
    for (FinishedSession session : allSessions) {
        String day = iso8601Formatter.apply(session.getDate());
        List<FinishedSession> sessionsOfDay = sessionsByDay.computeIfAbsent(day, Lists::create);
        sessionsOfDay.add(session);
    }
    return sessionsByDay;
}
Also used : FinishedSession(com.djrapitops.plan.gathering.domain.FinishedSession) Lists(com.djrapitops.plan.utilities.java.Lists)

Example 27 with FinishedSession

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

the class PlayerCalendar method getEntries.

public List<CalendarEntry> getEntries() {
    List<CalendarEntry> entries = new ArrayList<>();
    entries.add(CalendarEntry.of(locale.getString(HtmlLang.LABEL_REGISTERED) + ": " + year.apply(registered), registered).withColor(theme.getValue(ThemeVal.LIGHT_GREEN)));
    Map<String, List<FinishedSession>> sessionsByDay = getSessionsByDay();
    for (Map.Entry<String, List<FinishedSession>> entry : sessionsByDay.entrySet()) {
        String day = entry.getKey();
        List<FinishedSession> sessions = entry.getValue();
        int sessionCount = sessions.size();
        long playtime = sessions.stream().mapToLong(FinishedSession::getLength).sum();
        entries.add(CalendarEntry.of(locale.getString(HtmlLang.LABEL_PLAYTIME) + ": " + timeAmount.apply(playtime), day).withColor(theme.getValue(ThemeVal.GREEN)));
        entries.add(CalendarEntry.of(locale.getString(HtmlLang.SIDE_SESSIONS) + ": " + sessionCount, day));
    }
    long fiveMinutes = TimeUnit.MINUTES.toMillis(5L);
    for (FinishedSession session : allSessions) {
        String length = timeAmount.apply(session.getLength());
        long start = session.getStart();
        long end = session.getEnd();
        entries.add(CalendarEntry.of(length + " " + locale.getString(HtmlLang.SESSION), start + timeZone.getOffset(start)).withEnd(end + timeZone.getOffset(end)));
        for (PlayerKill kill : session.getExtraData(PlayerKills.class).map(PlayerKills::asList).orElseGet(ArrayList::new)) {
            long time = kill.getDate();
            String victim = kill.getVictim().getName();
            entries.add(CalendarEntry.of(locale.getString(HtmlLang.KILLED) + ": " + victim, time).withEnd(time + fiveMinutes).withColor(theme.getValue(ThemeVal.RED)));
        }
    }
    return entries;
}
Also used : PlayerKill(com.djrapitops.plan.gathering.domain.PlayerKill) FinishedSession(com.djrapitops.plan.gathering.domain.FinishedSession)

Example 28 with FinishedSession

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

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

the class SessionQueriesTest method serverSessionsAreFetchedByPlayerUUID.

@Test
default void serverSessionsAreFetchedByPlayerUUID() {
    prepareForSessionSave();
    FinishedSession session = RandomData.randomSession(serverUUID(), worlds, playerUUID, player2UUID);
    execute(DataStoreQueries.storeSession(session));
    forcePersistenceCheck();
    Map<UUID, List<FinishedSession>> expected = Collections.singletonMap(playerUUID, Collections.singletonList(session));
    Map<UUID, List<FinishedSession>> fetched = db().query(SessionQueries.fetchSessionsOfServer(serverUUID()));
    assertEquals(expected, fetched);
}
Also used : FinishedSession(com.djrapitops.plan.gathering.domain.FinishedSession) ServerUUID(com.djrapitops.plan.identification.ServerUUID) RepeatedTest(org.junit.jupiter.api.RepeatedTest) Test(org.junit.jupiter.api.Test)

Example 30 with FinishedSession

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

FinishedSession (com.djrapitops.plan.gathering.domain.FinishedSession)32 Test (org.junit.jupiter.api.Test)22 ServerUUID (com.djrapitops.plan.identification.ServerUUID)13 RepeatedTest (org.junit.jupiter.api.RepeatedTest)11 StoreSessionTransaction (com.djrapitops.plan.storage.database.transactions.events.StoreSessionTransaction)10 WorldNameStoreTransaction (com.djrapitops.plan.storage.database.transactions.events.WorldNameStoreTransaction)8 ActiveSession (com.djrapitops.plan.gathering.domain.ActiveSession)6 RandomData (utilities.RandomData)6 TestConstants (utilities.TestConstants)6 TablePlayer (com.djrapitops.plan.delivery.domain.TablePlayer)5 List (java.util.List)5 WorldTimes (com.djrapitops.plan.gathering.domain.WorldTimes)4 NetworkTablePlayersQuery (com.djrapitops.plan.storage.database.queries.objects.playertable.NetworkTablePlayersQuery)4 ServerTablePlayersQuery (com.djrapitops.plan.storage.database.queries.objects.playertable.ServerTablePlayersQuery)4 Sql (com.djrapitops.plan.storage.database.sql.building.Sql)4 UsersTable (com.djrapitops.plan.storage.database.sql.tables.UsersTable)4 ResultSet (java.sql.ResultSet)4 SQLException (java.sql.SQLException)4 Collection (java.util.Collection)4 TimeUnit (java.util.concurrent.TimeUnit)4