use of com.djrapitops.plan.delivery.domain.TablePlayer 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.delivery.domain.TablePlayer in project Plan by plan-player-analytics.
the class DatabaseTest method serverTablePlayersQueryQueriesAtLeastOnePlayer.
@Test
default void serverTablePlayersQueryQueriesAtLeastOnePlayer() {
db().executeTransaction(new WorldNameStoreTransaction(serverUUID(), worlds[0]));
db().executeTransaction(new WorldNameStoreTransaction(serverUUID(), worlds[1]));
db().executeTransaction(new PlayerServerRegisterTransaction(playerUUID, RandomData::randomTime, TestConstants.PLAYER_ONE_NAME, serverUUID(), TestConstants.GET_PLAYER_HOSTNAME));
db().executeTransaction(new PlayerServerRegisterTransaction(player2UUID, RandomData::randomTime, TestConstants.PLAYER_TWO_NAME, serverUUID(), TestConstants.GET_PLAYER_HOSTNAME));
db().executeTransaction(new SessionEndTransaction(RandomData.randomSession(serverUUID(), worlds, playerUUID, player2UUID)));
List<TablePlayer> result = db().query(new ServerTablePlayersQuery(serverUUID(), System.currentTimeMillis(), 10L, 1));
assertEquals(1, result.size(), () -> "Incorrect query result: " + result);
assertNotEquals(Collections.emptyList(), result);
}
use of com.djrapitops.plan.delivery.domain.TablePlayer in project Plan by plan-player-analytics.
the class DatabaseTest method networkTablePlayersQueryQueriesAtLeastOnePlayer.
@Test
default void networkTablePlayersQueryQueriesAtLeastOnePlayer() {
db().executeTransaction(new WorldNameStoreTransaction(serverUUID(), worlds[0]));
db().executeTransaction(new WorldNameStoreTransaction(serverUUID(), worlds[1]));
db().executeTransaction(new PlayerServerRegisterTransaction(playerUUID, RandomData::randomTime, TestConstants.PLAYER_ONE_NAME, serverUUID(), TestConstants.GET_PLAYER_HOSTNAME));
db().executeTransaction(new PlayerServerRegisterTransaction(player2UUID, RandomData::randomTime, TestConstants.PLAYER_TWO_NAME, serverUUID(), TestConstants.GET_PLAYER_HOSTNAME));
db().executeTransaction(new SessionEndTransaction(RandomData.randomSession(serverUUID(), worlds, playerUUID, player2UUID)));
List<TablePlayer> result = db().query(new NetworkTablePlayersQuery(System.currentTimeMillis(), 10L, 1));
assertEquals(1, result.size(), () -> "Incorrect query result: " + result);
}
use of com.djrapitops.plan.delivery.domain.TablePlayer in project Plan by plan-player-analytics.
the class PlayersTableJSONCreator method createData.
private List<Map<String, Object>> createData() {
List<Map<String, Object>> dataJson = new ArrayList<>();
ExtensionTabData emptyExtensionData = new ExtensionTabData.Builder(null).build();
for (TablePlayer player : players) {
UUID playerUUID = player.getPlayerUUID();
if (playerUUID == null) {
continue;
}
Map<String, Object> playerEntry = new HashMap<>();
addPlayerData(playerEntry, player);
addExtensionData(playerEntry, extensionData.getOrDefault(playerUUID, emptyExtensionData));
dataJson.add(playerEntry);
}
return dataJson;
}
use of com.djrapitops.plan.delivery.domain.TablePlayer 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();
});
}
Aggregations