Browse Source

statistic field

master
gsd 2 years ago
parent
commit
86a9e01ce0
  1. 14
      src/main/java/app/entities/Statistic.java
  2. 27
      src/main/java/app/entities/Stats.java
  3. 2
      src/main/java/app/entities/server/players/RCONPlayer.java

14
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;
}

27
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<String, Integer> countries = new HashMap<>();
HashMap<String, Server> servers = new HashMap<>();
HashMap<String, Long> uniq = new HashMap<>();
HashMap<String, Long> 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);

2
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;

Loading…
Cancel
Save