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;
}
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;
}
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);
}
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);
}
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);
}
Aggregations