use of com.djrapitops.plan.delivery.domain.mutators.SessionsMutator 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.delivery.domain.mutators.SessionsMutator 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.mutators.SessionsMutator in project Plan by plan-player-analytics.
the class ServerAccordion method asMaps.
public List<Map<String, Object>> asMaps() {
List<Map<String, Object>> servers = new ArrayList<>();
for (Map.Entry<ServerUUID, DataContainer> entry : perServer.entrySet()) {
ServerUUID serverUUID = entry.getKey();
DataContainer ofServer = entry.getValue();
Map<String, Object> server = new HashMap<>();
String serverName = serverNames.getOrDefault(serverUUID, unknown);
WorldTimes worldTimes = ofServer.getValue(PerServerKeys.WORLD_TIMES).orElse(new WorldTimes());
SessionsMutator sessionsMutator = SessionsMutator.forContainer(ofServer);
server.put("server_name", serverName);
server.put("banned", ofServer.getValue(PerServerKeys.BANNED).orElse(false));
server.put("operator", ofServer.getValue(PerServerKeys.OPERATOR).orElse(false));
server.put("registered", year.apply(ofServer.getValue(PerServerKeys.REGISTERED).orElse(0L)));
server.put("last_seen", year.apply(sessionsMutator.toLastSeen()));
server.put("join_address", ofServer.getValue(PerServerKeys.JOIN_ADDRESS).orElse("-"));
server.put("session_count", sessionsMutator.count());
server.put("playtime", timeAmount.apply(sessionsMutator.toPlaytime()));
server.put("afk_time", timeAmount.apply(sessionsMutator.toAfkTime()));
server.put("session_median", timeAmount.apply(sessionsMutator.toMedianSessionLength()));
server.put("longest_session_length", timeAmount.apply(sessionsMutator.toLongestSessionLength()));
server.put("mob_kills", sessionsMutator.toMobKillCount());
server.put("player_kills", sessionsMutator.toPlayerKillCount());
server.put("deaths", sessionsMutator.toDeathCount());
WorldPie worldPie = graphs.pie().worldPie(worldTimes);
server.put("world_pie_series", worldPie.getSlices());
server.put("gm_series", worldPie.toHighChartsDrillDownMaps());
servers.add(server);
}
return servers;
}
use of com.djrapitops.plan.delivery.domain.mutators.SessionsMutator in project Plan by plan-player-analytics.
the class JSONFactory method networkSessionsAsJSONMap.
public List<Map<String, Object>> networkSessionsAsJSONMap() {
Database db = dbSystem.getDatabase();
Integer perPageLimit = config.get(DisplaySettings.SESSIONS_PER_PAGE);
List<FinishedSession> sessions = db.query(SessionQueries.fetchLatestSessions(perPageLimit));
// Add online sessions
if (serverInfo.getServer().isProxy()) {
addActiveSessions(sessions);
sessions.sort(new SessionStartComparator());
while (true) {
int size = sessions.size();
if (size <= perPageLimit)
break;
// Remove last until it fits.
sessions.remove(size - 1);
}
}
List<Map<String, Object>> sessionMaps = new SessionsMutator(sessions).toPlayerNameJSONMaps(graphs, config.getWorldAliasSettings(), formatters);
// Add network_server property so that sessions have a server page link
sessionMaps.forEach(map -> map.put("network_server", map.get("server_name")));
return sessionMaps;
}
use of com.djrapitops.plan.delivery.domain.mutators.SessionsMutator in project Plan by plan-player-analytics.
the class JSONFactory method serverSessionsAsJSONMap.
public List<Map<String, Object>> serverSessionsAsJSONMap(ServerUUID serverUUID) {
Database db = dbSystem.getDatabase();
Integer perPageLimit = config.get(DisplaySettings.SESSIONS_PER_PAGE);
List<FinishedSession> sessions = db.query(SessionQueries.fetchLatestSessionsOfServer(serverUUID, perPageLimit));
// Add online sessions
if (serverUUID.equals(serverInfo.getServerUUID())) {
addActiveSessions(sessions);
sessions.sort(new SessionStartComparator());
while (true) {
int size = sessions.size();
if (size <= perPageLimit)
break;
// Remove last until it fits.
sessions.remove(size - 1);
}
}
return new SessionsMutator(sessions).toPlayerNameJSONMaps(graphs, config.getWorldAliasSettings(), formatters);
}
Aggregations