Server Accordion to Inspect page

This commit is contained in:
Rsl1122 2017-11-25 18:11:38 +02:00
parent 057cb3b9b3
commit 9cdd95c14f
4 changed files with 119 additions and 6 deletions

View File

@ -27,6 +27,7 @@ import main.java.com.djrapitops.plan.utilities.html.HtmlUtils;
import main.java.com.djrapitops.plan.utilities.html.graphs.PunchCardGraphCreator;
import main.java.com.djrapitops.plan.utilities.html.graphs.ServerPreferencePieCreator;
import main.java.com.djrapitops.plan.utilities.html.graphs.WorldPieCreator;
import main.java.com.djrapitops.plan.utilities.html.structure.ServerAccordionCreator;
import main.java.com.djrapitops.plan.utilities.html.tables.ActionsTableCreator;
import main.java.com.djrapitops.plan.utilities.html.tables.IpTableCreator;
import main.java.com.djrapitops.plan.utilities.html.tables.NicknameTableCreator;
@ -111,10 +112,11 @@ public class InspectPageParser extends PageParser {
.sorted(new SessionStartComparator())
.collect(Collectors.toList());
String[] sessionsTabContent = HtmlStructure.createSessionsTabContentInspectPage(sessionsByServerName, allSessions, uuid);
addValue("accordionSessions", sessionsTabContent[0]);
addValue("sessionTabGraphViewFunctions", sessionsTabContent[1]);
addValue("contentServerOverview", HtmlStructure.createServerOverviewColumn(sessionsByServerName));
String[] sessionsAccordion = HtmlStructure.createSessionsTabContentInspectPage(sessionsByServerName, allSessions, uuid);
String[] serverAccordion = ServerAccordionCreator.createAccordion(profile, serverNames);
addValue("accordionSessions", sessionsAccordion[0]);
addValue("accordionServers", serverAccordion[0]);
addValue("sessionTabGraphViewFunctions", sessionsAccordion[1] + serverAccordion[1]);
long dayAgo = now - TimeAmount.DAY.ms();
long weekAgo = now - TimeAmount.WEEK.ms();

View File

@ -0,0 +1,111 @@
/*
* 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 main.java.com.djrapitops.plan.utilities.html.structure;
import main.java.com.djrapitops.plan.data.PlayerProfile;
import main.java.com.djrapitops.plan.data.Session;
import main.java.com.djrapitops.plan.data.time.WorldTimes;
import main.java.com.djrapitops.plan.utilities.FormatUtils;
import main.java.com.djrapitops.plan.utilities.analysis.AnalysisUtils;
import main.java.com.djrapitops.plan.utilities.analysis.MathUtils;
import main.java.com.djrapitops.plan.utilities.html.graphs.WorldPieCreator;
import java.util.List;
import java.util.Map;
import java.util.UUID;
/**
* //TODO Class Javadoc Comment
*
* @author Rsl1122
*/
public class ServerAccordionCreator {
public static String[] createAccordion(PlayerProfile profile, Map<UUID, String> serverNames) {
StringBuilder html = new StringBuilder("<div class=\"panel-group scrollbar\" id=\"session_accordion\" role=\"tablist\" aria-multiselectable=\"true\">");
StringBuilder viewScript = new StringBuilder();
for (Map.Entry<UUID, WorldTimes> entry : profile.getWorldTimesPerServer().entrySet()) {
UUID serverUUID = entry.getKey();
String serverName = serverNames.getOrDefault(serverUUID, "Unknown");
WorldTimes worldTimes = entry.getValue();
List<Session> sessions = profile.getSessions(serverUUID);
long playtime = PlayerProfile.getPlaytime(sessions.stream());
int sessionCount = sessions.size();
long avgSession = MathUtils.averageLong(playtime, sessionCount);
long sessionMedian = PlayerProfile.getSessionMedian(sessions.stream());
long longestSession = PlayerProfile.getLongestSession(sessions.stream());
long mobKills = PlayerProfile.getMobKillCount(sessions.stream());
long playerKills = PlayerProfile.getPlayerKills(sessions.stream()).count();
long deaths = PlayerProfile.getDeathCount(sessions.stream());
String play = FormatUtils.formatTimeAmount(playtime);
String avg = sessionCount != 0 ? FormatUtils.formatTimeAmount(avgSession) : "-";
String median = sessionCount != 0 ? FormatUtils.formatTimeAmount(sessionMedian) : "-";
String longest = sessionCount != 0 ? FormatUtils.formatTimeAmount(longestSession) : "-";
String serverNameID = serverName.replace(" ", "_");
String htmlID = "server_" + serverNameID;
String worldId = "worldPieServer" + serverNameID;
AnalysisUtils.addMissingWorlds(worldTimes);
String[] worldData = WorldPieCreator.createSeriesData(worldTimes);
// Accordion panel header
html.append("<div class=\"panel panel-col-light-green\">")
.append("<div class=\"panel-heading\" role=\"tab\" id=\"heading_").append(htmlID).append("\">")
.append("<h4 class=\"panel-title\">")
.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(serverName).append("<span class=\"pull-right\">").append(play).append("</span>") // Title (header)
.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
// Sessions
.append("<p><i class=\"col-teal fa fa-calendar-check-o\"></i> Sessions <span class=\"pull-right\"><b>").append(sessionCount).append("</b></span></p>")
// Playtime
.append("<p><i class=\"col-green fa fa-clock-o\"></i> Server Playtime<span class=\"pull-right\"><b>").append(play).append("</b></span></p>")
.append("<p><i class=\"col-teal fa fa-clock-o\"></i> Longest Session<span class=\"pull-right\"><b>").append(longest).append("</b></span></p>")
.append("<p><i class=\"col-teal fa fa-clock-o\"></i> Session Median<span class=\"pull-right\"><b>").append(median).append("</b></span></p>")
.append("<br>")
// Player Kills
.append("<p><i class=\"col-red fa fa-crosshairs\"></i> Player Kills<span class=\"pull-right\"><b>").append(playerKills).append("</b></span></p>")
// Mob Kills
.append("<p><i class=\"col-green fa fa-crosshairs\"></i> Mob Kills<span class=\"pull-right\"><b>").append(mobKills).append("</b></span></p>")
// Deaths
.append("<p><i class=\"col-red fa fa-frown-o\"></i> Deaths<span class=\"pull-right\"><b>").append(deaths).append("</b></span></p>")
.append("</div>") // Closes 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',colors: worldPieColors,colorByPoint:true,data:").append(worldData[0]).append("};")
.append("var ").append(worldId).append("gmseries = ").append(worldData[1]).append(";")
.append("</script>")
.append("</div>") // Right col-6
.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(");");
}
return new String[]{html.append("</div>").toString(), viewScript.toString()};
}
}

View File

@ -534,7 +534,7 @@
</div>
</div>
</div>
${accorionServer}
${accordionServers}
</div>
</div>
<!-- #END# Sessions -->

View File

@ -573,7 +573,7 @@
</div>
</div>
<div class="body">
<div id="healthGauge" style="height: 300px; width: 100%;"></div>
<div id="healthGauge" style="height: 200px; width: 100%;"></div>
</div>
</div>
</div>