Search in sources :

Example 1 with AveragePing

use of com.djrapitops.plan.delivery.domain.AveragePing 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)

Example 2 with AveragePing

use of com.djrapitops.plan.delivery.domain.AveragePing in project Plan by plan-player-analytics.

the class SessionsMutator method toJSONMaps.

private List<Map<String, Object>> toJSONMaps(Graphs graphs, WorldAliasSettings worldAliasSettings, Formatters formatters, Function<Map<String, Object>, Object> nameFunction) {
    return Lists.map(sessions, session -> {
        Map<String, Object> sessionMap = new HashMap<>();
        String playerUUID = session.getPlayerUUID().toString();
        String serverUUID = session.getServerUUID().toString();
        String playerName = session.getExtraData(PlayerName.class).map(PlayerName::get).orElse(playerUUID);
        String serverName = session.getExtraData(ServerName.class).map(ServerName::get).orElse(serverUUID);
        sessionMap.put("player_name", playerName);
        sessionMap.put("player_url_name", Html.encodeToURL(playerName));
        sessionMap.put("player_uuid", playerUUID);
        sessionMap.put("server_name", serverName);
        sessionMap.put("server_url_name", Html.encodeToURL(serverName));
        sessionMap.put("server_uuid", serverUUID);
        sessionMap.put("name", nameFunction.apply(sessionMap));
        sessionMap.put("start", formatters.yearLong().apply(session.getStart()) + (session.getExtraData(ActiveSession.class).isPresent() ? " (Online)" : ""));
        sessionMap.put("end", formatters.yearLong().apply(session.getEnd()));
        sessionMap.put("most_used_world", worldAliasSettings.getLongestWorldPlayed(session));
        sessionMap.put("length", formatters.timeAmount().apply(session.getLength()));
        sessionMap.put("afk_time", formatters.timeAmount().apply(session.getAfkTime()));
        sessionMap.put("mob_kills", session.getMobKillCount());
        sessionMap.put("deaths", session.getDeathCount());
        sessionMap.put("player_kills", session.getExtraData(PlayerKills.class).map(PlayerKills::asMutator).map(killsMutator -> killsMutator.toJSONAsMap(formatters)).orElseGet(ArrayList::new));
        sessionMap.put("first_session", session.isFirstSession());
        WorldPie worldPie = graphs.pie().worldPie(session.getExtraData(WorldTimes.class).orElseGet(WorldTimes::new));
        sessionMap.put("world_series", worldPie.getSlices());
        sessionMap.put("gm_series", worldPie.toHighChartsDrillDownMaps());
        session.getExtraData(AveragePing.class).ifPresent(averagePing -> sessionMap.put("avg_ping", formatters.decimals().apply(averagePing.getValue()) + " ms"));
        return sessionMap;
    });
}
Also used : WorldPie(com.djrapitops.plan.delivery.rendering.json.graphs.pie.WorldPie) AveragePing(com.djrapitops.plan.delivery.domain.AveragePing)

Aggregations

AveragePing (com.djrapitops.plan.delivery.domain.AveragePing)2 DateHolder (com.djrapitops.plan.delivery.domain.DateHolder)1 WorldPie (com.djrapitops.plan.delivery.rendering.json.graphs.pie.WorldPie)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