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;
}
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;
}
}
}
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());
}));
}
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;
}
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) + "\"" + "}}";
}
Aggregations