Search in sources :

Example 6 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 7 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)

Example 8 with 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;
        }
    };
}
Also used : Ping(com.djrapitops.plan.gathering.domain.Ping) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) QueryStatement(com.djrapitops.plan.storage.database.queries.QueryStatement)

Example 9 with Ping

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;
        }
    };
}
Also used : Ping(com.djrapitops.plan.gathering.domain.Ping) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) QueryStatement(com.djrapitops.plan.storage.database.queries.QueryStatement)

Example 10 with Ping

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;
        }
    }
}
Also used : DBOpException(com.djrapitops.plan.exceptions.database.DBOpException) Ping(com.djrapitops.plan.gathering.domain.Ping)

Aggregations

Ping (com.djrapitops.plan.gathering.domain.Ping)12 ServerUUID (com.djrapitops.plan.identification.ServerUUID)4 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 DBOpException (com.djrapitops.plan.exceptions.database.DBOpException)1