Search in sources :

Example 1 with DateHolderOldestComparator

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;
        }
    }
}
Also used : ServerUUID(com.djrapitops.plan.identification.ServerUUID) DateHolder(com.djrapitops.plan.delivery.domain.DateHolder) AveragePing(com.djrapitops.plan.delivery.domain.AveragePing) FinishedSession(com.djrapitops.plan.gathering.domain.FinishedSession) Ping(com.djrapitops.plan.gathering.domain.Ping) AveragePing(com.djrapitops.plan.delivery.domain.AveragePing) DateHolderOldestComparator(com.djrapitops.plan.utilities.comparators.DateHolderOldestComparator)

Aggregations

AveragePing (com.djrapitops.plan.delivery.domain.AveragePing)1 DateHolder (com.djrapitops.plan.delivery.domain.DateHolder)1 FinishedSession (com.djrapitops.plan.gathering.domain.FinishedSession)1 Ping (com.djrapitops.plan.gathering.domain.Ping)1 ServerUUID (com.djrapitops.plan.identification.ServerUUID)1 DateHolderOldestComparator (com.djrapitops.plan.utilities.comparators.DateHolderOldestComparator)1