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;
}
};
}
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;
}
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;
}
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;
}
};
}
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;
}
};
}
Aggregations