Browse Source

goty 2

master
gsd 4 months ago
parent
commit
c76b6ff971
  1. 15
      src/main/java/app/controllers/StatsController.java
  2. 19
      src/main/java/app/services/ServerService.java
  3. 5
      src/main/java/app/services/db/DonateService.java
  4. 12
      src/main/java/app/services/db/MessageService.java

15
src/main/java/app/controllers/StatsController.java

@ -5,7 +5,9 @@ import app.annotations.interfaces.*;
import app.entities.StatisticRange; import app.entities.StatisticRange;
import app.entities.Stats; import app.entities.Stats;
import app.services.ExternalServices; import app.services.ExternalServices;
import app.services.ServerService;
import app.services.db.DonateService; import app.services.db.DonateService;
import app.services.db.MessageService;
import app.services.io.readers.ServersReader; import app.services.io.readers.ServersReader;
import app.updates.OnlineUpdater; import app.updates.OnlineUpdater;
import app.utils.RealIPService; import app.utils.RealIPService;
@ -33,16 +35,20 @@ public class StatsController {
private ServersReader serversReader; private ServersReader serversReader;
private RealIPService realIPService; private RealIPService realIPService;
private DonateService donateService; private DonateService donateService;
private ServerService serverService;
private MessageService messageService;
@Autowired @Autowired
public StatsController(Stats stats, ExternalServices externalServices, OnlineUpdater onlineUpdater, ServersReader serversReader, public StatsController(Stats stats, ExternalServices externalServices, OnlineUpdater onlineUpdater, ServersReader serversReader,
DonateService donateService){ DonateService donateService, ServerService serverService, MessageService messageService){
this.stats = stats; this.stats = stats;
this.externalServices = externalServices; this.externalServices = externalServices;
this.onlineUpdater = onlineUpdater; this.onlineUpdater = onlineUpdater;
this.serversReader = serversReader; this.serversReader = serversReader;
this.realIPService = new RealIPService(); this.realIPService = new RealIPService();
this.donateService = donateService; this.donateService = donateService;
this.serverService = serverService;
this.messageService = messageService;
} }
@GetMapping @GetMapping
@ -128,12 +134,13 @@ public class StatsController {
@GetMapping("/goty") @GetMapping("/goty")
@WaitAfterNext(order = "goty") @WaitAfterNext(order = "goty")
public Map getGoty() { public Map getGoty(@RequestParam StatisticRange statisticRange) {
//select message, count(*) as c from user_messages group by message order by c desc limit 15 - топ сообщений
//select weapon_name, count(*) as c from user_killfeed group by weapon_name order by c desc limit 10 - топ пушек //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 - скок умерло карликов //select count(*) as c from user_killfeed where attacker_id != user_killfeed.victim_id - скок умерло карликов
return Map.of( return Map.of(
"topdonate", donateService.getTopSteamSheikh(StatisticRange.YEAR) "top_donate", donateService.getTopSteamSheikh(statisticRange),
"server_avg", serverService.getServerAvgOnline(statisticRange),
"top_message", messageService.getTopMessage(statisticRange)
); );
} }
} }

19
src/main/java/app/services/ServerService.java

@ -1,24 +1,32 @@
package app.services; package app.services;
import app.entities.PlayerProfile; import app.entities.PlayerProfile;
import app.entities.StatisticRange;
import app.entities.Stats; import app.entities.Stats;
import app.entities.server.PlayOn; import app.entities.server.PlayOn;
import app.updates.SocialUpdater; import app.updates.SocialUpdater;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
@Service @Service
public class ServerService { public class ServerService {
Stats stats; private Stats stats;
@Autowired
@Qualifier("jt_ro")
private JdbcTemplate jdbcTemplate;
private final Logger logger = LoggerFactory.getLogger(ServerService.class); private final Logger logger = LoggerFactory.getLogger(ServerService.class);
@ -56,4 +64,13 @@ public class ServerService {
logger.error("Cancel burst execute rcon command: {}", command); logger.error("Cancel burst execute rcon command: {}", command);
} }
} }
public List<Map<String, Object>> 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")));
}
} }

5
src/main/java/app/services/db/DonateService.java

@ -6,6 +6,7 @@ import app.entities.Stats;
import app.entities.VipGiveMethod; import app.entities.VipGiveMethod;
import app.entities.db.DonateStat; import app.entities.db.DonateStat;
import app.entities.other.SteamID; import app.entities.other.SteamID;
import app.utils.SteamIDConverter;
import jakarta.annotation.PostConstruct; import jakarta.annotation.PostConstruct;
import lombok.Data; import lombok.Data;
import lombok.Getter; import lombok.Getter;
@ -154,6 +155,10 @@ public class DonateService {
private String steam2; private String steam2;
private long r; private long r;
private long k; private long k;
public String getUrl() {
SteamID steamID = SteamIDConverter.getSteamID(this.steam2);
return steamID!=null ? steamID.community_url : "";
}
} }
public List<DonateSheikh> getTopSteamSheikh(StatisticRange statisticRange) { public List<DonateSheikh> getTopSteamSheikh(StatisticRange statisticRange) {

12
src/main/java/app/services/db/MessageService.java

@ -1,5 +1,6 @@
package app.services.db; package app.services.db;
import app.entities.StatisticRange;
import app.entities.Stats; import app.entities.Stats;
import app.entities.other.SteamID; import app.entities.other.SteamID;
import lombok.Data; import lombok.Data;
@ -63,6 +64,17 @@ public class MessageService {
.stream().findFirst().orElse(0L); .stream().findFirst().orElse(0L);
} }
public List<Map<String, Object>> 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 ( CREATE TABLE user_messages (
id int(11) NOT NULL, id int(11) NOT NULL,

Loading…
Cancel
Save