use of com.djrapitops.plan.delivery.domain.DateObj in project Plan by plan-player-analytics.
the class BukkitPingCounter method run.
@Override
public void run() {
long time = System.currentTimeMillis();
Iterator<Map.Entry<UUID, Long>> starts = startRecording.entrySet().iterator();
while (starts.hasNext()) {
Map.Entry<UUID, Long> start = starts.next();
if (time >= start.getValue()) {
addPlayer(start.getKey());
starts.remove();
}
}
Iterator<Map.Entry<UUID, List<DateObj<Integer>>>> iterator = playerHistory.entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry<UUID, List<DateObj<Integer>>> entry = iterator.next();
UUID uuid = entry.getKey();
List<DateObj<Integer>> history = entry.getValue();
Player player = Bukkit.getPlayer(uuid);
if (player != null) {
int ping = getPing(player);
if (ping <= -1 || ping > TimeUnit.SECONDS.toMillis(8L)) {
// Don't accept bad values
continue;
}
history.add(new DateObj<>(time, ping));
if (history.size() >= 30) {
dbSystem.getDatabase().executeTransaction(new PingStoreTransaction(uuid, serverInfo.getServerUUID(), new ArrayList<>(history)));
history.clear();
}
} else {
iterator.remove();
}
}
}
use of com.djrapitops.plan.delivery.domain.DateObj in project Plan by plan-player-analytics.
the class NukkitPingCounter method run.
@Override
public void run() {
long time = System.currentTimeMillis();
Iterator<Map.Entry<UUID, Long>> starts = startRecording.entrySet().iterator();
while (starts.hasNext()) {
Map.Entry<UUID, Long> start = starts.next();
if (time >= start.getValue()) {
addPlayer(start.getKey());
starts.remove();
}
}
Iterator<Map.Entry<UUID, List<DateObj<Integer>>>> iterator = playerHistory.entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry<UUID, List<DateObj<Integer>>> entry = iterator.next();
UUID uuid = entry.getKey();
List<DateObj<Integer>> history = entry.getValue();
Optional<Player> player = Server.getInstance().getPlayer(uuid);
if (player.isPresent()) {
int ping = player.get().getPing();
if (ping <= -1 || ping > TimeUnit.SECONDS.toMillis(8L)) {
// Don't accept bad values
continue;
}
history.add(new DateObj<>(time, ping));
if (history.size() >= 30) {
dbSystem.getDatabase().executeTransaction(new PingStoreTransaction(uuid, serverInfo.getServerUUID(), new ArrayList<>(history)));
history.clear();
}
} else {
iterator.remove();
}
}
}
use of com.djrapitops.plan.delivery.domain.DateObj in project Plan by plan-player-analytics.
the class VelocityPingCounter method run.
@Override
public void run() {
long time = System.currentTimeMillis();
Iterator<Map.Entry<UUID, Long>> starts = startRecording.entrySet().iterator();
while (starts.hasNext()) {
Map.Entry<UUID, Long> start = starts.next();
if (time >= start.getValue()) {
addPlayer(start.getKey());
starts.remove();
}
}
Iterator<Map.Entry<UUID, List<DateObj<Integer>>>> iterator = playerHistory.entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry<UUID, List<DateObj<Integer>>> entry = iterator.next();
UUID uuid = entry.getKey();
List<DateObj<Integer>> history = entry.getValue();
Player player = plugin.getProxy().getPlayer(uuid).orElse(null);
if (player != null) {
int ping = getPing(player);
if (ping <= -1 || ping > TimeUnit.SECONDS.toMillis(8L)) {
// Don't accept bad values
continue;
}
history.add(new DateObj<>(time, ping));
if (history.size() >= 30) {
dbSystem.getDatabase().executeTransaction(new PingStoreTransaction(uuid, serverInfo.getServerUUID(), new ArrayList<>(history)));
history.clear();
}
} else {
iterator.remove();
}
}
}
use of com.djrapitops.plan.delivery.domain.DateObj in project Plan by plan-player-analytics.
the class JSONFactory method serversAsJSONMaps.
public Map<String, Object> serversAsJSONMaps() {
Database db = dbSystem.getDatabase();
long now = System.currentTimeMillis();
long weekAgo = now - TimeUnit.DAYS.toMillis(7L);
Formatter<Long> year = formatters.yearLong();
Formatter<Double> decimals = formatters.decimals();
Formatter<Long> timeAmount = formatters.timeAmount();
Map<ServerUUID, Server> serverInformation = db.query(ServerQueries.fetchPlanServerInformation());
ServerUUID proxyUUID = serverInformation.values().stream().filter(Server::isProxy).findFirst().map(Server::getUuid).orElse(null);
Map<ServerUUID, Integer> serverUuidToId = new HashMap<>();
for (Server server : serverInformation.values()) {
server.getId().ifPresent(serverId -> serverUuidToId.put(server.getUuid(), serverId));
}
Map<Integer, List<TPS>> tpsDataByServerId = db.query(TPSQueries.fetchTPSDataOfAllServersBut(weekAgo, now, proxyUUID));
Map<ServerUUID, Integer> totalPlayerCounts = db.query(PlayerCountQueries.newPlayerCounts(0, now));
Map<ServerUUID, Integer> newPlayerCounts = db.query(PlayerCountQueries.newPlayerCounts(weekAgo, now));
Map<ServerUUID, Integer> uniquePlayerCounts = db.query(PlayerCountQueries.uniquePlayerCounts(weekAgo, now));
List<Map<String, Object>> servers = new ArrayList<>();
serverInformation.entrySet().stream().sorted(Comparator.comparing(entry -> entry.getValue().getIdentifiableName().toLowerCase())).filter(entry -> entry.getValue().isNotProxy()).forEach(entry -> {
ServerUUID serverUUID = entry.getKey();
Map<String, Object> server = new HashMap<>();
server.put("name", entry.getValue().getIdentifiableName());
Optional<DateObj<Integer>> recentPeak = db.query(TPSQueries.fetchPeakPlayerCount(serverUUID, now - TimeUnit.DAYS.toMillis(2L)));
Optional<DateObj<Integer>> allTimePeak = db.query(TPSQueries.fetchAllTimePeakPlayerCount(serverUUID));
server.put("last_peak_date", recentPeak.map(DateObj::getDate).map(year).orElse("-"));
server.put("best_peak_date", allTimePeak.map(DateObj::getDate).map(year).orElse("-"));
server.put("last_peak_players", recentPeak.map(DateObj::getValue).orElse(0));
server.put("best_peak_players", allTimePeak.map(DateObj::getValue).orElse(0));
TPSMutator tpsMonth = new TPSMutator(tpsDataByServerId.getOrDefault(serverUuidToId.get(serverUUID), Collections.emptyList()));
server.put("playersOnline", tpsMonth.all().stream().map(tps -> new double[] { tps.getDate(), tps.getPlayers() }).toArray(double[][]::new));
server.put("players", totalPlayerCounts.getOrDefault(serverUUID, 0));
server.put("new_players", newPlayerCounts.getOrDefault(serverUUID, 0));
server.put("unique_players", uniquePlayerCounts.getOrDefault(serverUUID, 0));
TPSMutator tpsWeek = tpsMonth.filterDataBetween(weekAgo, now);
double averageTPS = tpsWeek.averageTPS();
server.put("avg_tps", averageTPS != -1 ? decimals.apply(averageTPS) : locale.get(HtmlLang.UNIT_NO_DATA).toString());
server.put("low_tps_spikes", tpsWeek.lowTpsSpikeCount(config.get(DisplaySettings.GRAPH_TPS_THRESHOLD_MED)));
server.put("downtime", timeAmount.apply(tpsWeek.serverDownTime()));
server.put("current_uptime", serverUptimeCalculator.getServerUptimeMillis(serverUUID).map(timeAmount).orElse(locale.getString(GenericLang.UNAVAILABLE)));
Optional<TPS> online = tpsWeek.getLast();
server.put("online", online.map(point -> point.getDate() >= now - TimeUnit.MINUTES.toMillis(3L) ? point.getPlayers() : "Possibly offline").orElse(locale.get(HtmlLang.UNIT_NO_DATA).toString()));
servers.add(server);
});
return Collections.singletonMap("servers", servers);
}
use of com.djrapitops.plan.delivery.domain.DateObj in project Plan by plan-player-analytics.
the class SessionPlaceHolders method register.
@Override
public void register(PlanPlaceholders placeholders) {
int tzOffsetMs = config.getTimeZone().getOffset(System.currentTimeMillis());
Formatter<Long> timeAmount = formatters.timeAmount();
Formatter<DateHolder> year = formatters.year();
Formatter<Double> decimals = formatters.decimals();
Database database = dbSystem.getDatabase();
placeholders.registerStatic("sessions_play_time_total", parameters -> timeAmount.apply(database.query(SessionQueries.playtime(0L, now(), getServerUUID(parameters)))));
placeholders.registerStatic("sessions_play_time_total_raw", parameters -> database.query(SessionQueries.playtime(0L, now(), getServerUUID(parameters))));
placeholders.registerStatic("sessions_play_time_day", parameters -> timeAmount.apply(database.query(SessionQueries.playtime(dayAgo(), now(), getServerUUID(parameters)))));
placeholders.registerStatic("sessions_play_time_day_raw", parameters -> database.query(SessionQueries.playtime(dayAgo(), now(), getServerUUID(parameters))));
placeholders.registerStatic("sessions_play_time_week", parameters -> timeAmount.apply(database.query(SessionQueries.playtime(weekAgo(), now(), getServerUUID(parameters)))));
placeholders.registerStatic("sessions_play_time_week_raw", parameters -> database.query(SessionQueries.playtime(weekAgo(), now(), getServerUUID(parameters))));
placeholders.registerStatic("sessions_play_time_month", parameters -> timeAmount.apply(database.query(SessionQueries.playtime(monthAgo(), now(), getServerUUID(parameters)))));
placeholders.registerStatic("sessions_play_time_month_raw", parameters -> database.query(SessionQueries.playtime(monthAgo(), now(), getServerUUID(parameters))));
placeholders.registerStatic("sessions_active_time_total", parameters -> timeAmount.apply(database.query(SessionQueries.activePlaytime(0L, now(), getServerUUID(parameters)))));
placeholders.registerStatic("sessions_active_time_total_raw", parameters -> database.query(SessionQueries.activePlaytime(0L, now(), getServerUUID(parameters))));
placeholders.registerStatic("sessions_active_time_day", parameters -> timeAmount.apply(database.query(SessionQueries.activePlaytime(dayAgo(), now(), getServerUUID(parameters)))));
placeholders.registerStatic("sessions_active_time_day_raw", parameters -> database.query(SessionQueries.activePlaytime(dayAgo(), now(), getServerUUID(parameters))));
placeholders.registerStatic("sessions_active_time_week", parameters -> timeAmount.apply(database.query(SessionQueries.activePlaytime(weekAgo(), now(), getServerUUID(parameters)))));
placeholders.registerStatic("sessions_active_time_week_raw", parameters -> database.query(SessionQueries.activePlaytime(weekAgo(), now(), getServerUUID(parameters))));
placeholders.registerStatic("sessions_active_time_month", parameters -> timeAmount.apply(database.query(SessionQueries.activePlaytime(monthAgo(), now(), getServerUUID(parameters)))));
placeholders.registerStatic("sessions_active_time_month_raw", parameters -> database.query(SessionQueries.activePlaytime(monthAgo(), now(), getServerUUID(parameters))));
placeholders.registerStatic("sessions_afk_time_total", parameters -> timeAmount.apply(database.query(SessionQueries.afkTime(0L, now(), getServerUUID(parameters)))));
placeholders.registerStatic("sessions_afk_time_total_raw", parameters -> database.query(SessionQueries.afkTime(0L, now(), getServerUUID(parameters))));
placeholders.registerStatic("sessions_afk_time_day", parameters -> timeAmount.apply(database.query(SessionQueries.afkTime(dayAgo(), now(), getServerUUID(parameters)))));
placeholders.registerStatic("sessions_afk_time_day_raw", parameters -> database.query(SessionQueries.afkTime(dayAgo(), now(), getServerUUID(parameters))));
placeholders.registerStatic("sessions_afk_time_week", parameters -> timeAmount.apply(database.query(SessionQueries.afkTime(weekAgo(), now(), getServerUUID(parameters)))));
placeholders.registerStatic("sessions_afk_time_week_raw", parameters -> database.query(SessionQueries.afkTime(weekAgo(), now(), getServerUUID(parameters))));
placeholders.registerStatic("sessions_afk_time_month", parameters -> timeAmount.apply(database.query(SessionQueries.afkTime(monthAgo(), now(), getServerUUID(parameters)))));
placeholders.registerStatic("sessions_afk_time_month_raw", parameters -> database.query(SessionQueries.afkTime(monthAgo(), now(), getServerUUID(parameters))));
PlanPlaceholders.StaticPlaceholderLoader uniquePlayers = parameters -> database.query(PlayerCountQueries.newPlayerCount(0L, now(), getServerUUID(parameters)));
placeholders.registerStatic("sessions_unique_players_total", uniquePlayers);
placeholders.registerStatic("sessions_new_players_total", uniquePlayers);
placeholders.registerStatic("sessions_unique_players_day", parameters -> database.query(PlayerCountQueries.uniquePlayerCount(dayAgo(), now(), getServerUUID(parameters))));
placeholders.registerStatic("sessions_unique_players_today", parameters -> {
NavigableMap<Long, Integer> playerCounts = database.query(PlayerCountQueries.uniquePlayerCounts(dayAgo(), now(), config.getTimeZone().getOffset(now()), getServerUUID(parameters)));
return playerCounts.isEmpty() ? 0 : playerCounts.lastEntry().getValue();
});
placeholders.registerStatic("sessions_unique_players_week", parameters -> database.query(PlayerCountQueries.uniquePlayerCount(weekAgo(), now(), getServerUUID(parameters))));
placeholders.registerStatic("sessions_unique_players_month", parameters -> database.query(PlayerCountQueries.uniquePlayerCount(monthAgo(), now(), getServerUUID(parameters))));
placeholders.registerStatic("sessions_players_death_total", parameters -> database.query(KillQueries.deathCount(0L, now(), getServerUUID(parameters))));
placeholders.registerStatic("sessions_players_death_day", parameters -> database.query(KillQueries.deathCount(dayAgo(), now(), getServerUUID(parameters))));
placeholders.registerStatic("sessions_players_death_week", parameters -> database.query(KillQueries.deathCount(weekAgo(), now(), getServerUUID(parameters))));
placeholders.registerStatic("sessions_players_death_month", parameters -> database.query(KillQueries.deathCount(monthAgo(), now(), getServerUUID(parameters))));
placeholders.registerStatic("sessions_players_kill_total", parameters -> database.query(KillQueries.playerKillCount(0L, now(), getServerUUID(parameters))));
placeholders.registerStatic("sessions_players_kill_day", parameters -> database.query(KillQueries.playerKillCount(dayAgo(), now(), getServerUUID(parameters))));
placeholders.registerStatic("sessions_players_kill_week", parameters -> database.query(KillQueries.playerKillCount(weekAgo(), now(), getServerUUID(parameters))));
placeholders.registerStatic("sessions_players_kill_month", parameters -> database.query(KillQueries.playerKillCount(monthAgo(), now(), getServerUUID(parameters))));
placeholders.registerStatic("sessions_mob_kill_total", parameters -> database.query(KillQueries.mobKillCount(0L, now(), getServerUUID(parameters))));
placeholders.registerStatic("sessions_mob_kill_day", parameters -> database.query(KillQueries.mobKillCount(dayAgo(), now(), getServerUUID(parameters))));
placeholders.registerStatic("sessions_mob_kill_week", parameters -> database.query(KillQueries.mobKillCount(weekAgo(), now(), getServerUUID(parameters))));
placeholders.registerStatic("sessions_mob_kill_month", parameters -> database.query(KillQueries.mobKillCount(monthAgo(), now(), getServerUUID(parameters))));
placeholders.registerStatic("sessions_average_session_length_total", parameters -> getPlaytime(database, 0L, now(), getServerUUID(parameters), timeAmount));
placeholders.registerStatic("sessions_average_session_length_day", parameters -> getPlaytime(database, dayAgo(), now(), getServerUUID(parameters), timeAmount));
placeholders.registerStatic("sessions_average_session_length_week", parameters -> getPlaytime(database, weekAgo(), now(), getServerUUID(parameters), timeAmount));
placeholders.registerStatic("sessions_average_session_length_month", parameters -> getPlaytime(database, monthAgo(), now(), getServerUUID(parameters), timeAmount));
placeholders.registerStatic("sessions_average_unique_players_total", parameters -> database.query(PlayerCountQueries.averageUniquePlayerCount(0L, now(), tzOffsetMs, getServerUUID(parameters))));
placeholders.registerStatic("sessions_average_unique_players_day", parameters -> database.query(PlayerCountQueries.averageUniquePlayerCount(dayAgo(), now(), tzOffsetMs, getServerUUID(parameters))));
placeholders.registerStatic("sessions_average_unique_players_week", parameters -> database.query(PlayerCountQueries.averageUniquePlayerCount(weekAgo(), now(), tzOffsetMs, getServerUUID(parameters))));
placeholders.registerStatic("sessions_average_unique_players_month", parameters -> database.query(PlayerCountQueries.averageUniquePlayerCount(monthAgo(), now(), tzOffsetMs, getServerUUID(parameters))));
placeholders.registerStatic("sessions_new_players_day", parameters -> database.query(PlayerCountQueries.newPlayerCount(dayAgo(), now(), getServerUUID(parameters))));
placeholders.registerStatic("sessions_new_players_week", parameters -> database.query(PlayerCountQueries.newPlayerCount(weekAgo(), now(), getServerUUID(parameters))));
placeholders.registerStatic("sessions_new_players_month", parameters -> database.query(PlayerCountQueries.newPlayerCount(monthAgo(), now(), getServerUUID(parameters))));
placeholders.registerStatic("ping_total", parameters -> decimals.apply(database.query(PingQueries.averagePing(0L, now(), getServerUUID(parameters)))) + " ms");
placeholders.registerStatic("ping_day", parameters -> decimals.apply(database.query(PingQueries.averagePing(dayAgo(), now(), getServerUUID(parameters)))) + " ms");
placeholders.registerStatic("ping_week", parameters -> decimals.apply(database.query(PingQueries.averagePing(weekAgo(), now(), getServerUUID(parameters)))) + " ms");
placeholders.registerStatic("ping_month", parameters -> decimals.apply(database.query(PingQueries.averagePing(monthAgo(), now(), getServerUUID(parameters)))) + " ms");
placeholders.registerStatic("sessions_peak_count", parameters -> database.query(TPSQueries.fetchAllTimePeakPlayerCount(getServerUUID(parameters))).map(DateObj::getValue).orElse(0));
placeholders.registerStatic("sessions_peak_date", parameters -> database.query(TPSQueries.fetchAllTimePeakPlayerCount(getServerUUID(parameters))).map(year).orElse("-"));
placeholders.registerStatic("sessions_recent_peak_count", parameters -> database.query(TPSQueries.fetchPeakPlayerCount(getServerUUID(parameters), now() - TimeUnit.DAYS.toMillis(2L))).map(DateObj::getValue).orElse(0));
placeholders.registerStatic("sessions_recent_peak_date", parameters -> database.query(TPSQueries.fetchPeakPlayerCount(getServerUUID(parameters), now() - TimeUnit.DAYS.toMillis(2L))).map(year).orElse("-"));
}
Aggregations