Search in sources :

Example 1 with Lists

use of com.djrapitops.plan.utilities.java.Lists in project Plan by plan-player-analytics.

the class LargeFetchQueries method fetchAllTPSData.

/**
 * Query database for TPS data.
 *
 * @return Map: Server UUID - List of TPS data
 */
public static Query<Map<ServerUUID, List<TPS>>> fetchAllTPSData() {
    String serverIDColumn = ServerTable.TABLE_NAME + '.' + ServerTable.SERVER_ID;
    String serverUUIDColumn = ServerTable.TABLE_NAME + '.' + ServerTable.SERVER_UUID + " as s_uuid";
    String sql = SELECT + TPSTable.DATE + ',' + TPSTable.TPS + ',' + TPSTable.PLAYERS_ONLINE + ',' + TPSTable.CPU_USAGE + ',' + TPSTable.RAM_USAGE + ',' + TPSTable.ENTITIES + ',' + TPSTable.CHUNKS + ',' + TPSTable.FREE_DISK + ',' + serverUUIDColumn + FROM + TPSTable.TABLE_NAME + INNER_JOIN + ServerTable.TABLE_NAME + " on " + serverIDColumn + "=" + TPSTable.SERVER_ID;
    return new QueryAllStatement<Map<ServerUUID, List<TPS>>>(sql, 50000) {

        @Override
        public Map<ServerUUID, List<TPS>> processResults(ResultSet set) throws SQLException {
            Map<ServerUUID, List<TPS>> serverMap = new HashMap<>();
            while (set.next()) {
                ServerUUID serverUUID = ServerUUID.fromString(set.getString("s_uuid"));
                List<TPS> tpsList = serverMap.computeIfAbsent(serverUUID, Lists::create);
                TPS tps = TPSBuilder.get().date(set.getLong(TPSTable.DATE)).tps(set.getDouble(TPSTable.TPS)).playersOnline(set.getInt(TPSTable.PLAYERS_ONLINE)).usedCPU(set.getDouble(TPSTable.CPU_USAGE)).usedMemory(set.getLong(TPSTable.RAM_USAGE)).entities(set.getInt(TPSTable.ENTITIES)).chunksLoaded(set.getInt(TPSTable.CHUNKS)).freeDiskSpace(set.getLong(TPSTable.FREE_DISK)).toTPS();
                tpsList.add(tps);
            }
            return serverMap;
        }
    };
}
Also used : ServerUUID(com.djrapitops.plan.identification.ServerUUID) HashMap(java.util.HashMap) Lists(com.djrapitops.plan.utilities.java.Lists) TPS(com.djrapitops.plan.gathering.domain.TPS) ResultSet(java.sql.ResultSet) List(java.util.List)

Example 2 with Lists

use of com.djrapitops.plan.utilities.java.Lists 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 3 with Lists

use of com.djrapitops.plan.utilities.java.Lists in project Plan by plan-player-analytics.

the class PingQueries method extractUserPings.

private static Map<UUID, List<Ping>> extractUserPings(ResultSet set) throws SQLException {
    Map<UUID, List<Ping>> userPings = new HashMap<>();
    while (set.next()) {
        UUID uuid = UUID.fromString(set.getString(PingTable.USER_UUID));
        ServerUUID serverUUID = ServerUUID.fromString(set.getString(PingTable.SERVER_UUID));
        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);
        List<Ping> pings = userPings.computeIfAbsent(uuid, Lists::create);
        pings.add(new Ping(date, serverUUID, minPing, maxPing, avgPing));
    }
    return userPings;
}
Also used : ServerUUID(com.djrapitops.plan.identification.ServerUUID) Lists(com.djrapitops.plan.utilities.java.Lists) Ping(com.djrapitops.plan.gathering.domain.Ping) ServerUUID(com.djrapitops.plan.identification.ServerUUID)

Example 4 with Lists

use of com.djrapitops.plan.utilities.java.Lists in project Plan by plan-player-analytics.

the class NicknameQueries method fetchAllNicknameData.

/**
 * Query database for all nickname data.
 *
 * @return Multimap: Server UUID - (Player UUID - List of nicknames)
 */
