use of com.djrapitops.plan.utilities.comparators.DateHolderOldestComparator 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;
}
}
}
Aggregations