Changed InspectPageParser to use PlayerProfile

This commit is contained in:
Rsl1122 2017-11-20 15:53:17 +02:00
parent f77eb460cc
commit 8c889698f9
5 changed files with 101 additions and 80 deletions

View File

@ -156,7 +156,7 @@ public class PlayerProfile implements OfflinePlayer {
if (longestSession.isPresent()) { if (longestSession.isPresent()) {
return longestSession.getAsLong(); return longestSession.getAsLong();
} }
return 0L; return -1;
} }
public long getSessionMedian() { public long getSessionMedian() {

View File

@ -11,17 +11,14 @@ import main.java.com.djrapitops.plan.Settings;
import main.java.com.djrapitops.plan.api.IPlan; import main.java.com.djrapitops.plan.api.IPlan;
import main.java.com.djrapitops.plan.api.exceptions.ParseException; import main.java.com.djrapitops.plan.api.exceptions.ParseException;
import main.java.com.djrapitops.plan.data.Action; import main.java.com.djrapitops.plan.data.Action;
import main.java.com.djrapitops.plan.data.PlayerKill; import main.java.com.djrapitops.plan.data.PlayerProfile;
import main.java.com.djrapitops.plan.data.Session; import main.java.com.djrapitops.plan.data.Session;
import main.java.com.djrapitops.plan.data.UserInfo;
import main.java.com.djrapitops.plan.data.time.WorldTimes; import main.java.com.djrapitops.plan.data.time.WorldTimes;
import main.java.com.djrapitops.plan.database.Database; import main.java.com.djrapitops.plan.database.Database;
import main.java.com.djrapitops.plan.database.tables.SessionsTable;
import main.java.com.djrapitops.plan.database.tables.UsersTable;
import main.java.com.djrapitops.plan.utilities.FormatUtils; import main.java.com.djrapitops.plan.utilities.FormatUtils;
import main.java.com.djrapitops.plan.utilities.MiscUtils; import main.java.com.djrapitops.plan.utilities.MiscUtils;
import main.java.com.djrapitops.plan.utilities.analysis.AnalysisUtils; import main.java.com.djrapitops.plan.utilities.analysis.AnalysisUtils;
import main.java.com.djrapitops.plan.utilities.comparators.ActionComparator; import main.java.com.djrapitops.plan.utilities.analysis.MathUtils;
import main.java.com.djrapitops.plan.utilities.comparators.SessionLengthComparator; import main.java.com.djrapitops.plan.utilities.comparators.SessionLengthComparator;
import main.java.com.djrapitops.plan.utilities.comparators.SessionStartComparator; import main.java.com.djrapitops.plan.utilities.comparators.SessionStartComparator;
import main.java.com.djrapitops.plan.utilities.file.FileUtil; import main.java.com.djrapitops.plan.utilities.file.FileUtil;
@ -32,7 +29,10 @@ import main.java.com.djrapitops.plan.utilities.html.graphs.ServerPreferencePieCr
import main.java.com.djrapitops.plan.utilities.html.graphs.WorldPieCreator; import main.java.com.djrapitops.plan.utilities.html.graphs.WorldPieCreator;
import main.java.com.djrapitops.plan.utilities.html.tables.ActionsTableCreator; import main.java.com.djrapitops.plan.utilities.html.tables.ActionsTableCreator;
import java.util.*; import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
@ -56,103 +56,121 @@ public class InspectPageParser extends PageParser {
Log.logDebug("Database", "Inspect Parse Fetch"); Log.logDebug("Database", "Inspect Parse Fetch");
Benchmark.start("Inspect Parse, Fetch"); Benchmark.start("Inspect Parse, Fetch");
Database db = plugin.getDB(); Database db = plugin.getDB();
SessionsTable sessionsTable = db.getSessionsTable();
UserInfo userInfo = db.getUserInfoTable().getUserInfo(uuid); long now = MiscUtils.getTime();
UsersTable usersTable = db.getUsersTable();
String playerName = usersTable.getPlayerName(uuid);
Optional<Long> registerDate = usersTable.getRegisterDate(uuid);
if (registerDate.isPresent()) {
addValue("registered", FormatUtils.formatTimeStampYear(registerDate.get()));
} else {
addValue("registered", "-");
}
addValue("playerName", playerName);
int timesKicked = usersTable.getTimesKicked(uuid);
addValue("refresh", FormatUtils.formatTimeStamp(now));
addValue("version", MiscUtils.getPlanVersion()); addValue("version", MiscUtils.getPlanVersion());
addValue("timeZone", MiscUtils.getTimeZoneOffsetHours()); addValue("timeZone", MiscUtils.getTimeZoneOffsetHours());
long lastSeen = sessionsTable.getLastSeen(uuid); PlayerProfile profile = db.getPlayerProfile(uuid);
Benchmark.stop("Inspect Parse, Fetch");
String playerName = profile.getName();
long registered = profile.getRegistered();
int timesKicked = profile.getTimesKicked();
long lastSeen = profile.getLastSeen();
addValue("registered", FormatUtils.formatTimeStampYear(registered));
addValue("playerName", playerName);
addValue("kickCount", timesKicked);
if (lastSeen != 0) { if (lastSeen != 0) {
addValue("lastSeen", FormatUtils.formatTimeStampYear(lastSeen)); addValue("lastSeen", FormatUtils.formatTimeStampYear(lastSeen));
} else { } else {
addValue("lastSeen", "-"); addValue("lastSeen", "-");
} }
addValue("kickCount", timesKicked);
Map<String, Long> playtimeByServer = sessionsTable.getPlaytimeByServer(uuid); Map<UUID, String> serverNames = db.getServerTable().getServerNames();
addValue("serverPieSeries", ServerPreferencePieCreator.createSeriesData(playtimeByServer)); Map<UUID, WorldTimes> worldTimesPerServer = profile.getWorldTimesPerServer();
addValue("serverPieSeries", ServerPreferencePieCreator.createSeriesData(serverNames, worldTimesPerServer));
addValue("worldPieColors", Settings.THEME_GRAPH_WORLD_PIE.toString()); addValue("worldPieColors", Settings.THEME_GRAPH_WORLD_PIE.toString());
addValue("gmPieColors", Settings.THEME_GRAPH_GM_PIE.toString()); addValue("gmPieColors", Settings.THEME_GRAPH_GM_PIE.toString());
addValue("serverPieColors", Settings.THEME_GRAPH_SERVER_PREF_PIE.toString()); addValue("serverPieColors", Settings.THEME_GRAPH_SERVER_PREF_PIE.toString());
// TODO IP Timestamp table
// List<String> geolocations = db.getIpsTable().getGeolocations(uuid); // List<String> geolocations = db.getIpsTable().getGeolocations(uuid);
List<String> nicknames = db.getNicknamesTable().getNicknames(uuid).stream() List<String> nicknames = profile.getNicknames().stream()
.map(HtmlUtils::swapColorsToSpan) .map(HtmlUtils::swapColorsToSpan)
.collect(Collectors.toList()); .collect(Collectors.toList());
addValue("nicknames", HtmlStructure.createDotList(nicknames.toArray(new String[nicknames.size()]))); addValue("nicknames", HtmlStructure.createDotList(nicknames.toArray(new String[nicknames.size()])));
// addValue("geolocations", HtmlStructure.createDotList(geolocations.toArray(new String[geolocations.size()]))); // addValue("geolocations", HtmlStructure.createDotList(geolocations.toArray(new String[geolocations.size()])));
Map<UUID, List<Session>> sessions = sessionsTable.getSessions(uuid); Map<UUID, List<Session>> sessions = profile.getSessions();
List<Session> allSessions = sessions.values().stream() Map<String, List<Session>> sessionsByServerName = sessions.entrySet().stream()
.flatMap(Collection::stream) .collect(Collectors.toMap(entry -> serverNames.get(entry.getKey()), Map.Entry::getValue));
.sorted(new SessionStartComparator()) // Sorted Newest first.
List<Session> allSessions = profile.getAllSessions()
.sorted(new SessionStartComparator())
.collect(Collectors.toList()); .collect(Collectors.toList());
// String[] sessionsTabContent = HtmlStructure.createSessionsTabContentInspectPage(sessions, allSessions, uuid); String[] sessionsTabContent = HtmlStructure.createSessionsTabContentInspectPage(sessionsByServerName, allSessions, uuid);
// addValue("contentSessions", sessionsTabContent[0]); addValue("contentSessions", sessionsTabContent[0]);
// addValue("sessionTabGraphViewFunctions", sessionsTabContent[1]); addValue("sessionTabGraphViewFunctions", sessionsTabContent[1]);
// addValue("contentServerOverview", HtmlStructure.createServerOverviewColumn(sessions)); addValue("contentServerOverview", HtmlStructure.createServerOverviewColumn(sessionsByServerName));
long now = MiscUtils.getTime();
addValue("refresh", FormatUtils.formatTimeStamp(now));
long dayAgo = now - TimeAmount.DAY.ms(); long dayAgo = now - TimeAmount.DAY.ms();
long weekAgo = now - TimeAmount.WEEK.ms(); long weekAgo = now - TimeAmount.WEEK.ms();
long monthAgo = now - TimeAmount.MONTH.ms();
List<Session> sessionsDay = allSessions.stream() List<Session> sessionsDay = profile.getSessions(dayAgo, now).collect(Collectors.toList());
.filter(s -> s.getSessionStart() > dayAgo) List<Session> sessionsWeek = profile.getSessions(weekAgo, now).collect(Collectors.toList());
.sorted(new SessionLengthComparator()) List<Session> sessionsMonth = profile.getSessions(monthAgo, now).collect(Collectors.toList());
.collect(Collectors.toList());
List<Session> sessionsWeek = allSessions.stream()
.filter(s -> s.getSessionStart() > weekAgo)
.sorted(new SessionLengthComparator())
.collect(Collectors.toList());
long playtime = PlayerProfile.getPlaytime(allSessions.stream());
long playtimeDay = PlayerProfile.getPlaytime(sessionsDay.stream());
long playtimeWeek = PlayerProfile.getPlaytime(sessionsWeek.stream());
long playtimeMonth = PlayerProfile.getPlaytime(sessionsMonth.stream());
long longestSession = PlayerProfile.getLongestSession(allSessions.stream());
long longestSessionDay = PlayerProfile.getLongestSession(sessionsDay.stream());
long longestSessionWeek = PlayerProfile.getLongestSession(sessionsWeek.stream());
long longestSessionMonth = PlayerProfile.getLongestSession(sessionsMonth.stream());
long sessionMedian = PlayerProfile.getSessionMedian(allSessions.stream());
long sessionMedianDay = PlayerProfile.getSessionMedian(sessionsDay.stream());
long sessionMedianWeek = PlayerProfile.getSessionMedian(sessionsWeek.stream());
long sessionMedianMonth = PlayerProfile.getSessionMedian(sessionsMonth.stream());
int sessionCount = allSessions.size();
int sessionCountDay = sessionsDay.size(); int sessionCountDay = sessionsDay.size();
int sessionCountWeek = sessionsWeek.size(); int sessionCountWeek = sessionsWeek.size();
long playtimeDay = AnalysisUtils.getTotalPlaytime(sessionsDay); int sessionCountMonth = sessionsMonth.size();
long playtimeWeek = AnalysisUtils.getTotalPlaytime(sessionsWeek);
addValue("sessionLengthLongestDay", !sessionsDay.isEmpty() ? FormatUtils.formatTimeAmount(sessionsDay.get(0).getLength()) : "-"); long sessionAverage = MathUtils.averageLong(playtime, sessionCount);
addValue("sessionLengthLongestWeek", !sessionsWeek.isEmpty() ? FormatUtils.formatTimeAmount(sessionsWeek.get(0).getLength()) : "-"); long sessionAverageDay = MathUtils.averageLong(playtimeDay, sessionCountDay);
long sessionAverageWeek = MathUtils.averageLong(playtimeWeek, sessionCountWeek);
long sessionAverageMonth = MathUtils.averageLong(playtimeMonth, sessionCountMonth);
addValue("sessionCountDay", sessionCountDay); addValue("playtimeTotal", playtime > 0L ? FormatUtils.formatTimeAmount(playtime) : "-");
addValue("sessionCountWeek", sessionCountWeek); addValue("playtimeDay", playtimeDay > 0L ? FormatUtils.formatTimeAmount(playtimeDay) : "-");
addValue("playtimeDay", FormatUtils.formatTimeAmount(playtimeDay)); addValue("playtimeWeek", playtimeWeek > 0L ? FormatUtils.formatTimeAmount(playtimeWeek) : "-");
addValue("playtimeWeek", FormatUtils.formatTimeAmount(playtimeWeek)); addValue("playtimeMonth", playtimeMonth > 0L ? FormatUtils.formatTimeAmount(playtimeMonth) : "-");
List<Action> actions = db.getActionsTable().getActions(uuid); addValue("sessionLengthLongest", longestSession > 0L ? FormatUtils.formatTimeAmount(longestSession) : "-");
actions.addAll(allSessions.stream() addValue("sessionLongestDay", longestSessionDay > 0L ? FormatUtils.formatTimeAmount(longestSessionDay) : "-");
.map(Session::getPlayerKills) addValue("sessionLongestWeek", longestSessionWeek > 0L ? FormatUtils.formatTimeAmount(longestSessionWeek) : "-");
.flatMap(Collection::stream) addValue("sessionLongestMonth", longestSessionMonth > 0L ? FormatUtils.formatTimeAmount(longestSessionMonth) : "-");
.map(PlayerKill::convertToAction)
.collect(Collectors.toList()));
actions.sort(new ActionComparator());
addValue("tableBodyActions", ActionsTableCreator.createTable(actions)); addValue("sessionLengthMedian", sessionMedian > 0L ? FormatUtils.formatTimeAmount(sessionMedian) : "-");
addValue("sessionMedianDay", sessionMedianDay > 0L ? FormatUtils.formatTimeAmount(sessionMedianDay) : "-");
addValue("sessionMedianWeek", sessionMedianWeek > 0L ? FormatUtils.formatTimeAmount(sessionMedianWeek) : "-");
addValue("sessionMedianMonth", sessionMedianMonth > 0L ? FormatUtils.formatTimeAmount(sessionMedianMonth) : "-");
Benchmark.stop("Inspect Parse, Fetch"); addValue("sessionAverage", sessionAverage > 0L ? FormatUtils.formatTimeAmount(sessionAverage) : "-");
addValue("sessionAverageDay", sessionAverageDay > 0L ? FormatUtils.formatTimeAmount(sessionAverageDay) : "-");
addValue("sessionAverageWeek", sessionAverageWeek > 0L ? FormatUtils.formatTimeAmount(sessionAverageWeek) : "-");
addValue("sessionAverageMonth", sessionAverageMonth > 0L ? FormatUtils.formatTimeAmount(sessionAverageMonth) : "-");
long playTime = AnalysisUtils.getTotalPlaytime(allSessions);
int sessionCount = allSessions.size();
addValue("sessionCount", sessionCount); addValue("sessionCount", sessionCount);
addValue("playtimeTotal", FormatUtils.formatTimeAmount(playTime)); addValue("sessionCountDay", sessionCountDay);
addValue("sessionCountWeek", sessionCountWeek);
addValue("sessionCountMonth", sessionCountMonth);
List<Action> actions = profile.getAllActions();
addValue("tableBodyActions", ActionsTableCreator.createTable(actions));
String punchCardData = PunchCardGraphCreator.createDataSeries(allSessions); String punchCardData = PunchCardGraphCreator.createDataSeries(allSessions);
WorldTimes worldTimes = db.getWorldTimesTable().getWorldTimesOfUser(uuid); WorldTimes worldTimes = db.getWorldTimesTable().getWorldTimesOfUser(uuid);
@ -185,13 +203,9 @@ public class InspectPageParser extends PageParser {
addValue("mobKillCount", mobKillCount); addValue("mobKillCount", mobKillCount);
addValue("deathCount", deathCount); addValue("deathCount", deathCount);
boolean isActive = AnalysisUtils.isActive(MiscUtils.getTime(), lastSeen, playTime, sessionCount); boolean isActive = AnalysisUtils.isActive(MiscUtils.getTime(), lastSeen, playtime, sessionCount);
String active = isActive ? "Active" : "Inactive"; String active = isActive ? "Active" : "Inactive";
if (userInfo != null) { playerClassification(profile, active);
playerClassification(userInfo, active);
} else {
addValue("playerClassification", active);
}
if (!plugin.getInfoManager().isUsingAnotherWebServer()) { if (!plugin.getInfoManager().isUsingAnotherWebServer()) {
addValue("networkName", Settings.SERVER_NAME.toString()); addValue("networkName", Settings.SERVER_NAME.toString());
@ -204,14 +218,13 @@ public class InspectPageParser extends PageParser {
} }
} }
private void playerClassification(UserInfo userInfo, String active) { private void playerClassification(PlayerProfile profile, String active) {
boolean isBanned = userInfo.isBanned(); boolean isBanned = profile.isBanned();
boolean isOP = userInfo.isOpped(); boolean isOP = profile.isOp();
String banned = isBanned ? "Banned" : ""; String banned = isBanned ? "Banned" : "";
String op = isOP ? "Operator (OP)" : ""; String op = isOP ? "Operator (OP)" : "";
addValue("playerClassification", HtmlStructure.separateWithDots(active, banned, op)); addValue("playerClassification", HtmlStructure.separateWithDots(active, banned, op));
} }
} }

View File

@ -95,6 +95,9 @@ public class MathUtils {
* @see #average(int, int) * @see #average(int, int)
*/ */
public static long averageLong(long total, long size) { public static long averageLong(long total, long size) {
if (size == 0) {
return -1L;
}
return total / size; return total / size;
} }

View File

@ -58,6 +58,7 @@ public class HtmlStructure {
return builder.toString(); return builder.toString();
} }
@Deprecated
public static String createServerOverviewColumn(Map<String, List<Session>> sessions) { public static String createServerOverviewColumn(Map<String, List<Session>> sessions) {
StringBuilder builder = new StringBuilder("<div class=\"column\">"); StringBuilder builder = new StringBuilder("<div class=\"column\">");
if (Verify.isEmpty(sessions)) { if (Verify.isEmpty(sessions)) {
@ -91,6 +92,7 @@ public class HtmlStructure {
return builder.toString(); return builder.toString();
} }
@Deprecated
public static String[] createSessionsTabContentInspectPage(Map<String, List<Session>> sessions, List<Session> allSessions, UUID uuid) { public static String[] createSessionsTabContentInspectPage(Map<String, List<Session>> sessions, List<Session> allSessions, UUID uuid) {
Map<UUID, Map<String, List<Session>>> map = new HashMap<>(); Map<UUID, Map<String, List<Session>>> map = new HashMap<>();
map.put(uuid, sessions); map.put(uuid, sessions);

View File

@ -1,6 +1,9 @@
package main.java.com.djrapitops.plan.utilities.html.graphs; package main.java.com.djrapitops.plan.utilities.html.graphs;
import main.java.com.djrapitops.plan.data.time.WorldTimes;
import java.util.Map; import java.util.Map;
import java.util.UUID;
public class ServerPreferencePieCreator { public class ServerPreferencePieCreator {
@ -8,14 +11,14 @@ public class ServerPreferencePieCreator {
throw new IllegalStateException("Utility Class"); throw new IllegalStateException("Utility Class");
} }
public static String createSeriesData(Map<String, Long> serverPlaytimes) { public static String createSeriesData(Map<UUID, String> serverNames, Map<UUID, WorldTimes> serverWorldTimes) {
StringBuilder seriesBuilder = new StringBuilder("["); StringBuilder seriesBuilder = new StringBuilder("[");
int i = 0; int i = 0;
int size = serverPlaytimes.size(); int size = serverWorldTimes.size();
for (Map.Entry<String, Long> server : serverPlaytimes.entrySet()) { for (Map.Entry<UUID, WorldTimes> server : serverWorldTimes.entrySet()) {
String serverName = server.getKey(); String serverName = serverNames.getOrDefault(server.getKey(), "Unknown");
seriesBuilder.append("{name:'").append(serverName) seriesBuilder.append("{name:'").append(serverName)
.append("',y:").append(server.getValue()); .append("',y:").append(server.getValue().getTotal());
seriesBuilder.append("}"); seriesBuilder.append("}");
if (i < size - 1) { if (i < size - 1) {