use of com.djrapitops.plan.gathering.domain.FinishedSession in project Plan by plan-player-analytics.
the class ActivityIndexQueriesTest method activityIndexCalculationsMatchWithMissingData.
@RepeatedTest(value = 3, name = "Activity Index calculations match with missing data {currentRepetition}/{totalRepetitions}")
default void activityIndexCalculationsMatchWithMissingData() {
long keepAfter = System.currentTimeMillis() - TimeUnit.DAYS.toMillis(7L);
storeSessions(session -> session.getDate() >= keepAfter && session.getEnd() >= keepAfter);
long date = System.currentTimeMillis();
long playtimeThreshold = TimeUnit.HOURS.toMillis(5L);
List<FinishedSession> sessions = db().query(SessionQueries.fetchSessionsOfPlayer(playerUUID)).values().stream().flatMap(Collection::stream).collect(Collectors.toList());
ActivityIndex javaCalculation = new ActivityIndex(sessions, date, playtimeThreshold);
List<TablePlayer> players = db().query(new ServerTablePlayersQuery(serverUUID(), date, playtimeThreshold, 5));
Optional<TablePlayer> found = players.stream().filter(tp -> playerUUID.equals(tp.getPlayerUUID())).findFirst();
assertTrue(found.isPresent());
Optional<ActivityIndex> currentActivityIndex = found.get().getCurrentActivityIndex();
assertTrue(currentActivityIndex.isPresent());
assertEquals(javaCalculation.getValue(), currentActivityIndex.get().getValue(), 0.001, () -> {
StringBuilder errorMsg = new StringBuilder("Activity indexes did not match\n");
long week = TimeUnit.DAYS.toMillis(7L);
long weekAgo = date - week;
long twoWeeksAgo = date - 2L * week;
long threeWeeksAgo = date - 3L * week;
SessionsMutator mutator = new SessionsMutator(sessions);
SessionsMutator w1 = mutator.filterSessionsBetween(weekAgo, date);
SessionsMutator w2 = mutator.filterSessionsBetween(twoWeeksAgo, weekAgo);
SessionsMutator w3 = mutator.filterSessionsBetween(threeWeeksAgo, twoWeeksAgo);
Long dbW1 = db().query(SessionQueries.activePlaytime(weekAgo, date, serverUUID()));
Long dbW2 = db().query(SessionQueries.activePlaytime(twoWeeksAgo, weekAgo, serverUUID()));
Long dbW3 = db().query(SessionQueries.activePlaytime(threeWeeksAgo, twoWeeksAgo, serverUUID()));
errorMsg.append("Java calculation playtimes: ").append(w1.toActivePlaytime()).append("ms,").append(w2.toActivePlaytime()).append("ms,").append(w3.toActivePlaytime()).append("ms\n").append("DB calculation playtimes: ").append(dbW1).append("ms,").append(dbW2).append("ms,").append(dbW3).append("ms");
return errorMsg.toString();
});
}
use of com.djrapitops.plan.gathering.domain.FinishedSession in project Plan by plan-player-analytics.
the class ActivityIndexQueriesTest method networkActivityIndexCalculationsMatch.
@RepeatedTest(value = 3, name = "Network Activity Index calculations match {currentRepetition}/{totalRepetitions}")
default void networkActivityIndexCalculationsMatch() {
storeSessions(session -> true);
long date = System.currentTimeMillis();
long playtimeThreshold = TimeUnit.HOURS.toMillis(5L);
List<FinishedSession> sessions = db().query(SessionQueries.fetchSessionsOfPlayer(playerUUID)).values().stream().flatMap(Collection::stream).collect(Collectors.toList());
ActivityIndex javaCalculation = new ActivityIndex(sessions, date, playtimeThreshold);
List<TablePlayer> players = db().query(new NetworkTablePlayersQuery(date, playtimeThreshold, 5));
Optional<TablePlayer> found = players.stream().filter(tp -> playerUUID.equals(tp.getPlayerUUID())).findFirst();
assertTrue(found.isPresent());
Optional<ActivityIndex> currentActivityIndex = found.get().getCurrentActivityIndex();
assertTrue(currentActivityIndex.isPresent());
assertEquals(javaCalculation.getValue(), currentActivityIndex.get().getValue(), 0.001, () -> {
StringBuilder errorMsg = new StringBuilder("Activity indexes did not match\n");
long week = TimeUnit.DAYS.toMillis(7L);
long weekAgo = date - week;
long twoWeeksAgo = date - 2L * week;
long threeWeeksAgo = date - 3L * week;
SessionsMutator mutator = new SessionsMutator(sessions);
SessionsMutator w1 = mutator.filterSessionsBetween(weekAgo, date);
SessionsMutator w2 = mutator.filterSessionsBetween(twoWeeksAgo, weekAgo);
SessionsMutator w3 = mutator.filterSessionsBetween(threeWeeksAgo, twoWeeksAgo);
Long dbW1 = db().query(activePlaytime(weekAgo, date));
Long dbW2 = db().query(activePlaytime(twoWeeksAgo, weekAgo));
Long dbW3 = db().query(activePlaytime(threeWeeksAgo, twoWeeksAgo));
errorMsg.append("Java calculation playtimes: ").append(w1.toActivePlaytime()).append("ms,").append(w2.toActivePlaytime()).append("ms,").append(w3.toActivePlaytime()).append("ms\n").append("DB calculation playtimes: ").append(dbW1).append("ms,").append(dbW2).append("ms,").append(dbW3).append("ms");
return errorMsg.toString();
});
}
use of com.djrapitops.plan.gathering.domain.FinishedSession in project Plan by plan-player-analytics.
the class JoinAddressQueriesTest method latestJoinAddressIsUpdatedUponSecondSession.
@Test
default void latestJoinAddressIsUpdatedUponSecondSession() {
joinAddressCanBeUnknown();
FinishedSession session = RandomData.randomSession(serverUUID(), worlds, playerUUID, player2UUID);
String expectedAddress = TestConstants.GET_PLAYER_HOSTNAME.get();
session.getExtraData().put(JoinAddress.class, new JoinAddress(expectedAddress));
db().executeTransaction(new StoreSessionTransaction(session));
Map<String, Integer> expected = Map.of(expectedAddress, 1);
Map<String, Integer> result = db().query(JoinAddressQueries.latestJoinAddresses());
assertEquals(expected, result);
}
use of com.djrapitops.plan.gathering.domain.FinishedSession in project Plan by plan-player-analytics.
the class JoinAddressQueriesTest method joinAddressUpdateIsUniquePerServer.
@Test
default void joinAddressUpdateIsUniquePerServer() {
joinAddressCanBeUnknown();
db().executeTransaction(TestData.storeServers());
db().executeTransaction(new WorldNameStoreTransaction(TestConstants.SERVER_TWO_UUID, worlds[0]));
db().executeTransaction(new WorldNameStoreTransaction(TestConstants.SERVER_TWO_UUID, worlds[1]));
FinishedSession session = RandomData.randomSession(TestConstants.SERVER_TWO_UUID, worlds, playerUUID, player2UUID);
String expectedAddress = TestConstants.GET_PLAYER_HOSTNAME.get();
session.getExtraData().put(JoinAddress.class, new JoinAddress(expectedAddress));
db().executeTransaction(new StoreSessionTransaction(session));
Map<String, Integer> expected1 = Map.of(JoinAddressTable.DEFAULT_VALUE_FOR_LOOKUP, 1);
Map<String, Integer> result1 = db().query(JoinAddressQueries.latestJoinAddresses(serverUUID()));
assertEquals(expected1, result1);
Map<String, Integer> expected2 = Map.of(expectedAddress, 1);
Map<String, Integer> result2 = db().query(JoinAddressQueries.latestJoinAddresses(TestConstants.SERVER_TWO_UUID));
assertEquals(expected2, result2);
}
use of com.djrapitops.plan.gathering.domain.FinishedSession in project Plan by plan-player-analytics.
the class DatabaseTest method playerContainerSupportsAllPlayerKeys.
@Test
default void playerContainerSupportsAllPlayerKeys() throws IllegalAccessException {
saveUserOne();
saveUserTwo();
saveTwoWorlds();
FinishedSession session = RandomData.randomSession(serverUUID(), worlds, playerUUID, player2UUID);
db().executeTransaction(new StoreSessionTransaction(session));
db().executeTransaction(new NicknameStoreTransaction(playerUUID, RandomData.randomNickname(serverUUID()), (uuid, name) -> false));
saveGeoInfo(playerUUID, new GeoInfo("TestLoc", RandomData.randomTime()));
assertTrue(db().query(PlayerFetchQueries.isPlayerRegistered(playerUUID)));
db().executeTransaction(new PingStoreTransaction(playerUUID, serverUUID(), RandomData.randomIntDateObjects()));
PlayerContainer playerContainer = db().query(ContainerFetchQueries.fetchPlayerContainer(playerUUID));
// Active sessions are added after fetching
playerContainer.putRawData(PlayerKeys.ACTIVE_SESSION, RandomData.randomUnfinishedSession(serverUUID(), worlds, playerUUID));
List<String> unsupported = new ArrayList<>();
List<Key> keys = FieldFetcher.getPublicStaticFields(PlayerKeys.class, Key.class);
for (Key<?> key : keys) {
if (!playerContainer.supports(key)) {
unsupported.add(key.getKeyName());
}
}
assertTrue(unsupported.isEmpty(), () -> "Some keys are not supported by PlayerContainer: PlayerKeys." + unsupported.toString());
}
Aggregations