use of com.djrapitops.plan.gathering.domain.FinishedSession in project Plan by plan-player-analytics.
the class JoinAddressQueriesTest method joinAddressCanBeUnknown.
@Test
default void joinAddressCanBeUnknown() {
db().executeTransaction(new WorldNameStoreTransaction(serverUUID(), worlds[0]));
db().executeTransaction(new WorldNameStoreTransaction(serverUUID(), worlds[1]));
db().executeTransaction(new PlayerRegisterTransaction(playerUUID, System::currentTimeMillis, TestConstants.PLAYER_ONE_NAME));
FinishedSession session = RandomData.randomSession(serverUUID(), worlds, playerUUID, player2UUID);
session.getExtraData().remove(JoinAddress.class);
db().executeTransaction(new StoreSessionTransaction(session));
Set<Integer> expected = Set.of(db().query(BaseUserQueries.fetchUserId(playerUUID)).orElseThrow(AssertionError::new));
Set<Integer> result = db().query(JoinAddressQueries.userIdsOfPlayersWithJoinAddresses(List.of(JoinAddressTable.DEFAULT_VALUE_FOR_LOOKUP)));
assertEquals(expected, result);
Map<String, Integer> expectedAddressCounts = Map.of(JoinAddressTable.DEFAULT_VALUE_FOR_LOOKUP, 1);
Map<String, Integer> resultAddressCounts = db().query(JoinAddressQueries.latestJoinAddresses());
assertEquals(expectedAddressCounts, resultAddressCounts);
}
use of com.djrapitops.plan.gathering.domain.FinishedSession in project Plan by plan-player-analytics.
the class JoinAddressQueriesTest method joinAddressQueryHasDistinctPlayers.
@Test
default void joinAddressQueryHasDistinctPlayers() {
joinAddressCanBeUnknown();
db().executeTransaction(TestData.storeServers());
FinishedSession session = RandomData.randomSession(serverUUID(), worlds, player2UUID, playerUUID);
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(JoinAddressTable.DEFAULT_VALUE_FOR_LOOKUP, 1, 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 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();
if (!serverSessions.isEmpty()) {
serverSessions.get(0).getExtraData().get(JoinAddress.class).map(JoinAddress::getAddress).ifPresent(address -> perServerContainer.putToContainerOfServer(serverUUID, PerServerKeys.JOIN_ADDRESS, address));
}
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 PingMutator method addPingToSessions.
public void addPingToSessions(List<FinishedSession> sessions) {
if (sessions.isEmpty())
return;
Comparator<DateHolder> comparator = new DateHolderOldestComparator();
sessions.sort(comparator);
pings.sort(comparator);
Map<ServerUUID, SortedMap<Long, Ping>> pingByServer = sortByServers(pings);
Map<ServerUUID, List<FinishedSession>> sessionsByServer = SessionsMutator.sortByServers(sessions);
for (Map.Entry<ServerUUID, SortedMap<Long, Ping>> entry : pingByServer.entrySet()) {
ServerUUID serverUUID = entry.getKey();
SortedMap<Long, Ping> pingOfServer = entry.getValue();
if (pingOfServer.isEmpty())
continue;
List<FinishedSession> sessionsOfServer = sessionsByServer.getOrDefault(serverUUID, Collections.emptyList());
double pingCount = 0.0;
int pingEntries = 0;
for (FinishedSession session : sessionsOfServer) {
long start = session.getDate();
long end = session.getEnd();
if (end < start)
continue;
// Calculate average ping for each session with a section of the Ping map
SortedMap<Long, Ping> duringSession = pingOfServer.subMap(start, end);
for (Ping ping : duringSession.values()) {
pingCount += ping.getAverage();
pingEntries++;
}
if (pingEntries != 0) {
session.getExtraData().put(AveragePing.class, new AveragePing(pingCount / pingEntries));
}
pingCount = 0.0;
pingEntries = 0;
}
}
}
use of com.djrapitops.plan.gathering.domain.FinishedSession in project Plan by plan-player-analytics.
the class TimeSegmentsMutator method sessionClockSegments.
public static TimeSegmentsMutator<Integer> sessionClockSegments(List<FinishedSession> sessions) {
List<DateObj<Integer>> changes = new ArrayList<>();
for (FinishedSession session : sessions) {
long startTime = (session.getStart()) % TimeUnit.DAYS.toMillis(1);
long endTime = (session.getEnd()) % TimeUnit.DAYS.toMillis(1);
changes.add(new DateObj<>(startTime, 1));
changes.add(new DateObj<>(endTime, -1));
}
changes.sort(new DateHolderOldestComparator());
int count = 0;
long previousTime = 0L;
List<TimeSegment<Integer>> segments = new ArrayList<>();
for (DateObj<Integer> change : changes) {
segments.add(new TimeSegment<>(previousTime, change.getDate(), count));
count += change.getValue();
previousTime = change.getDate();
}
return new TimeSegmentsMutator<>(segments);
}
Aggregations