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 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) + "\"" + "}}";
}
use of com.djrapitops.plan.gathering.domain.Ping in project Plan by plan-player-analytics.
the class PingQueries method fetchPingDataOfServer.
public static Query<List<Ping>> fetchPingDataOfServer(long after, long before, ServerUUID serverUUID) {
String sql = SELECT + PingTable.DATE + ", " + PingTable.MAX_PING + ", " + PingTable.MIN_PING + ", " + PingTable.AVG_PING + FROM + PingTable.TABLE_NAME + WHERE + PingTable.SERVER_ID + "=" + ServerTable.SELECT_SERVER_ID + AND + PingTable.DATE + ">=?" + AND + PingTable.DATE + "<=?";
return new QueryStatement<List<Ping>>(sql, 1000) {
@Override
public void prepare(PreparedStatement statement) throws SQLException {
statement.setString(1, serverUUID.toString());
statement.setLong(2, after);
statement.setLong(3, before);
}
@Override
public List<Ping> processResults(ResultSet set) throws SQLException {
List<Ping> pings = new ArrayList<>();
while (set.next()) {
long date = set.getLong(PingTable.DATE);
double avgPing = set.getDouble(PingTable.AVG_PING);
int minPing = set.getInt(PingTable.MIN_PING);
int maxPing = set.getInt(PingTable.MAX_PING);
pings.add(new Ping(date, serverUUID, minPing, maxPing, avgPing));
}
return pings;
}
};
}
use of com.djrapitops.plan.gathering.domain.Ping in project Plan by plan-player-analytics.
the class PingQueries method fetchPingDataOfServerByGeolocation.
public static Query<Map<String, Ping>> fetchPingDataOfServerByGeolocation(ServerUUID serverUUID) {
String selectPingByGeolocation = SELECT + "a." + GeoInfoTable.GEOLOCATION + ", MIN(" + PingTable.MIN_PING + ") as minPing" + ", MAX(" + PingTable.MAX_PING + ") as maxPing" + ", AVG(" + PingTable.AVG_PING + ") as avgPing" + FROM + GeoInfoTable.TABLE_NAME + " a" + // That way the biggest a.last_used value will have NULL on the b.last_used column and MAX doesn't need to be used.
LEFT_JOIN + GeoInfoTable.TABLE_NAME + " b ON a." + GeoInfoTable.USER_ID + "=b." + GeoInfoTable.USER_ID + AND + "a." + GeoInfoTable.LAST_USED + "<b." + GeoInfoTable.LAST_USED + INNER_JOIN + PingTable.TABLE_NAME + " sp on sp." + PingTable.USER_ID + "=a." + GeoInfoTable.USER_ID + WHERE + "b." + GeoInfoTable.LAST_USED + IS_NULL + AND + "sp." + PingTable.SERVER_ID + "=" + ServerTable.SELECT_SERVER_ID + GROUP_BY + "a." + GeoInfoTable.GEOLOCATION;
return new QueryStatement<Map<String, Ping>>(selectPingByGeolocation) {
@Override
public void prepare(PreparedStatement statement) throws SQLException {
statement.setString(1, serverUUID.toString());
}
@Override
public Map<String, Ping> processResults(ResultSet set) throws SQLException {
// TreeMap to sort alphabetically
Map<String, Ping> pingByGeolocation = new TreeMap<>();
while (set.next()) {
Ping ping = new Ping(0L, serverUUID, set.getInt("minPing"), set.getInt("maxPing"), (int) set.getDouble("avgPing"));
pingByGeolocation.put(set.getString(GeoInfoTable.GEOLOCATION), ping);
}
return pingByGeolocation;
}
};
}
use of com.djrapitops.plan.gathering.domain.Ping in project Plan by plan-player-analytics.
the class PingStoreTransaction method performOperations.
@Override
protected void performOperations() {
Ping ping = calculateAggregatePing();
DBOpException userInsertError = null;
if (Boolean.FALSE.equals(query(PlayerFetchQueries.isPlayerRegistered(playerUUID)))) {
userInsertError = tryToRegisterUser(ping.getDate());
}
try {
execute(DataStoreQueries.storePing(playerUUID, serverUUID, ping));
} catch (DBOpException failed) {
if (userInsertError != null)
failed.addSuppressed(userInsertError);
if (failed.isUserIdConstraintViolation()) {
retry(ping, failed);
} else {
throw failed;
}
}
}
Aggregations