mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-09-12 06:48:50 +02:00
Split Session table creation for Player page to a separate class
This commit is contained in:
parent
a092e39ee4
commit
a83c871bf8
@ -71,7 +71,7 @@ public class DataContainer extends HashMap<Key, Supplier> {
|
||||
public <T> T getUnsafe(Key<T> key) {
|
||||
Supplier supplier = get(key);
|
||||
if (supplier == null) {
|
||||
throw new IllegalArgumentException("Unsupported Key");
|
||||
throw new IllegalArgumentException("Unsupported Key: " + key.getKeyName());
|
||||
}
|
||||
return (T) supplier.get();
|
||||
}
|
||||
|
@ -39,6 +39,7 @@ import com.djrapitops.plan.utilities.html.structure.SessionAccordion;
|
||||
import com.djrapitops.plan.utilities.html.tables.ActionsTable;
|
||||
import com.djrapitops.plan.utilities.html.tables.GeoInfoTable;
|
||||
import com.djrapitops.plan.utilities.html.tables.NicknameTable;
|
||||
import com.djrapitops.plan.utilities.html.tables.PlayerSessionTable;
|
||||
import com.djrapitops.plugin.api.Benchmark;
|
||||
import com.djrapitops.plugin.api.TimeAmount;
|
||||
|
||||
@ -134,7 +135,19 @@ public class InspectPage extends Page {
|
||||
SessionsMutator allSessionsMutator = new SessionsMutator(allSessions);
|
||||
allSessions.sort(new SessionStartComparator());
|
||||
|
||||
SessionAccordion sessionAccordion = SessionAccordion.forPlayer(allSessions, () -> serverNames);
|
||||
String sessionAccordionViewScript = "";
|
||||
if (allSessions.isEmpty()) {
|
||||
addValue("accordionSessions", "<div class=\"body\">" + "<p>No Sessions</p>" + "</div>");
|
||||
} else {
|
||||
if (Settings.DISPLAY_SESSIONS_AS_TABLE.isTrue()) {
|
||||
addValue("accordionSessions", new PlayerSessionTable(playerName, allSessions).parseHtml());
|
||||
} else {
|
||||
SessionAccordion sessionAccordion = SessionAccordion.forPlayer(allSessions, () -> serverNames);
|
||||
addValue("accordionSessions", sessionAccordion.toHtml());
|
||||
sessionAccordionViewScript = sessionAccordion.toViewScript();
|
||||
}
|
||||
}
|
||||
|
||||
// TODO Session table if setting is enabled
|
||||
ServerAccordion serverAccordion = new ServerAccordion(container, serverNames);
|
||||
|
||||
@ -143,9 +156,8 @@ public class InspectPage extends Page {
|
||||
addValue("calendarSeries", playerCalendar.toCalendarSeries());
|
||||
addValue("firstDay", 1);
|
||||
|
||||
addValue("accordionSessions", sessionAccordion.toHtml());
|
||||
addValue("accordionServers", serverAccordion.toHtml());
|
||||
addValue("sessionTabGraphViewFunctions", sessionAccordion.toViewScript() + serverAccordion.toViewScript());
|
||||
addValue("sessionTabGraphViewFunctions", sessionAccordionViewScript + serverAccordion.toViewScript());
|
||||
|
||||
long dayAgo = now - TimeAmount.DAY.ms();
|
||||
long weekAgo = now - TimeAmount.WEEK.ms();
|
||||
|
@ -4,9 +4,11 @@ import com.djrapitops.plan.data.PlayerProfile;
|
||||
import com.djrapitops.plan.data.calculation.ActivityIndex;
|
||||
import com.djrapitops.plan.data.container.Session;
|
||||
import com.djrapitops.plan.data.container.StickyData;
|
||||
import com.djrapitops.plan.data.store.keys.SessionKeys;
|
||||
import com.djrapitops.plan.data.time.GMTimes;
|
||||
import com.djrapitops.plan.data.time.WorldTimes;
|
||||
import com.djrapitops.plan.system.settings.WorldAliasSettings;
|
||||
import com.djrapitops.plan.utilities.FormatUtils;
|
||||
import com.djrapitops.plugin.api.TimeAmount;
|
||||
|
||||
import java.util.*;
|
||||
@ -258,4 +260,33 @@ public class AnalysisUtils {
|
||||
|
||||
return new StickyData(averageIndex, averageMessagesSent, averagePlayersOnline);
|
||||
}
|
||||
|
||||
public static String getLongestWorldPlayed(Session session) {
|
||||
Map<String, String> aliases = WorldAliasSettings.getAliases();
|
||||
if (!session.supports(SessionKeys.WORLD_TIMES)) {
|
||||
return "No World Time Data";
|
||||
}
|
||||
if (!session.supports(SessionKeys.END)) {
|
||||
return "Current: " + aliases.get(session.getUnsafe(SessionKeys.WORLD_TIMES).getCurrentWorld());
|
||||
}
|
||||
|
||||
WorldTimes worldTimes = session.getUnsafe(SessionKeys.WORLD_TIMES);
|
||||
Map<String, Long> playtimePerAlias = getPlaytimePerAlias(worldTimes);
|
||||
long total = worldTimes.getTotal();
|
||||
|
||||
long longest = 0;
|
||||
String theWorld = "-";
|
||||
for (Map.Entry<String, Long> entry : playtimePerAlias.entrySet()) {
|
||||
String world = entry.getKey();
|
||||
long time = entry.getValue();
|
||||
if (time > longest) {
|
||||
longest = time;
|
||||
theWorld = world;
|
||||
}
|
||||
}
|
||||
|
||||
double percentage = longest * 100.0 / total;
|
||||
|
||||
return theWorld + " (" + FormatUtils.cutDecimals(percentage) + "%)";
|
||||
}
|
||||
}
|
||||
|
@ -5,17 +5,13 @@
|
||||
package com.djrapitops.plan.utilities.html;
|
||||
|
||||
import com.djrapitops.plan.api.exceptions.database.DBOpException;
|
||||
import com.djrapitops.plan.data.container.Session;
|
||||
import com.djrapitops.plan.system.database.databases.Database;
|
||||
import com.djrapitops.plan.system.info.server.Server;
|
||||
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.utilities.FormatUtils;
|
||||
import com.djrapitops.plan.utilities.analysis.Analysis;
|
||||
import com.djrapitops.plan.utilities.html.graphs.line.OnlineActivityGraph;
|
||||
import com.djrapitops.plan.utilities.html.structure.SessionTabStructureCreator;
|
||||
import com.djrapitops.plan.utilities.html.tables.SessionsTableCreator;
|
||||
import com.djrapitops.plugin.api.utility.log.Log;
|
||||
import com.djrapitops.plugin.utilities.Verify;
|
||||
|
||||
@ -61,19 +57,6 @@ public class HtmlStructure {
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static String[] createSessionsTabContentInspectPage(Map<String, List<Session>> sessions, List<Session> allSessions, UUID uuid) {
|
||||
if (Settings.DISPLAY_SESSIONS_AS_TABLE.isTrue()) {
|
||||
Map<UUID, List<Session>> sessionsByPlayer = new HashMap<>();
|
||||
sessionsByPlayer.put(uuid, allSessions);
|
||||
return new String[]{Html.TABLE_SESSIONS.parse("", "", "", SessionsTableCreator.createTable(sessionsByPlayer, allSessions)[0]), ""};
|
||||
} else {
|
||||
Map<UUID, Map<String, List<Session>>> map = new HashMap<>();
|
||||
map.put(uuid, sessions);
|
||||
return SessionTabStructureCreator.createStructure(map, allSessions, false);
|
||||
}
|
||||
}
|
||||
|
||||
public static String[] createInspectPageTabContentCalculating() {
|
||||
String tab = "<div class=\"tab\">" +
|
||||
"<div class=\"row clearfix\">" +
|
||||
|
@ -10,10 +10,10 @@ import com.djrapitops.plan.data.time.WorldTimes;
|
||||
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.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 java.util.*;
|
||||
import java.util.function.Supplier;
|
||||
@ -107,7 +107,7 @@ public class SessionAccordion extends AbstractAccordion {
|
||||
int deaths = session.getValue(SessionKeys.DEATH_COUNT).orElse(0);
|
||||
|
||||
String info = appendWorldPercentage
|
||||
? HtmlStructure.separateWithDots(sessionStart, SessionsTableCreator.getLongestWorldPlayed(session))
|
||||
? HtmlStructure.separateWithDots(sessionStart, AnalysisUtils.getLongestWorldPlayed(session))
|
||||
: sessionStart;
|
||||
String title = HtmlStructure.separateWithDots(playerName, info) + "<span class=\"pull-right\">" + length + "</span>";
|
||||
String htmlID = "" + session.getValue(SessionKeys.START).orElse(0L) + i;
|
||||
@ -178,7 +178,7 @@ public class SessionAccordion extends AbstractAccordion {
|
||||
int deaths = session.getValue(SessionKeys.DEATH_COUNT).orElse(0);
|
||||
|
||||
String info = appendWorldPercentage
|
||||
? HtmlStructure.separateWithDots(sessionStart, SessionsTableCreator.getLongestWorldPlayed(session))
|
||||
? HtmlStructure.separateWithDots(sessionStart, AnalysisUtils.getLongestWorldPlayed(session))
|
||||
: sessionStart;
|
||||
String title = HtmlStructure.separateWithDots(serverName, info) + "<span class=\"pull-right\">" + length + "</span>";
|
||||
String htmlID = "" + session.getValue(SessionKeys.START).orElse(0L) + i;
|
||||
|
@ -14,6 +14,7 @@ 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;
|
||||
@ -79,7 +80,7 @@ public class SessionTabStructureCreator {
|
||||
String link = PlanAPI.getInstance().getPlayerInspectPageLink(name);
|
||||
|
||||
String info = appendWorldPercentage
|
||||
? HtmlStructure.separateWithDots(sessionStart, SessionsTableCreator.getLongestWorldPlayed(session))
|
||||
? HtmlStructure.separateWithDots(sessionStart, AnalysisUtils.getLongestWorldPlayed(session))
|
||||
: sessionStart;
|
||||
String nameAndInfo = appendName ?
|
||||
HtmlStructure.separateWithDots(name, info) :
|
||||
|
@ -0,0 +1,60 @@
|
||||
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;
|
||||
|
||||
/**
|
||||
* TableContainer for a Session table for a single player.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class PlayerSessionTable extends TableContainer {
|
||||
|
||||
private final String playerName;
|
||||
private final List<Session> sessions;
|
||||
|
||||
public PlayerSessionTable(String playerName, List<Session> sessions) {
|
||||
super("Player", "Start", "Length", "World");
|
||||
this.playerName = playerName;
|
||||
this.sessions = sessions;
|
||||
|
||||
addRows();
|
||||
}
|
||||
|
||||
private void addRows() {
|
||||
int maxSessions = Settings.MAX_SESSIONS.getNumber();
|
||||
if (maxSessions <= 0) {
|
||||
maxSessions = 50;
|
||||
}
|
||||
|
||||
String inspectUrl = PlanAPI.getInstance().getPlayerInspectPageLink(playerName);
|
||||
|
||||
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.");
|
||||
addRow(Html.LINK_TOOLTIP.parse(inspectUrl, playerName, toolTip), start, length, world);
|
||||
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
@ -7,12 +7,9 @@ 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.data.time.WorldTimes;
|
||||
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.system.settings.WorldAliasSettings;
|
||||
import com.djrapitops.plan.utilities.FormatUtils;
|
||||
import com.djrapitops.plan.utilities.analysis.AnalysisUtils;
|
||||
import com.djrapitops.plan.utilities.comparators.SessionStartComparator;
|
||||
import com.djrapitops.plan.utilities.html.Html;
|
||||
@ -79,7 +76,7 @@ public class SessionsTableCreator {
|
||||
String name = dataCache.getName(uuid);
|
||||
String start = Formatters.year().apply(session);
|
||||
String length = session.getSessionEnd() != -1 ? Formatters.timeAmount().apply(session.getLength()) : "Online";
|
||||
String world = getLongestWorldPlayed(session);
|
||||
String world = AnalysisUtils.getLongestWorldPlayed(session);
|
||||
|
||||
String inspectUrl = PlanAPI.getInstance().getPlayerInspectPageLink(name);
|
||||
String toolTip = "Session ID: " + (session.isFetchedFromDB() ? session.getSessionID() : "Not Saved.");
|
||||
@ -104,29 +101,4 @@ public class SessionsTableCreator {
|
||||
return new String[]{sessionTableBuilder.toString(), recentLoginsBuilder.toString()};
|
||||
}
|
||||
|
||||
public static String getLongestWorldPlayed(Session session) {
|
||||
Map<String, String> aliases = WorldAliasSettings.getAliases();
|
||||
if (session.getSessionEnd() == -1) {
|
||||
return "Current: " + aliases.get(session.getWorldTimes().getCurrentWorld());
|
||||
}
|
||||
|
||||
WorldTimes worldTimes = session.getWorldTimes();
|
||||
Map<String, Long> playtimePerAlias = AnalysisUtils.getPlaytimePerAlias(worldTimes);
|
||||
long total = worldTimes.getTotal();
|
||||
|
||||
long longest = 0;
|
||||
String theWorld = "-";
|
||||
for (Map.Entry<String, Long> entry : playtimePerAlias.entrySet()) {
|
||||
String world = entry.getKey();
|
||||
long time = entry.getValue();
|
||||
if (time > longest) {
|
||||
longest = time;
|
||||
theWorld = world;
|
||||
}
|
||||
}
|
||||
|
||||
double percentage = longest * 100.0 / total;
|
||||
|
||||
return theWorld + " (" + FormatUtils.cutDecimals(percentage) + "%)";
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user