mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-01-13 11:41:34 +01:00
Replaced SessionsTableCreator with easier to grasp classes:
- RecentLoginList - ServerSessionTable - PlaceholderReplacer - all() to SessionsMutator
This commit is contained in:
parent
a83c871bf8
commit
4f89c8df8c
@ -9,7 +9,6 @@ import com.djrapitops.plan.data.container.Action;
|
||||
import com.djrapitops.plan.data.container.GeoInfo;
|
||||
import com.djrapitops.plan.data.container.PlayerKill;
|
||||
import com.djrapitops.plan.data.container.Session;
|
||||
import com.djrapitops.plan.data.store.containers.PlayerContainer;
|
||||
import com.djrapitops.plan.data.time.WorldTimes;
|
||||
import com.djrapitops.plan.system.info.server.ServerInfo;
|
||||
import com.djrapitops.plan.utilities.comparators.ActionComparator;
|
||||
@ -124,7 +123,7 @@ public class PlayerProfile {
|
||||
|
||||
// Calculating Getters
|
||||
public ActivityIndex getActivityIndex(long date) {
|
||||
return activityIndexCache.computeIfAbsent(date, dateValue -> new ActivityIndex(new PlayerContainer(), dateValue));
|
||||
return activityIndexCache.computeIfAbsent(date, dateValue -> new ActivityIndex());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -16,6 +16,12 @@ public class ActivityIndex {
|
||||
|
||||
private final double value;
|
||||
|
||||
// Temp constructor for PlayerProfile support
|
||||
@Deprecated
|
||||
public ActivityIndex() {
|
||||
value = 0.0;
|
||||
}
|
||||
|
||||
public ActivityIndex(DataContainer container, long date) {
|
||||
Verify.isTrue(container.supports(PlayerKeys.SESSIONS),
|
||||
() -> new IllegalArgumentException("Given container does not support sessions."));
|
||||
|
@ -30,9 +30,7 @@ import com.djrapitops.plan.utilities.html.graphs.line.*;
|
||||
import com.djrapitops.plan.utilities.html.graphs.pie.ActivityPie;
|
||||
import com.djrapitops.plan.utilities.html.graphs.pie.WorldPie;
|
||||
import com.djrapitops.plan.utilities.html.structure.AnalysisPluginsTabContentCreator;
|
||||
import com.djrapitops.plan.utilities.html.structure.SessionTabStructureCreator;
|
||||
import com.djrapitops.plan.utilities.html.tables.CommandUseTable;
|
||||
import com.djrapitops.plan.utilities.html.tables.SessionsTableCreator;
|
||||
import com.djrapitops.plugin.api.TimeAmount;
|
||||
|
||||
import java.util.*;
|
||||
@ -321,14 +319,12 @@ public class AnalysisData extends RawData {
|
||||
List<Session> sessionsMonth = allSessions.stream()
|
||||
.filter(s -> s.getSessionStart() >= monthAgo)
|
||||
.collect(Collectors.toList());
|
||||
String[] tables = SessionsTableCreator.createTable(sessions, allSessions);
|
||||
String[] sessionContent = SessionTabStructureCreator.createStructure(sessions, allSessions);
|
||||
|
||||
addValue("sessionCount", allSessions.size());
|
||||
addValue("accordionSessions", sessionContent[0]);
|
||||
addValue("sessionTabGraphViewFunctions", sessionContent[1]);
|
||||
addValue("tableBodySessions", tables[0]);
|
||||
addValue("listRecentLogins", tables[1]);
|
||||
addValue("accordionSessions", "");
|
||||
addValue("sessionTabGraphViewFunctions", "");
|
||||
addValue("tableBodySessions", "");
|
||||
addValue("listRecentLogins", "");
|
||||
addValue("sessionAverage", Formatters.timeAmount().apply(new SessionsMutator(allSessions).toAverageSessionLength()));
|
||||
addValue("punchCardSeries", new PunchCardGraph(sessionsMonth).toHighChartsSeries());
|
||||
|
||||
|
@ -2,19 +2,25 @@ package com.djrapitops.plan.data.store.containers;
|
||||
|
||||
import com.djrapitops.plan.PlanPlugin;
|
||||
import com.djrapitops.plan.data.store.keys.AnalysisKeys;
|
||||
import com.djrapitops.plan.data.store.keys.PlayerKeys;
|
||||
import com.djrapitops.plan.data.store.keys.ServerKeys;
|
||||
import com.djrapitops.plan.data.store.mutators.SessionsMutator;
|
||||
import com.djrapitops.plan.data.store.mutators.formatting.Formatters;
|
||||
import com.djrapitops.plan.system.database.databases.Database;
|
||||
import com.djrapitops.plan.system.info.server.ServerInfo;
|
||||
import com.djrapitops.plan.system.info.server.ServerProperties;
|
||||
import com.djrapitops.plan.system.settings.Settings;
|
||||
import com.djrapitops.plan.system.settings.theme.Theme;
|
||||
import com.djrapitops.plan.system.settings.theme.ThemeVal;
|
||||
import com.djrapitops.plan.utilities.MiscUtils;
|
||||
import com.djrapitops.plan.utilities.html.structure.RecentLoginList;
|
||||
import com.djrapitops.plan.utilities.html.structure.SessionAccordion;
|
||||
import com.djrapitops.plan.utilities.html.tables.ServerSessionTable;
|
||||
import com.djrapitops.plugin.api.TimeAmount;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Container used for analysis.
|
||||
@ -77,6 +83,11 @@ public class AnalysisContainer extends DataContainer {
|
||||
}
|
||||
|
||||
private void addPlayerSuppliers() {
|
||||
putSupplier(AnalysisKeys.PLAYER_NAMES, () -> serverContainer.getValue(ServerKeys.PLAYERS).orElse(new ArrayList<>())
|
||||
.stream().collect(Collectors.toMap(
|
||||
p -> p.getUnsafe(PlayerKeys.UUID), p -> p.getValue(PlayerKeys.NAME).orElse("?"))
|
||||
)
|
||||
);
|
||||
putSupplier(AnalysisKeys.PLAYERS_TOTAL, () -> serverContainer.getValue(ServerKeys.PLAYER_COUNT).orElse(0));
|
||||
putSupplier(AnalysisKeys.PLAYERS_LAST_PEAK, () ->
|
||||
serverContainer.getValue(ServerKeys.RECENT_PEAK_PLAYERS)
|
||||
@ -98,6 +109,21 @@ public class AnalysisContainer extends DataContainer {
|
||||
}
|
||||
|
||||
private void addSessionSuppliers() {
|
||||
putSupplier(AnalysisKeys.SESSION_ACCORDION, () -> SessionAccordion.forServer(
|
||||
getUnsafe(AnalysisKeys.SESSIONS_MUTATOR).all(),
|
||||
() -> Database.getActive().fetch().getServerNames(),
|
||||
() -> getUnsafe(AnalysisKeys.PLAYER_NAMES)
|
||||
));
|
||||
putSupplier(AnalysisKeys.RECENT_LOGINS, () -> new RecentLoginList(
|
||||
serverContainer.getValue(ServerKeys.PLAYERS).orElse(new ArrayList<>())
|
||||
).toHtml()
|
||||
);
|
||||
putSupplier(AnalysisKeys.SESSION_TABLE, () -> new ServerSessionTable(
|
||||
getUnsafe(AnalysisKeys.PLAYER_NAMES), getUnsafe(AnalysisKeys.SESSIONS_MUTATOR).all()).parseHtml()
|
||||
);
|
||||
putSupplier(AnalysisKeys.SESSION_ACCORDION_HTML, () -> getUnsafe(AnalysisKeys.SESSION_ACCORDION).toHtml());
|
||||
putSupplier(AnalysisKeys.SESSION_ACCORDION_FUNCTIONS, () -> getUnsafe(AnalysisKeys.SESSION_ACCORDION).toViewScript());
|
||||
|
||||
putSupplier(AnalysisKeys.SESSIONS_MUTATOR, () -> new SessionsMutator(serverContainer.getValue(ServerKeys.SESSIONS).orElse(new ArrayList<>())));
|
||||
putSupplier(AnalysisKeys.AVERAGE_SESSION_LENGTH_F, () -> Formatters.timeAmount()
|
||||
.apply(getUnsafe(AnalysisKeys.SESSIONS_MUTATOR).toAverageSessionLength())
|
||||
|
@ -2,9 +2,13 @@ package com.djrapitops.plan.data.store.keys;
|
||||
|
||||
import com.djrapitops.plan.data.store.Key;
|
||||
import com.djrapitops.plan.data.store.PlaceholderKey;
|
||||
import com.djrapitops.plan.data.store.Type;
|
||||
import com.djrapitops.plan.data.store.mutators.SessionsMutator;
|
||||
import com.djrapitops.plan.utilities.html.structure.SessionAccordion;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Key objects used for Analysis.
|
||||
* <p>
|
||||
@ -127,7 +131,7 @@ public class AnalysisKeys {
|
||||
public static final Key<Long> ANALYSIS_TIME_WEEK_AGO = new Key<>(Long.class, "ANALYSIS_TIME_WEEK_AGO");
|
||||
public static final Key<Long> ANALYSIS_TIME_MONTH_AGO = new Key<>(Long.class, "ANALYSIS_TIME_MONTH_AGO");
|
||||
public static final Key<SessionAccordion> SESSION_ACCORDION = new Key<>(SessionAccordion.class, "SESSION_ACCORDION");
|
||||
|
||||
public static final Key<Map<UUID, String>> PLAYER_NAMES = new Key<>(new Type<Map<UUID, String>>() {}, "PLAYER_NAMES");
|
||||
|
||||
private AnalysisKeys() {
|
||||
/* Static variable class */
|
||||
|
@ -35,6 +35,10 @@ public class SessionsMutator {
|
||||
this.sessions = sessions;
|
||||
}
|
||||
|
||||
public List<Session> all() {
|
||||
return sessions;
|
||||
}
|
||||
|
||||
public SessionsMutator filterSessionsBetween(long after, long before) {
|
||||
sessions = sessions.stream()
|
||||
.filter(session -> session.getSessionEnd() >= after && session.getSessionStart() <= before)
|
||||
|
@ -0,0 +1,36 @@
|
||||
package com.djrapitops.plan.data.store.mutators.formatting;
|
||||
|
||||
import com.djrapitops.plan.data.store.PlaceholderKey;
|
||||
import com.djrapitops.plan.data.store.containers.DataContainer;
|
||||
import org.apache.commons.text.StringSubstitutor;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* Formatter for replacing ${placeholder} values inside strings.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class PlaceholderReplacer extends HashMap<String, Serializable> implements Formatter<String> {
|
||||
|
||||
public void addPlaceholder(DataContainer container, PlaceholderKey key) {
|
||||
if (!container.supports(key)) {
|
||||
return;
|
||||
}
|
||||
put(key.getPlaceholder(), container.get(key).get().toString());
|
||||
}
|
||||
|
||||
public void addAllPlaceholders(DataContainer container, PlaceholderKey... keys) {
|
||||
for (PlaceholderKey key : keys) {
|
||||
addPlaceholder(container, key);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String apply(String string) {
|
||||
StringSubstitutor sub = new StringSubstitutor(this);
|
||||
sub.setEnableSubstitutionInVariables(true);
|
||||
return sub.replace(string);
|
||||
}
|
||||
}
|
@ -5,7 +5,7 @@ import com.djrapitops.plan.data.container.Session;
|
||||
import java.util.Comparator;
|
||||
|
||||
/**
|
||||
* Comparator for Sessions in descending start order (Latest first).
|
||||
* Comparator for Sessions in descending start order (Most recent first).
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
|
@ -25,7 +25,9 @@ public class HtmlUtils {
|
||||
* @param html Html to replace placeholders from
|
||||
* @param replaceMap Placeholders and values
|
||||
* @return Html with placeholders replaced
|
||||
* @deprecated Use {@link com.djrapitops.plan.data.store.mutators.formatting.PlaceholderReplacer} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public static String replacePlaceholders(String html, Map<String, Serializable> replaceMap) {
|
||||
StringSubstitutor sub = new StringSubstitutor(replaceMap);
|
||||
sub.setEnableSubstitutionInVariables(true);
|
||||
|
@ -0,0 +1,119 @@
|
||||
package com.djrapitops.plan.utilities.html.structure;
|
||||
|
||||
import com.djrapitops.plan.api.PlanAPI;
|
||||
import com.djrapitops.plan.data.container.Session;
|
||||
import com.djrapitops.plan.data.store.containers.PlayerContainer;
|
||||
import com.djrapitops.plan.data.store.keys.PlayerKeys;
|
||||
import com.djrapitops.plan.data.store.keys.SessionKeys;
|
||||
import com.djrapitops.plan.data.store.mutators.formatting.Formatter;
|
||||
import com.djrapitops.plan.data.store.mutators.formatting.Formatters;
|
||||
import com.djrapitops.plan.data.store.objects.DateHolder;
|
||||
import com.djrapitops.plan.utilities.comparators.SessionStartComparator;
|
||||
import com.djrapitops.plugin.api.TimeAmount;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Utility class for creating recent login list html.
|
||||
* <p>
|
||||
* This item can be seen on the Information tab on Server page.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class RecentLoginList {
|
||||
|
||||
private final List<PlayerContainer> players;
|
||||
|
||||
public RecentLoginList(List<PlayerContainer> players) {
|
||||
this.players = players;
|
||||
}
|
||||
|
||||
public String toHtml() {
|
||||
StringBuilder html = new StringBuilder();
|
||||
|
||||
List<RecentLogin> recentLogins = getMostRecentLogins();
|
||||
|
||||
Formatter<DateHolder> formatter = Formatters.year();
|
||||
|
||||
int i = 0;
|
||||
for (RecentLogin recentLogin : recentLogins) {
|
||||
if (i >= 20) {
|
||||
break;
|
||||
}
|
||||
|
||||
String name = recentLogin.name;
|
||||
String url = PlanAPI.getInstance().getPlayerInspectPageLink(name);
|
||||
boolean isNew = recentLogin.isNew;
|
||||
String start = formatter.apply(recentLogin);
|
||||
|
||||
html.append("<li><a class=\"col-").append(isNew ? "light-green" : "blue").append(" font-bold\" href=\"").append(url)
|
||||
.append("\">").append(name).append("</a><span class=\"pull-right\">").append(start).append("</span></li>");
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
return html.toString();
|
||||
}
|
||||
|
||||
private List<RecentLogin> getMostRecentLogins() {
|
||||
List<RecentLogin> recentLogins = new ArrayList<>();
|
||||
for (PlayerContainer player : players) {
|
||||
if (!player.supports(PlayerKeys.NAME)
|
||||
|| !player.supports(PlayerKeys.SESSIONS)) {
|
||||
continue;
|
||||
}
|
||||
String name = player.getUnsafe(PlayerKeys.NAME);
|
||||
long registerDate = player.getValue(PlayerKeys.REGISTERED).orElse(0L);
|
||||
|
||||
List<Session> sessions = player.getUnsafe(PlayerKeys.SESSIONS);
|
||||
if (sessions.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
sessions.sort(new SessionStartComparator());
|
||||
Session session = sessions.get(0);
|
||||
|
||||
if (!session.supports(SessionKeys.START)) {
|
||||
continue;
|
||||
}
|
||||
long mostRecentStart = session.getUnsafe(SessionKeys.START);
|
||||
boolean isFirstSession = Math.abs(registerDate - mostRecentStart) < TimeAmount.SECOND.ms() * 10L;
|
||||
recentLogins.add(new RecentLogin(mostRecentStart, isFirstSession, name));
|
||||
}
|
||||
return recentLogins;
|
||||
}
|
||||
|
||||
class RecentLogin implements DateHolder {
|
||||
final long date;
|
||||
final boolean isNew;
|
||||
final String name;
|
||||
|
||||
RecentLogin(long date, boolean isNew, String name) {
|
||||
this.date = date;
|
||||
this.isNew = isNew;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof RecentLogin)) return false;
|
||||
RecentLogin that = (RecentLogin) o;
|
||||
return date == that.date &&
|
||||
isNew == that.isNew &&
|
||||
Objects.equals(name, that.name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(date, isNew, name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getDate() {
|
||||
return date;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,214 +0,0 @@
|
||||
/*
|
||||
* Licence is provided in the jar as license.yml also here:
|
||||
* https://github.com/Rsl1122/Plan-PlayerAnalytics/blob/master/Plan/src/main/resources/license.yml
|
||||
*/
|
||||
package com.djrapitops.plan.utilities.html.structure;
|
||||
|
||||
import com.djrapitops.plan.api.PlanAPI;
|
||||
import com.djrapitops.plan.data.container.Session;
|
||||
import com.djrapitops.plan.data.store.mutators.formatting.Formatter;
|
||||
import com.djrapitops.plan.data.store.mutators.formatting.Formatters;
|
||||
import com.djrapitops.plan.data.store.objects.DateHolder;
|
||||
import com.djrapitops.plan.data.time.WorldTimes;
|
||||
import com.djrapitops.plan.system.cache.DataCache;
|
||||
import com.djrapitops.plan.system.settings.Settings;
|
||||
import com.djrapitops.plan.system.settings.theme.Theme;
|
||||
import com.djrapitops.plan.system.settings.theme.ThemeVal;
|
||||
import com.djrapitops.plan.utilities.analysis.AnalysisUtils;
|
||||
import com.djrapitops.plan.utilities.html.Html;
|
||||
import com.djrapitops.plan.utilities.html.HtmlStructure;
|
||||
import com.djrapitops.plan.utilities.html.graphs.pie.WorldPie;
|
||||
import com.djrapitops.plan.utilities.html.tables.KillsTable;
|
||||
import com.djrapitops.plan.utilities.html.tables.SessionsTableCreator;
|
||||
import com.djrapitops.plugin.utilities.Verify;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* HTML utility class used for creating main element on Sessions tabs.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class SessionTabStructureCreator {
|
||||
|
||||
public static String[] createStructure(Map<UUID, Map<String, List<Session>>> sessions, List<Session> allSessions, boolean appendName) {
|
||||
|
||||
Map<Integer, UUID> uuidsByID = generateIDtoUUIDMap(sessions);
|
||||
|
||||
if (Verify.isEmpty(allSessions)) {
|
||||
return new String[]{"<div class=\"body\">" +
|
||||
"<p>No Sessions</p>" +
|
||||
"</div>", ""};
|
||||
}
|
||||
|
||||
Map<Integer, String> serverNameIDMap = generateIDtoServerNameMap(sessions);
|
||||
|
||||
StringBuilder html = new StringBuilder("<div class=\"panel-group scrollbar\" id=\"session_accordion\" role=\"tablist\" aria-multiselectable=\"true\">");
|
||||
StringBuilder viewScript = new StringBuilder();
|
||||
int i = 0;
|
||||
int maxSessions = Settings.MAX_SESSIONS.getNumber();
|
||||
if (maxSessions <= 0) {
|
||||
maxSessions = 50;
|
||||
}
|
||||
|
||||
boolean appendWorldPercentage = Settings.APPEND_WORLD_PERC.isTrue();
|
||||
|
||||
Formatter<Long> timeAmountFormatter = Formatters.timeAmount();
|
||||
Formatter<DateHolder> timeStampFormatter = Formatters.year();
|
||||
|
||||
for (Session session : allSessions) {
|
||||
if (i >= maxSessions) {
|
||||
break;
|
||||
}
|
||||
|
||||
int sessionID = session.getSessionID();
|
||||
UUID uuid = uuidsByID.get(sessionID);
|
||||
String serverName = serverNameIDMap.get(sessionID);
|
||||
|
||||
String sessionStart = timeStampFormatter.apply(session);
|
||||
long endOfSession = session.getSessionEnd();
|
||||
String sessionLength = endOfSession == -1 ? "Online" : timeAmountFormatter.apply(session.getLength());
|
||||
String afk = (endOfSession == -1 ? "(Inaccurate) " : "") + timeAmountFormatter.apply(session.getAfkLength());
|
||||
String sessionEnd = endOfSession == -1 ? "Online" : timeStampFormatter.apply(session::getSessionEnd);
|
||||
|
||||
int playerKillCount = session.getPlayerKills().size();
|
||||
|
||||
String name = DataCache.getInstance().getName(uuid);
|
||||
String link = PlanAPI.getInstance().getPlayerInspectPageLink(name);
|
||||
|
||||
String info = appendWorldPercentage
|
||||
? HtmlStructure.separateWithDots(sessionStart, AnalysisUtils.getLongestWorldPlayed(session))
|
||||
: sessionStart;
|
||||
String nameAndInfo = appendName ?
|
||||
HtmlStructure.separateWithDots(name, info) :
|
||||
HtmlStructure.separateWithDots(serverName, info);
|
||||
|
||||
|
||||
String htmlID = "" + session.getSessionStart() + sessionID + i;
|
||||
|
||||
String worldId = "worldPie" + session.getSessionStart() + i;
|
||||
WorldTimes worldTimes = session.getWorldTimes();
|
||||
|
||||
WorldPie worldPie = new WorldPie(worldTimes);
|
||||
|
||||
String killTable = new KillsTable(session.getPlayerKills()).parseHtml();
|
||||
|
||||
// Accordion panel header
|
||||
html.append("<div title=\"Session ID: ").append(sessionID)
|
||||
.append("\"class=\"panel panel-col-").append(Theme.getValue(ThemeVal.PARSED_SESSION_ACCORDION)).append("\">")
|
||||
.append("<div class=\"panel-heading\" role=\"tab\" id=\"heading_").append(htmlID).append("\">")
|
||||
.append("<h4 class=\"panel-title\">") // Title (header)
|
||||
.append("<a class=\"collapsed\" role=\"button\" data-toggle=\"collapse\" data-parent=\"#session_accordion\" ")
|
||||
.append("href=\"#session_").append(htmlID).append("\" aria-expanded=\"false\" ")
|
||||
.append("aria-controls=\"session_").append(htmlID).append("\">")
|
||||
.append(nameAndInfo)
|
||||
.append("<span class=\"pull-right\">").append(sessionLength).append("</span>")
|
||||
.append("</a></h4>") // Closes collapsed, panel title
|
||||
.append("</div>"); // Closes panel heading
|
||||
|
||||
// Content
|
||||
html.append("<div id=\"session_").append(htmlID).append("\" class=\"panel-collapse collapse\" role=\"tabpanel\"")
|
||||
.append(" aria-labelledby=\"heading_").append(htmlID).append("\">")
|
||||
.append("<div class=\"panel-body\"><div class=\"row clearfix\">")
|
||||
.append("<div class=\"col-xs-12 col-sm-6 col-md-6 col-lg-6\">") // Left col-6
|
||||
//
|
||||
.append("<div class=\"font-bold m-b--35\"><i class=\"col-teal fa fa-clock-o\"></i> ")
|
||||
.append(sessionStart).append(" -> ").append(sessionEnd).append(" </div>")
|
||||
//
|
||||
.append("<ul class=\"dashboard-stat-list\">")
|
||||
// End
|
||||
.append("<li><i class=\"col-teal fa fa-clock-o\"></i> Session Ended<span class=\"pull-right\"><b>").append(sessionEnd).append("</b></span></li>")
|
||||
// Length
|
||||
.append("<li><i class=\"col-teal fa fa-clock-o\"></i> Session Length<span class=\"pull-right\"><b>").append(sessionLength).append("</b></span></li>")
|
||||
// AFK
|
||||
.append("<li><i class=\"col-grey fa fa-clock-o\"></i> AFK<span class=\"pull-right\"><b>").append(afk).append("</b></span></li>")
|
||||
// Server
|
||||
.append("<li><i class=\"col-light-green fa fa-server\"></i> Server<span class=\"pull-right\"><b>").append(serverName).append("</b></span></li>")
|
||||
.append("<li></li>")
|
||||
// Player Kills
|
||||
.append("<li><i class=\"col-red fa fa-crosshairs\"></i> Player Kills<span class=\"pull-right\"><b>").append(playerKillCount).append("</b></span></li>")
|
||||
// Mob Kills
|
||||
.append("<li><i class=\"col-green fa fa-crosshairs\"></i> Mob Kills<span class=\"pull-right\"><b>").append(session.getMobKills()).append("</b></span></li>")
|
||||
// Deaths
|
||||
.append("<li><i class=\"col-red fa fa-frown-o\"></i> Deaths<span class=\"pull-right\"><b>").append(session.getDeaths()).append("</b></span></li>")
|
||||
.append("</ul></div>") // Closes stat-list, Left col-6
|
||||
.append("<div class=\"col-xs-12 col-sm-6 col-md-6 col-lg-6\">") // Right col-6
|
||||
.append("<div id=\"").append(worldId).append("\" class=\"dashboard-donut-chart\"></div>")
|
||||
// World Pie data script
|
||||
.append("<script>")
|
||||
.append("var ").append(worldId).append("series = {name:'World Playtime',colorByPoint:true,data:").append(worldPie.toHighChartsSeries()).append("};")
|
||||
.append("var ").append(worldId).append("gmseries = ").append(worldPie.toHighChartsDrilldown()).append(";")
|
||||
.append("</script>")
|
||||
.append("</div>") // Right col-6
|
||||
.append("</div>") // Closes row clearfix
|
||||
.append("<div class=\"row clearfix\">")
|
||||
.append("<div class=\"col-xs-12 col-sm-6 col-md-6 col-lg-6\">") // Left2 col-6
|
||||
.append(killTable)
|
||||
.append("</div>"); // Closes Left2 col-6
|
||||
if (appendName) {
|
||||
html.append("<div class=\"col-xs-12 col-sm-6 col-md-6 col-lg-6\">") // Right2 col-6
|
||||
.append("<a target=\"_blank\" href=\"").append(link).append("\"><button href=\"").append(link)
|
||||
.append("\" type=\"button\" class=\"pull-right btn bg-blue waves-effect\"><i class=\"material-icons\">person</i><span>INSPECT PAGE</span></button></a>")
|
||||
.append("</div>"); // Closes Right2 col-6
|
||||
}
|
||||
html.append("</div>") // Closes row clearfix
|
||||
.append("</div>") // Closes panel-body
|
||||
.append("</div>") // Closes panel-collapse
|
||||
.append("</div>"); // Closes panel
|
||||
|
||||
viewScript.append("worldPie(")
|
||||
.append(worldId).append(", ")
|
||||
.append(worldId).append("series, ")
|
||||
.append(worldId).append("gmseries")
|
||||
.append(");");
|
||||
i++;
|
||||
}
|
||||
return new String[]{html.append("</div>").toString(), viewScript.toString()};
|
||||
}
|
||||
|
||||
private static Map<Integer, String> generateIDtoServerNameMap(Map<UUID, Map<String, List<Session>>> sessions) {
|
||||
Map<Integer, String> serverNameIDRelationMap = new HashMap<>();
|
||||
for (Map<String, List<Session>> map : sessions.values()) {
|
||||
for (Map.Entry<String, List<Session>> entry : map.entrySet()) {
|
||||
String serverName = entry.getKey();
|
||||
List<Session> serverSessions = entry.getValue();
|
||||
for (Session session : serverSessions) {
|
||||
serverNameIDRelationMap.put(session.getSessionID(), serverName);
|
||||
}
|
||||
}
|
||||
}
|
||||
return serverNameIDRelationMap;
|
||||
}
|
||||
|
||||
private static Map<Integer, UUID> generateIDtoUUIDMap(Map<UUID, Map<String, List<Session>>> sessions) {
|
||||
Map<Integer, UUID> uuidsByID = new HashMap<>();
|
||||
for (Map.Entry<UUID, Map<String, List<Session>>> entry : sessions.entrySet()) {
|
||||
UUID uuid = entry.getKey();
|
||||
for (List<Session> sessionList : entry.getValue().values()) {
|
||||
for (Session session : sessionList) {
|
||||
uuidsByID.put(session.getSessionID(), uuid);
|
||||
}
|
||||
}
|
||||
}
|
||||
return uuidsByID;
|
||||
}
|
||||
|
||||
public static String[] createStructure(Map<UUID, List<Session>> sessions, List<Session> allSessions) {
|
||||
if (Settings.DISPLAY_SESSIONS_AS_TABLE.isTrue()) {
|
||||
return new String[]{Html.TABLE_SESSIONS.parse("", "", "", SessionsTableCreator.createTable(sessions, allSessions)[0]), ""};
|
||||
}
|
||||
|
||||
Map<UUID, Map<String, List<Session>>> map = new HashMap<>();
|
||||
|
||||
for (Map.Entry<UUID, List<Session>> entry : sessions.entrySet()) {
|
||||
Map<String, List<Session>> serverSpecificMap = new HashMap<>();
|
||||
serverSpecificMap.put("This server", entry.getValue());
|
||||
map.put(entry.getKey(), serverSpecificMap);
|
||||
}
|
||||
|
||||
return createStructure(map, allSessions, true);
|
||||
}
|
||||
}
|
@ -0,0 +1,64 @@
|
||||
package com.djrapitops.plan.utilities.html.tables;
|
||||
|
||||
import com.djrapitops.plan.api.PlanAPI;
|
||||
import com.djrapitops.plan.data.container.Session;
|
||||
import com.djrapitops.plan.data.element.TableContainer;
|
||||
import com.djrapitops.plan.data.store.keys.SessionKeys;
|
||||
import com.djrapitops.plan.data.store.mutators.formatting.Formatters;
|
||||
import com.djrapitops.plan.system.settings.Settings;
|
||||
import com.djrapitops.plan.utilities.analysis.AnalysisUtils;
|
||||
import com.djrapitops.plan.utilities.html.Html;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* TableContainer for a Session table for a single player.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class ServerSessionTable extends TableContainer {
|
||||
|
||||
private final List<Session> sessions;
|
||||
private Map<UUID, String> playerNames;
|
||||
|
||||
public ServerSessionTable(Map<UUID, String> playerNames, List<Session> sessions) {
|
||||
super("Player", "Start", "Length", "World");
|
||||
this.playerNames = playerNames;
|
||||
this.sessions = sessions;
|
||||
|
||||
addRows();
|
||||
}
|
||||
|
||||
private void addRows() {
|
||||
int maxSessions = Settings.MAX_SESSIONS.getNumber();
|
||||
if (maxSessions <= 0) {
|
||||
maxSessions = 50;
|
||||
}
|
||||
|
||||
int i = 0;
|
||||
for (Session session : sessions) {
|
||||
if (i >= maxSessions) {
|
||||
break;
|
||||
}
|
||||
|
||||
String start = Formatters.year().apply(session);
|
||||
String length = session.supports(SessionKeys.END)
|
||||
? Formatters.timeAmount().apply(session.getValue(SessionKeys.LENGTH).orElse(0L))
|
||||
: "Online";
|
||||
String world = AnalysisUtils.getLongestWorldPlayed(session);
|
||||
|
||||
String toolTip = "Session ID: " + session.getValue(SessionKeys.DB_ID)
|
||||
.map(id -> Integer.toString(id))
|
||||
.orElse("Not Saved.");
|
||||
|
||||
String playerName = playerNames.getOrDefault(session.getValue(SessionKeys.UUID).orElse(null), "Unknown");
|
||||
String inspectUrl = PlanAPI.getInstance().getPlayerInspectPageLink(playerName);
|
||||
|
||||
addRow(Html.LINK_TOOLTIP.parse(inspectUrl, playerName, toolTip), start, length, world);
|
||||
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,104 +0,0 @@
|
||||
/*
|
||||
* Licence is provided in the jar as license.yml also here:
|
||||
* https://github.com/Rsl1122/Plan-PlayerAnalytics/blob/master/Plan/src/main/resources/license.yml
|
||||
*/
|
||||
package com.djrapitops.plan.utilities.html.tables;
|
||||
|
||||
import com.djrapitops.plan.api.PlanAPI;
|
||||
import com.djrapitops.plan.data.container.Session;
|
||||
import com.djrapitops.plan.data.store.mutators.formatting.Formatters;
|
||||
import com.djrapitops.plan.system.cache.DataCache;
|
||||
import com.djrapitops.plan.system.cache.SessionCache;
|
||||
import com.djrapitops.plan.system.settings.Settings;
|
||||
import com.djrapitops.plan.utilities.analysis.AnalysisUtils;
|
||||
import com.djrapitops.plan.utilities.comparators.SessionStartComparator;
|
||||
import com.djrapitops.plan.utilities.html.Html;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Utility for creating HTML {@code <table>}-element with Sessions inside it.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
// TODO start using TableContainer
|
||||
public class SessionsTableCreator {
|
||||
|
||||
private static Map<Integer, UUID> getUUIDsByID(Map<UUID, List<Session>> sessionsByUser) {
|
||||
Map<Integer, UUID> uuidByID = new HashMap<>();
|
||||
for (Map.Entry<UUID, List<Session>> entry : sessionsByUser.entrySet()) {
|
||||
List<Session> sessions = entry.getValue();
|
||||
for (Session session : sessions) {
|
||||
uuidByID.put(session.getSessionID(), entry.getKey());
|
||||
}
|
||||
}
|
||||
return uuidByID;
|
||||
}
|
||||
|
||||
public static String[] createTable(Map<UUID, List<Session>> sessionsByUser, List<Session> allSessions) {
|
||||
if (allSessions.isEmpty()) {
|
||||
return new String[]{Html.TABLELINE_4.parse("<b>No Sessions</b>", "", "", ""),
|
||||
Html.TABLELINE_2.parse("<b>No Sessions</b>", "")};
|
||||
}
|
||||
|
||||
Map<Integer, UUID> uuidByID = getUUIDsByID(sessionsByUser);
|
||||
|
||||
allSessions.sort(new SessionStartComparator());
|
||||
|
||||
StringBuilder sessionTableBuilder = new StringBuilder();
|
||||
StringBuilder recentLoginsBuilder = new StringBuilder();
|
||||
|
||||
Set<String> recentLoginsNames = new HashSet<>();
|
||||
|
||||
Map<Long, UUID> uuidBySessionStart = new HashMap<>();
|
||||
for (Map.Entry<UUID, Session> entry : SessionCache.getActiveSessions().entrySet()) {
|
||||
uuidBySessionStart.put(entry.getValue().getSessionStart(), entry.getKey());
|
||||
}
|
||||
int i = 0;
|
||||
int maxSessions = Settings.MAX_SESSIONS.getNumber();
|
||||
if (maxSessions <= 0) {
|
||||
maxSessions = 50;
|
||||
}
|
||||
|
||||
DataCache dataCache = DataCache.getInstance();
|
||||
for (Session session : allSessions) {
|
||||
if (i >= maxSessions) {
|
||||
break;
|
||||
}
|
||||
|
||||
UUID uuid;
|
||||
if (session.isFetchedFromDB()) {
|
||||
uuid = uuidByID.get(session.getSessionID());
|
||||
} else {
|
||||
uuid = uuidBySessionStart.get(session.getSessionStart());
|
||||
}
|
||||
|
||||
String name = dataCache.getName(uuid);
|
||||
String start = Formatters.year().apply(session);
|
||||
String length = session.getSessionEnd() != -1 ? Formatters.timeAmount().apply(session.getLength()) : "Online";
|
||||
String world = AnalysisUtils.getLongestWorldPlayed(session);
|
||||
|
||||
String inspectUrl = PlanAPI.getInstance().getPlayerInspectPageLink(name);
|
||||
String toolTip = "Session ID: " + (session.isFetchedFromDB() ? session.getSessionID() : "Not Saved.");
|
||||
sessionTableBuilder.append(Html.TABLELINE_4.parse(
|
||||
Html.LINK_TOOLTIP.parse(inspectUrl, name, toolTip),
|
||||
start,
|
||||
length,
|
||||
world
|
||||
));
|
||||
|
||||
if (recentLoginsNames.size() < 20 && !recentLoginsNames.contains(name)) {
|
||||
boolean isNew = sessionsByUser.get(uuid).size() <= 2;
|
||||
|
||||
recentLoginsBuilder.append("<li><a class=\"col-").append(isNew ? "light-green" : "blue").append(" font-bold\" href=\"").append(inspectUrl)
|
||||
.append("\">").append(name).append("</a><span class=\"pull-right\">").append(start).append("</span></li>");
|
||||
|
||||
recentLoginsNames.add(name);
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
return new String[]{sessionTableBuilder.toString(), recentLoginsBuilder.toString()};
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user