mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-08-26 22:49:51 +02:00
Made Graph Factories that use Dagger to initialize new Graphs.
Inject Graphs to access these factories. Moved WorldTimes Alias playtime calculations to WorldAliasSettings Renamed some Graphs to be shorter and unambiguous: AbstractLineGraph -> LineGraph AbstractPieChart -> Pie AbstractPieChartWithDrilldown -> PieWithDrilldown AbstractStackGraph -> StackGraph Abstracted away some details and made some graph classes package private Fixed tests for Line graphs, removed Stack graph test for now
This commit is contained in:
parent
cb351c80f1
commit
b104e8ca03
|
@ -2,11 +2,11 @@ package com.djrapitops.plan.data.container;
|
|||
|
||||
import com.djrapitops.plan.data.store.containers.DataContainer;
|
||||
import com.djrapitops.plan.data.store.keys.SessionKeys;
|
||||
import com.djrapitops.plan.utilities.formatting.Formatters;
|
||||
import com.djrapitops.plan.data.store.objects.DateHolder;
|
||||
import com.djrapitops.plan.data.time.WorldTimes;
|
||||
import com.djrapitops.plan.system.info.server.ServerInfo;
|
||||
import com.djrapitops.plan.system.settings.WorldAliasSettings;
|
||||
import com.djrapitops.plan.utilities.formatting.Formatters;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
@ -230,7 +230,7 @@ public class Session extends DataContainer implements DateHolder {
|
|||
return "Current: " + aliases.get(worldTimes.getCurrentWorld());
|
||||
}
|
||||
|
||||
Map<String, Long> playtimePerAlias = worldTimes.getPlaytimePerAlias();
|
||||
Map<String, Long> playtimePerAlias = new HashMap<>(); //TODO Call WorldAliasSettings#getPlaytimePerAlias(WorldTimes)
|
||||
long total = worldTimes.getTotal();
|
||||
|
||||
long longest = 0;
|
||||
|
|
|
@ -18,14 +18,11 @@ import com.djrapitops.plan.system.settings.theme.ThemeVal;
|
|||
import com.djrapitops.plan.utilities.MiscUtils;
|
||||
import com.djrapitops.plan.utilities.analysis.ServerBanDataReader;
|
||||
import com.djrapitops.plan.utilities.formatting.Formatters;
|
||||
import com.djrapitops.plan.utilities.html.graphs.ActivityStackGraph;
|
||||
import com.djrapitops.plan.utilities.html.graphs.PunchCardGraph;
|
||||
import com.djrapitops.plan.utilities.html.graphs.WorldMap;
|
||||
import com.djrapitops.plan.utilities.html.graphs.bar.GeolocationBarGraph;
|
||||
import com.djrapitops.plan.utilities.html.graphs.calendar.ServerCalendar;
|
||||
import com.djrapitops.plan.utilities.html.graphs.line.*;
|
||||
import com.djrapitops.plan.utilities.html.graphs.pie.ActivityPie;
|
||||
import com.djrapitops.plan.utilities.html.graphs.Graphs;
|
||||
import com.djrapitops.plan.utilities.html.graphs.bar.BarGraph;
|
||||
import com.djrapitops.plan.utilities.html.graphs.line.PingGraph;
|
||||
import com.djrapitops.plan.utilities.html.graphs.pie.WorldPie;
|
||||
import com.djrapitops.plan.utilities.html.graphs.stack.StackGraph;
|
||||
import com.djrapitops.plan.utilities.html.structure.AnalysisPluginsTabContentCreator;
|
||||
import com.djrapitops.plan.utilities.html.structure.RecentLoginList;
|
||||
import com.djrapitops.plan.utilities.html.structure.SessionAccordion;
|
||||
|
@ -50,11 +47,13 @@ public class AnalysisContainer extends DataContainer {
|
|||
|
||||
private final ServerContainer serverContainer;
|
||||
|
||||
// TODO
|
||||
private String version;
|
||||
private PlanConfig config;
|
||||
private Theme theme;
|
||||
private Database database;
|
||||
private ServerProperties serverProperties;
|
||||
private Graphs graphs;
|
||||
|
||||
private static final Key<Map<UUID, String>> serverNames = new Key<>(new Type<Map<UUID, String>>() {}, "SERVER_NAMES");
|
||||
|
||||
|
@ -206,13 +205,11 @@ public class AnalysisContainer extends DataContainer {
|
|||
|
||||
putSupplier(AnalysisKeys.UNIQUE_PLAYERS_PER_DAY, () -> getUnsafe(AnalysisKeys.SESSIONS_MUTATOR).uniqueJoinsPerDay());
|
||||
putSupplier(AnalysisKeys.NEW_PLAYERS_PER_DAY, () -> getUnsafe(AnalysisKeys.PLAYERS_MUTATOR).newPerDay());
|
||||
putSupplier(AnalysisKeys.UNIQUE_PLAYERS_SERIES, () -> new AbstractLineGraph(
|
||||
MutatorFunctions.toPoints(getUnsafe(AnalysisKeys.UNIQUE_PLAYERS_PER_DAY))
|
||||
).toHighChartsSeries()
|
||||
putSupplier(AnalysisKeys.UNIQUE_PLAYERS_SERIES, () -> graphs.line().lineGraph(
|
||||
MutatorFunctions.toPoints(getUnsafe(AnalysisKeys.UNIQUE_PLAYERS_PER_DAY))).toHighChartsSeries()
|
||||
);
|
||||
putSupplier(AnalysisKeys.NEW_PLAYERS_SERIES, () -> new AbstractLineGraph(
|
||||
MutatorFunctions.toPoints(getUnsafe(AnalysisKeys.NEW_PLAYERS_PER_DAY))
|
||||
).toHighChartsSeries()
|
||||
putSupplier(AnalysisKeys.NEW_PLAYERS_SERIES, () -> graphs.line().lineGraph(
|
||||
MutatorFunctions.toPoints(getUnsafe(AnalysisKeys.NEW_PLAYERS_PER_DAY))).toHighChartsSeries()
|
||||
);
|
||||
|
||||
Key<Integer> retentionDay = new Key<>(Integer.class, "RETENTION_DAY");
|
||||
|
@ -316,7 +313,7 @@ public class AnalysisContainer extends DataContainer {
|
|||
.filterSessionsBetween(getUnsafe(AnalysisKeys.ANALYSIS_TIME_MONTH_AGO), getUnsafe(AnalysisKeys.ANALYSIS_TIME))
|
||||
);
|
||||
|
||||
putSupplier(AnalysisKeys.PUNCHCARD_SERIES, () -> new PunchCardGraph(getUnsafe(sessionsMonth).all()).toHighChartsSeries());
|
||||
putSupplier(AnalysisKeys.PUNCHCARD_SERIES, () -> graphs.special().punchCard(getUnsafe(sessionsMonth).all()).toHighChartsSeries());
|
||||
putSupplier(AnalysisKeys.AVG_PLAYERS, () -> getUnsafe(AnalysisKeys.SESSIONS_MUTATOR).toAverageUniqueJoinsPerDay());
|
||||
putSupplier(AnalysisKeys.AVG_PLAYERS_DAY, () -> getUnsafe(sessionsDay).toAverageUniqueJoinsPerDay());
|
||||
putSupplier(AnalysisKeys.AVG_PLAYERS_WEEK, () -> getUnsafe(sessionsWeek).toAverageUniqueJoinsPerDay());
|
||||
|
@ -325,46 +322,48 @@ public class AnalysisContainer extends DataContainer {
|
|||
|
||||
private void addGraphSuppliers() {
|
||||
Key<WorldPie> worldPie = new Key<>(WorldPie.class, "WORLD_PIE");
|
||||
putSupplier(worldPie, () -> new WorldPie(serverContainer.getValue(ServerKeys.WORLD_TIMES).orElse(new WorldTimes(new HashMap<>()))));
|
||||
putSupplier(worldPie, () -> graphs.pie().worldPie(
|
||||
serverContainer.getValue(ServerKeys.WORLD_TIMES).orElse(new WorldTimes(new HashMap<>()))
|
||||
));
|
||||
putSupplier(AnalysisKeys.WORLD_PIE_SERIES, () -> getUnsafe(worldPie).toHighChartsSeries());
|
||||
putSupplier(AnalysisKeys.GM_PIE_SERIES, () -> getUnsafe(worldPie).toHighChartsDrilldown());
|
||||
putSupplier(AnalysisKeys.PLAYERS_ONLINE_SERIES, () ->
|
||||
new OnlineActivityGraph(getUnsafe(AnalysisKeys.TPS_MUTATOR)).toHighChartsSeries()
|
||||
graphs.line().playersOnlineGraph(getUnsafe(AnalysisKeys.TPS_MUTATOR)).toHighChartsSeries()
|
||||
);
|
||||
putSupplier(AnalysisKeys.TPS_SERIES, () -> new TPSGraph(getUnsafe(AnalysisKeys.TPS_MUTATOR)).toHighChartsSeries());
|
||||
putSupplier(AnalysisKeys.CPU_SERIES, () -> new CPUGraph(getUnsafe(AnalysisKeys.TPS_MUTATOR)).toHighChartsSeries());
|
||||
putSupplier(AnalysisKeys.RAM_SERIES, () -> new RamGraph(getUnsafe(AnalysisKeys.TPS_MUTATOR)).toHighChartsSeries());
|
||||
putSupplier(AnalysisKeys.ENTITY_SERIES, () -> new EntityGraph(getUnsafe(AnalysisKeys.TPS_MUTATOR)).toHighChartsSeries());
|
||||
putSupplier(AnalysisKeys.CHUNK_SERIES, () -> new ChunkGraph(getUnsafe(AnalysisKeys.TPS_MUTATOR)).toHighChartsSeries());
|
||||
putSupplier(AnalysisKeys.TPS_SERIES, () -> graphs.line().tpsGraph(getUnsafe(AnalysisKeys.TPS_MUTATOR)).toHighChartsSeries());
|
||||
putSupplier(AnalysisKeys.CPU_SERIES, () -> graphs.line().cpuGraph(getUnsafe(AnalysisKeys.TPS_MUTATOR)).toHighChartsSeries());
|
||||
putSupplier(AnalysisKeys.RAM_SERIES, () -> graphs.line().ramGraph(getUnsafe(AnalysisKeys.TPS_MUTATOR)).toHighChartsSeries());
|
||||
putSupplier(AnalysisKeys.ENTITY_SERIES, () -> graphs.line().entityGraph(getUnsafe(AnalysisKeys.TPS_MUTATOR)).toHighChartsSeries());
|
||||
putSupplier(AnalysisKeys.CHUNK_SERIES, () -> graphs.line().cpuGraph(getUnsafe(AnalysisKeys.TPS_MUTATOR)).toHighChartsSeries());
|
||||
putSupplier(AnalysisKeys.WORLD_MAP_SERIES, () ->
|
||||
new WorldMap(getUnsafe(AnalysisKeys.PLAYERS_MUTATOR).getGeolocations()).toHighChartsSeries()
|
||||
graphs.special().worldMap(getUnsafe(AnalysisKeys.PLAYERS_MUTATOR)).toHighChartsSeries()
|
||||
);
|
||||
Key<GeolocationBarGraph> geolocationBarChart = new Key<>(GeolocationBarGraph.class, "GEOLOCATION_BAR_CHART");
|
||||
putSupplier(geolocationBarChart, () -> new GeolocationBarGraph(getUnsafe(AnalysisKeys.PLAYERS_MUTATOR)));
|
||||
Key<BarGraph> geolocationBarChart = new Key<>(BarGraph.class, "GEOLOCATION_BAR_GRAPH");
|
||||
putSupplier(geolocationBarChart, () -> graphs.bar().geolocationBarGraph(getUnsafe(AnalysisKeys.PLAYERS_MUTATOR)));
|
||||
putSupplier(AnalysisKeys.COUNTRY_CATEGORIES, () -> getUnsafe(geolocationBarChart).toHighChartsCategories());
|
||||
putSupplier(AnalysisKeys.COUNTRY_SERIES, () -> getUnsafe(geolocationBarChart).toHighChartsSeries());
|
||||
|
||||
Key<PingGraph> pingGraph = new Key<>(PingGraph.class, "PING_GRAPH");
|
||||
putSupplier(pingGraph, () -> new PingGraph(
|
||||
PingMutator.forContainer(serverContainer).mutateToByMinutePings().all()
|
||||
));
|
||||
putSupplier(pingGraph, () ->
|
||||
graphs.line().pingGraph(PingMutator.forContainer(serverContainer).mutateToByMinutePings().all())
|
||||
);
|
||||
putSupplier(AnalysisKeys.AVG_PING_SERIES, () -> getUnsafe(pingGraph).toAvgSeries());
|
||||
putSupplier(AnalysisKeys.MAX_PING_SERIES, () -> getUnsafe(pingGraph).toMaxSeries());
|
||||
putSupplier(AnalysisKeys.MIN_PING_SERIES, () -> getUnsafe(pingGraph).toMinSeries());
|
||||
|
||||
putSupplier(AnalysisKeys.CALENDAR_SERIES, () -> new ServerCalendar(
|
||||
putSupplier(AnalysisKeys.CALENDAR_SERIES, () -> graphs.calendar().serverCalendar(
|
||||
getUnsafe(AnalysisKeys.PLAYERS_MUTATOR),
|
||||
getUnsafe(AnalysisKeys.UNIQUE_PLAYERS_PER_DAY),
|
||||
getUnsafe(AnalysisKeys.NEW_PLAYERS_PER_DAY)
|
||||
).toCalendarSeries());
|
||||
|
||||
putSupplier(AnalysisKeys.ACTIVITY_DATA, () -> getUnsafe(AnalysisKeys.PLAYERS_MUTATOR).toActivityDataMap(getUnsafe(AnalysisKeys.ANALYSIS_TIME)));
|
||||
Key<ActivityStackGraph> activityStackGraph = new Key<>(ActivityStackGraph.class, "ACTIVITY_STACK_GRAPH");
|
||||
putSupplier(activityStackGraph, () -> new ActivityStackGraph(getUnsafe(AnalysisKeys.ACTIVITY_DATA)));
|
||||
Key<StackGraph> activityStackGraph = new Key<>(StackGraph.class, "ACTIVITY_STACK_GRAPH");
|
||||
putSupplier(activityStackGraph, () -> graphs.stack().activityStackGraph(getUnsafe(AnalysisKeys.ACTIVITY_DATA)));
|
||||
putSupplier(AnalysisKeys.ACTIVITY_STACK_CATEGORIES, () -> getUnsafe(activityStackGraph).toHighChartsLabels());
|
||||
putSupplier(AnalysisKeys.ACTIVITY_STACK_SERIES, () -> getUnsafe(activityStackGraph).toHighChartsSeries());
|
||||
putSupplier(AnalysisKeys.ACTIVITY_PIE_SERIES, () ->
|
||||
new ActivityPie(getUnsafe(AnalysisKeys.ACTIVITY_DATA).get(getUnsafe(AnalysisKeys.ANALYSIS_TIME))).toHighChartsSeries()
|
||||
putSupplier(AnalysisKeys.ACTIVITY_PIE_SERIES, () -> graphs.pie().activityPie(
|
||||
getUnsafe(AnalysisKeys.ACTIVITY_DATA).get(getUnsafe(AnalysisKeys.ANALYSIS_TIME))).toHighChartsSeries()
|
||||
);
|
||||
putSupplier(AnalysisKeys.PLAYERS_REGULAR, () -> {
|
||||
Map<String, Set<UUID>> activityNow = getUnsafe(AnalysisKeys.ACTIVITY_DATA)
|
||||
|
|
|
@ -6,7 +6,6 @@ import com.djrapitops.plan.data.store.keys.NetworkKeys;
|
|||
import com.djrapitops.plan.data.store.keys.ServerKeys;
|
||||
import com.djrapitops.plan.data.store.mutators.PlayersMutator;
|
||||
import com.djrapitops.plan.data.store.mutators.TPSMutator;
|
||||
import com.djrapitops.plan.utilities.formatting.Formatters;
|
||||
import com.djrapitops.plan.data.store.mutators.health.NetworkHealthInformation;
|
||||
import com.djrapitops.plan.system.database.databases.Database;
|
||||
import com.djrapitops.plan.system.info.server.ServerInfo;
|
||||
|
@ -14,11 +13,10 @@ 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.graphs.ActivityStackGraph;
|
||||
import com.djrapitops.plan.utilities.html.graphs.WorldMap;
|
||||
import com.djrapitops.plan.utilities.html.graphs.bar.GeolocationBarGraph;
|
||||
import com.djrapitops.plan.utilities.html.graphs.line.OnlineActivityGraph;
|
||||
import com.djrapitops.plan.utilities.html.graphs.pie.ActivityPie;
|
||||
import com.djrapitops.plan.utilities.formatting.Formatters;
|
||||
import com.djrapitops.plan.utilities.html.graphs.Graphs;
|
||||
import com.djrapitops.plan.utilities.html.graphs.bar.BarGraph;
|
||||
import com.djrapitops.plan.utilities.html.graphs.stack.StackGraph;
|
||||
import com.djrapitops.plugin.api.Check;
|
||||
import com.djrapitops.plugin.api.TimeAmount;
|
||||
|
||||
|
@ -38,7 +36,9 @@ public class NetworkContainer extends DataContainer {
|
|||
|
||||
private final ServerContainer bungeeContainer;
|
||||
|
||||
// TODO
|
||||
private Database database;
|
||||
private Graphs graphs;
|
||||
|
||||
private final Map<UUID, AnalysisContainer> serverContainers;
|
||||
|
||||
|
@ -99,23 +99,23 @@ public class NetworkContainer extends DataContainer {
|
|||
private void addPlayerInformation() {
|
||||
putSupplier(NetworkKeys.PLAYERS_TOTAL, () -> getUnsafe(NetworkKeys.PLAYERS_MUTATOR).count());
|
||||
putSupplier(NetworkKeys.WORLD_MAP_SERIES, () ->
|
||||
new WorldMap(PlayersMutator.forContainer(bungeeContainer)).toHighChartsSeries()
|
||||
graphs.special().worldMap(PlayersMutator.forContainer(bungeeContainer)).toHighChartsSeries()
|
||||
);
|
||||
Key<GeolocationBarGraph> geolocationBarChart = new Key<>(GeolocationBarGraph.class, "GEOLOCATION_BAR_CHART");
|
||||
putSupplier(geolocationBarChart, () -> new GeolocationBarGraph(getUnsafe(NetworkKeys.PLAYERS_MUTATOR)));
|
||||
Key<BarGraph> geolocationBarChart = new Key<>(BarGraph.class, "GEOLOCATION_BAR_GRAPH");
|
||||
putSupplier(geolocationBarChart, () -> graphs.bar().geolocationBarGraph(getUnsafe(NetworkKeys.PLAYERS_MUTATOR)));
|
||||
putSupplier(NetworkKeys.COUNTRY_CATEGORIES, () -> getUnsafe(geolocationBarChart).toHighChartsCategories());
|
||||
putSupplier(NetworkKeys.COUNTRY_SERIES, () -> getUnsafe(geolocationBarChart).toHighChartsSeries());
|
||||
|
||||
putSupplier(NetworkKeys.PLAYERS_ONLINE_SERIES, () ->
|
||||
new OnlineActivityGraph(TPSMutator.forContainer(bungeeContainer)).toHighChartsSeries()
|
||||
graphs.line().playersOnlineGraph(TPSMutator.forContainer(bungeeContainer)).toHighChartsSeries()
|
||||
);
|
||||
Key<ActivityStackGraph> activityStackGraph = new Key<>(ActivityStackGraph.class, "ACTIVITY_STACK_GRAPH");
|
||||
Key<StackGraph> activityStackGraph = new Key<>(StackGraph.class, "ACTIVITY_STACK_GRAPH");
|
||||
putSupplier(NetworkKeys.ACTIVITY_DATA, () -> getUnsafe(NetworkKeys.PLAYERS_MUTATOR).toActivityDataMap(getUnsafe(NetworkKeys.REFRESH_TIME)));
|
||||
putSupplier(activityStackGraph, () -> new ActivityStackGraph(getUnsafe(NetworkKeys.ACTIVITY_DATA)));
|
||||
putSupplier(activityStackGraph, () -> graphs.stack().activityStackGraph(getUnsafe(NetworkKeys.ACTIVITY_DATA)));
|
||||
putSupplier(NetworkKeys.ACTIVITY_STACK_CATEGORIES, () -> getUnsafe(activityStackGraph).toHighChartsLabels());
|
||||
putSupplier(NetworkKeys.ACTIVITY_STACK_SERIES, () -> getUnsafe(activityStackGraph).toHighChartsSeries());
|
||||
putSupplier(NetworkKeys.ACTIVITY_PIE_SERIES, () ->
|
||||
new ActivityPie(getUnsafe(NetworkKeys.ACTIVITY_DATA).get(getUnsafe(NetworkKeys.REFRESH_TIME))).toHighChartsSeries()
|
||||
putSupplier(NetworkKeys.ACTIVITY_PIE_SERIES, () -> graphs.pie().activityPie(
|
||||
getUnsafe(NetworkKeys.ACTIVITY_DATA).get(getUnsafe(NetworkKeys.REFRESH_TIME))).toHighChartsSeries()
|
||||
);
|
||||
|
||||
putSupplier(NetworkKeys.ALL_TIME_PEAK_TIME_F, () ->
|
||||
|
|
|
@ -1,11 +1,8 @@
|
|||
package com.djrapitops.plan.data.time;
|
||||
|
||||
import com.djrapitops.plan.system.settings.WorldAliasSettings;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Class that tracks the time spent in each World based on GMTimes.
|
||||
|
@ -169,30 +166,4 @@ public class WorldTimes {
|
|||
}
|
||||
}
|
||||
|
||||
public Map<String, Long> getPlaytimePerAlias() {
|
||||
Map<String, Long> playtimePerWorld = getWorldTimes() // WorldTimes Map<String, GMTimes>
|
||||
.entrySet().stream()
|
||||
.collect(Collectors.toMap(
|
||||
Map.Entry::getKey,
|
||||
entry -> entry.getValue().getTotal() // GMTimes.getTotal
|
||||
));
|
||||
|
||||
Map<String, String> aliases = WorldAliasSettings.getAliases_Old();
|
||||
|
||||
Map<String, Long> playtimePerAlias = new HashMap<>();
|
||||
for (Map.Entry<String, Long> entry : playtimePerWorld.entrySet()) {
|
||||
String worldName = entry.getKey();
|
||||
long playtime = entry.getValue();
|
||||
|
||||
if (!aliases.containsKey(worldName)) {
|
||||
aliases.put(worldName, worldName);
|
||||
WorldAliasSettings.addWorld_Old(worldName);
|
||||
}
|
||||
|
||||
String alias = aliases.get(worldName);
|
||||
|
||||
playtimePerAlias.put(alias, playtimePerAlias.getOrDefault(alias, 0L) + playtime);
|
||||
}
|
||||
return playtimePerAlias;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
*/
|
||||
package com.djrapitops.plan.system.settings;
|
||||
|
||||
import com.djrapitops.plan.data.time.GMTimes;
|
||||
import com.djrapitops.plan.data.time.WorldTimes;
|
||||
import com.djrapitops.plan.system.processing.Processing;
|
||||
import com.djrapitops.plan.system.settings.config.PlanConfig;
|
||||
import com.djrapitops.plugin.config.ConfigNode;
|
||||
|
@ -17,6 +19,7 @@ import javax.inject.Singleton;
|
|||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Class responsible for managing config settings for World Aliases.
|
||||
|
@ -92,4 +95,58 @@ public class WorldAliasSettings {
|
|||
});
|
||||
}
|
||||
}
|
||||
|
||||
public Map<String, Long> getPlaytimePerAlias(WorldTimes worldTimes) {
|
||||
Map<String, Long> playtimePerWorld = worldTimes.getWorldTimes() // WorldTimes Map<String, GMTimes>
|
||||
.entrySet().stream()
|
||||
.collect(Collectors.toMap(
|
||||
Map.Entry::getKey,
|
||||
entry -> entry.getValue().getTotal() // GMTimes.getTotal
|
||||
));
|
||||
|
||||
Map<String, String> aliases = getAliases();
|
||||
|
||||
Map<String, Long> playtimePerAlias = new HashMap<>();
|
||||
for (Map.Entry<String, Long> entry : playtimePerWorld.entrySet()) {
|
||||
String worldName = entry.getKey();
|
||||
long playtime = entry.getValue();
|
||||
|
||||
if (!aliases.containsKey(worldName)) {
|
||||
aliases.put(worldName, worldName);
|
||||
addWorld(worldName);
|
||||
}
|
||||
|
||||
String alias = aliases.get(worldName);
|
||||
|
||||
playtimePerAlias.put(alias, playtimePerAlias.getOrDefault(alias, 0L) + playtime);
|
||||
}
|
||||
return playtimePerAlias;
|
||||
}
|
||||
|
||||
public Map<String, GMTimes> getGMTimesPerAlias(WorldTimes worldTimes) {
|
||||
Map<String, String> aliases = getAliases();
|
||||
|
||||
Map<String, GMTimes> gmTimesPerAlias = new HashMap<>();
|
||||
|
||||
String[] gms = GMTimes.getGMKeyArray();
|
||||
|
||||
for (Map.Entry<String, GMTimes> entry : worldTimes.getWorldTimes().entrySet()) {
|
||||
String worldName = entry.getKey();
|
||||
GMTimes gmTimes = entry.getValue();
|
||||
|
||||
if (!aliases.containsKey(worldName)) {
|
||||
aliases.put(worldName, worldName);
|
||||
addWorld(worldName);
|
||||
}
|
||||
|
||||
String alias = aliases.get(worldName);
|
||||
|
||||
GMTimes aliasGMTimes = gmTimesPerAlias.getOrDefault(alias, new GMTimes());
|
||||
for (String gm : gms) {
|
||||
aliasGMTimes.addTime(gm, gmTimes.getTime(gm));
|
||||
}
|
||||
gmTimesPerAlias.put(alias, aliasGMTimes);
|
||||
}
|
||||
return gmTimesPerAlias;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,12 +4,13 @@
|
|||
*/
|
||||
package com.djrapitops.plan.utilities.html;
|
||||
|
||||
import com.djrapitops.plan.data.store.mutators.TPSMutator;
|
||||
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.properties.ServerProperties;
|
||||
import com.djrapitops.plan.utilities.FormatUtils;
|
||||
import com.djrapitops.plan.utilities.html.graphs.line.OnlineActivityGraph;
|
||||
import com.djrapitops.plan.utilities.html.graphs.Graphs;
|
||||
import com.djrapitops.plan.utilities.html.icon.Color;
|
||||
import com.djrapitops.plan.utilities.html.icon.Icon;
|
||||
import com.djrapitops.plan.utilities.html.icon.Icons;
|
||||
|
@ -81,7 +82,8 @@ public class HtmlStructure {
|
|||
int playerCount = 0;
|
||||
String playerData = "[]";
|
||||
playerCount = db.count().getServerPlayerCount(serverUUID);
|
||||
playerData = new OnlineActivityGraph(db.fetch().getTPSData(serverUUID)).toHighChartsSeries();
|
||||
Graphs graphs = null; // TODO
|
||||
playerData = graphs.line().playersOnlineGraph(new TPSMutator(db.fetch().getTPSData(serverUUID))).toHighChartsSeries();
|
||||
|
||||
return "<div class=\"col-xs-12 col-sm-12 col-md-6 col-lg-6\">" +
|
||||
"<div class=\"card\">" +
|
||||
|
|
|
@ -0,0 +1,68 @@
|
|||
package com.djrapitops.plan.utilities.html.graphs;
|
||||
|
||||
import com.djrapitops.plan.utilities.html.graphs.bar.BarGraphFactory;
|
||||
import com.djrapitops.plan.utilities.html.graphs.calendar.CalendarFactory;
|
||||
import com.djrapitops.plan.utilities.html.graphs.line.LineGraphFactory;
|
||||
import com.djrapitops.plan.utilities.html.graphs.pie.PieGraphFactory;
|
||||
import com.djrapitops.plan.utilities.html.graphs.special.SpecialGraphFactory;
|
||||
import com.djrapitops.plan.utilities.html.graphs.stack.StackGraphFactory;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
/**
|
||||
* Factory class for different objects representing HTML graphs.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
@Singleton
|
||||
public class Graphs {
|
||||
|
||||
private final BarGraphFactory barGraphFactory;
|
||||
private final CalendarFactory calendarFactory;
|
||||
private final LineGraphFactory lineGraphFactory;
|
||||
private final PieGraphFactory pieGraphFactory;
|
||||
private final StackGraphFactory stackGraphFactory;
|
||||
private final SpecialGraphFactory specialGraphFactory;
|
||||
|
||||
@Inject
|
||||
public Graphs(
|
||||
BarGraphFactory barGraphFactory,
|
||||
CalendarFactory calendarFactory,
|
||||
LineGraphFactory lineGraphFactory,
|
||||
PieGraphFactory pieGraphFactory,
|
||||
StackGraphFactory stackGraphFactory,
|
||||
SpecialGraphFactory specialGraphFactory
|
||||
) {
|
||||
this.barGraphFactory = barGraphFactory;
|
||||
this.calendarFactory = calendarFactory;
|
||||
this.lineGraphFactory = lineGraphFactory;
|
||||
this.pieGraphFactory = pieGraphFactory;
|
||||
this.stackGraphFactory = stackGraphFactory;
|
||||
this.specialGraphFactory = specialGraphFactory;
|
||||
}
|
||||
|
||||
public BarGraphFactory bar() {
|
||||
return barGraphFactory;
|
||||
}
|
||||
|
||||
public CalendarFactory calendar() {
|
||||
return calendarFactory;
|
||||
}
|
||||
|
||||
public LineGraphFactory line() {
|
||||
return lineGraphFactory;
|
||||
}
|
||||
|
||||
public PieGraphFactory pie() {
|
||||
return pieGraphFactory;
|
||||
}
|
||||
|
||||
public StackGraphFactory stack() {
|
||||
return stackGraphFactory;
|
||||
}
|
||||
|
||||
public SpecialGraphFactory special() {
|
||||
return specialGraphFactory;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
package com.djrapitops.plan.utilities.html.graphs.bar;
|
||||
|
||||
import com.djrapitops.plan.data.store.mutators.PlayersMutator;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
/**
|
||||
* Factory class for Bar Graphs.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
@Singleton
|
||||
public class BarGraphFactory {
|
||||
@Inject
|
||||
public BarGraphFactory() {
|
||||
// Inject Constructor.
|
||||
}
|
||||
|
||||
public BarGraph geolocationBarGraph(PlayersMutator playersMutator) {
|
||||
return new GeolocationBarGraph(playersMutator);
|
||||
}
|
||||
}
|
|
@ -9,11 +9,11 @@ import java.util.stream.Collectors;
|
|||
|
||||
public class GeolocationBarGraph extends BarGraph {
|
||||
|
||||
public GeolocationBarGraph(PlayersMutator mutator) {
|
||||
GeolocationBarGraph(PlayersMutator mutator) {
|
||||
this(mutator.getGeolocations());
|
||||
}
|
||||
|
||||
public GeolocationBarGraph(List<String> geolocations) {
|
||||
private GeolocationBarGraph(List<String> geolocations) {
|
||||
super(turnToBars(geolocations));
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
package com.djrapitops.plan.utilities.html.graphs.calendar;
|
||||
|
||||
import com.djrapitops.plan.data.store.containers.PlayerContainer;
|
||||
import com.djrapitops.plan.data.store.mutators.PlayersMutator;
|
||||
import com.djrapitops.plan.system.settings.theme.Theme;
|
||||
import com.djrapitops.plan.utilities.formatting.Formatter;
|
||||
import com.djrapitops.plan.utilities.formatting.Formatters;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.util.TreeMap;
|
||||
|
||||
/**
|
||||
* Factory class for different objects representing HTML calendars.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
@Singleton
|
||||
public class CalendarFactory {
|
||||
|
||||
private final Formatter<Long> iso8601Formatter;
|
||||
private final Formatter<Long> timeAmountFormatter;
|
||||
private final Theme theme;
|
||||
|
||||
@Inject
|
||||
public CalendarFactory(
|
||||
Formatters formatters,
|
||||
Theme theme
|
||||
) {
|
||||
this.iso8601Formatter = formatters.iso8601NoClockLong();
|
||||
this.timeAmountFormatter = formatters.timeAmount();
|
||||
this.theme = theme;
|
||||
}
|
||||
|
||||
public PlayerCalendar playerCalendar(PlayerContainer player) {
|
||||
return new PlayerCalendar(player);
|
||||
}
|
||||
|
||||
public ServerCalendar serverCalendar(
|
||||
PlayersMutator mutator,
|
||||
TreeMap<Long, Integer> uniquePerDay,
|
||||
TreeMap<Long, Integer> newPerDay
|
||||
) {
|
||||
return new ServerCalendar(mutator, uniquePerDay, newPerDay, iso8601Formatter, timeAmountFormatter, theme);
|
||||
}
|
||||
}
|
|
@ -9,11 +9,11 @@ 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.utilities.formatting.Formatter;
|
||||
import com.djrapitops.plan.utilities.formatting.Formatters;
|
||||
import com.djrapitops.plan.system.settings.theme.Theme;
|
||||
import com.djrapitops.plan.system.settings.theme.ThemeVal;
|
||||
import com.djrapitops.plan.utilities.FormatUtils;
|
||||
import com.djrapitops.plan.utilities.formatting.Formatter;
|
||||
import com.djrapitops.plan.utilities.formatting.Formatters;
|
||||
import com.djrapitops.plugin.api.TimeAmount;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -31,7 +31,7 @@ public class PlayerCalendar {
|
|||
private final List<Session> allSessions;
|
||||
private final long registered;
|
||||
|
||||
public PlayerCalendar(PlayerContainer container) {
|
||||
PlayerCalendar(PlayerContainer container) {
|
||||
this(
|
||||
container.getValue(PlayerKeys.SESSIONS).orElse(new ArrayList<>()),
|
||||
container.getValue(PlayerKeys.REGISTERED).orElse(0L)
|
||||
|
|
|
@ -7,10 +7,9 @@ package com.djrapitops.plan.utilities.html.graphs.calendar;
|
|||
import com.djrapitops.plan.data.container.Session;
|
||||
import com.djrapitops.plan.data.store.mutators.PlayersMutator;
|
||||
import com.djrapitops.plan.data.store.mutators.SessionsMutator;
|
||||
import com.djrapitops.plan.utilities.formatting.Formatters;
|
||||
import com.djrapitops.plan.system.settings.theme.Theme;
|
||||
import com.djrapitops.plan.system.settings.theme.ThemeVal;
|
||||
import com.djrapitops.plan.utilities.FormatUtils;
|
||||
import com.djrapitops.plan.utilities.formatting.Formatter;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
@ -25,12 +24,22 @@ public class ServerCalendar {
|
|||
private final TreeMap<Long, Integer> uniquePerDay;
|
||||
private final TreeMap<Long, Integer> newPerDay;
|
||||
|
||||
public ServerCalendar(PlayersMutator mutator,
|
||||
TreeMap<Long, Integer> uniquePerDay,
|
||||
TreeMap<Long, Integer> newPerDay) {
|
||||
private final Formatter<Long> iso8601Formatter;
|
||||
private final Formatter<Long> timeAmountFormatter;
|
||||
private final Theme theme;
|
||||
|
||||
ServerCalendar(
|
||||
PlayersMutator mutator, TreeMap<Long, Integer> uniquePerDay, TreeMap<Long, Integer> newPerDay,
|
||||
Formatter<Long> iso8601Formatter,
|
||||
Formatter<Long> timeAmountFormatter,
|
||||
Theme theme
|
||||
) {
|
||||
this.mutator = mutator;
|
||||
this.uniquePerDay = uniquePerDay;
|
||||
this.newPerDay = newPerDay;
|
||||
this.iso8601Formatter = iso8601Formatter;
|
||||
this.timeAmountFormatter = timeAmountFormatter;
|
||||
this.theme = theme;
|
||||
}
|
||||
|
||||
public String toCalendarSeries() {
|
||||
|
@ -51,12 +60,12 @@ public class ServerCalendar {
|
|||
if (newPlayers <= 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
String day = entry.getKey();
|
||||
|
||||
series.append(",{title: 'New: ").append(newPlayers)
|
||||
.append("',start:'").append(day)
|
||||
.append("',color: '").append(Theme.getValue_Old(ThemeVal.LIGHT_GREEN)).append("'")
|
||||
.append("',color: '").append(theme.getThemeValue(ThemeVal.LIGHT_GREEN)).append("'")
|
||||
.append("}");
|
||||
}
|
||||
|
||||
|
@ -72,7 +81,7 @@ public class ServerCalendar {
|
|||
}
|
||||
|
||||
Long key = entry.getKey();
|
||||
String day = FormatUtils.formatTimeStampISO8601NoClock(key);
|
||||
String day = iso8601Formatter.apply(key);
|
||||
List<Session> sessions = byStartOfDay.getOrDefault(key, new ArrayList<>());
|
||||
|
||||
SessionsMutator dayMutator = new SessionsMutator(sessions);
|
||||
|
@ -80,14 +89,14 @@ public class ServerCalendar {
|
|||
long playtime = dayMutator.toPlaytime();
|
||||
long uniquePlayers = entry.getValue();
|
||||
|
||||
series.append(",{title: 'Playtime: ").append(Formatters.timeAmount_Old().apply(playtime))
|
||||
series.append(",{title: 'Playtime: ").append(timeAmountFormatter.apply(playtime))
|
||||
.append("',start:'").append(day)
|
||||
.append("',color: '").append(Theme.getValue_Old(ThemeVal.GREEN)).append("'")
|
||||
.append("',color: '").append(theme.getThemeValue(ThemeVal.GREEN)).append("'")
|
||||
.append("}");
|
||||
|
||||
series.append(",{title: 'Sessions: ").append(sessionCount)
|
||||
.append("',start:'").append(day)
|
||||
.append("',color: '").append(Theme.getValue_Old(ThemeVal.TEAL)).append("'")
|
||||
.append("',color: '").append(theme.getThemeValue(ThemeVal.TEAL)).append("'")
|
||||
.append("}");
|
||||
|
||||
series.append(",{title: 'Unique: ").append(uniquePlayers)
|
||||
|
@ -99,7 +108,7 @@ public class ServerCalendar {
|
|||
private Map<String, Integer> getRegisteredByDay() {
|
||||
Map<String, Integer> registeredByDay = new HashMap<>();
|
||||
for (Map.Entry<Long, Integer> entry : newPerDay.entrySet()) {
|
||||
String day = FormatUtils.formatTimeStampISO8601NoClock(entry.getKey());
|
||||
String day = iso8601Formatter.apply(entry.getKey());
|
||||
registeredByDay.put(day, entry.getValue());
|
||||
}
|
||||
return registeredByDay;
|
||||
|
|
|
@ -1,93 +0,0 @@
|
|||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package com.djrapitops.plan.utilities.html.graphs.line;
|
||||
|
||||
import com.djrapitops.plan.system.settings.Settings;
|
||||
import com.djrapitops.plan.utilities.html.graphs.HighChart;
|
||||
import com.djrapitops.plan.utilities.html.graphs.line.alg.DouglasPeuckerAlgorithm;
|
||||
import com.djrapitops.plan.utilities.html.graphs.line.alg.ReduceGapTriangles;
|
||||
import com.djrapitops.plugin.api.TimeAmount;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This is a LineGraph for any set of Points, thus it is Abstract.
|
||||
*
|
||||
* @author Rsl1122
|
||||
* @since 4.2.0
|
||||
*/
|
||||
public class AbstractLineGraph implements HighChart {
|
||||
|
||||
protected List<Point> points;
|
||||
protected boolean reduceGapTriangles = false;
|
||||
protected boolean reducePoints = false;
|
||||
|
||||
public AbstractLineGraph() {
|
||||
points = new ArrayList<>();
|
||||
}
|
||||
|
||||
public AbstractLineGraph(List<Point> points) {
|
||||
this.points = points;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toHighChartsSeries() {
|
||||
StringBuilder arrayBuilder = new StringBuilder("[");
|
||||
|
||||
if (reducePoints) {
|
||||
points = DouglasPeuckerAlgorithm.reducePoints(points, 0);
|
||||
}
|
||||
if (reduceGapTriangles) {
|
||||
points = ReduceGapTriangles.reduce(points);
|
||||
}
|
||||
|
||||
int size = points.size();
|
||||
Long lastX = null;
|
||||
boolean addMissingPoints = Settings.DISPLAY_GAPS_IN_GRAPH_DATA.isTrue();
|
||||
for (int i = 0; i < size; i++) {
|
||||
Point point = points.get(i);
|
||||
Double y = point.getY();
|
||||
long date = (long) point.getX();
|
||||
if (addMissingPoints && lastX != null && date - lastX > TimeAmount.MINUTE.ms() * 3L) {
|
||||
addMissingPoints(arrayBuilder, lastX, date);
|
||||
}
|
||||
lastX = date;
|
||||
arrayBuilder.append("[").append(date).append(",").append(y).append("]");
|
||||
if (i < size - 1) {
|
||||
arrayBuilder.append(",");
|
||||
}
|
||||
}
|
||||
|
||||
arrayBuilder.append("]");
|
||||
return arrayBuilder.toString();
|
||||
}
|
||||
|
||||
private void addMissingPoints(StringBuilder arrayBuilder, Long lastX, long date) {
|
||||
long iterate = lastX + TimeAmount.MINUTE.ms();
|
||||
while (iterate < date) {
|
||||
arrayBuilder.append("[").append(iterate).append(",null],");
|
||||
iterate += TimeAmount.MINUTE.ms() * 30L;
|
||||
}
|
||||
}
|
||||
|
||||
public void reduceGapTriangles() {
|
||||
this.reduceGapTriangles = true;
|
||||
}
|
||||
|
||||
public void reducePoints() {
|
||||
this.reducePoints = true;
|
||||
}
|
||||
|
||||
public void setPoints(List<Point> points) {
|
||||
this.points = points;
|
||||
}
|
||||
|
||||
public void addPoints(Collection<Point> points) {
|
||||
this.points.addAll(points);
|
||||
}
|
||||
}
|
|
@ -1,10 +1,7 @@
|
|||
package com.djrapitops.plan.utilities.html.graphs.line;
|
||||
|
||||
import com.djrapitops.plan.data.container.TPS;
|
||||
import com.djrapitops.plan.data.store.mutators.TPSMutator;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Graph about CPU Usage gathered by TPSCountTimer.
|
||||
*
|
||||
|
@ -12,13 +9,9 @@ import java.util.List;
|
|||
* @see com.djrapitops.plan.system.tasks.TPSCountTimer
|
||||
* @since 4.2.0
|
||||
*/
|
||||
public class CPUGraph extends AbstractLineGraph {
|
||||
class CPUGraph extends LineGraph {
|
||||
|
||||
public CPUGraph(List<TPS> tpsData) {
|
||||
this(new TPSMutator(tpsData));
|
||||
}
|
||||
|
||||
public CPUGraph(TPSMutator mutator) {
|
||||
super(mutator.cpuPoints());
|
||||
CPUGraph(TPSMutator mutator, boolean displayGaps) {
|
||||
super(mutator.cpuPoints(), displayGaps);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +1,7 @@
|
|||
package com.djrapitops.plan.utilities.html.graphs.line;
|
||||
|
||||
import com.djrapitops.plan.data.container.TPS;
|
||||
import com.djrapitops.plan.data.store.mutators.TPSMutator;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Graph about Chunk Counts gathered by TPSCountTimer.
|
||||
*
|
||||
|
@ -12,13 +9,9 @@ import java.util.List;
|
|||
* @see com.djrapitops.plan.system.tasks.TPSCountTimer
|
||||
* @since 4.2.0
|
||||
*/
|
||||
public class ChunkGraph extends AbstractLineGraph {
|
||||
class ChunkGraph extends LineGraph {
|
||||
|
||||
public ChunkGraph(List<TPS> tpsData) {
|
||||
this(new TPSMutator(tpsData));
|
||||
}
|
||||
|
||||
public ChunkGraph(TPSMutator mutator) {
|
||||
super(mutator.chunkPoints());
|
||||
ChunkGraph(TPSMutator mutator, boolean displayGaps) {
|
||||
super(mutator.chunkPoints(), displayGaps);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +1,7 @@
|
|||
package com.djrapitops.plan.utilities.html.graphs.line;
|
||||
|
||||
import com.djrapitops.plan.data.container.TPS;
|
||||
import com.djrapitops.plan.data.store.mutators.TPSMutator;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Graph about Entity Counts gathered by TPSCountTimer.
|
||||
*
|
||||
|
@ -12,13 +9,9 @@ import java.util.List;
|
|||
* @see com.djrapitops.plan.system.tasks.TPSCountTimer
|
||||
* @since 4.2.0
|
||||
*/
|
||||
public class EntityGraph extends AbstractLineGraph {
|
||||
class EntityGraph extends LineGraph {
|
||||
|
||||
public EntityGraph(List<TPS> tpsData) {
|
||||
this(new TPSMutator(tpsData));
|
||||
}
|
||||
|
||||
public EntityGraph(TPSMutator mutator) {
|
||||
super(mutator.entityPoints());
|
||||
EntityGraph(TPSMutator mutator, boolean displayGaps) {
|
||||
super(mutator.entityPoints(), displayGaps);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,62 @@
|
|||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package com.djrapitops.plan.utilities.html.graphs.line;
|
||||
|
||||
import com.djrapitops.plan.utilities.html.graphs.HighChart;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* This is a LineGraph for any set of Points, thus it is Abstract.
|
||||
*
|
||||
* @author Rsl1122
|
||||
* @since 4.2.0
|
||||
*/
|
||||
public class LineGraph implements HighChart {
|
||||
|
||||
private final boolean displayGaps;
|
||||
private List<Point> points;
|
||||
|
||||
public LineGraph(List<Point> points, boolean displayGaps) {
|
||||
this.points = points;
|
||||
this.displayGaps = displayGaps;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toHighChartsSeries() {
|
||||
StringBuilder arrayBuilder = new StringBuilder("[");
|
||||
|
||||
int size = points.size();
|
||||
Long lastX = null;
|
||||
for (int i = 0; i < size; i++) {
|
||||
Point point = points.get(i);
|
||||
Double y = point.getY();
|
||||
long date = (long) point.getX();
|
||||
|
||||
if (displayGaps && lastX != null && date - lastX > TimeUnit.MINUTES.toMillis(3L)) {
|
||||
addMissingPoints(arrayBuilder, lastX, date);
|
||||
}
|
||||
lastX = date;
|
||||
|
||||
arrayBuilder.append("[").append(date).append(",").append(y).append("]");
|
||||
if (i < size - 1) {
|
||||
arrayBuilder.append(",");
|
||||
}
|
||||
}
|
||||
|
||||
arrayBuilder.append("]");
|
||||
return arrayBuilder.toString();
|
||||
}
|
||||
|
||||
private void addMissingPoints(StringBuilder arrayBuilder, Long lastX, long date) {
|
||||
long iterate = lastX + TimeUnit.MINUTES.toMillis(1L);
|
||||
while (iterate < date) {
|
||||
arrayBuilder.append("[").append(iterate).append(",null],");
|
||||
iterate += TimeUnit.MINUTES.toMillis(30L);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
package com.djrapitops.plan.utilities.html.graphs.line;
|
||||
|
||||
import com.djrapitops.plan.data.container.Ping;
|
||||
import com.djrapitops.plan.data.store.mutators.TPSMutator;
|
||||
import com.djrapitops.plan.system.settings.Settings;
|
||||
import com.djrapitops.plan.system.settings.config.PlanConfig;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Factory class for different objects representing HTML line graphs.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
@Singleton
|
||||
public class LineGraphFactory {
|
||||
|
||||
private final PlanConfig config;
|
||||
|
||||
@Inject
|
||||
public LineGraphFactory(
|
||||
PlanConfig config
|
||||
) {
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
public LineGraph lineGraph(List<Point> points) {
|
||||
return new LineGraph(points, config.isTrue(Settings.DISPLAY_GAPS_IN_GRAPH_DATA));
|
||||
}
|
||||
|
||||
public LineGraph chunkGraph(TPSMutator mutator) {
|
||||
return new ChunkGraph(mutator, config.isTrue(Settings.DISPLAY_GAPS_IN_GRAPH_DATA));
|
||||
}
|
||||
|
||||
public LineGraph cpuGraph(TPSMutator mutator) {
|
||||
return new CPUGraph(mutator, config.isTrue(Settings.DISPLAY_GAPS_IN_GRAPH_DATA));
|
||||
}
|
||||
|
||||
public LineGraph entityGraph(TPSMutator mutator) {
|
||||
return new EntityGraph(mutator, config.isTrue(Settings.DISPLAY_GAPS_IN_GRAPH_DATA));
|
||||
}
|
||||
|
||||
public LineGraph playersOnlineGraph(TPSMutator mutator) {
|
||||
return new PlayersOnlineGraph(mutator, config.isTrue(Settings.DISPLAY_GAPS_IN_GRAPH_DATA));
|
||||
}
|
||||
|
||||
public PingGraph pingGraph(List<Ping> pingList) {
|
||||
return new PingGraph(pingList, config.isTrue(Settings.DISPLAY_GAPS_IN_GRAPH_DATA));
|
||||
}
|
||||
|
||||
public LineGraph ramGraph(TPSMutator mutator) {
|
||||
return new RamGraph(mutator, config.isTrue(Settings.DISPLAY_GAPS_IN_GRAPH_DATA));
|
||||
}
|
||||
|
||||
public LineGraph tpsGraph(TPSMutator mutator) {
|
||||
return new TPSGraph(mutator, config.isTrue(Settings.DISPLAY_GAPS_IN_GRAPH_DATA));
|
||||
}
|
||||
}
|
|
@ -1,24 +0,0 @@
|
|||
package com.djrapitops.plan.utilities.html.graphs.line;
|
||||
|
||||
import com.djrapitops.plan.data.container.TPS;
|
||||
import com.djrapitops.plan.data.store.mutators.TPSMutator;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Graph about Player Counts gathered by TPSCountTimer.
|
||||
*
|
||||
* @author Rsl1122
|
||||
* @see com.djrapitops.plan.system.tasks.TPSCountTimer
|
||||
* @since 4.2.0
|
||||
*/
|
||||
public class OnlineActivityGraph extends AbstractLineGraph {
|
||||
|
||||
public OnlineActivityGraph(List<TPS> tpsData) {
|
||||
this(new TPSMutator(tpsData));
|
||||
}
|
||||
|
||||
public OnlineActivityGraph(TPSMutator mutator) {
|
||||
super(mutator.playersOnlinePoints());
|
||||
}
|
||||
}
|
|
@ -7,17 +7,18 @@ import java.util.List;
|
|||
|
||||
public class PingGraph {
|
||||
|
||||
private final AbstractLineGraph maxGraph;
|
||||
private final AbstractLineGraph minGraph;
|
||||
private final AbstractLineGraph avgGraph;
|
||||
private final LineGraph maxGraph;
|
||||
private final LineGraph minGraph;
|
||||
private final LineGraph avgGraph;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param pings List of Ping values:
|
||||
* List should be filtered so that only a single entry for each date exists.
|
||||
* @param pings List of Ping values:
|
||||
* List should be filtered so that only a single entry for each date exists.
|
||||
* @param displayGaps Should data gaps be displayed.
|
||||
*/
|
||||
public PingGraph(List<Ping> pings) {
|
||||
PingGraph(List<Ping> pings, boolean displayGaps) {
|
||||
List<Point> max = new ArrayList<>();
|
||||
List<Point> min = new ArrayList<>();
|
||||
List<Point> avg = new ArrayList<>();
|
||||
|
@ -30,9 +31,9 @@ public class PingGraph {
|
|||
avg.add(new Point(date, ping.getAverage()));
|
||||
}
|
||||
|
||||
maxGraph = new AbstractLineGraph(max);
|
||||
minGraph = new AbstractLineGraph(min);
|
||||
avgGraph = new AbstractLineGraph(avg);
|
||||
maxGraph = new LineGraph(max, displayGaps);
|
||||
minGraph = new LineGraph(min, displayGaps);
|
||||
avgGraph = new LineGraph(avg, displayGaps);
|
||||
}
|
||||
|
||||
public String toMaxSeries() {
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
package com.djrapitops.plan.utilities.html.graphs.line;
|
||||
|
||||
import com.djrapitops.plan.data.store.mutators.TPSMutator;
|
||||
|
||||
/**
|
||||
* Graph about Player Counts gathered by TPSCountTimer.
|
||||
*
|
||||
* @author Rsl1122
|
||||
* @see com.djrapitops.plan.system.tasks.TPSCountTimer
|
||||
* @since 4.2.0
|
||||
*/
|
||||
class PlayersOnlineGraph extends LineGraph {
|
||||
|
||||
PlayersOnlineGraph(TPSMutator mutator, boolean displayGaps) {
|
||||
super(mutator.playersOnlinePoints(), displayGaps);
|
||||
}
|
||||
}
|
|
@ -1,10 +1,7 @@
|
|||
package com.djrapitops.plan.utilities.html.graphs.line;
|
||||
|
||||
import com.djrapitops.plan.data.container.TPS;
|
||||
import com.djrapitops.plan.data.store.mutators.TPSMutator;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Graph about RAM Usage gathered by TPSCountTimer.
|
||||
*
|
||||
|
@ -12,13 +9,9 @@ import java.util.List;
|
|||
* @see com.djrapitops.plan.system.tasks.TPSCountTimer
|
||||
* @since 4.2.0
|
||||
*/
|
||||
public class RamGraph extends AbstractLineGraph {
|
||||
class RamGraph extends LineGraph {
|
||||
|
||||
public RamGraph(List<TPS> tpsData) {
|
||||
this(new TPSMutator(tpsData));
|
||||
}
|
||||
|
||||
public RamGraph(TPSMutator mutator) {
|
||||
super(mutator.ramUsagePoints());
|
||||
RamGraph(TPSMutator mutator, boolean displayGaps) {
|
||||
super(mutator.ramUsagePoints(), displayGaps);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +1,7 @@
|
|||
package com.djrapitops.plan.utilities.html.graphs.line;
|
||||
|
||||
import com.djrapitops.plan.data.container.TPS;
|
||||
import com.djrapitops.plan.data.store.mutators.TPSMutator;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Graph about TPS gathered by TPSCountTimer.
|
||||
*
|
||||
|
@ -12,13 +9,9 @@ import java.util.List;
|
|||
* @see com.djrapitops.plan.system.tasks.TPSCountTimer
|
||||
* @since 4.2.0
|
||||
*/
|
||||
public class TPSGraph extends AbstractLineGraph {
|
||||
class TPSGraph extends LineGraph {
|
||||
|
||||
public TPSGraph(List<TPS> tpsData) {
|
||||
this(new TPSMutator(tpsData));
|
||||
}
|
||||
|
||||
public TPSGraph(TPSMutator mutator) {
|
||||
super(mutator.tpsPoints());
|
||||
TPSGraph(TPSMutator mutator, boolean displayGaps) {
|
||||
super(mutator.tpsPoints(), displayGaps);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,8 +5,6 @@
|
|||
package com.djrapitops.plan.utilities.html.graphs.pie;
|
||||
|
||||
import com.djrapitops.plan.data.store.mutators.ActivityIndex;
|
||||
import com.djrapitops.plan.system.settings.theme.Theme;
|
||||
import com.djrapitops.plan.system.settings.theme.ThemeVal;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
@ -17,14 +15,13 @@ import java.util.*;
|
|||
* @see ActivityIndex
|
||||
* @since 4.2.0
|
||||
*/
|
||||
public class ActivityPie extends AbstractPieChart {
|
||||
public class ActivityPie extends Pie {
|
||||
|
||||
public ActivityPie(Map<String, Set<UUID>> activityData) {
|
||||
super(turnToSlices(activityData));
|
||||
ActivityPie(Map<String, Set<UUID>> activityData, String[] colors) {
|
||||
super(turnToSlices(activityData, colors));
|
||||
}
|
||||
|
||||
private static List<PieSlice> turnToSlices(Map<String, Set<UUID>> activityData) {
|
||||
String[] colors = Theme.getValue_Old(ThemeVal.GRAPH_ACTIVITY_PIE).split(", ");
|
||||
private static List<PieSlice> turnToSlices(Map<String, Set<UUID>> activityData, String[] colors) {
|
||||
int maxCol = colors.length;
|
||||
|
||||
List<PieSlice> slices = new ArrayList<>();
|
||||
|
|
|
@ -7,7 +7,6 @@ package com.djrapitops.plan.utilities.html.graphs.pie;
|
|||
import com.djrapitops.plan.utilities.html.graphs.HighChart;
|
||||
import org.apache.commons.text.TextStringBuilder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
@ -16,15 +15,11 @@ import java.util.List;
|
|||
* @author Rsl1122
|
||||
* @since 4.2.0
|
||||
*/
|
||||
public class AbstractPieChart implements HighChart {
|
||||
public class Pie implements HighChart {
|
||||
|
||||
protected List<PieSlice> slices;
|
||||
protected final List<PieSlice> slices;
|
||||
|
||||
public AbstractPieChart() {
|
||||
slices = new ArrayList<>();
|
||||
}
|
||||
|
||||
public AbstractPieChart(List<PieSlice> slices) {
|
||||
public Pie(List<PieSlice> slices) {
|
||||
this.slices = slices;
|
||||
}
|
||||
|
||||
|
@ -34,12 +29,4 @@ public class AbstractPieChart implements HighChart {
|
|||
series.appendWithSeparators(slices, ",");
|
||||
return series.append("]").toString();
|
||||
}
|
||||
|
||||
public void setSlices(List<PieSlice> slices) {
|
||||
this.slices = slices;
|
||||
}
|
||||
|
||||
public void addSlices(List<PieSlice> slices) {
|
||||
this.slices.addAll(slices);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
package com.djrapitops.plan.utilities.html.graphs.pie;
|
||||
|
||||
import com.djrapitops.plan.data.time.GMTimes;
|
||||
import com.djrapitops.plan.data.time.WorldTimes;
|
||||
import com.djrapitops.plan.system.settings.Settings;
|
||||
import com.djrapitops.plan.system.settings.WorldAliasSettings;
|
||||
import com.djrapitops.plan.system.settings.config.PlanConfig;
|
||||
import com.djrapitops.plan.system.settings.theme.Theme;
|
||||
import com.djrapitops.plan.system.settings.theme.ThemeVal;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Factory class for different objects representing HTML pie graphs.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
@Singleton
|
||||
public class PieGraphFactory {
|
||||
|
||||
private final PlanConfig config;
|
||||
private final Theme theme;
|
||||
|
||||
@Inject
|
||||
public PieGraphFactory(
|
||||
PlanConfig config,
|
||||
Theme theme
|
||||
) {
|
||||
this.config = config;
|
||||
this.theme = theme;
|
||||
}
|
||||
|
||||
public Pie activityPie(Map<String, Set<UUID>> activityData) {
|
||||
String[] colors = theme.getThemeValue(ThemeVal.GRAPH_ACTIVITY_PIE).split(", ");
|
||||
return new ActivityPie(activityData, colors);
|
||||
}
|
||||
|
||||
public Pie serverPreferencePie(Map<UUID, String> serverNames, Map<UUID, WorldTimes> serverWorldTimes) {
|
||||
return new ServerPreferencePie(serverNames, serverWorldTimes);
|
||||
}
|
||||
|
||||
public WorldPie worldPie(WorldTimes worldTimes) {
|
||||
WorldAliasSettings worldAliasSettings = config.getWorldAliasSettings();
|
||||
Map<String, Long> playtimePerAlias = worldAliasSettings.getPlaytimePerAlias(worldTimes);
|
||||
Map<String, GMTimes> gmTimesPerAlias = worldAliasSettings.getGMTimesPerAlias(worldTimes);
|
||||
String[] colors = theme.getThemeValue(ThemeVal.GRAPH_WORLD_PIE).split(", ");
|
||||
boolean orderByPercentage = config.isTrue(Settings.ORDER_WORLD_PIE_BY_PERC);
|
||||
return new WorldPie(playtimePerAlias, gmTimesPerAlias, colors, orderByPercentage);
|
||||
}
|
||||
}
|
|
@ -11,12 +11,9 @@ import java.util.List;
|
|||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public abstract class AbstractPieChartWithDrilldown extends AbstractPieChart {
|
||||
public abstract class PieWithDrilldown extends Pie {
|
||||
|
||||
public AbstractPieChartWithDrilldown() {
|
||||
}
|
||||
|
||||
public AbstractPieChartWithDrilldown(List<PieSlice> slices) {
|
||||
public PieWithDrilldown(List<PieSlice> slices) {
|
||||
super(slices);
|
||||
}
|
||||
|
|
@ -7,9 +7,9 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public class ServerPreferencePie extends AbstractPieChart {
|
||||
public class ServerPreferencePie extends Pie {
|
||||
|
||||
public ServerPreferencePie(Map<UUID, String> serverNames, Map<UUID, WorldTimes> serverWorldTimes) {
|
||||
ServerPreferencePie(Map<UUID, String> serverNames, Map<UUID, WorldTimes> serverWorldTimes) {
|
||||
super(turnToSlices(serverNames, serverWorldTimes));
|
||||
}
|
||||
|
||||
|
|
|
@ -1,35 +1,35 @@
|
|||
package com.djrapitops.plan.utilities.html.graphs.pie;
|
||||
|
||||
import com.djrapitops.plan.data.time.GMTimes;
|
||||
import com.djrapitops.plan.data.time.WorldTimes;
|
||||
import com.djrapitops.plan.system.settings.Settings;
|
||||
import com.djrapitops.plan.system.settings.WorldAliasSettings;
|
||||
import com.djrapitops.plan.system.settings.theme.Theme;
|
||||
import com.djrapitops.plan.system.settings.theme.ThemeVal;
|
||||
import com.djrapitops.plan.utilities.comparators.PieSliceComparator;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class WorldPie extends AbstractPieChartWithDrilldown {
|
||||
public class WorldPie extends PieWithDrilldown {
|
||||
|
||||
private WorldTimes worldTimes;
|
||||
private final Map<String, GMTimes> gmTimesAliasMap;
|
||||
|
||||
public WorldPie(WorldTimes worldTimes) {
|
||||
super(turnIntoSlices(worldTimes));
|
||||
WorldPie(
|
||||
Map<String, Long> playtimePerAlias,
|
||||
Map<String, GMTimes> gmTimesAliasMap,
|
||||
String[] colors,
|
||||
boolean orderByPercentage
|
||||
) {
|
||||
super(turnIntoSlices(playtimePerAlias, colors));
|
||||
|
||||
this.worldTimes = worldTimes;
|
||||
this.gmTimesAliasMap = gmTimesAliasMap;
|
||||
|
||||
if (Settings.ORDER_WORLD_PIE_BY_PERC.isTrue()) {
|
||||
if (orderByPercentage) {
|
||||
slices.sort(new PieSliceComparator());
|
||||
}
|
||||
}
|
||||
|
||||
private static List<PieSlice> turnIntoSlices(WorldTimes worldTimes) {
|
||||
String[] colors = Theme.getValue_Old(ThemeVal.GRAPH_WORLD_PIE).split(", ");
|
||||
private static List<PieSlice> turnIntoSlices(Map<String, Long> playtimePerAlias, String[] colors) {
|
||||
int colLength = colors.length;
|
||||
|
||||
Map<String, Long> playtimePerAlias = worldTimes.getPlaytimePerAlias();
|
||||
|
||||
List<String> worlds = new ArrayList<>(playtimePerAlias.keySet());
|
||||
Collections.sort(worlds);
|
||||
|
||||
|
@ -46,44 +46,16 @@ public class WorldPie extends AbstractPieChartWithDrilldown {
|
|||
return slices;
|
||||
}
|
||||
|
||||
private Map<String, GMTimes> getGMTimesPerAlias() {
|
||||
Map<String, String> aliases = WorldAliasSettings.getAliases_Old();
|
||||
|
||||
Map<String, GMTimes> gmTimesPerAlias = new HashMap<>();
|
||||
|
||||
String[] gms = GMTimes.getGMKeyArray();
|
||||
|
||||
for (Map.Entry<String, GMTimes> entry : worldTimes.getWorldTimes().entrySet()) {
|
||||
String worldName = entry.getKey();
|
||||
GMTimes gmTimes = entry.getValue();
|
||||
|
||||
if (!aliases.containsKey(worldName)) {
|
||||
aliases.put(worldName, worldName);
|
||||
WorldAliasSettings.addWorld_Old(worldName);
|
||||
}
|
||||
|
||||
String alias = aliases.get(worldName);
|
||||
|
||||
GMTimes aliasGMTimes = gmTimesPerAlias.getOrDefault(alias, new GMTimes());
|
||||
for (String gm : gms) {
|
||||
aliasGMTimes.addTime(gm, gmTimes.getTime(gm));
|
||||
}
|
||||
gmTimesPerAlias.put(alias, aliasGMTimes);
|
||||
}
|
||||
return gmTimesPerAlias;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toHighChartsDrilldown() {
|
||||
StringBuilder drilldownBuilder = new StringBuilder();
|
||||
int i = 0;
|
||||
|
||||
Map<String, GMTimes> gmTimesAliasMap = getGMTimesPerAlias();
|
||||
if (gmTimesAliasMap.isEmpty()) {
|
||||
return "[]";
|
||||
}
|
||||
int size = gmTimesAliasMap.size();
|
||||
|
||||
|
||||
drilldownBuilder.append("[");
|
||||
for (Map.Entry<String, GMTimes> worldAlias : gmTimesAliasMap.entrySet()) {
|
||||
drilldownBuilder.append("{name:'").append(worldAlias.getKey())
|
||||
|
|
|
@ -3,10 +3,11 @@
|
|||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package com.djrapitops.plan.utilities.html.graphs;
|
||||
package com.djrapitops.plan.utilities.html.graphs.special;
|
||||
|
||||
import com.djrapitops.plan.data.container.Session;
|
||||
import com.djrapitops.plan.data.store.keys.SessionKeys;
|
||||
import com.djrapitops.plan.utilities.html.graphs.HighChart;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Collection;
|
||||
|
@ -20,16 +21,16 @@ import java.util.stream.Collectors;
|
|||
* @author Rsl1122
|
||||
* @since 4.2.0
|
||||
*/
|
||||
public class PunchCardGraph implements HighChart {
|
||||
public class PunchCard implements HighChart {
|
||||
|
||||
private final Collection<Session> sessions;
|
||||
|
||||
/**
|
||||
* Constuctor for the graph.
|
||||
* Constructor for the graph.
|
||||
*
|
||||
* @param sessions All sessions of All users this PunchCard represents.
|
||||
*/
|
||||
public PunchCardGraph(Collection<Session> sessions) {
|
||||
PunchCard(Collection<Session> sessions) {
|
||||
this.sessions = sessions;
|
||||
}
|
||||
|
||||
|
@ -37,7 +38,7 @@ public class PunchCardGraph implements HighChart {
|
|||
* First number signifies the Day of Week. (0 = Monday, 6 = Sunday)
|
||||
* Second number signifies the Hour of Day. (0 = 0 AM, 23 = 11 PM)
|
||||
*/
|
||||
private static List<int[]> getDaysAndHours(Collection<Long> sessionStarts) {
|
||||
private List<int[]> getDaysAndHours(Collection<Long> sessionStarts) {
|
||||
return sessionStarts.stream().map((Long start) -> {
|
||||
Calendar day = Calendar.getInstance();
|
||||
day.setTimeInMillis(start);
|
||||
|
@ -57,7 +58,7 @@ public class PunchCardGraph implements HighChart {
|
|||
}).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private static int[][] turnIntoArray(Collection<Long> sessionStarts) {
|
||||
private int[][] turnIntoArray(Collection<Long> sessionStarts) {
|
||||
List<int[]> daysAndHours = getDaysAndHours(sessionStarts);
|
||||
int[][] dataArray = createEmptyArray();
|
||||
for (int[] dAndH : daysAndHours) {
|
||||
|
@ -96,7 +97,7 @@ public class PunchCardGraph implements HighChart {
|
|||
return arrayBuilder.toString();
|
||||
}
|
||||
|
||||
private static List<Long> getSessionStarts(Collection<Session> data) {
|
||||
private List<Long> getSessionStarts(Collection<Session> data) {
|
||||
return data.stream()
|
||||
.filter(Objects::nonNull)
|
||||
.map(s -> s.getUnsafe(SessionKeys.START))
|
||||
|
@ -104,7 +105,7 @@ public class PunchCardGraph implements HighChart {
|
|||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private static int[][] createEmptyArray() {
|
||||
private int[][] createEmptyArray() {
|
||||
int[][] dataArray = new int[7][24];
|
||||
for (int i = 0; i < 7; i++) {
|
||||
for (int j = 0; j < 24; j++) {
|
||||
|
@ -114,7 +115,7 @@ public class PunchCardGraph implements HighChart {
|
|||
return dataArray;
|
||||
}
|
||||
|
||||
private static int findBiggestValue(int[][] dataArray) {
|
||||
private int findBiggestValue(int[][] dataArray) {
|
||||
int highest = 1;
|
||||
for (int i = 0; i < 7; i++) {
|
||||
for (int j = 0; j < 24; j++) {
|
||||
|
@ -127,8 +128,7 @@ public class PunchCardGraph implements HighChart {
|
|||
return highest;
|
||||
}
|
||||
|
||||
private static int[][] scale(int[][] dataArray, int big) {
|
||||
|
||||
private int[][] scale(int[][] dataArray, int big) {
|
||||
int[][] scaled = new int[7][24];
|
||||
for (int i = 0; i < 7; i++) {
|
||||
for (int j = 0; j < 24; j++) {
|
|
@ -0,0 +1,31 @@
|
|||
package com.djrapitops.plan.utilities.html.graphs.special;
|
||||
|
||||
import com.djrapitops.plan.data.container.Session;
|
||||
import com.djrapitops.plan.data.store.mutators.PlayersMutator;
|
||||
import com.djrapitops.plan.utilities.html.graphs.HighChart;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* Factory class for different objects representing special HTML graphs.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
@Singleton
|
||||
public class SpecialGraphFactory {
|
||||
|
||||
@Inject
|
||||
public SpecialGraphFactory() {
|
||||
// Inject Constructor.
|
||||
}
|
||||
|
||||
public HighChart punchCard(Collection<Session> sessions) {
|
||||
return new PunchCard(sessions);
|
||||
}
|
||||
|
||||
public HighChart worldMap(PlayersMutator mutator) {
|
||||
return new WorldMap(mutator);
|
||||
}
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
package com.djrapitops.plan.utilities.html.graphs;
|
||||
package com.djrapitops.plan.utilities.html.graphs.special;
|
||||
|
||||
import com.djrapitops.plan.data.store.mutators.PlayersMutator;
|
||||
import com.djrapitops.plan.utilities.html.graphs.HighChart;
|
||||
import org.apache.commons.text.TextStringBuilder;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
@ -17,12 +18,8 @@ public class WorldMap implements HighChart {
|
|||
|
||||
private final List<String> geoLocations;
|
||||
|
||||
public WorldMap(List<String> geoLocations) {
|
||||
this.geoLocations = geoLocations;
|
||||
}
|
||||
|
||||
public WorldMap(PlayersMutator mutator) {
|
||||
this(mutator.getGeolocations());
|
||||
WorldMap(PlayersMutator mutator) {
|
||||
this.geoLocations = mutator.getGeolocations();
|
||||
}
|
||||
|
||||
private static Map<String, String> getGeoCodes(Map<String, Integer> geoCodeCounts) {
|
|
@ -2,15 +2,10 @@
|
|||
* License is provided in the jar as LICENSE also here:
|
||||
* https://github.com/Rsl1122/Plan-PlayerAnalytics/blob/master/Plan/src/main/resources/LICENSE
|
||||
*/
|
||||
package com.djrapitops.plan.utilities.html.graphs;
|
||||
package com.djrapitops.plan.utilities.html.graphs.stack;
|
||||
|
||||
import com.djrapitops.plan.data.store.mutators.ActivityIndex;
|
||||
import com.djrapitops.plan.data.store.mutators.PlayersMutator;
|
||||
import com.djrapitops.plan.system.settings.theme.Theme;
|
||||
import com.djrapitops.plan.system.settings.theme.ThemeVal;
|
||||
import com.djrapitops.plan.utilities.FormatUtils;
|
||||
import com.djrapitops.plan.utilities.html.graphs.stack.AbstractStackGraph;
|
||||
import com.djrapitops.plan.utilities.html.graphs.stack.StackDataSet;
|
||||
import com.djrapitops.plan.utilities.formatting.Formatter;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
@ -21,25 +16,20 @@ import java.util.*;
|
|||
* @see ActivityIndex
|
||||
* @since 4.2.0
|
||||
*/
|
||||
public class ActivityStackGraph extends AbstractStackGraph {
|
||||
class ActivityStackGraph extends StackGraph {
|
||||
|
||||
public ActivityStackGraph(TreeMap<Long, Map<String, Set<UUID>>> activityData) {
|
||||
super(getLabels(activityData.navigableKeySet()), getDataSets(activityData));
|
||||
ActivityStackGraph(TreeMap<Long, Map<String, Set<UUID>>> activityData, String[] colors, Formatter<Long> dayFormatter) {
|
||||
super(getLabels(activityData.navigableKeySet(), dayFormatter), getDataSets(activityData, colors));
|
||||
}
|
||||
|
||||
public ActivityStackGraph(long date, PlayersMutator mutator) {
|
||||
this(mutator.toActivityDataMap(date));
|
||||
}
|
||||
|
||||
private static String[] getLabels(NavigableSet<Long> dates) {
|
||||
private static String[] getLabels(Collection<Long> dates, Formatter<Long> dayFormatter) {
|
||||
return dates.stream()
|
||||
.map(FormatUtils::formatTimeStampDay)
|
||||
.map(dayFormatter)
|
||||
.toArray(String[]::new);
|
||||
}
|
||||
|
||||
private static StackDataSet[] getDataSets(TreeMap<Long, Map<String, Set<UUID>>> activityData) {
|
||||
private static StackDataSet[] getDataSets(TreeMap<Long, Map<String, Set<UUID>>> activityData, String[] colors) {
|
||||
String[] groups = ActivityIndex.getGroups();
|
||||
String[] colors = Theme.getValue_Old(ThemeVal.GRAPH_ACTIVITY_PIE).split(", ");
|
||||
int maxCol = colors.length;
|
||||
StackDataSet[] dataSets = new StackDataSet[groups.length];
|
||||
|
|
@ -11,12 +11,12 @@ import com.djrapitops.plan.utilities.html.graphs.HighChart;
|
|||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class AbstractStackGraph implements HighChart {
|
||||
public class StackGraph implements HighChart {
|
||||
|
||||
private final StackDataSet[] dataSets;
|
||||
private final String[] labels;
|
||||
|
||||
public AbstractStackGraph(String[] labels, StackDataSet... dataSets) {
|
||||
public StackGraph(String[] labels, StackDataSet... dataSets) {
|
||||
this.dataSets = dataSets;
|
||||
this.labels = labels;
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
package com.djrapitops.plan.utilities.html.graphs.stack;
|
||||
|
||||
import com.djrapitops.plan.system.settings.theme.Theme;
|
||||
import com.djrapitops.plan.system.settings.theme.ThemeVal;
|
||||
import com.djrapitops.plan.utilities.formatting.Formatter;
|
||||
import com.djrapitops.plan.utilities.formatting.Formatters;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TreeMap;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Factory class for different objects representing HTML stack graphs.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
@Singleton
|
||||
public class StackGraphFactory {
|
||||
|
||||
private final Theme theme;
|
||||
private final Formatter<Long> dayFormatter;
|
||||
|
||||
@Inject
|
||||
public StackGraphFactory(
|
||||
Formatters formatters,
|
||||
Theme theme
|
||||
) {
|
||||
this.theme = theme;
|
||||
this.dayFormatter = formatters.dayLong();
|
||||
}
|
||||
|
||||
public StackGraph activityStackGraph(TreeMap<Long, Map<String, Set<UUID>>> activityData) {
|
||||
String[] colors = theme.getThemeValue(ThemeVal.GRAPH_ACTIVITY_PIE).split(", ");
|
||||
return new ActivityStackGraph(activityData, colors, dayFormatter);
|
||||
}
|
||||
}
|
|
@ -10,9 +10,6 @@ import com.djrapitops.plan.data.store.containers.PerServerContainer;
|
|||
import com.djrapitops.plan.data.store.containers.PlayerContainer;
|
||||
import com.djrapitops.plan.data.store.keys.PlayerKeys;
|
||||
import com.djrapitops.plan.data.store.mutators.*;
|
||||
import com.djrapitops.plan.utilities.formatting.Formatter;
|
||||
import com.djrapitops.plan.utilities.formatting.Formatters;
|
||||
import com.djrapitops.plan.utilities.formatting.PlaceholderReplacer;
|
||||
import com.djrapitops.plan.data.time.WorldTimes;
|
||||
import com.djrapitops.plan.system.cache.SessionCache;
|
||||
import com.djrapitops.plan.system.info.server.ServerInfo;
|
||||
|
@ -24,10 +21,12 @@ import com.djrapitops.plan.utilities.FormatUtils;
|
|||
import com.djrapitops.plan.utilities.MiscUtils;
|
||||
import com.djrapitops.plan.utilities.comparators.SessionStartComparator;
|
||||
import com.djrapitops.plan.utilities.file.FileUtil;
|
||||
import com.djrapitops.plan.utilities.formatting.Formatter;
|
||||
import com.djrapitops.plan.utilities.formatting.Formatters;
|
||||
import com.djrapitops.plan.utilities.formatting.PlaceholderReplacer;
|
||||
import com.djrapitops.plan.utilities.html.HtmlStructure;
|
||||
import com.djrapitops.plan.utilities.html.graphs.PunchCardGraph;
|
||||
import com.djrapitops.plan.utilities.html.graphs.Graphs;
|
||||
import com.djrapitops.plan.utilities.html.graphs.calendar.PlayerCalendar;
|
||||
import com.djrapitops.plan.utilities.html.graphs.pie.ServerPreferencePie;
|
||||
import com.djrapitops.plan.utilities.html.graphs.pie.WorldPie;
|
||||
import com.djrapitops.plan.utilities.html.structure.ServerAccordion;
|
||||
import com.djrapitops.plan.utilities.html.structure.SessionAccordion;
|
||||
|
@ -49,18 +48,21 @@ public class InspectPage implements Page {
|
|||
private final Map<UUID, String> serverNames;
|
||||
|
||||
private final PlanConfig config;
|
||||
private final Graphs graphs;
|
||||
private final ServerInfo serverInfo;
|
||||
private final Timings timings;
|
||||
|
||||
InspectPage(
|
||||
PlayerContainer player, Map<UUID, String> serverNames,
|
||||
PlanConfig config,
|
||||
Graphs graphs,
|
||||
ServerInfo serverInfo,
|
||||
Timings timings
|
||||
) {
|
||||
this.player = player;
|
||||
this.serverNames = serverNames;
|
||||
this.config = config;
|
||||
this.graphs = graphs;
|
||||
this.serverInfo = serverInfo;
|
||||
this.timings = timings;
|
||||
}
|
||||
|
@ -115,7 +117,7 @@ public class InspectPage implements Page {
|
|||
PerServerMutator perServerMutator = new PerServerMutator(perServerContainer);
|
||||
|
||||
Map<UUID, WorldTimes> worldTimesPerServer = perServerMutator.worldTimesPerServer();
|
||||
replacer.put("serverPieSeries", new ServerPreferencePie(serverNames, worldTimesPerServer).toHighChartsSeries());
|
||||
replacer.put("serverPieSeries", graphs.pie().serverPreferencePie(serverNames, worldTimesPerServer).toHighChartsSeries());
|
||||
replacer.put("worldPieColors", Theme.getValue_Old(ThemeVal.GRAPH_WORLD_PIE));
|
||||
replacer.put("gmPieColors", Theme.getValue_Old(ThemeVal.GRAPH_GM_PIE));
|
||||
replacer.put("serverPieColors", Theme.getValue_Old(ThemeVal.GRAPH_SERVER_PREF_PIE));
|
||||
|
@ -156,7 +158,7 @@ public class InspectPage implements Page {
|
|||
|
||||
ServerAccordion serverAccordion = new ServerAccordion(player, serverNames);
|
||||
|
||||
PlayerCalendar playerCalendar = new PlayerCalendar(player);
|
||||
PlayerCalendar playerCalendar = graphs.calendar().playerCalendar(player);
|
||||
|
||||
replacer.put("calendarSeries", playerCalendar.toCalendarSeries());
|
||||
replacer.put("firstDay", 1);
|
||||
|
@ -174,10 +176,10 @@ public class InspectPage implements Page {
|
|||
|
||||
sessionsAndPlaytime(replacer, sessionsMutator, daySessionsMutator, weekSessionsMutator, monthSessionsMutator);
|
||||
|
||||
String punchCardData = new PunchCardGraph(allSessions).toHighChartsSeries();
|
||||
String punchCardData = graphs.special().punchCard(allSessions).toHighChartsSeries();
|
||||
WorldTimes worldTimes = player.getValue(PlayerKeys.WORLD_TIMES).orElse(new WorldTimes(new HashMap<>()));
|
||||
|
||||
WorldPie worldPie = new WorldPie(worldTimes);
|
||||
WorldPie worldPie = graphs.pie().worldPie(worldTimes);
|
||||
|
||||
replacer.put("worldPieSeries", worldPie.toHighChartsSeries());
|
||||
replacer.put("gmSeries", worldPie.toHighChartsDrilldown());
|
||||
|
|
|
@ -7,6 +7,7 @@ import com.djrapitops.plan.system.database.databases.Database;
|
|||
import com.djrapitops.plan.system.info.connection.ConnectionSystem;
|
||||
import com.djrapitops.plan.system.info.server.ServerInfo;
|
||||
import com.djrapitops.plan.system.settings.config.PlanConfig;
|
||||
import com.djrapitops.plan.utilities.html.graphs.Graphs;
|
||||
import com.djrapitops.plugin.benchmarking.Timings;
|
||||
import com.djrapitops.plugin.logging.debug.DebugLogger;
|
||||
import com.djrapitops.plugin.logging.error.ErrorHandler;
|
||||
|
@ -31,6 +32,7 @@ public class PageFactory {
|
|||
private final Lazy<Database> database;
|
||||
private final Lazy<ServerInfo> serverInfo;
|
||||
private final Lazy<ConnectionSystem> connectionSystem;
|
||||
private final Lazy<Graphs> graphs;
|
||||
private final Lazy<DebugLogger> debugLogger;
|
||||
private final Lazy<Timings> timings;
|
||||
private final Lazy<ErrorHandler> errorHandler;
|
||||
|
@ -42,7 +44,7 @@ public class PageFactory {
|
|||
Lazy<Database> database,
|
||||
Lazy<ServerInfo> serverInfo,
|
||||
Lazy<ConnectionSystem> connectionSystem,
|
||||
Lazy<DebugLogger> debugLogger,
|
||||
Lazy<Graphs> graphs, Lazy<DebugLogger> debugLogger,
|
||||
Lazy<Timings> timings,
|
||||
Lazy<ErrorHandler> errorHandler
|
||||
) {
|
||||
|
@ -51,6 +53,7 @@ public class PageFactory {
|
|||
this.database = database;
|
||||
this.serverInfo = serverInfo;
|
||||
this.connectionSystem = connectionSystem;
|
||||
this.graphs = graphs;
|
||||
this.debugLogger = debugLogger;
|
||||
this.timings = timings;
|
||||
this.errorHandler = errorHandler;
|
||||
|
@ -73,7 +76,7 @@ public class PageFactory {
|
|||
public InspectPage inspectPage(UUID uuid) {
|
||||
PlayerContainer player = database.get().fetch().getPlayerContainer(uuid);
|
||||
Map<UUID, String> serverNames = database.get().fetch().getServerNames();
|
||||
return new InspectPage(player, serverNames, config.get(), serverInfo.get(), timings.get());
|
||||
return new InspectPage(player, serverNames, config.get(), graphs.get(), serverInfo.get(), timings.get());
|
||||
}
|
||||
|
||||
public NetworkPage networkPage() {
|
||||
|
|
|
@ -10,11 +10,12 @@ import com.djrapitops.plan.data.store.containers.PlayerContainer;
|
|||
import com.djrapitops.plan.data.store.keys.PerServerKeys;
|
||||
import com.djrapitops.plan.data.store.keys.PlayerKeys;
|
||||
import com.djrapitops.plan.data.store.mutators.SessionsMutator;
|
||||
import com.djrapitops.plan.utilities.formatting.Formatter;
|
||||
import com.djrapitops.plan.utilities.formatting.Formatters;
|
||||
import com.djrapitops.plan.data.time.WorldTimes;
|
||||
import com.djrapitops.plan.system.settings.theme.Theme;
|
||||
import com.djrapitops.plan.system.settings.theme.ThemeVal;
|
||||
import com.djrapitops.plan.utilities.formatting.Formatter;
|
||||
import com.djrapitops.plan.utilities.formatting.Formatters;
|
||||
import com.djrapitops.plan.utilities.html.graphs.Graphs;
|
||||
import com.djrapitops.plan.utilities.html.graphs.pie.WorldPie;
|
||||
import com.djrapitops.plan.utilities.html.icon.Color;
|
||||
import com.djrapitops.plan.utilities.html.icon.Icon;
|
||||
|
@ -38,6 +39,8 @@ public class ServerAccordion extends AbstractAccordion {
|
|||
private final Map<UUID, String> serverNames;
|
||||
private PerServerContainer perServer;
|
||||
|
||||
private Graphs graphs;
|
||||
|
||||
public ServerAccordion(PlayerContainer container, Map<UUID, String> serverNames) {
|
||||
super("server_accordion");
|
||||
|
||||
|
@ -96,7 +99,7 @@ public class ServerAccordion extends AbstractAccordion {
|
|||
|
||||
String worldId = "worldPieServer" + sanitizedServerName;
|
||||
|
||||
WorldPie worldPie = new WorldPie(worldTimes);
|
||||
WorldPie worldPie = graphs.pie().worldPie(worldTimes);
|
||||
|
||||
String title = serverName + "<span class=\"pull-right\">" + play + "</span>";
|
||||
|
||||
|
|
|
@ -3,15 +3,16 @@ 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.keys.SessionKeys;
|
||||
import com.djrapitops.plan.utilities.formatting.Formatter;
|
||||
import com.djrapitops.plan.utilities.formatting.Formatters;
|
||||
import com.djrapitops.plan.data.store.objects.DateHolder;
|
||||
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.comparators.DateHolderRecentComparator;
|
||||
import com.djrapitops.plan.utilities.formatting.Formatter;
|
||||
import com.djrapitops.plan.utilities.formatting.Formatters;
|
||||
import com.djrapitops.plan.utilities.html.HtmlStructure;
|
||||
import com.djrapitops.plan.utilities.html.graphs.Graphs;
|
||||
import com.djrapitops.plan.utilities.html.graphs.pie.WorldPie;
|
||||
import com.djrapitops.plan.utilities.html.icon.Icons;
|
||||
import com.djrapitops.plan.utilities.html.tables.KillsTable;
|
||||
|
@ -36,6 +37,8 @@ public class SessionAccordion extends AbstractAccordion {
|
|||
private final boolean appendWorldPercentage;
|
||||
private int maxSessions;
|
||||
|
||||
private Graphs graphs;
|
||||
|
||||
private SessionAccordion(boolean forPlayer, List<Session> sessions,
|
||||
Supplier<Map<UUID, String>> serverNamesSupplier,
|
||||
Supplier<Map<UUID, String>> playerNamesSupplier) {
|
||||
|
@ -84,7 +87,7 @@ public class SessionAccordion extends AbstractAccordion {
|
|||
Formatter<Long> timeFormatter = Formatters.timeAmount_Old();
|
||||
Formatter<DateHolder> timeStampFormatter = Formatters.year_Old();
|
||||
sessions.sort(new DateHolderRecentComparator());
|
||||
|
||||
|
||||
int i = 0;
|
||||
for (Session session : sessions) {
|
||||
if (i >= maxSessions) {
|
||||
|
@ -96,7 +99,7 @@ public class SessionAccordion extends AbstractAccordion {
|
|||
String sessionStart = timeStampFormatter.apply(session);
|
||||
|
||||
WorldTimes worldTimes = session.getValue(SessionKeys.WORLD_TIMES).orElse(new WorldTimes(new HashMap<>()));
|
||||
WorldPie worldPie = new WorldPie(worldTimes);
|
||||
WorldPie worldPie = graphs.pie().worldPie(worldTimes);
|
||||
String longestWorldPlayed = session.getValue(SessionKeys.LONGEST_WORLD_PLAYED).orElse("Unknown");
|
||||
|
||||
boolean hasEnded = session.supports(SessionKeys.END);
|
||||
|
@ -169,7 +172,7 @@ public class SessionAccordion extends AbstractAccordion {
|
|||
String sessionStart = timeStampFormatter.apply(session);
|
||||
|
||||
WorldTimes worldTimes = session.getValue(SessionKeys.WORLD_TIMES).orElse(new WorldTimes(new HashMap<>()));
|
||||
WorldPie worldPie = new WorldPie(worldTimes);
|
||||
WorldPie worldPie = graphs.pie().worldPie(worldTimes);
|
||||
String longestWorldPlayed = session.getValue(SessionKeys.LONGEST_WORLD_PLAYED).orElse("Unknown");
|
||||
|
||||
boolean hasEnded = session.supports(SessionKeys.END);
|
||||
|
|
|
@ -1,121 +0,0 @@
|
|||
/*
|
||||
* License is provided in the jar as LICENSE also here:
|
||||
* https://github.com/Rsl1122/Plan-PlayerAnalytics/blob/master/Plan/src/main/resources/LICENSE
|
||||
*/
|
||||
package com.djrapitops.plan.utilities.html.graphs;
|
||||
|
||||
import com.djrapitops.plan.data.container.TPS;
|
||||
import com.djrapitops.plan.data.store.mutators.ActivityIndex;
|
||||
import com.djrapitops.plan.system.settings.Settings;
|
||||
import com.djrapitops.plan.utilities.html.graphs.line.*;
|
||||
import com.djrapitops.plan.utilities.html.graphs.stack.AbstractStackGraph;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import utilities.RandomData;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Tests various Graphs.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class GraphTest {
|
||||
|
||||
private final List<TPS> tpsList = new ArrayList<>();
|
||||
private final TreeMap<Long, Map<String, Set<UUID>>> activityData = new TreeMap<>();
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
String[] groups = ActivityIndex.getGroups();
|
||||
for (int i = 0; i < 10; i++) {
|
||||
tpsList.add(new TPS(i, i, i, i, i, i, i));
|
||||
Map<String, Set<UUID>> gData = new HashMap<>();
|
||||
for (String group : groups) {
|
||||
Set<UUID> uuids = new HashSet<>();
|
||||
for (int j = 0; j < RandomData.randomInt(1, 20); j++) {
|
||||
uuids.add(UUID.randomUUID());
|
||||
}
|
||||
gData.put(group, uuids);
|
||||
}
|
||||
activityData.put((long) i, gData);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore // TODO Settings stuff
|
||||
public void testLineGraphsForBracketErrors() {
|
||||
AbstractLineGraph[] graphs = new AbstractLineGraph[]{
|
||||
new CPUGraph(tpsList),
|
||||
new OnlineActivityGraph(tpsList),
|
||||
new RamGraph(tpsList),
|
||||
new TPSGraph(tpsList),
|
||||
new EntityGraph(tpsList),
|
||||
new ChunkGraph(tpsList)
|
||||
};
|
||||
|
||||
for (AbstractLineGraph graph : graphs) {
|
||||
System.out.print("Bracket Test: " + graph.getClass().getSimpleName() + " | ");
|
||||
String series = graph.toHighChartsSeries();
|
||||
|
||||
System.out.println(series);
|
||||
|
||||
char[] chars = series.toCharArray();
|
||||
assertBracketMatch(chars);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore // TODO Settings stuff
|
||||
public void testStackGraphsForBracketErrors() {
|
||||
Settings.FORMAT_DECIMALS.setTemporaryValue("#.##");
|
||||
|
||||
AbstractStackGraph[] graphs = new AbstractStackGraph[]{
|
||||
new ActivityStackGraph(activityData)
|
||||
};
|
||||
|
||||
for (AbstractStackGraph graph : graphs) {
|
||||
System.out.print("Bracket Test: " + graph.getClass().getSimpleName() + " | ");
|
||||
String series = graph.toHighChartsSeries();
|
||||
System.out.println(series);
|
||||
char[] chars = series.toCharArray();
|
||||
assertBracketMatch(chars);
|
||||
|
||||
String labels = graph.toHighChartsLabels();
|
||||
System.out.println(labels);
|
||||
chars = labels.toCharArray();
|
||||
assertBracketMatch(chars);
|
||||
}
|
||||
}
|
||||
|
||||
private void assertBracketMatch(char[] chars) {
|
||||
Stack<Character> bracketStack = new Stack<>();
|
||||
for (int i = 0; i < chars.length; i++) {
|
||||
char c = chars[i];
|
||||
switch (c) {
|
||||
case '{':
|
||||
case '[':
|
||||
case '(':
|
||||
bracketStack.push(c);
|
||||
break;
|
||||
case ')':
|
||||
Character pop = bracketStack.pop();
|
||||
assertTrue("Bracket mismatch at char: " + i + " Expected (, got " + pop, '(' == pop);
|
||||
break;
|
||||
case ']':
|
||||
Character pop1 = bracketStack.pop();
|
||||
assertTrue("Bracket mismatch at char: " + i + " Expected [, got " + pop1, '[' == pop1);
|
||||
break;
|
||||
case '}':
|
||||
Character pop2 = bracketStack.pop();
|
||||
assertTrue("Bracket mismatch at char: " + i + " Expected {, got " + pop2, '{' == pop2);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,80 @@
|
|||
package com.djrapitops.plan.utilities.html.graphs.line;
|
||||
|
||||
import com.djrapitops.plan.data.container.TPS;
|
||||
import com.djrapitops.plan.data.store.mutators.TPSMutator;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Stack;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Test class for {@link LineGraph}.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class LineGraphTest {
|
||||
|
||||
private final List<TPS> tpsList = new ArrayList<>();
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
for (int i = 0; i < 10; i++) {
|
||||
tpsList.add(new TPS(i, i, i, i, i, i, i));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLineGraphsForBracketErrors() {
|
||||
TPSMutator mutator = new TPSMutator(tpsList);
|
||||
LineGraph[] graphs = new LineGraph[]{
|
||||
new CPUGraph(mutator, true),
|
||||
new PlayersOnlineGraph(mutator, false),
|
||||
new RamGraph(mutator, true),
|
||||
new TPSGraph(mutator, false),
|
||||
new EntityGraph(mutator, true),
|
||||
new ChunkGraph(mutator, false)
|
||||
};
|
||||
|
||||
for (LineGraph graph : graphs) {
|
||||
System.out.print("Bracket Test: " + graph.getClass().getSimpleName() + " | ");
|
||||
String series = graph.toHighChartsSeries();
|
||||
|
||||
System.out.println(series);
|
||||
|
||||
char[] chars = series.toCharArray();
|
||||
assertBracketMatch(chars);
|
||||
}
|
||||
}
|
||||
|
||||
private void assertBracketMatch(char[] chars) {
|
||||
Stack<Character> bracketStack = new Stack<>();
|
||||
for (int i = 0; i < chars.length; i++) {
|
||||
char c = chars[i];
|
||||
switch (c) {
|
||||
case '{':
|
||||
case '[':
|
||||
case '(':
|
||||
bracketStack.push(c);
|
||||
break;
|
||||
case ')':
|
||||
Character pop = bracketStack.pop();
|
||||
assertTrue("Bracket mismatch at char: " + i + " Expected (, got " + pop, '(' == pop);
|
||||
break;
|
||||
case ']':
|
||||
Character pop1 = bracketStack.pop();
|
||||
assertTrue("Bracket mismatch at char: " + i + " Expected [, got " + pop1, '[' == pop1);
|
||||
break;
|
||||
case '}':
|
||||
Character pop2 = bracketStack.pop();
|
||||
assertTrue("Bracket mismatch at char: " + i + " Expected {, got " + pop2, '{' == pop2);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user