From c4c5b374f864eab6f65fa4ec4fda1965985a15ee Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Thu, 21 Jun 2018 11:36:47 +0300 Subject: [PATCH] Rest of NetworkKey suppliers, tests, Plugins tab stuff to Analysis --- .../plan/data/calculation/AnalysisData.java | 9 -- .../store/containers/AnalysisContainer.java | 19 +++- .../store/containers/NetworkContainer.java | 103 ++++++++++++++++++ .../plan/data/store/keys/NetworkKeys.java | 9 +- .../data/store/mutators/PlayersMutator.java | 15 +++ .../databases/sql/operation/SQLFetchOps.java | 9 ++ .../plan/utilities/analysis/Analysis.java | 28 ++--- .../plan/utilities/html/graphs/WorldMap.java | 6 + .../AnalysisPluginsTabContentCreator.java | 41 ++++++- Plan/src/main/resources/web/network.html | 6 +- .../system/database/databases/SQLiteTest.java | 58 ++++++++++ Plan/src/test/java/utilities/RandomData.java | 6 +- 12 files changed, 272 insertions(+), 37 deletions(-) diff --git a/Plan/src/main/java/com/djrapitops/plan/data/calculation/AnalysisData.java b/Plan/src/main/java/com/djrapitops/plan/data/calculation/AnalysisData.java index 3cdcc1a41..7784d0d7d 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/calculation/AnalysisData.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/calculation/AnalysisData.java @@ -5,8 +5,6 @@ import com.djrapitops.plan.data.PlayerProfile; import com.djrapitops.plan.data.ServerProfile; import com.djrapitops.plan.data.container.Session; import com.djrapitops.plan.data.container.TPS; -import com.djrapitops.plan.data.element.AnalysisContainer; -import com.djrapitops.plan.data.plugin.PluginData; import com.djrapitops.plan.data.store.mutators.RetentionData; import com.djrapitops.plan.data.store.mutators.SessionsMutator; import com.djrapitops.plan.data.store.mutators.formatting.Formatters; @@ -29,7 +27,6 @@ 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.pie.WorldPie; -import com.djrapitops.plan.utilities.html.structure.AnalysisPluginsTabContentCreator; import com.djrapitops.plan.utilities.html.tables.CommandUseTable; import com.djrapitops.plugin.api.TimeAmount; @@ -64,12 +61,6 @@ public class AnalysisData extends RawData { stickyMonthData = new HashSet<>(); } - public void parsePluginsSection(Map containers) { - String[] navAndTabs = AnalysisPluginsTabContentCreator.createContent(containers); - addValue("navPluginsTabs", navAndTabs[0]); - addValue("tabsPlugins", navAndTabs[1]); - } - private void addConstants() { addValue("version", PlanPlugin.getInstance().getVersion()); addValue("worldPieColors", Theme.getValue(ThemeVal.GRAPH_WORLD_PIE)); diff --git a/Plan/src/main/java/com/djrapitops/plan/data/store/containers/AnalysisContainer.java b/Plan/src/main/java/com/djrapitops/plan/data/store/containers/AnalysisContainer.java index d09cb30d3..a0da5d4e0 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/store/containers/AnalysisContainer.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/store/containers/AnalysisContainer.java @@ -23,6 +23,7 @@ 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.pie.WorldPie; +import com.djrapitops.plan.utilities.html.structure.AnalysisPluginsTabContentCreator; import com.djrapitops.plan.utilities.html.structure.RecentLoginList; import com.djrapitops.plan.utilities.html.structure.SessionAccordion; import com.djrapitops.plan.utilities.html.tables.CommandUseTable; @@ -51,6 +52,10 @@ public class AnalysisContainer extends DataContainer { addAnalysisSuppliers(); } + public ServerContainer getServerContainer() { + return serverContainer; + } + private void addAnalysisSuppliers() { putSupplier(AnalysisKeys.SESSIONS_MUTATOR, () -> SessionsMutator.forContainer(serverContainer)); putSupplier(AnalysisKeys.TPS_MUTATOR, () -> TPSMutator.forContainer(serverContainer)); @@ -63,6 +68,7 @@ public class AnalysisContainer extends DataContainer { addTPSAverageSuppliers(); addCommandSuppliers(); addServerHealth(); + addPluginSuppliers(); } private void addConstants() { @@ -140,9 +146,9 @@ public class AnalysisContainer extends DataContainer { Key newDay = new Key<>(PlayersMutator.class, "NEW_DAY"); Key newWeek = new Key<>(PlayersMutator.class, "NEW_WEEK"); Key newMonth = new Key<>(PlayersMutator.class, "NEW_MONTH"); - Key uniqueDay = new Key<>(PlayersMutator.class, "NEW_DAY"); - Key uniqueWeek = new Key<>(PlayersMutator.class, "NEW_WEEK"); - Key uniqueMonth = new Key<>(PlayersMutator.class, "NEW_MONTH"); + Key uniqueDay = new Key<>(PlayersMutator.class, "UNIQUE_DAY"); + Key uniqueWeek = new Key<>(PlayersMutator.class, "UNIQUE_WEEK"); + Key uniqueMonth = new Key<>(PlayersMutator.class, "UNIQUE_MONTH"); putSupplier(newDay, () -> PlayersMutator.copyOf(getUnsafe(AnalysisKeys.PLAYERS_MUTATOR)) .filterRegisteredBetween(getUnsafe(AnalysisKeys.ANALYSIS_TIME_DAY_AGO), getUnsafe(AnalysisKeys.ANALYSIS_TIME)) ); @@ -366,4 +372,11 @@ public class AnalysisContainer extends DataContainer { putSupplier(AnalysisKeys.HEALTH_INDEX, () -> getUnsafe(healthInformation).getServerHealth()); putSupplier(AnalysisKeys.HEALTH_NOTES, () -> getUnsafe(healthInformation).toHtml()); } + + private void addPluginSuppliers() { + // TODO Refactor into a system that supports running the analysis on Bungee + String[] navAndTabs = AnalysisPluginsTabContentCreator.createContent(getUnsafe(AnalysisKeys.PLAYERS_MUTATOR).uuids()); + putRawData(AnalysisKeys.PLUGINS_TAB_NAV, navAndTabs[0]); + putRawData(AnalysisKeys.PLUGINS_TAB, navAndTabs[1]); + } } \ No newline at end of file diff --git a/Plan/src/main/java/com/djrapitops/plan/data/store/containers/NetworkContainer.java b/Plan/src/main/java/com/djrapitops/plan/data/store/containers/NetworkContainer.java index 464c03132..0f687c58e 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/store/containers/NetworkContainer.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/store/containers/NetworkContainer.java @@ -1,11 +1,26 @@ package com.djrapitops.plan.data.store.containers; import com.djrapitops.plan.PlanPlugin; +import com.djrapitops.plan.api.exceptions.database.DBOpException; +import com.djrapitops.plan.data.store.Key; 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.data.store.mutators.formatting.Formatters; +import com.djrapitops.plan.system.database.databases.Database; import com.djrapitops.plan.system.info.server.ServerInfo; +import com.djrapitops.plan.system.settings.theme.Theme; +import com.djrapitops.plan.system.settings.theme.ThemeVal; import com.djrapitops.plan.utilities.MiscUtils; +import com.djrapitops.plan.utilities.html.graphs.WorldMap; +import com.djrapitops.plan.utilities.html.graphs.line.OnlineActivityGraph; +import com.djrapitops.plugin.api.utility.log.Log; + +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; +import java.util.UUID; /** * DataContainer for the whole network. @@ -18,8 +33,35 @@ public class NetworkContainer extends DataContainer { private final ServerContainer bungeeContainer; + private final Map serverContainers; + public NetworkContainer(ServerContainer bungeeContainer) { this.bungeeContainer = bungeeContainer; + serverContainers = new HashMap<>(); + + putSupplier(NetworkKeys.PLAYERS_MUTATOR, () -> PlayersMutator.forContainer(bungeeContainer)); + + addConstants(); + addPlayerInformation(); + } + + public void putAnalysisContainer(AnalysisContainer analysisContainer) { + serverContainers.put(analysisContainer.getServerContainer().getUnsafe(ServerKeys.SERVER_UUID), analysisContainer); + } + + public Optional getAnalysisContainer(UUID serverUUID) { + AnalysisContainer container = serverContainers.get(serverUUID); + if (container != null) { + return Optional.of(container); + } + try { + AnalysisContainer analysisContainer = new AnalysisContainer(Database.getActive().fetch().getServerContainer(serverUUID)); + serverContainers.put(serverUUID, analysisContainer); + return Optional.of(analysisContainer); + } catch (DBOpException e) { + Log.toLog(this.getClass(), e); + } + return Optional.empty(); } private void addConstants() { @@ -32,6 +74,67 @@ public class NetworkContainer extends DataContainer { putSupplier(NetworkKeys.NETWORK_NAME, () -> bungeeContainer.getValue(ServerKeys.NAME).orElse("Plan")); putSupplier(NetworkKeys.PLAYERS_ONLINE, ServerInfo.getServerProperties()::getOnlinePlayers); + putRawData(NetworkKeys.WORLD_MAP_LOW_COLOR, Theme.getValue(ThemeVal.WORLD_MAP_LOW)); + putRawData(NetworkKeys.WORLD_MAP_HIGH_COLOR, Theme.getValue(ThemeVal.WORLD_MAP_HIGH)); + putRawData(NetworkKeys.PLAYERS_GRAPH_COLOR, Theme.getValue(ThemeVal.GRAPH_PLAYERS_ONLINE)); + } + + private void addPlayerInformation() { + putSupplier(NetworkKeys.PLAYERS_TOTAL, () -> bungeeContainer.getValue(ServerKeys.PLAYER_COUNT).orElse(-1)); + putSupplier(NetworkKeys.WORLD_MAP_SERIES, () -> + new WorldMap(PlayersMutator.forContainer(bungeeContainer)).toHighChartsSeries() + ); + putSupplier(NetworkKeys.PLAYERS_ONLINE_SERIES, () -> + new OnlineActivityGraph(TPSMutator.forContainer(bungeeContainer)).toHighChartsSeries() + ); + putSupplier(NetworkKeys.ALL_TIME_PEAK_TIME_F, () -> + bungeeContainer.getValue(ServerKeys.ALL_TIME_PEAK_PLAYERS).map(Formatters.year()::apply).orElse("No data") + ); + putSupplier(NetworkKeys.RECENT_PEAK_TIME_F, () -> + bungeeContainer.getValue(ServerKeys.RECENT_PEAK_PLAYERS).map(Formatters.year()::apply).orElse("No data") + ); + putSupplier(NetworkKeys.PLAYERS_ALL_TIME_PEAK, () -> + bungeeContainer.getValue(ServerKeys.ALL_TIME_PEAK_PLAYERS).map(dateObj -> "" + dateObj.getValue()).orElse("-") + ); + putSupplier(NetworkKeys.PLAYERS_RECENT_PEAK, () -> + bungeeContainer.getValue(ServerKeys.RECENT_PEAK_PLAYERS).map(dateObj -> "" + dateObj.getValue()).orElse("-") + ); + + addPlayerCounts(); + } + + private void addPlayerCounts() { + Key newDay = new Key<>(PlayersMutator.class, "NEW_DAY"); + Key newWeek = new Key<>(PlayersMutator.class, "NEW_WEEK"); + Key newMonth = new Key<>(PlayersMutator.class, "NEW_MONTH"); + Key uniqueDay = new Key<>(PlayersMutator.class, "UNIQUE_DAY"); + Key uniqueWeek = new Key<>(PlayersMutator.class, "UNIQUE_WEEK"); + Key uniqueMonth = new Key<>(PlayersMutator.class, "UNIQUE_MONTH"); + putSupplier(newDay, () -> PlayersMutator.copyOf(getUnsafe(NetworkKeys.PLAYERS_MUTATOR)) + .filterRegisteredBetween(getUnsafe(NetworkKeys.REFRESH_TIME_DAY_AGO), getUnsafe(NetworkKeys.REFRESH_TIME)) + ); + putSupplier(newWeek, () -> PlayersMutator.copyOf(getUnsafe(NetworkKeys.PLAYERS_MUTATOR)) + .filterRegisteredBetween(getUnsafe(NetworkKeys.REFRESH_TIME_WEEK_AGO), getUnsafe(NetworkKeys.REFRESH_TIME)) + ); + putSupplier(newMonth, () -> PlayersMutator.copyOf(getUnsafe(NetworkKeys.PLAYERS_MUTATOR)) + .filterRegisteredBetween(getUnsafe(NetworkKeys.REFRESH_TIME_MONTH_AGO), getUnsafe(NetworkKeys.REFRESH_TIME)) + ); + putSupplier(uniqueDay, () -> PlayersMutator.copyOf(getUnsafe(NetworkKeys.PLAYERS_MUTATOR)) + .filterRegisteredBetween(getUnsafe(NetworkKeys.REFRESH_TIME_DAY_AGO), getUnsafe(NetworkKeys.REFRESH_TIME)) + ); + putSupplier(uniqueWeek, () -> PlayersMutator.copyOf(getUnsafe(NetworkKeys.PLAYERS_MUTATOR)) + .filterRegisteredBetween(getUnsafe(NetworkKeys.REFRESH_TIME_WEEK_AGO), getUnsafe(NetworkKeys.REFRESH_TIME)) + ); + putSupplier(uniqueMonth, () -> PlayersMutator.copyOf(getUnsafe(NetworkKeys.PLAYERS_MUTATOR)) + .filterRegisteredBetween(getUnsafe(NetworkKeys.REFRESH_TIME_MONTH_AGO), getUnsafe(NetworkKeys.REFRESH_TIME)) + ); + + putSupplier(NetworkKeys.PLAYERS_NEW_DAY, () -> getUnsafe(newDay).count()); + putSupplier(NetworkKeys.PLAYERS_NEW_WEEK, () -> getUnsafe(newWeek).count()); + putSupplier(NetworkKeys.PLAYERS_NEW_MONTH, () -> getUnsafe(newMonth).count()); + putSupplier(NetworkKeys.PLAYERS_DAY, () -> getUnsafe(uniqueDay).count()); + putSupplier(NetworkKeys.PLAYERS_WEEK, () -> getUnsafe(uniqueWeek).count()); + putSupplier(NetworkKeys.PLAYERS_MONTH, () -> getUnsafe(uniqueMonth).count()); } } \ No newline at end of file diff --git a/Plan/src/main/java/com/djrapitops/plan/data/store/keys/NetworkKeys.java b/Plan/src/main/java/com/djrapitops/plan/data/store/keys/NetworkKeys.java index b9ba2d12d..3796387ff 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/store/keys/NetworkKeys.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/store/keys/NetworkKeys.java @@ -2,6 +2,7 @@ package com.djrapitops.plan.data.store.keys; import com.djrapitops.plan.data.store.Key; import com.djrapitops.plan.data.store.PlaceholderKey; +import com.djrapitops.plan.data.store.mutators.PlayersMutator; /** * Key objects for {@link com.djrapitops.plan.data.store.containers.NetworkContainer}. @@ -21,9 +22,9 @@ public class NetworkKeys { public static final PlaceholderKey WORLD_MAP_LOW_COLOR = CommonPlaceholderKeys.WORLD_MAP_LOW_COLOR; public static final PlaceholderKey REFRESH_TIME_F = CommonPlaceholderKeys.REFRESH_TIME_F; - public static final PlaceholderKey LAST_PEAK_TIME_F = CommonPlaceholderKeys.LAST_PEAK_TIME_F; + public static final PlaceholderKey RECENT_PEAK_TIME_F = CommonPlaceholderKeys.LAST_PEAK_TIME_F; public static final PlaceholderKey ALL_TIME_PEAK_TIME_F = CommonPlaceholderKeys.ALL_TIME_PEAK_TIME_F; - public static final PlaceholderKey PLAYERS_LAST_PEAK = CommonPlaceholderKeys.PLAYERS_LAST_PEAK; + public static final PlaceholderKey PLAYERS_RECENT_PEAK = CommonPlaceholderKeys.PLAYERS_LAST_PEAK; public static final PlaceholderKey PLAYERS_ALL_TIME_PEAK = CommonPlaceholderKeys.PLAYERS_ALL_TIME_PEAK; public static final PlaceholderKey PLAYERS_DAY = CommonPlaceholderKeys.PLAYERS_DAY; public static final PlaceholderKey PLAYERS_WEEK = CommonPlaceholderKeys.PLAYERS_WEEK; @@ -36,6 +37,10 @@ public class NetworkKeys { public static final PlaceholderKey PLAYERS_ONLINE_SERIES = CommonPlaceholderKeys.PLAYERS_ONLINE_SERIES; public static final Key REFRESH_TIME = new Key<>(Long.class, "REFRESH_TIME"); + public static final Key REFRESH_TIME_DAY_AGO = new Key<>(Long.class, "REFRESH_TIME_DAY_AGO"); + public static final Key REFRESH_TIME_WEEK_AGO = new Key<>(Long.class, "REFRESH_TIME_WEEK_AGO"); + public static final Key REFRESH_TIME_MONTH_AGO = new Key<>(Long.class, "REFRESH_TIME_MONTH_AGO"); + public static final Key PLAYERS_MUTATOR = CommonKeys.PLAYERS_MUTATOR; private NetworkKeys() { /* static variable class */ diff --git a/Plan/src/main/java/com/djrapitops/plan/data/store/mutators/PlayersMutator.java b/Plan/src/main/java/com/djrapitops/plan/data/store/mutators/PlayersMutator.java index 2cce31746..890ddc0f1 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/store/mutators/PlayersMutator.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/store/mutators/PlayersMutator.java @@ -1,6 +1,7 @@ package com.djrapitops.plan.data.store.mutators; import com.djrapitops.plan.data.container.GeoInfo; +import com.djrapitops.plan.data.container.Session; import com.djrapitops.plan.data.store.containers.DataContainer; import com.djrapitops.plan.data.store.containers.PlayerContainer; import com.djrapitops.plan.data.store.keys.PlayerKeys; @@ -194,4 +195,18 @@ public class PlayersMutator { } return new PlayersMutator(toBeRetained); } + + public List getSessions() { + return players.stream() + .map(player -> player.getValue(PlayerKeys.SESSIONS).orElse(new ArrayList<>())) + .flatMap(Collection::stream) + .collect(Collectors.toList()); + } + + public List uuids() { + return players.stream() + .map(player -> player.getValue(PlayerKeys.UUID).orElse(null)) + .filter(Objects::nonNull) + .collect(Collectors.toList()); + } } \ No newline at end of file diff --git a/Plan/src/main/java/com/djrapitops/plan/system/database/databases/sql/operation/SQLFetchOps.java b/Plan/src/main/java/com/djrapitops/plan/system/database/databases/sql/operation/SQLFetchOps.java index dcfec59d8..1dc67a55a 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/database/databases/sql/operation/SQLFetchOps.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/database/databases/sql/operation/SQLFetchOps.java @@ -12,6 +12,7 @@ import com.djrapitops.plan.data.store.keys.PerServerKeys; import com.djrapitops.plan.data.store.keys.PlayerKeys; import com.djrapitops.plan.data.store.keys.ServerKeys; import com.djrapitops.plan.data.store.mutators.PerServerDataMutator; +import com.djrapitops.plan.data.store.mutators.PlayersMutator; import com.djrapitops.plan.data.store.mutators.SessionsMutator; import com.djrapitops.plan.data.store.objects.DateObj; import com.djrapitops.plan.data.time.WorldTimes; @@ -33,6 +34,13 @@ public class SQLFetchOps extends SQLOps implements FetchOperations { public ServerContainer getServerContainer(UUID serverUUID) { ServerContainer container = new ServerContainer(); + Optional serverInfo = serverTable.getServerInfo(serverUUID); + if (!serverInfo.isPresent()) { + return container; + } + + container.putRawData(ServerKeys.SERVER_UUID, serverUUID); + container.putRawData(ServerKeys.NAME, serverInfo.get().getName()); container.putSupplier(ServerKeys.PLAYERS, () -> getPlayerContainers(serverUUID)); container.putSupplier(ServerKeys.PLAYER_COUNT, container.getUnsafe(ServerKeys.PLAYERS)::size); @@ -61,6 +69,7 @@ public class SQLFetchOps extends SQLOps implements FetchOperations { // Calculating getters container.putSupplier(ServerKeys.OPERATORS, () -> container.getUnsafe(ServerKeys.PLAYERS).stream() .filter(player -> player.getValue(PlayerKeys.OPERATOR).orElse(false)).collect(Collectors.toList())); + container.putSupplier(ServerKeys.SESSIONS, () -> PlayersMutator.forContainer(container).getSessions()); container.putSupplier(ServerKeys.PLAYER_KILLS, SessionsMutator.forContainer(container)::toPlayerKillList); container.putSupplier(ServerKeys.PLAYER_KILL_COUNT, container.getUnsafe(ServerKeys.PLAYER_KILLS)::size); container.putSupplier(ServerKeys.MOB_KILL_COUNT, SessionsMutator.forContainer(container)::toMobKillCount); diff --git a/Plan/src/main/java/com/djrapitops/plan/utilities/analysis/Analysis.java b/Plan/src/main/java/com/djrapitops/plan/utilities/analysis/Analysis.java index f47167ba2..b9fd962e0 100644 --- a/Plan/src/main/java/com/djrapitops/plan/utilities/analysis/Analysis.java +++ b/Plan/src/main/java/com/djrapitops/plan/utilities/analysis/Analysis.java @@ -69,21 +69,20 @@ public class Analysis implements Callable { * * @return ServerProfile being analyzed or null if analysis is not being run. */ + // TODO Remove use of this method in PluginData public static ServerProfile getServerProfile() { return serverProfile; } - @Override - public AnalysisData call() throws Exception { - return runAnalysis(); + // TODO Remove use of this method and replace with a new source for the method + @Deprecated + public static boolean isAnalysisBeingRun() { + return serverProfile != null; } - private AnalysisData runAnalysis() throws Exception { - ((ServerTaskSystem) TaskSystem.getInstance()).cancelBootAnalysis(); - - Benchmark.start("Analysis: Total"); - log(Locale.get(Msg.ANALYSIS_START).toString()); - return analyze(); + @Override + public AnalysisData call() { + return runAnalysis(); } private static void updateRefreshDate() { @@ -157,9 +156,12 @@ public class Analysis implements Callable { return containers; } - @Deprecated - public static boolean isAnalysisBeingRun() { - return serverProfile != null; + private AnalysisData runAnalysis() { + ((ServerTaskSystem) TaskSystem.getInstance()).cancelBootAnalysis(); + + Benchmark.start("Analysis: Total"); + log(Locale.get(Msg.ANALYSIS_START).toString()); + return analyze(); } private static void setServerProfile(ServerProfile serverProfile) { @@ -194,8 +196,6 @@ public class Analysis implements Callable { Benchmark.stop("Analysis", "Analysis: Data Analysis"); log(Locale.get(Msg.ANALYSIS_3RD_PARTY).toString()); - Log.logDebug("Analysis", "Analyzing additional data sources (3rd party)"); - analysisData.parsePluginsSection(analyzeAdditionalPluginData(server.getUuids())); return analysisData; } finally { Analysis.updateRefreshDate(); diff --git a/Plan/src/main/java/com/djrapitops/plan/utilities/html/graphs/WorldMap.java b/Plan/src/main/java/com/djrapitops/plan/utilities/html/graphs/WorldMap.java index 9330a6001..3546ed899 100644 --- a/Plan/src/main/java/com/djrapitops/plan/utilities/html/graphs/WorldMap.java +++ b/Plan/src/main/java/com/djrapitops/plan/utilities/html/graphs/WorldMap.java @@ -1,5 +1,7 @@ package com.djrapitops.plan.utilities.html.graphs; +import com.djrapitops.plan.data.store.mutators.PlayersMutator; + import java.util.HashMap; import java.util.List; import java.util.Map; @@ -18,6 +20,10 @@ public class WorldMap implements HighChart { this.geoLocations = geoLocations; } + public WorldMap(PlayersMutator mutator) { + this(mutator.getGeolocations()); + } + private static Map getGeoCodes(Map geoCodeCounts) { Map geoCodes = new HashMap<>(); // Countries & Codes have been copied from a iso-a3 specification file. diff --git a/Plan/src/main/java/com/djrapitops/plan/utilities/html/structure/AnalysisPluginsTabContentCreator.java b/Plan/src/main/java/com/djrapitops/plan/utilities/html/structure/AnalysisPluginsTabContentCreator.java index 63ab170e7..55b9e7276 100644 --- a/Plan/src/main/java/com/djrapitops/plan/utilities/html/structure/AnalysisPluginsTabContentCreator.java +++ b/Plan/src/main/java/com/djrapitops/plan/utilities/html/structure/AnalysisPluginsTabContentCreator.java @@ -4,16 +4,19 @@ */ package com.djrapitops.plan.utilities.html.structure; +import com.djrapitops.plan.PlanPlugin; import com.djrapitops.plan.data.element.AnalysisContainer; import com.djrapitops.plan.data.element.InspectContainer; +import com.djrapitops.plan.data.plugin.HookHandler; import com.djrapitops.plan.data.plugin.PluginData; import com.djrapitops.plan.utilities.analysis.Analysis; import com.djrapitops.plan.utilities.comparators.PluginDataNameComparator; import com.djrapitops.plan.utilities.html.tables.PluginPlayersTable; +import com.djrapitops.plugin.StaticHolder; +import com.djrapitops.plugin.api.Benchmark; +import com.djrapitops.plugin.api.utility.log.Log; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; +import java.util.*; /** * Creates Plugin section contents for Analysis page. @@ -22,11 +25,13 @@ import java.util.Map; */ public class AnalysisPluginsTabContentCreator { - public static String[] createContent(Map containers) { - if (containers.isEmpty()) { + public static String[] createContent(List uuids) { + if (uuids.isEmpty()) { return new String[]{"
  • No Data
  • ", ""}; } + Map containers = analyzeAdditionalPluginData(uuids); + List order = new ArrayList<>(containers.keySet()); order.sort(new PluginDataNameComparator()); @@ -84,6 +89,32 @@ public class AnalysisPluginsTabContentCreator { }; } + private static Map analyzeAdditionalPluginData(Collection uuids) { + Map containers = new HashMap<>(); + + List sources = HookHandler.getInstance().getAdditionalDataSources(); + + sources.parallelStream().forEach(source -> { + PlanPlugin plugin = PlanPlugin.getInstance(); + StaticHolder.saveInstance(AnalysisPluginsTabContentCreator.class, plugin.getClass()); + try { + Benchmark.start("Analysis", "Analysis: Source " + source.getSourcePlugin()); + + AnalysisContainer container = source.getServerData(uuids, new AnalysisContainer()); + if (container != null && !container.isEmpty()) { + containers.put(source, container); + } + + } catch (Exception | NoClassDefFoundError | NoSuchFieldError | NoSuchMethodError e) { + Log.error("A PluginData-source caused an exception: " + source.getSourcePlugin()); + Log.toLog(AnalysisPluginsTabContentCreator.class, e); + } finally { + Benchmark.stop("Analysis", "Analysis: Source " + source.getSourcePlugin()); + } + }); + return containers; + } + public static void appendThird(PluginData pluginData, InspectContainer container, StringBuilder generalTab) { generalTab.append("
    " + "
    " + diff --git a/Plan/src/main/resources/web/network.html b/Plan/src/main/resources/web/network.html index c75ceb494..3cf9eddd7 100644 --- a/Plan/src/main/resources/web/network.html +++ b/Plan/src/main/resources/web/network.html @@ -293,7 +293,7 @@
    • Unique | 24h - ${playersUniqueDay} + ${playersDay}
    • New | 24h @@ -302,7 +302,7 @@
    • Unique | 7d - ${playersUniqueWeek} + ${playersWeek}
    • New | 7d @@ -311,7 +311,7 @@
    • Unique | 30d - ${playersUniqueMonth} + ${playersMonth}
    • New | 30d diff --git a/Plan/src/test/java/com/djrapitops/plan/system/database/databases/SQLiteTest.java b/Plan/src/test/java/com/djrapitops/plan/system/database/databases/SQLiteTest.java index b5e576f82..8d76008ed 100644 --- a/Plan/src/test/java/com/djrapitops/plan/system/database/databases/SQLiteTest.java +++ b/Plan/src/test/java/com/djrapitops/plan/system/database/databases/SQLiteTest.java @@ -11,8 +11,13 @@ import com.djrapitops.plan.api.exceptions.database.DBInitException; import com.djrapitops.plan.data.Actions; import com.djrapitops.plan.data.WebUser; import com.djrapitops.plan.data.container.*; +import com.djrapitops.plan.data.store.Key; +import com.djrapitops.plan.data.store.containers.AnalysisContainer; import com.djrapitops.plan.data.store.containers.PlayerContainer; +import com.djrapitops.plan.data.store.containers.ServerContainer; +import com.djrapitops.plan.data.store.keys.AnalysisKeys; import com.djrapitops.plan.data.store.keys.PlayerKeys; +import com.djrapitops.plan.data.store.keys.ServerKeys; import com.djrapitops.plan.data.store.objects.Nickname; import com.djrapitops.plan.data.time.GMTimes; import com.djrapitops.plan.data.time.WorldTimes; @@ -38,6 +43,7 @@ import utilities.mocks.SystemMockUtil; import java.io.UnsupportedEncodingException; import java.lang.management.ManagementFactory; import java.lang.management.OperatingSystemMXBean; +import java.lang.reflect.Field; import java.security.NoSuchAlgorithmException; import java.util.*; @@ -1083,4 +1089,56 @@ public class SQLiteTest { // TODO Test rest } + + @Test + public void playerContainerSupportsAllPlayerKeys() throws UnsupportedEncodingException, NoSuchAlgorithmException, IllegalAccessException { + saveAllData(db); + + PlayerContainer playerContainer = db.fetch().getPlayerContainer(TestConstants.PLAYER_ONE_UUID); + // Active sessions are added after fetching + playerContainer.putRawData(PlayerKeys.ACTIVE_SESSION, RandomData.randomSession()); + + List unsupported = new ArrayList<>(); + for (Field field : PlayerKeys.class.getDeclaredFields()) { + Key key = (Key) field.get(null); + if (!playerContainer.supports(key)) { + unsupported.add(field.getName()); + } + } + + assertTrue("Some keys are not supported by PlayerContainer: PlayerKeys." + unsupported.toString(), unsupported.isEmpty()); + } + + @Test + public void serverContainerSupportsAllServerKeys() throws UnsupportedEncodingException, NoSuchAlgorithmException, IllegalAccessException { + saveAllData(db); + + ServerContainer serverContainer = db.fetch().getServerContainer(TestConstants.SERVER_UUID); + + List unsupported = new ArrayList<>(); + for (Field field : ServerKeys.class.getDeclaredFields()) { + Key key = (Key) field.get(null); + if (!serverContainer.supports(key)) { + unsupported.add(field.getName()); + } + } + + assertTrue("Some keys are not supported by ServerContainer: ServerKeys." + unsupported.toString(), unsupported.isEmpty()); + } + + @Test + public void analysisContainerSupportsAllAnalysisKeys() throws IllegalAccessException, UnsupportedEncodingException, NoSuchAlgorithmException { + serverContainerSupportsAllServerKeys(); + AnalysisContainer analysisContainer = new AnalysisContainer(db.fetch().getServerContainer(TestConstants.SERVER_UUID)); + + List unsupported = new ArrayList<>(); + for (Field field : AnalysisKeys.class.getDeclaredFields()) { + Key key = (Key) field.get(null); + if (!analysisContainer.supports(key)) { + unsupported.add(field.getName()); + } + } + + assertTrue("Some keys are not supported by AnalysisContainer: AnalysisKeys." + unsupported.toString(), unsupported.isEmpty()); + } } diff --git a/Plan/src/test/java/utilities/RandomData.java b/Plan/src/test/java/utilities/RandomData.java index 9988bd44d..2e90abf8f 100644 --- a/Plan/src/test/java/utilities/RandomData.java +++ b/Plan/src/test/java/utilities/RandomData.java @@ -48,11 +48,15 @@ public class RandomData { public static List randomSessions() { List test = new ArrayList<>(); for (int i = 0; i < 20; i++) { - test.add(new Session(1, TestConstants.PLAYER_ONE_UUID, TestConstants.SERVER_UUID, r.nextLong(), r.nextLong(), 0, 0, 0)); + test.add(randomSession()); } return test; } + public static Session randomSession() { + return new Session(1, TestConstants.PLAYER_ONE_UUID, TestConstants.SERVER_UUID, r.nextLong(), r.nextLong(), 0, 0, 0); + } + public static List randomPoints() { List test = new ArrayList<>(); for (int i = 0; i < 20; i++) {