From 86a9e01ce074635b692d192e576c8ce9a41bf4bb Mon Sep 17 00:00:00 2001 From: gsd Date: Wed, 15 Feb 2023 15:13:30 +0300 Subject: [PATCH] statistic field --- src/main/java/app/entities/Statistic.java | 14 ++++++++++ src/main/java/app/entities/Stats.java | 27 ++++++++++++++++++- .../entities/server/players/RCONPlayer.java | 2 ++ 3 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 src/main/java/app/entities/Statistic.java diff --git a/src/main/java/app/entities/Statistic.java b/src/main/java/app/entities/Statistic.java new file mode 100644 index 0000000..0f4e339 --- /dev/null +++ b/src/main/java/app/entities/Statistic.java @@ -0,0 +1,14 @@ +package app.entities; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import lombok.Data; + +@Data +public class Statistic { + int player_max = 0; + int player_now = 0; + int total_servers = 0; + int working_servers = 0; + @JsonIgnore + int current_day = 0; +} diff --git a/src/main/java/app/entities/Stats.java b/src/main/java/app/entities/Stats.java index b8828ec..6fdc186 100644 --- a/src/main/java/app/entities/Stats.java +++ b/src/main/java/app/entities/Stats.java @@ -5,6 +5,7 @@ import app.entities.server.PlayOn; import app.entities.server.Server; import app.entities.server.players.DefaultPlayer; import app.entities.server.players.RCONPlayer; +import com.fasterxml.jackson.annotation.JsonGetter; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.databind.annotation.JsonSerialize; import com.ibasco.agql.protocols.valve.source.query.SourceQueryClient; @@ -19,6 +20,8 @@ import org.springframework.stereotype.Component; import org.springframework.stereotype.Service; import java.io.IOException; +import java.time.Instant; +import java.time.LocalDate; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -32,13 +35,35 @@ public class Stats { long ban_count = 0; int discord_users = 0; long freevip_players = 0; - int server_uptime = 0; + long server_uptime = Instant.now().getEpochSecond(); long vip_players = 0; int vk_users = 0; HashMap countries = new HashMap<>(); HashMap servers = new HashMap<>(); HashMap uniq = new HashMap<>(); HashMap updates = new HashMap<>(); + Statistic statistic = new Statistic(); + @JsonGetter + public Statistic getStatistic() { + statistic.setTotal_servers(servers.size()); + statistic.setWorking_servers((int) servers.entrySet().stream().filter(x -> x.getValue().isStatus() == true).count()); + statistic.setPlayer_now(servers.entrySet().stream().mapToInt(x -> x.getValue().getPlayer_count()).sum()); + + if (LocalDate.now().getDayOfMonth() != statistic.getCurrent_day()) { + statistic.setCurrent_day(LocalDate.now().getDayOfMonth()); + statistic.setPlayer_max(0); + } + + if(statistic.getPlayer_max() < statistic.getPlayer_now()) { + statistic.setPlayer_max(statistic.getPlayer_now()); + } + return statistic; + } + + @JsonGetter + public long getServer_uptime() { + return Instant.now().getEpochSecond() - server_uptime; + } public void UpdateUniq(String key, Long value) { uniq.merge(key, value, (x,y) -> y); diff --git a/src/main/java/app/entities/server/players/RCONPlayer.java b/src/main/java/app/entities/server/players/RCONPlayer.java index bb1bc5b..bac52aa 100644 --- a/src/main/java/app/entities/server/players/RCONPlayer.java +++ b/src/main/java/app/entities/server/players/RCONPlayer.java @@ -3,6 +3,7 @@ package app.entities.server.players; import app.entities.other.SteamID; import app.entities.server.players.DefaultPlayer; import app.utils.SteamIDConverter; +import com.fasterxml.jackson.annotation.JsonIgnore; import lombok.Data; import java.util.List; @@ -11,6 +12,7 @@ import java.util.List; public class RCONPlayer extends DefaultPlayer { String duration; int id; + @JsonIgnore String ip; int loss; int ping;