Merge branch '4.0.0-BungeeCord-Support' of https://github.com/Rsl1122/Plan-PlayerAnalytics

This commit is contained in:
Fuzzlemann 2017-09-01 19:57:24 +02:00
commit fe1329eef0
19 changed files with 253 additions and 74 deletions

View File

@ -14,6 +14,7 @@ public class ServerVariableHolder {
private final String version;
private final String implVersion;
private final String ip;
private final int maxPlayers;
private final boolean usingPaper;
/**
@ -28,6 +29,8 @@ public class ServerVariableHolder {
version = server.getVersion();
implVersion = server.getBukkitVersion();
maxPlayers = server.getMaxPlayers();
usingPaper = name.equals("Paper")
|| name.equals("TacoSpigot"); //Fork of Paper
}
@ -43,6 +46,9 @@ public class ServerVariableHolder {
port = -1;
version = server.getVersion();
implVersion = server.getVersion();
maxPlayers = server.getConfig().getPlayerLimit();
usingPaper = false;
}
@ -79,4 +85,8 @@ public class ServerVariableHolder {
public String getImplVersion() {
return implVersion;
}
public int getMaxPlayers() {
return maxPlayers;
}
}

View File

@ -43,14 +43,14 @@ public class AnalysisData extends RawData {
private Map<String, Serializable> additionalDataReplaceMap;
private String playersTable;
public AnalysisData(Map<String, Integer> commandUsage, List<TPS> tpsData) {
commandUsagePart = new CommandUsagePart(commandUsage);
public AnalysisData() {
commandUsagePart = new CommandUsagePart();
geolocationPart = new GeolocationPart();
joinInfoPart = new JoinInfoPart();
playerCountPart = new PlayerCountPart();
playtimePart = new PlaytimePart();
killPart = new KillPart();
tpsPart = new TPSPart(tpsData);
tpsPart = new TPSPart();
activityPart = new ActivityPart(joinInfoPart, tpsPart);
worldPart = new WorldPart();
}

View File

@ -8,6 +8,7 @@ package main.java.com.djrapitops.plan.data.analysis;
import main.java.com.djrapitops.plan.utilities.html.HtmlUtils;
import main.java.com.djrapitops.plan.utilities.html.tables.CommandUseTableCreator;
import java.util.HashMap;
import java.util.Map;
/**
@ -25,10 +26,10 @@ import java.util.Map;
*/
public class CommandUsagePart extends RawData {
private final Map<String, Integer> commandUsage;
private Map<String, Integer> commandUsage;
public CommandUsagePart(Map<String, Integer> commandUsage) {
this.commandUsage = commandUsage;
public CommandUsagePart() {
this.commandUsage = new HashMap<>();
}
@Override
@ -39,6 +40,14 @@ public class CommandUsagePart extends RawData {
addValue("tableBodyCommands", HtmlUtils.removeXSS(commandUsageTable));
}
public void setCommandUsage(Map<String, Integer> commandUsage) {
this.commandUsage = commandUsage;
}
public void addCommands(Map<String, Integer> commandUsage) {
this.commandUsage.putAll(commandUsage);
}
public int getUniqueCommands() {
return commandUsage.keySet().size();
}

View File

@ -54,6 +54,8 @@ public class JoinInfoPart extends RawData {
newPlayers();
uniquePlayers();
uniquePlayersPerDay();
addValue("sessionCount", getAllSessions().size());
}
private void uniquePlayers() {
@ -117,7 +119,9 @@ public class JoinInfoPart extends RawData {
}
public List<Session> getAllSessions() {
return MiscUtils.flatMap(sessions.values());
List<Session> sessions = MiscUtils.flatMap(this.sessions.values());
sessions.addAll(activeSessions.values());
return sessions;
}
public void addRegistered(UUID uuid, long registerDate) {
@ -137,8 +141,7 @@ public class JoinInfoPart extends RawData {
}
public void addSessions(Map<UUID, List<Session>> sessions) {
Verify.nullCheck(sessions);
this.sessions.putAll(sessions);
this.sessions.putAll(Verify.nullCheck(sessions));
}
public void addSessions(UUID uuid, List<Session> sessions) {

View File

@ -1,6 +1,7 @@
package main.java.com.djrapitops.plan.data.analysis;
import com.djrapitops.plugin.api.TimeAmount;
import com.djrapitops.plugin.utilities.Verify;
import main.java.com.djrapitops.plan.Settings;
import main.java.com.djrapitops.plan.data.TPS;
import main.java.com.djrapitops.plan.systems.webserver.theme.Colors;
@ -12,6 +13,8 @@ import main.java.com.djrapitops.plan.utilities.html.graphs.RamGraphCreator;
import main.java.com.djrapitops.plan.utilities.html.graphs.TPSGraphCreator;
import main.java.com.djrapitops.plan.utilities.html.graphs.WorldLoadGraphCreator;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
/**
@ -49,9 +52,11 @@ import java.util.List;
public class TPSPart extends RawData {
private final List<TPS> tpsData;
private TPS allTimePeak;
private TPS lastPeak;
public TPSPart(List<TPS> tpsData) {
this.tpsData = tpsData;
public TPSPart() {
this.tpsData = new ArrayList<>();
}
@Override
@ -60,18 +65,34 @@ public class TPSPart extends RawData {
List<TPS> week = TPSGraphCreator.filterTPS(tpsData, now - TimeAmount.WEEK.ms());
List<TPS> day = TPSGraphCreator.filterTPS(tpsData, now - TimeAmount.DAY.ms());
addValue("tpsHighColor", Colors.TPS_HIGH.getColor());
addValue("tpsMediumColor", Colors.TPS_MED.getColor());
addValue("tpsLowColor", Colors.TPS_LOW.getColor());
addValue("tpsMedium", Settings.THEME_GRAPH_TPS_THRESHOLD_MED.getNumber());
addValue("tpsHigh", Settings.THEME_GRAPH_TPS_THRESHOLD_HIGH.getNumber());
tpsGraphOptions();
addValue("tpsSeries", TPSGraphCreator.buildSeriesDataString(tpsData));
addValue("cpuSeries", CPUGraphCreator.buildSeriesDataString(tpsData));
addValue("ramSeries", RamGraphCreator.buildSeriesDataString(tpsData));
addValue("entitySeries", WorldLoadGraphCreator.buildSeriesDataStringEntities(tpsData));
addValue("chunkSeries", WorldLoadGraphCreator.buildSeriesDataStringChunks(tpsData));
chartData();
averages(week, day);
peaks();
}
private void peaks() {
if (lastPeak != null) {
addValue("lastPeakTime", FormatUtils.formatTimeStampYear(lastPeak.getDate()));
addValue("playersLastPeak", lastPeak.getPlayers());
} else {
addValue("lastPeakTime", "No Data");
addValue("playersLastPeak", "-");
}
if (allTimePeak != null) {
addValue("bestPeakTime", FormatUtils.formatTimeStampYear(allTimePeak.getDate()));
addValue("playersBestPeak", allTimePeak.getPlayers());
} else {
addValue("bestPeakTime", "No Data");
addValue("playersBestPeak", "-");
}
}
private void averages(List<TPS> week, List<TPS> day) {
double averageTPSWeek = MathUtils.averageDouble(week.stream().map(TPS::getTicksPerSecond));
double averageTPSDay = MathUtils.averageDouble(day.stream().map(TPS::getTicksPerSecond));
@ -103,7 +124,35 @@ public class TPSPart extends RawData {
addValue("chunkAverageDay", FormatUtils.cutDecimals(averageChunksLoadedDay));
}
private void chartData() {
addValue("tpsSeries", TPSGraphCreator.buildSeriesDataString(tpsData));
addValue("cpuSeries", CPUGraphCreator.buildSeriesDataString(tpsData));
addValue("ramSeries", RamGraphCreator.buildSeriesDataString(tpsData));
addValue("entitySeries", WorldLoadGraphCreator.buildSeriesDataStringEntities(tpsData));
addValue("chunkSeries", WorldLoadGraphCreator.buildSeriesDataStringChunks(tpsData));
}
private void tpsGraphOptions() {
addValue("tpsHighColor", Colors.TPS_HIGH.getColor());
addValue("tpsMediumColor", Colors.TPS_MED.getColor());
addValue("tpsLowColor", Colors.TPS_LOW.getColor());
addValue("tpsMedium", Settings.THEME_GRAPH_TPS_THRESHOLD_MED.getNumber());
addValue("tpsHigh", Settings.THEME_GRAPH_TPS_THRESHOLD_HIGH.getNumber());
}
public List<TPS> getTpsData() {
return tpsData;
}
public void addTpsData(Collection<TPS> data) {
tpsData.addAll(Verify.nullCheck(data));
}
public void setAllTimePeak(TPS allTimePeak) {
this.allTimePeak = allTimePeak;
}
public void setLastPeak(TPS lastPeak) {
this.lastPeak = lastPeak;
}
}

View File

@ -31,7 +31,9 @@ public class WorldPart extends RawData {
@Override
protected void analyse() {
addValue("worldTotal", FormatUtils.formatTimeAmount(worldTimes.getTotal()));
addValue("worldSeries", WorldPieCreator.createSeriesData(worldTimes));
String[] seriesData = WorldPieCreator.createSeriesData(worldTimes);
addValue("worldSeries", seriesData[0]);
addValue("gmSeries", seriesData[1]);
}
public WorldTimes getWorldTimes() {

View File

@ -39,6 +39,7 @@ public class ServerTable extends Table {
private final String columnServerName = "name";
private final String columnWebserverAddress = "web_address";
private final String columnInstalled = "is_installed";
private final String columnMaxPlayers = "max_players";
public ServerTable(SQLDB db, boolean usingMySQL) {
super("plan_servers", db, usingMySQL);
@ -54,6 +55,7 @@ public class ServerTable extends Table {
.column(columnServerName, Sql.varchar(100))
.column(columnWebserverAddress, Sql.varchar(100))
.column(columnInstalled, Sql.BOOL).notNull().defaultValue(false)
.column(columnMaxPlayers, Sql.BOOL).notNull().defaultValue("-1")
.primaryKey(usingMySQL, columnServerID)
.toString()
);
@ -74,7 +76,8 @@ public class ServerTable extends Table {
columnServerUUID,
columnServerName,
columnWebserverAddress,
columnInstalled)
columnInstalled,
columnMaxPlayers)
.where(columnServerID + "=?")
.toString()
);
@ -82,7 +85,8 @@ public class ServerTable extends Table {
statement.setString(2, info.getName());
statement.setString(3, info.getWebAddress());
statement.setBoolean(4, true);
statement.setInt(5, info.getId());
statement.setInt(5, info.getMaxPlayers());
statement.setInt(6, info.getId());
statement.executeUpdate();
commit(statement.getConnection());
@ -109,12 +113,14 @@ public class ServerTable extends Table {
columnServerUUID,
columnServerName,
columnWebserverAddress,
columnInstalled));
columnInstalled,
columnMaxPlayers));
statement.setString(1, uuid.toString());
statement.setString(2, name);
statement.setString(3, webAddress);
statement.setBoolean(4, true);
statement.setInt(5, info.getMaxPlayers());
statement.execute();
commit(statement.getConnection());
@ -219,7 +225,8 @@ public class ServerTable extends Table {
set.getInt(columnServerID),
UUID.fromString(set.getString(columnServerUUID)),
set.getString(columnServerName),
set.getString(columnWebserverAddress)));
set.getString(columnWebserverAddress),
set.getInt(columnMaxPlayers)));
} else {
return Optional.empty();
}
@ -244,7 +251,8 @@ public class ServerTable extends Table {
set.getInt(columnServerID),
UUID.fromString(set.getString(columnServerUUID)),
set.getString(columnServerName),
set.getString(columnWebserverAddress)));
set.getString(columnWebserverAddress),
set.getInt(columnMaxPlayers)));
}
return servers;
} finally {

View File

@ -179,7 +179,7 @@ public class SessionsTable extends UserIDTable {
int deaths = set.getInt(columnDeaths);
int mobKills = set.getInt(columnMobKills);
List<Session> sessions = sessionsByServer.getOrDefault(serverName, new ArrayList<>());
sessions.add(new Session(id, start, end, deaths, mobKills));
sessions.add(new Session(id, start, end, mobKills, deaths));
sessionsByServer.put(serverName, sessions);
}
return sessionsByServer;
@ -450,6 +450,7 @@ public class SessionsTable extends UserIDTable {
return getSessionInfoOfServer(Plan.getServerUUID());
}
// TODO Write tests for this method
public Map<UUID, List<Session>> getSessionInfoOfServer(UUID serverUUID) throws SQLException {
Optional<Integer> id = serverTable.getServerID(serverUUID);
if (!id.isPresent()) {
@ -484,7 +485,7 @@ public class SessionsTable extends UserIDTable {
int deaths = set.getInt(columnDeaths);
int mobKills = set.getInt(columnMobKills);
List<Session> sessions = sessionsByUser.getOrDefault(uuid, new ArrayList<>());
sessions.add(new Session(serverID, start, end, deaths, mobKills));
sessions.add(new Session(serverID, start, end, mobKills, deaths));
sessionsByUser.put(uuid, sessions);
}
return sessionsByUser;
@ -494,6 +495,7 @@ public class SessionsTable extends UserIDTable {
}
}
// TODO Write tests for this method
public long getLastSeen(UUID uuid) throws SQLException {
PreparedStatement statement = null;
ResultSet set = null;
@ -514,6 +516,7 @@ public class SessionsTable extends UserIDTable {
}
}
// TODO Write tests for this method
public Map<UUID, Long> getLastSeenForAllPlayers() throws SQLException {
PreparedStatement statement = null;
ResultSet set = null;
@ -525,7 +528,8 @@ public class SessionsTable extends UserIDTable {
" MAX(" + columnSessionEnd + ") as last_seen, " +
usersUUIDColumn +
" FROM " + tableName +
" JOIN " + usersTable + " on " + usersIDColumn + "=" + columnUserID);
" JOIN " + usersTable + " on " + usersIDColumn + "=" + columnUserID +
" GROUP BY uuid");
statement.setFetchSize(5000);
set = statement.executeQuery();
Map<UUID, Long> lastSeenMap = new HashMap<>();

View File

@ -16,6 +16,8 @@ import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
/**
* Class representing database table plan_tps
@ -73,7 +75,7 @@ public class TPSTable extends Table {
statement = prepareStatement(Select.all(tableName)
.where(columnServerID + "=" + serverTable.statementSelectServerID)
.toString());
statement.setFetchSize(5000);
statement.setFetchSize(10000);
statement.setString(1, Plan.getServerUUID().toString());
set = statement.executeQuery();
while (set.next()) {
@ -132,7 +134,10 @@ public class TPSTable extends Table {
public void clean() throws SQLException {
PreparedStatement statement = null;
try {
statement = prepareStatement("DELETE FROM " + tableName + " WHERE (" + columnDate + "<?)");
statement = prepareStatement("DELETE FROM " + tableName +
" WHERE (" + columnDate + "<?)" +
" AND (" + columnPlayers + "" +
" != (SELECT MAX(" + columnPlayers + ") FROM " + tableName + "))");
// More than 2 Months ago.
long fiveWeeks = TimeAmount.MONTH.ms() * 2L;
statement.setLong(1, MiscUtils.getTime() - fiveWeeks);
@ -143,4 +148,45 @@ public class TPSTable extends Table {
close(statement);
}
}
public Optional<TPS> getAllTimePeak(UUID serverUUID) throws SQLException {
return getPeakPlayerCount(serverUUID, 0);
}
public Optional<TPS> getAllTimePeak() throws SQLException {
return getPeakPlayerCount(0);
}
public Optional<TPS> getPeakPlayerCount(long afterDate) throws SQLException {
return getPeakPlayerCount(Plan.getServerUUID(), afterDate);
}
public Optional<TPS> getPeakPlayerCount(UUID serverUUID, long afterDate) throws SQLException {
PreparedStatement statement = null;
ResultSet set = null;
try {
statement = prepareStatement(Select.all(tableName)
.where(columnServerID + "=" + serverTable.statementSelectServerID)
.and(columnPlayers + "= (SELECT MAX(" + columnPlayers + ") FROM " + tableName+")")
.and(columnDate + ">= ?")
.toString());
statement.setString(1, serverUUID.toString());
statement.setLong(2, afterDate);
set = statement.executeQuery();
if (set.next()) {
long date = set.getLong(columnDate);
double tps = set.getDouble(columnTPS);
int players = set.getInt(columnPlayers);
double cpuUsage = set.getDouble(columnCPUUsage);
long ramUsage = set.getLong(columnRAMUsage);
int entities = set.getInt(columnEntities);
int chunksLoaded = set.getInt(columnChunksLoaded);
return Optional.of(new TPS(date, tps, players, cpuUsage, ramUsage, entities, chunksLoaded));
}
return Optional.empty();
} finally {
endTransaction(statement);
close(set, statement);
}
}
}

View File

@ -4,9 +4,11 @@
*/
package main.java.com.djrapitops.plan.systems.info.parsing;
import com.djrapitops.plugin.utilities.Compatibility;
import main.java.com.djrapitops.plan.Settings;
import main.java.com.djrapitops.plan.api.IPlan;
import main.java.com.djrapitops.plan.api.exceptions.ParseException;
import main.java.com.djrapitops.plan.bungee.PlanBungee;
import main.java.com.djrapitops.plan.data.AnalysisData;
import main.java.com.djrapitops.plan.utilities.MiscUtils;
import main.java.com.djrapitops.plan.utilities.file.FileUtil;
@ -35,10 +37,20 @@ public class AnalysisPageParser extends PageParser {
addValue("tabContentPlugins", data.replacePluginsTabLayout());
addValue("serverName", Settings.SERVER_NAME.toString());
addValue("timeZone", MiscUtils.getTimeZoneOffsetHours());
addValue("playersMax", plugin.getVariable().getMaxPlayers());
addValue("playersOnline", getPlayersOnline());
try {
return HtmlUtils.replacePlaceholders(FileUtil.getStringFromResource("server.html"), placeHolders);
} catch (FileNotFoundException e) {
throw new ParseException(e);
}
}
private int getPlayersOnline() {
if (Compatibility.isBukkitAvailable()) {
return plugin.fetch().getOnlinePlayers().size();
}
return ((PlanBungee) plugin).getProxy().getOnlineCount();
}
}

View File

@ -17,12 +17,14 @@ public class ServerInfo {
private int id;
private String name;
private String webAddress;
private int maxPlayers = -1;
public ServerInfo(int id, UUID uuid, String name, String webAddress) {
public ServerInfo(int id, UUID uuid, String name, String webAddress, int maxPlayers) {
this.id = id;
this.uuid = uuid;
this.name = name;
this.webAddress = webAddress;
this.maxPlayers = maxPlayers;
}
public int getId() {
@ -53,6 +55,10 @@ public class ServerInfo {
this.webAddress = webAddress;
}
public int getMaxPlayers() {
return maxPlayers;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;

View File

@ -59,7 +59,7 @@ public class ServerInfoManager {
}
}
public ServerInfoManager(PlanBungee plugin) {
public ServerInfoManager(PlanBungee plugin) throws PlanEnableException {
this.plugin = plugin;
serverTable = plugin.getDB().getServerTable();
}
@ -75,8 +75,9 @@ public class ServerInfoManager {
if ("plan".equalsIgnoreCase(name)) {
name = "Server " + serverID.get();
}
int maxPlayers = plugin.getVariable().getMaxPlayers();
serverInfo = new ServerInfo(serverID.get(), serverUUID, name, webAddress);
serverInfo = new ServerInfo(serverID.get(), serverUUID, name, webAddress, maxPlayers);
serverTable.saveCurrentServerInfo(serverInfo);
}
@ -87,7 +88,8 @@ public class ServerInfoManager {
private void registerServer(UUID serverUUID) throws SQLException, IOException {
String webAddress = plugin.getWebServer().getAccessAddress();
String name = Settings.SERVER_NAME.toString();
serverInfo = new ServerInfo(-1, serverUUID, name, webAddress);
int maxPlayers = plugin.getVariable().getMaxPlayers();
serverInfo = new ServerInfo(-1, serverUUID, name, webAddress, maxPlayers);
serverTable.saveCurrentServerInfo(serverInfo);
Optional<Integer> serverID = serverTable.getServerID(serverUUID);
if (!serverID.isPresent()) {
@ -97,7 +99,7 @@ public class ServerInfoManager {
int id = serverID.get();
serverInfo.setId(id);
serverInfoFile.saveInfo(serverInfo, new ServerInfo(id, serverUUID, name, webAddress));
serverInfoFile.saveInfo(serverInfo, new ServerInfo(id, serverUUID, name, webAddress, maxPlayers));
}
private UUID generateNewUUID(ServerVariableHolder variableHolder) {
@ -117,8 +119,14 @@ public class ServerInfoManager {
return Optional.empty();
}
/**
* Saves Bungee connection information to local file on Bukkit servers.
*
* @param address
* @throws IOException
*/
public void saveBungeeConnectionAddress(String address) throws IOException {
serverInfoFile.saveInfo(serverInfo, new ServerInfo(-1, null, "Bungee", address));
serverInfoFile.saveInfo(serverInfo, new ServerInfo(-1, null, "Bungee", address, -1));
}
public int getServerID() {

View File

@ -16,10 +16,7 @@ import main.java.com.djrapitops.plan.locale.Msg;
import java.io.Closeable;
import java.io.IOException;
import java.sql.SQLException;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.TimeZone;
import java.util.*;
import java.util.stream.Collectors;
/**
@ -99,7 +96,7 @@ public class MiscUtils {
matches = db.getUsersTable().getMatchingNames(search);
} catch (SQLException e) {
Log.toLog("MiscUtils.getMatchingPlayerNames", e);
return null;
return new ArrayList<>();
}
Collections.sort(matches);
return matches;

View File

@ -15,6 +15,7 @@ import main.java.com.djrapitops.plan.data.additional.PluginData;
import main.java.com.djrapitops.plan.data.analysis.*;
import main.java.com.djrapitops.plan.data.time.WorldTimes;
import main.java.com.djrapitops.plan.database.Database;
import main.java.com.djrapitops.plan.database.tables.TPSTable;
import main.java.com.djrapitops.plan.locale.Locale;
import main.java.com.djrapitops.plan.locale.Msg;
import main.java.com.djrapitops.plan.systems.cache.DataCache;
@ -32,7 +33,10 @@ import org.apache.commons.lang3.StringUtils;
import java.io.Serializable;
import java.sql.SQLException;
import java.util.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.function.Function;
import java.util.stream.Collectors;
@ -90,33 +94,24 @@ public class Analysis {
Benchmark.start("Fetch Phase");
Log.debug("Database", "Analysis Fetch");
Log.debug("Analysis", "Analysis Fetch Phase");
//TODO Rewrite FETCH
List<TPS> tpsData = new ArrayList<>();
try {
tpsData = db.getTpsTable().getTPSData();
Log.debug("Analysis", "TPS Data Size: " + tpsData.size());
} catch (Exception ex) {
Log.toLog(this.getClass().getName(), ex);
}
return analyzeData(tpsData, infoManager, db);
return analyzeData(infoManager, db);
}
/**
* @param tpsData
* @param infoManager InformationManager of the plugin.
* @return
*/
public boolean analyzeData(List<TPS> tpsData, InformationManager infoManager, Database db) {
public boolean analyzeData(InformationManager infoManager, Database db) {
try {
// rawData.sort(new UserInfoLastPlayedComparator());
// List<UUID> uuids = rawData.stream().map(UserInfo::getUuid).collect(Collectors.toList());
Benchmark.start("Create Empty dataset");
DataCache dataCache = plugin.getDataCache();
Map<String, Integer> commandUse = plugin.getDB().getCommandUse();
AnalysisData analysisData = new AnalysisData(commandUse, tpsData);
AnalysisData analysisData = new AnalysisData();
List<PluginData> thirdPartyPlugins = plugin.getHookHandler().getAdditionalDataSources();
analysisData.setPluginsTabLayout(HtmlStructure.createAnalysisPluginsTabLayout(thirdPartyPlugins));
analysisData.setPlanVersion(plugin.getVersion());
@ -242,16 +237,29 @@ public class Analysis {
private void fillDataset(AnalysisData analysisData, Database db) {
ActivityPart activity = analysisData.getActivityPart();
CommandUsagePart commandUsagePart = analysisData.getCommandUsagePart();
GeolocationPart geolocPart = analysisData.getGeolocationPart();
JoinInfoPart joinInfo = analysisData.getJoinInfoPart();
PlayerCountPart playerCount = analysisData.getPlayerCountPart();
PlaytimePart playtime = analysisData.getPlaytimePart();
TPSPart tpsPart = analysisData.getTpsPart();
WorldPart worldPart = analysisData.getWorldPart();
long now = MiscUtils.getTime();
Benchmark.start("Fetch Phase");
try {
Map<String, Integer> commandUse = plugin.getDB().getCommandUse();
commandUsagePart.setCommandUsage(commandUse);
TPSTable tpsTable = db.getTpsTable();
List<TPS> tpsData = tpsTable.getTPSData();
tpsTable.getAllTimePeak().ifPresent(tpsPart::setAllTimePeak);
tpsTable.getPeakPlayerCount(now - (TimeAmount.DAY.ms() * 2)).ifPresent(tpsPart::setLastPeak);
tpsPart.addTpsData(tpsData);
Log.debug("Analysis", "TPS Data Size: " + tpsData.size());
List<UserInfo> userInfo = db.getUserInfoTable().getAllUserInfo();
Map<UUID, UserInfo> mappedUserInfo = userInfo.stream().collect(Collectors.toMap(UserInfo::getUuid, Function.identity()));
Map<UUID, Long> lastSeen = db.getSessionsTable().getLastSeenForAllPlayers();

View File

@ -27,6 +27,10 @@ public class PlayersTableCreator {
}
public static String createSortablePlayersTable(List<UserInfo> userInfo, JoinInfoPart joinInfoPart, GeolocationPart geolocationPart) {
if (userInfo.isEmpty()) {
return Html.TABLELINE_PLAYERS.parse("<b>No Players</b>", "", "", "", "", "", "", "", "", "");
}
StringBuilder html = new StringBuilder();
Map<UUID, List<Session>> sessions = joinInfoPart.getSessions();
@ -45,16 +49,17 @@ public class PlayersTableCreator {
boolean isBanned = user.isBanned();
List<Session> userSessions = sessions.get(uuid);
int loginTimes = 0;
long playtime = 0;
if (userSessions != null) {
loginTimes = userSessions.size();
playtime = AnalysisUtils.getTotalPlaytime(userSessions);
}
boolean isUnknown = loginTimes == 1;
long registered = user.getRegistered();
long playtime = AnalysisUtils.getTotalPlaytime(userSessions);
boolean isActive = AnalysisUtils.isActive(now, user.getLastSeen(), playtime, loginTimes);
long lastSeen = AnalysisUtils.getLastSeen(userSessions);
long lastSeen = user.getLastSeen();
String activityString = getActivityString(isBanned, isUnknown, isActive);
@ -73,6 +78,7 @@ public class PlayersTableCreator {
String.valueOf(geoLocation)
));
} catch (NullPointerException ignored) {
ignored.printStackTrace(); // TODO IGNORE AGAIN
}
i++;

View File

@ -82,16 +82,17 @@
</p>
</div>
<div class="column">
<p><b>Averages:</b></p>
<li>Session Length: ${sessionAverage}</li>
<li>Players / Day: ${playersAverage}</li>
<li>New Players / Day: ${playersNewAverage}</li>
<p><b>Total:</b></p>
<li>Playtime: ${playtimeTotal}</li>
<li>Sessions: ${sessionCount}</li>
<li>Kills: ${killCount}</li>
<li>Mob Kills: ${mobKillCount}</li>
<li>Deaths: ${deathCount}</li>
<p><b>Averages:</b><br>
&#x2022; Session Length: ${sessionAverage}<br>
&#x2022; Players / Day: ${playersAverage}<br>
&#x2022; New Players / Day: ${playersNewAverage}<br>
<br>
<b>Total:</b><br>
&#x2022; Playtime: ${playtimeTotal}<br>
&#x2022; Sessions: ${sessionCount}<br>
&#x2022; Kills: ${killCount}<br>
&#x2022; Mob Kills: ${mobKillCount}<br>
&#x2022; Deaths: ${deathCount}<br></p>
</div>
</div>
</div>
@ -337,6 +338,8 @@
<script src="https://code.highcharts.com/stock/highstock.js"></script>
<script src="https://code.highcharts.com/maps/modules/map.js"></script>
<script src="https://code.highcharts.com/mapdata/custom/world.js"></script>
<script src="https://code.highcharts.com/modules/drilldown.js"></script>
<script src="https://code.highcharts.com/modules/no-data-to-display.js"></script>
<script src="./js/activityPie.js"></script>
<script src="./js/playerGraph.js"></script>
<script src="./js/punchCard.js"></script>
@ -347,6 +350,7 @@
<script src="./js/worldPie.js"></script>
<script>
Highcharts.setOptions({
lang: {noData: "No Data to Display"},
global: {
timezoneOffset: ${timeZone} * 60
}
@ -442,6 +446,7 @@
colorByPoint: true,
data: ${worldSeries}
};
var gmSeries = ${gmSeries};
var mapSeries = {
name: 'Players',
type: 'map',
@ -473,7 +478,7 @@
x.style.opacity = "1";
openFunc(slideIndex)();
activityPie('activityPie', activitySeries, ${playersTotal}, [${activityColors}]);
worldPie('worldPie', worldSeries, '${worldTotal}');
worldPie('worldPie', worldSeries, gmSeries);
playersChart('playerChartDay', playersOnlineSeries, 1);
playersChart('playerChartMonth', playersOnlineSeries, 4);
tpsChart('tpsGraph', tpsSeries, playersOnlineSeries);

View File

@ -1,7 +1,7 @@
name: Plan
author: Rsl1122
main: main.java.com.djrapitops.plan.Plan
version: 3.6.4
version: 4.0.0
softdepend:
- OnTime
- EssentialsX

View File

@ -60,7 +60,7 @@ public class DatabaseTest {
db = new SQLiteDB(plan, "debug" + MiscUtils.getTime());
db.init();
db.getServerTable().saveCurrentServerInfo(new ServerInfo(-1, TestInit.getServerUUID(), "ServerName", ""));
db.getServerTable().saveCurrentServerInfo(new ServerInfo(-1, TestInit.getServerUUID(), "ServerName", "", 20));
File f = new File(plan.getDataFolder(), "Errors.txt");
rows = FileUtil.lines(f).size();
@ -609,7 +609,7 @@ public class DatabaseTest {
assertFalse(bungeeInfo.isPresent());
UUID bungeeUUID = UUID.randomUUID();
ServerInfo bungeeCord = new ServerInfo(-1, bungeeUUID, "BungeeCord", "Random:1234");
ServerInfo bungeeCord = new ServerInfo(-1, bungeeUUID, "BungeeCord", "Random:1234", 20);
serverTable.saveCurrentServerInfo(bungeeCord);
bungeeCord.setId(2);
@ -631,4 +631,10 @@ public class DatabaseTest {
List<ServerInfo> bukkitServers = serverTable.getBukkitServers();
assertEquals(1, bukkitServers.size());
}
@Test
public void testSessionTableNPEWhenNoPlayers() throws SQLException {
Map<UUID, Long> lastSeen = db.getSessionsTable().getLastSeenForAllPlayers();
assertTrue(lastSeen.isEmpty());
}
}

View File

@ -156,7 +156,7 @@ public class MiscUtilsTest {
db = new SQLiteDB(plan, "debug" + MiscUtils.getTime());
db.init();
db.getServerTable().saveCurrentServerInfo(new ServerInfo(-1, TestInit.getServerUUID(), "ServerName", ""));
db.getServerTable().saveCurrentServerInfo(new ServerInfo(-1, TestInit.getServerUUID(), "ServerName", "", 20));
when(plan.getDB()).thenReturn(db);
}