public static Query<Map<ServerUUID, Map<UUID, List<Nickname>>>> fetchAllNicknameData() {
    String sql = SELECT + NicknamesTable.NICKNAME + ',' + NicknamesTable.LAST_USED + ',' + NicknamesTable.USER_UUID + ',' + NicknamesTable.SERVER_UUID + FROM + NicknamesTable.TABLE_NAME;
    return new QueryAllStatement<Map<ServerUUID, Map<UUID, List<Nickname>>>>(sql, 5000) {

        @Override
        public Map<ServerUUID, Map<UUID, List<Nickname>>> processResults(ResultSet set) throws SQLException {
            Map<ServerUUID, Map<UUID, List<Nickname>>> map = new HashMap<>();
            while (set.next()) {
                ServerUUID serverUUID = ServerUUID.fromString(set.getString(NicknamesTable.SERVER_UUID));
                UUID uuid = UUID.fromString(set.getString(NicknamesTable.USER_UUID));
                Map<UUID, List<Nickname>> serverMap = map.computeIfAbsent(serverUUID, Maps::create);
                List<Nickname> nicknames = serverMap.computeIfAbsent(uuid, Lists::create);
                nicknames.add(new Nickname(set.getString(NicknamesTable.NICKNAME), set.getLong(NicknamesTable.LAST_USED), serverUUID));
            }
            return map;
        }
    };
}
Also used : ServerUUID(com.djrapitops.plan.identification.ServerUUID) QueryAllStatement(com.djrapitops.plan.storage.database.queries.QueryAllStatement) Maps(com.djrapitops.plan.utilities.java.Maps) Lists(com.djrapitops.plan.utilities.java.Lists) ResultSet(java.sql.ResultSet) ServerUUID(com.djrapitops.plan.identification.ServerUUID) Nickname(com.djrapitops.plan.delivery.domain.Nickname)

Example 5 with Lists

use of com.djrapitops.plan.utilities.java.Lists in project Plan by plan-player-analytics.

the class TPSQueries method fetchTPSDataOfAllServersBut.

public static Query<Map<ServerUUID, List<TPS>>> fetchTPSDataOfAllServersBut(long after, long before, ServerUUID leaveOut) {
    String sql = SELECT + '*' + FROM + TABLE_NAME + INNER_JOIN + ServerTable.TABLE_NAME + " on " + ServerTable.TABLE_NAME + '.' + ServerTable.SERVER_ID + '=' + SERVER_ID + WHERE + ServerTable.SERVER_UUID + "!=?" + AND + ServerTable.INSTALLED + "=?" + AND + DATE + "<?" + AND + DATE + ">?";
    return new QueryStatement<Map<ServerUUID, List<TPS>>>(sql, 1000) {

        @Override
        public void prepare(PreparedStatement statement) throws SQLException {
            if (leaveOut != null) {
                statement.setString(1, leaveOut.toString());
            } else {
                statement.setNull(1, Types.VARCHAR);
            }
            statement.setBoolean(2, true);
            statement.setLong(3, before);
            statement.setLong(4, after);
        }

        @Override
        public Map<ServerUUID, List<TPS>> processResults(ResultSet set) throws SQLException {
            Map<ServerUUID, List<TPS>> byServer = new HashMap<>();
            while (set.next()) {
                ServerUUID serverUUID = ServerUUID.fromString(set.getString(ServerTable.SERVER_UUID));
                List<TPS> ofServer = byServer.computeIfAbsent(serverUUID, Lists::create);
                ofServer.add(extractTPS(set));
            }
            return byServer;
        }
    };
}
Also used : ServerUUID(com.djrapitops.plan.identification.ServerUUID) Lists(com.djrapitops.plan.utilities.java.Lists) TPS(com.djrapitops.plan.gathering.domain.TPS) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) QueryStatement(com.djrapitops.plan.storage.database.queries.QueryStatement)

Aggregations

Lists (com.djrapitops.plan.utilities.java.Lists)13 ServerUUID (com.djrapitops.plan.identification.ServerUUID)11 ResultSet (java.sql.ResultSet)6 QueryAllStatement (com.djrapitops.plan.storage.database.queries.QueryAllStatement)3 Nickname (com.djrapitops.plan.delivery.domain.Nickname)2 GeoInfo (com.djrapitops.plan.gathering.domain.GeoInfo)2 Ping (com.djrapitops.plan.gathering.domain.Ping)2 TPS (com.djrapitops.plan.gathering.domain.TPS)2 QueryStatement (com.djrapitops.plan.storage.database.queries.QueryStatement)2 PreparedStatement (java.sql.PreparedStatement)2 HashMap (java.util.HashMap)2 List (java.util.List)2 PlayerContainer (com.djrapitops.plan.delivery.domain.container.PlayerContainer)1 ExtensionInformation (com.djrapitops.plan.extension.implementation.results.ExtensionInformation)1 FinishedSession (com.djrapitops.plan.gathering.domain.FinishedSession)1 UserInfo (com.djrapitops.plan.gathering.domain.UserInfo)1 Maps (com.djrapitops.plan.utilities.java.Maps)1 ArrayList (java.util.ArrayList)1