Search in sources :

Example 1 with Ping

use of com.djrapitops.plan.gathering.domain.Ping in project Plan by plan-player-analytics.

the class PlayersMutator method getPingPerCountry.

public Map<String, List<Ping>> getPingPerCountry(ServerUUID serverUUID) {
    Map<String, List<Ping>> pingPerCountry = new HashMap<>();
    for (PlayerContainer player : players) {
        Optional<GeoInfo> mostRecent = GeoInfoMutator.forContainer(player).mostRecent();
        if (!mostRecent.isPresent()) {
            continue;
        }
        List<Ping> pings = player.getValue(PlayerKeys.PING).orElse(new ArrayList<>());
        String country = mostRecent.get().getGeolocation();
        List<Ping> countryPings = pingPerCountry.computeIfAbsent(country, Lists::create);
        countryPings.addAll(new PingMutator(pings).filterByServer(serverUUID).all());
    }
    return pingPerCountry;
}
Also used : PlayerContainer(com.djrapitops.plan.delivery.domain.container.PlayerContainer) Lists(com.djrapitops.plan.utilities.java.Lists) Ping(com.djrapitops.plan.gathering.domain.Ping) GeoInfo(com.djrapitops.plan.gathering.domain.GeoInfo)

Example 2 with Ping

use of com.djrapitops.plan.gathering.domain.Ping 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 3 with Ping

use of com.djrapitops.plan.gathering.domain.Ping in project Plan by plan-player-analytics.

the class PingMutator method mutateToByMinutePings.

public PingMutator mutateToByMinutePings() {
    DateHoldersMutator<Ping> dateMutator = new DateHoldersMutator<>(pings);
    SortedMap<Long, List<Ping>> byStartOfMinute = dateMutator.groupByStartOfMinute();
    return new PingMutator(Lists.map(byStartOfMinute.entrySet(), entry -> {
        PingMutator mutator = new PingMutator(entry.getValue());
        return new Ping(entry.getKey(), null, mutator.min(), mutator.max(), mutator.average());
    }));
}
Also used : java.util(java.util) DateHolder(com.djrapitops.plan.delivery.domain.DateHolder) Lists(com.djrapitops.plan.utilities.java.Lists) FinishedSession(com.djrapitops.plan.gathering.domain.FinishedSession) Predicate(java.util.function.Predicate) ServerUUID(com.djrapitops.plan.identification.ServerUUID) Ping(com.djrapitops.plan.gathering.domain.Ping) Predicates(com.djrapitops.plan.utilities.Predicates) AveragePing(com.djrapitops.plan.delivery.domain.AveragePing) CommonKeys(com.djrapitops.plan.delivery.domain.keys.CommonKeys) DataContainer(com.djrapitops.plan.delivery.domain.container.DataContainer) DateHolderOldestComparator(com.djrapitops.plan.utilities.comparators.DateHolderOldestComparator) Ping(com.djrapitops.plan.gathering.domain.Ping) AveragePing(com.djrapitops.plan.delivery.domain.AveragePing)

Example 4 with Ping

use of com.djrapitops.plan.gathering.domain.Ping in project Plan by plan-player-analytics.

the class PingMutator method sortByServers.

public static Map<ServerUUID, SortedMap<Long, Ping>> sortByServers(List<Ping> pings) {
    Map<ServerUUID, SortedMap<Long, Ping>> sorted = new HashMap<>();
    for (Ping ping : pings) {
        ServerUUID serverUUID = ping.getServerUUID();
        SortedMap<Long, Ping> serverSessions = sorted.getOrDefault(serverUUID, new TreeMap<>());
        serverSessions.put(ping.getDate(), ping);
        sorted.put(serverUUID, serverSessions);
    }
    return sorted;
}
Also used : ServerUUID(com.djrapitops.plan.identification.ServerUUID) Ping(com.djrapitops.plan.gathering.domain.Ping) AveragePing(com.djrapitops.plan.delivery.domain.AveragePing)

Example 5 with Ping

use of com.djrapitops.plan.gathering.domain.Ping in project Plan by plan-player-analytics.

the class GraphJSONCreator method pingGraphsJSON.

public String pingGraphsJSON(ServerUUID serverUUID) {
    Database db = dbSystem.getDatabase();
    long now = System.currentTimeMillis();
    List<Ping> pings = db.query(PingQueries.fetchPingDataOfServer(now - TimeUnit.DAYS.toMillis(180L), now, serverUUID));
    // TODO Optimize in query
    PingGraph pingGraph = graphs.line().pingGraph(new PingMutator(pings).mutateToByMinutePings().all());
    return "{\"min_ping_series\":" + pingGraph.getMinGraph().toHighChartsSeries() + ",\"avg_ping_series\":" + pingGraph.getAvgGraph().toHighChartsSeries() + ",\"max_ping_series\":" + pingGraph.getMaxGraph().toHighChartsSeries() + ",\"colors\":{" + "\"min\":\"" + theme.getValue(ThemeVal.GRAPH_MIN_PING) + "\"," + "\"avg\":\"" + theme.getValue(ThemeVal.GRAPH_AVG_PING) + "\"," + "\"max\":\"" + theme.getValue(ThemeVal.GRAPH_MAX_PING) + "\"" + "}}";
}
Also used : PingGraph(com.djrapitops.plan.delivery.rendering.json.graphs.line.PingGraph) Ping(com.djrapitops.plan.gathering.domain.Ping) Database(com.djrapitops.plan.storage.database.Database) PingMutator(com.djrapitops.plan.delivery.domain.mutators.PingMutator)

Aggregations

Ping (com.djrapitops.plan.gathering.domain.Ping)12 ServerUUID (com.djrapitops.plan.identification.ServerUUID)5 AveragePing (com.djrapitops.plan.delivery.domain.AveragePing)3 Lists (com.djrapitops.plan.utilities.java.Lists)3 ResultSet (java.sql.ResultSet)3 DateHolder (com.djrapitops.plan.delivery.domain.DateHolder)2 FinishedSession (com.djrapitops.plan.gathering.domain.FinishedSession)2 Database (com.djrapitops.plan.storage.database.Database)2 QueryStatement (com.djrapitops.plan.storage.database.queries.QueryStatement)2 PingStoreTransaction (com.djrapitops.plan.storage.database.transactions.events.PingStoreTransaction)2 DateHolderOldestComparator (com.djrapitops.plan.utilities.comparators.DateHolderOldestComparator)2 PreparedStatement (java.sql.PreparedStatement)2 Test (org.junit.jupiter.api.Test)2 DateObj (com.djrapitops.plan.delivery.domain.DateObj)1 DataContainer (com.djrapitops.plan.delivery.domain.container.DataContainer)1 PlayerContainer (com.djrapitops.plan.delivery.domain.container.PlayerContainer)1 CommonKeys (com.djrapitops.plan.delivery.domain.keys.CommonKeys)1 PingMutator (com.djrapitops.plan.delivery.domain.mutators.PingMutator)1 PingGraph (com.djrapitops.plan.delivery.rendering.json.graphs.line.PingGraph)1 GeoInfo (com.djrapitops.plan.gathering.domain.GeoInfo)1