Browse Source

group hype

master
gsd 6 months ago
parent
commit
948e523eb5
  1. 26
      src/main/java/app/updates/OnlineUpdater.java

26
src/main/java/app/updates/OnlineUpdater.java

@ -90,21 +90,37 @@ public class OnlineUpdater extends BaseUpdater {
public List<MaxPeakOfDay> getMaxPeakOfDays(String server_id, int limit) {
return jdbcTemplate_ro.query("SELECT SUM(s.player_count) as player_count, s.fulldate as fl FROM (SELECT max(player_count) as player_count, cast(to_timestamp(utime) as date) as fulldate,server_id FROM servers_online WHERE player_count != 0 and server_id like ? GROUP BY cast(to_timestamp(utime) as date), server_id ORDER BY fulldate DESC) s GROUP BY s.fulldate ORDER BY s.fulldate DESC LIMIT ?",
return jdbcTemplate_ro.query("""
SELECT round(sum(s.player_count))::int as player_count, s.ts as fl FROM (
SELECT round(max(player_count), 4) as player_count, to_timestamp(utime)::date as ts
FROM servers_online
WHERE server_id like ? and player_count != 0
GROUP BY ts, server_id) as s group by s.ts order by s.ts desc limit ?
""",
new Object[]{server_id==null||server_id.isEmpty()?"%":server_id, limit},
(rs, rowNum) -> new MaxPeakOfDay(rs));
}
public List<AvgPeakOfDay> getAvgPeakOfDays(String server_id, int limit) {
return jdbcTemplate_ro.query("SELECT SUM(s.player_count) as player_count, s.fulldate as fl FROM (SELECT avg(player_count) as player_count, cast(to_timestamp(utime) as date) as fulldate,server_id FROM servers_online WHERE player_count != 0 and server_id like ? GROUP BY cast(to_timestamp(utime) as date), server_id ORDER BY fulldate DESC) s GROUP BY s.fulldate ORDER BY s.fulldate DESC LIMIT ?",
return jdbcTemplate_ro.query("""
SELECT round(sum(s.player_count))::int as player_count, s.ts as fl FROM (
SELECT round(avg(player_count), 4) as player_count, to_timestamp(utime)::date as ts
FROM servers_online
WHERE server_id like ? and player_count != 0
GROUP BY ts, server_id) as s group by s.ts order by s.ts desc limit ?
""",
new Object[]{server_id==null||server_id.isEmpty()?"%":server_id, limit},
(rs, rowNum) -> new AvgPeakOfDay(rs));
}
public List<StatsOfPeakOfPerFiveMinutes> getMaxPeakOfFiveMinutes(String server_id, int limit, int minutes) {
public List<StatsOfPeakOfPerFiveMinutes> getMaxPeakOfFiveMinutes(String server_id, int limit, Integer minutes) {
long utime = LocalDate.now().minusDays(limit -1).toEpochSecond(LocalTime.MIN, ZoneOffset.ofHours(3));
return jdbcTemplate_ro.query("select sum(sub.player_count) as player_count, sub.fulldate from (SELECT max(player_count) as player_count, cast(to_timestamp(utime) as date) as fulldate, utime as ts, server_id FROM servers_online WHERE utime >= ? and server_id like ? GROUP BY cast(to_timestamp(utime) as date) / ?, server_id ORDER BY ts DESC) sub GROUP BY sub.fulldate",
new Object[]{utime, server_id==null||server_id.isEmpty()?"%":server_id, minutes * 100},
return jdbcTemplate_ro.query("select round(sum(sub.player_count))::int as player_count, sub.ts as fulldate from ("+
"SELECT round(avg(player_count), 4) as player_count, date_bin('"+minutes+" minutes'"+",to_timestamp(utime)::timestamp, '2001-01-01 00:02:30') as ts "+
"FROM servers_online " +
"WHERE utime >= ? and server_id like ? "+
"GROUP BY ts, server_id) sub GROUP BY sub.ts ",
new Object[]{utime, server_id==null||server_id.isEmpty()?"%":server_id},
(rs, rowNum) -> new StatsOfPeakOfPerFiveMinutes(rs));
}

Loading…
Cancel
Save