From c76b6ff9714ae83ad3784f2e73eb74b0b5c2b31d Mon Sep 17 00:00:00 2001 From: gsd Date: Sat, 14 Dec 2024 20:27:05 +0300 Subject: [PATCH] goty 2 --- .../java/app/controllers/StatsController.java | 15 +++++++++++---- src/main/java/app/services/ServerService.java | 19 ++++++++++++++++++- .../java/app/services/db/DonateService.java | 5 +++++ .../java/app/services/db/MessageService.java | 12 ++++++++++++ 4 files changed, 46 insertions(+), 5 deletions(-) diff --git a/src/main/java/app/controllers/StatsController.java b/src/main/java/app/controllers/StatsController.java index 335d2c1..524cbc8 100644 --- a/src/main/java/app/controllers/StatsController.java +++ b/src/main/java/app/controllers/StatsController.java @@ -5,7 +5,9 @@ import app.annotations.interfaces.*; import app.entities.StatisticRange; import app.entities.Stats; import app.services.ExternalServices; +import app.services.ServerService; import app.services.db.DonateService; +import app.services.db.MessageService; import app.services.io.readers.ServersReader; import app.updates.OnlineUpdater; import app.utils.RealIPService; @@ -33,16 +35,20 @@ public class StatsController { private ServersReader serversReader; private RealIPService realIPService; private DonateService donateService; + private ServerService serverService; + private MessageService messageService; @Autowired public StatsController(Stats stats, ExternalServices externalServices, OnlineUpdater onlineUpdater, ServersReader serversReader, - DonateService donateService){ + DonateService donateService, ServerService serverService, MessageService messageService){ this.stats = stats; this.externalServices = externalServices; this.onlineUpdater = onlineUpdater; this.serversReader = serversReader; this.realIPService = new RealIPService(); this.donateService = donateService; + this.serverService = serverService; + this.messageService = messageService; } @GetMapping @@ -128,12 +134,13 @@ public class StatsController { @GetMapping("/goty") @WaitAfterNext(order = "goty") - public Map getGoty() { - //select message, count(*) as c from user_messages group by message order by c desc limit 15 - топ сообщений + public Map getGoty(@RequestParam StatisticRange statisticRange) { //select weapon_name, count(*) as c from user_killfeed group by weapon_name order by c desc limit 10 - топ пушек //select count(*) as c from user_killfeed where attacker_id != user_killfeed.victim_id - скок умерло карликов return Map.of( - "topdonate", donateService.getTopSteamSheikh(StatisticRange.YEAR) + "top_donate", donateService.getTopSteamSheikh(statisticRange), + "server_avg", serverService.getServerAvgOnline(statisticRange), + "top_message", messageService.getTopMessage(statisticRange) ); } } diff --git a/src/main/java/app/services/ServerService.java b/src/main/java/app/services/ServerService.java index 7b257d5..88d7b5b 100644 --- a/src/main/java/app/services/ServerService.java +++ b/src/main/java/app/services/ServerService.java @@ -1,24 +1,32 @@ package app.services; import app.entities.PlayerProfile; +import app.entities.StatisticRange; import app.entities.Stats; import app.entities.server.PlayOn; import app.updates.SocialUpdater; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.context.ApplicationContext; +import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.stereotype.Service; import java.util.ArrayList; import java.util.List; +import java.util.Map; import java.util.concurrent.Callable; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @Service public class ServerService { - Stats stats; + private Stats stats; + + @Autowired + @Qualifier("jt_ro") + private JdbcTemplate jdbcTemplate; private final Logger logger = LoggerFactory.getLogger(ServerService.class); @@ -56,4 +64,13 @@ public class ServerService { logger.error("Cancel burst execute rcon command: {}", command); } } + + public List> getServerAvgOnline(StatisticRange statisticRange) { + return jdbcTemplate.query("select round(avg(player_count)) as a, server_id from servers_online " + + "where player_count!=0 and server_id not like 'srv12' and " + + "utime > extract(epoch from date_trunc(?,now())) " + + "group by server_id order by a desc", + new Object[]{StatisticRange.cast(statisticRange)}, + (rs, n) -> Map.of("server_id",rs.getString("server_id"), "avg", rs.getLong("a"))); + } } diff --git a/src/main/java/app/services/db/DonateService.java b/src/main/java/app/services/db/DonateService.java index 6ad1317..e17cf63 100644 --- a/src/main/java/app/services/db/DonateService.java +++ b/src/main/java/app/services/db/DonateService.java @@ -6,6 +6,7 @@ import app.entities.Stats; import app.entities.VipGiveMethod; import app.entities.db.DonateStat; import app.entities.other.SteamID; +import app.utils.SteamIDConverter; import jakarta.annotation.PostConstruct; import lombok.Data; import lombok.Getter; @@ -154,6 +155,10 @@ public class DonateService { private String steam2; private long r; private long k; + public String getUrl() { + SteamID steamID = SteamIDConverter.getSteamID(this.steam2); + return steamID!=null ? steamID.community_url : ""; + } } public List getTopSteamSheikh(StatisticRange statisticRange) { diff --git a/src/main/java/app/services/db/MessageService.java b/src/main/java/app/services/db/MessageService.java index 0163282..7f80213 100644 --- a/src/main/java/app/services/db/MessageService.java +++ b/src/main/java/app/services/db/MessageService.java @@ -1,5 +1,6 @@ package app.services.db; +import app.entities.StatisticRange; import app.entities.Stats; import app.entities.other.SteamID; import lombok.Data; @@ -63,6 +64,17 @@ public class MessageService { .stream().findFirst().orElse(0L); } + public List> getTopMessage(StatisticRange statisticRange) { + return jdbcTemplate.query("select message, count(*) as c from user_messages\n" + + " where utime > extract(epoch from date_trunc(?, now()))\n" + + " and message not ilike 'menu'\n" + + " and message not ilike 'vty.'\n" + + " and message not ilike 'меню'\n" + + "group by message order by c desc limit ?", + new Object[]{StatisticRange.cast(statisticRange), 15}, + (rs, n) -> Map.of("message", rs.getString("message"), "count", rs.getLong("c"))); + } + /* CREATE TABLE user_messages ( id int(11) NOT NULL,