* Removed the LogServices (H2 DB file that logs actions).

This commit is contained in:
LevelX2 2016-10-28 23:46:55 +02:00
parent e1ca3b5cc5
commit 88af59697e
4 changed files with 3 additions and 216 deletions

View file

@ -1,39 +0,0 @@
package mage.server.services;
/**
* @author noxx
*/
public interface LogKeys {
String KEY_GAME_STARTED = "gameStarted";
String KEY_USER_REGISTERED = "userRegistered";
String KEY_USER_CONNECTED = "userConnected";
String KEY_ADMIN_CONNECTED = "adminConnected";
String KEY_SESSION_KILLED = "sessionKilled";
String KEY_SESSION_EXPIRED = "sessionExpired";
String KEY_SESSION_DISCONNECTED = "sessionDisconnected";
String KEY_SESSION_DISCONNECTED_BY_ADMIN = "sessionDisconnectedByAdmin";
String KEY_SESSION_END_BY_ADMIN = "sessionEndSessionByAdmin";
String KEY_NOT_VALID_SESSION = "sessionNotValid";
String KEY_NOT_VALID_SESSION_INTERNAL = "sessionNotValidInternal";
String KEY_TABLE_CREATED = "tableCreated";
String KEY_TOURNAMENT_TABLE_CREATED = "tournamentTableCreated";
String KEY_WRONG_VERSION = "wrongVersion";
String KEY_NOT_ADMIN = "notAdminRestrictedOperation";
String KEY_FEEDBACK_ADDED = "feedbackAdded";
}

View file

@ -1,122 +0,0 @@
package com.xmage.core.entity.repositories.impl;
import com.xmage.core.entity.model.ServerStats;
import com.xmage.core.entity.repositories.XMageStatsRepository;
import mage.db.EntityManager;
import mage.db.model.Log;
import mage.server.services.LogKeys;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.*;
/**
* Implementation for {@link com.xmage.core.entity.repositories.XMageStatsRepository}
*
* @author noxx
*/
public class XMageStatsRepositoryImpl implements XMageStatsRepository {
private static final Logger logger = LoggerFactory.getLogger(XMageStatsRepositoryImpl.class);
@Override
public ServerStats getServerStats() {
ServerStats serverStats = new ServerStats();
List<Log> logs = EntityManager.instance.getAllLogs();
logger.info("logs found count: " + logs.size());
int numberOfGamesPlayed = 0;
Set<String> playerNames = new HashSet<String>();
// Get nicknames and games started count
Map<String, Integer> nicknames = new HashMap<String, Integer>();
for (Log log : logs) {
if (log.getKey().equals(LogKeys.KEY_GAME_STARTED)) {
if (log.getArguments() != null) {
int index = 0;
for (String argument : log.getArguments()) {
if (index > 0) {
inc(nicknames, argument);
}
index++;
}
}
numberOfGamesPlayed++;
}
}
// Sort games
Collection<Integer> values = nicknames.values();
List<Integer> games = new ArrayList<Integer>();
games.addAll(values);
Collections.sort(games, new Comparator<Integer>() {
@Override
public int compare(Integer i1, Integer i2) {
return i2.compareTo(i1);
}
});
// Top-3
List<Integer> numbersToFind = new ArrayList<Integer>();
for (Integer numberOfGames : games) {
numbersToFind.add(numberOfGames);
if (numbersToFind.size() == 3) {
break;
}
}
Map<Integer, String> players = new LinkedHashMap<Integer, String>();
for (Integer number : numbersToFind) {
for (Map.Entry<String, Integer> entry : nicknames.entrySet()) {
if (entry.getValue().equals(number)) {
players.put(entry.getValue(), entry.getKey());
break;
}
}
if (players.size() == 3) {
break;
}
}
// Build top-3 string
StringBuilder top3 = new StringBuilder();
for (Map.Entry<Integer, String> entry : players.entrySet()) {
top3.append("[").append(entry.getValue()).append(":").append(entry.getKey()).append("]");
}
// Played only once
Integer oneGamePlayers = 0;
for (Integer numberOfGames : games) {
if (numberOfGames == 1) {
oneGamePlayers++;
}
}
serverStats.setNumberOfGamesPlayed(numberOfGamesPlayed);
serverStats.setNumberOfUniquePlayers(nicknames.size());
serverStats.setTop3Players(top3.toString());
serverStats.setNumberOfPlayersPlayedOnce(oneGamePlayers);
return serverStats;
}
private static void inc(Map<String, Integer> map, String player) {
if (map.containsKey(player)) {
Integer count = map.get(player);
count++;
map.put(player, count);
} else {
map.put(player, 1);
}
}
private static boolean check(List<Integer> numbers, Integer value) {
for (Integer number : numbers) {
if (number.equals(value)) {
return true;
}
}
return false;
}
}

View file

@ -3,9 +3,8 @@ package com.xmage.ws.resource;
import com.xmage.core.decorators.Decorator;
import com.xmage.ws.model.DomainErrors;
import com.xmage.ws.representer.Representer;
import net.minidev.json.JSONObject;
import java.util.ArrayList;
import net.minidev.json.JSONObject;
/**
*
@ -19,8 +18,8 @@ public abstract class DefaultResource<R> implements Resource<R> {
protected Representer<R> representer;
protected java.util.List<Decorator> decorators = new ArrayList<Decorator>();
protected java.util.List<Decorator> decorators = new ArrayList<>();
protected int version;
protected DefaultResource(Representer<R> representer) {

View file

@ -1,51 +0,0 @@
package com.xmage.ws.resource;
import com.xmage.core.entity.model.ServerStats;
import com.xmage.core.entity.repositories.XMageStatsRepository;
import com.xmage.core.entity.repositories.impl.XMageStatsRepositoryImpl;
import com.xmage.ws.model.DomainErrors;
import com.xmage.ws.representer.XMageStatsRepresenter;
import com.xmage.ws.representer.Representer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class XMageStatsResource extends DefaultResource<ServerStats> {
private static final Logger logger = LoggerFactory.getLogger(XMageStatsResource.class);
private static XMageStatsRepository xmageStatsRepository = new XMageStatsRepositoryImpl();
private static final Representer<ServerStats> defaultRepresenter = new XMageStatsRepresenter();
public XMageStatsResource() {
super(defaultRepresenter);
}
public XMageStatsResource(ServerStats event) {
super(defaultRepresenter);
defaultResource = event;
}
public Resource getAll() {
try {
ServerStats serverStats = xmageStatsRepository.getServerStats();
if (serverStats != null) {
defaultResource = serverStats;
} else {
error = DomainErrors.Errors.STATUS_NOT_FOUND;
}
} catch (Exception e) {
logger.error("Getting server stats error:", e);
error = DomainErrors.Errors.STATUS_SERVER_ERROR;
}
return this;
}
@Override
public String getName() {
return "serverStats";
}
}