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