mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-11-05 02:09:50 +01:00
TPS Related graphs and averages
This commit is contained in:
parent
4f89c8df8c
commit
5ed77a1940
@ -8,14 +8,12 @@ import com.djrapitops.plan.data.container.GeoInfo;
|
||||
import com.djrapitops.plan.data.container.PlayerKill;
|
||||
import com.djrapitops.plan.data.container.Session;
|
||||
import com.djrapitops.plan.data.container.TPS;
|
||||
import com.djrapitops.plan.data.store.mutators.TPSMutator;
|
||||
import com.djrapitops.plan.data.time.WorldTimes;
|
||||
import com.djrapitops.plan.system.settings.Settings;
|
||||
import com.djrapitops.plan.utilities.analysis.AnalysisUtils;
|
||||
import com.djrapitops.plan.utilities.analysis.MathUtils;
|
||||
import com.djrapitops.plan.utilities.comparators.PlayerProfileLastPlayedComparator;
|
||||
import com.djrapitops.plan.utilities.comparators.TPSComparator;
|
||||
import com.djrapitops.plan.utilities.html.tables.PlayersTableCreator;
|
||||
import com.djrapitops.plugin.api.TimeAmount;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
@ -61,24 +59,7 @@ public class ServerProfile {
|
||||
}
|
||||
|
||||
public static long getLowSpikeCount(List<TPS> tpsData) {
|
||||
int mediumThreshold = Settings.THEME_GRAPH_TPS_THRESHOLD_MED.getNumber();
|
||||
|
||||
boolean wasLow = false;
|
||||
long spikeCount = 0L;
|
||||
|
||||
for (TPS tpsObj : tpsData) {
|
||||
double tps = tpsObj.getTicksPerSecond();
|
||||
if (tps < mediumThreshold) {
|
||||
if (!wasLow) {
|
||||
spikeCount++;
|
||||
wasLow = true;
|
||||
}
|
||||
} else {
|
||||
wasLow = false;
|
||||
}
|
||||
}
|
||||
|
||||
return spikeCount;
|
||||
return new TPSMutator(tpsData).lowTpsSpikeCount();
|
||||
}
|
||||
|
||||
public static List<PlayerKill> getPlayerKills(List<Session> s) {
|
||||
@ -106,65 +87,15 @@ public class ServerProfile {
|
||||
}
|
||||
|
||||
public static long serverDownTime(List<TPS> tpsData) {
|
||||
long lastDate = -1;
|
||||
long downTime = 0;
|
||||
for (TPS tps : tpsData) {
|
||||
long date = tps.getDate();
|
||||
if (lastDate == -1) {
|
||||
lastDate = date;
|
||||
continue;
|
||||
}
|
||||
|
||||
long diff = date - lastDate;
|
||||
if (diff > TimeAmount.MINUTE.ms() * 3L) {
|
||||
downTime += diff;
|
||||
}
|
||||
lastDate = date;
|
||||
}
|
||||
|
||||
return downTime;
|
||||
return new TPSMutator(tpsData).serverDownTime();
|
||||
}
|
||||
|
||||
public static long serverIdleTime(List<TPS> tpsData) {
|
||||
long lastDate = -1;
|
||||
int lastPlayers = 0;
|
||||
long idleTime = 0;
|
||||
for (TPS tps : tpsData) {
|
||||
long date = tps.getDate();
|
||||
int players = tps.getPlayers();
|
||||
if (lastDate == -1) {
|
||||
lastDate = date;
|
||||
lastPlayers = players;
|
||||
continue;
|
||||
}
|
||||
|
||||
long diff = date - lastDate;
|
||||
if (lastPlayers == 0 && players == 0) {
|
||||
idleTime += diff;
|
||||
}
|
||||
|
||||
lastDate = date;
|
||||
lastPlayers = players;
|
||||
}
|
||||
|
||||
return idleTime;
|
||||
return new TPSMutator(tpsData).serverIdleTime();
|
||||
}
|
||||
|
||||
public static double aboveLowThreshold(List<TPS> tpsData) {
|
||||
if (tpsData.isEmpty()) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
int threshold = Settings.THEME_GRAPH_TPS_THRESHOLD_MED.getNumber();
|
||||
|
||||
long count = 0;
|
||||
for (TPS tps : tpsData) {
|
||||
if (tps.getTicksPerSecond() >= threshold) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
return count * 1.0 / tpsData.size();
|
||||
return new TPSMutator(tpsData).percentageTPSAboveLowThreshold();
|
||||
}
|
||||
|
||||
public List<PlayerProfile> getPlayers() {
|
||||
@ -191,57 +122,6 @@ public class ServerProfile {
|
||||
this.commandUsage = commandUsage;
|
||||
}
|
||||
|
||||
public double getAverageTPS(long after, long before) {
|
||||
OptionalDouble average = getTPSData(after, before)
|
||||
.mapToDouble(TPS::getTicksPerSecond)
|
||||
.average();
|
||||
if (average.isPresent()) {
|
||||
return average.getAsDouble();
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public double getAverageCPU(long after, long before) {
|
||||
OptionalDouble average = getTPSData(after, before)
|
||||
.mapToDouble(TPS::getCPUUsage)
|
||||
.filter(num -> num >= 0)
|
||||
.average();
|
||||
if (average.isPresent()) {
|
||||
return average.getAsDouble();
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public double getAverageRAM(long after, long before) {
|
||||
OptionalDouble average = getTPSData(after, before)
|
||||
.mapToDouble(TPS::getUsedMemory)
|
||||
.average();
|
||||
if (average.isPresent()) {
|
||||
return average.getAsDouble();
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public double getAverageEntities(long after, long before) {
|
||||
OptionalDouble average = getTPSData(after, before)
|
||||
.mapToDouble(TPS::getEntityCount)
|
||||
.average();
|
||||
if (average.isPresent()) {
|
||||
return average.getAsDouble();
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public double getAverageChunks(long after, long before) {
|
||||
OptionalDouble average = getTPSData(after, before)
|
||||
.mapToDouble(TPS::getChunksLoaded)
|
||||
.average();
|
||||
if (average.isPresent()) {
|
||||
return average.getAsDouble();
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public long getNewPlayers(long after, long before) {
|
||||
return getPlayersWhoRegistered(after, before).count();
|
||||
}
|
||||
@ -356,18 +236,6 @@ public class ServerProfile {
|
||||
return uuids;
|
||||
}
|
||||
|
||||
public long serverDownTime(long after, long before) {
|
||||
return serverDownTime(getTPSData(after, before)
|
||||
.sorted(new TPSComparator())
|
||||
.collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
public long serverIdleTime(long after, long before) {
|
||||
return serverIdleTime(getTPSData(after, before)
|
||||
.sorted(new TPSComparator())
|
||||
.collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
public PlayerProfile getPlayer(UUID uuid) {
|
||||
if (playerMap == null) {
|
||||
playerMap = players.stream().collect(Collectors.toMap(PlayerProfile::getUuid, Function.identity()));
|
||||
|
@ -1,11 +1,14 @@
|
||||
package com.djrapitops.plan.data.store.containers;
|
||||
|
||||
import com.djrapitops.plan.PlanPlugin;
|
||||
import com.djrapitops.plan.data.store.Key;
|
||||
import com.djrapitops.plan.data.store.keys.AnalysisKeys;
|
||||
import com.djrapitops.plan.data.store.keys.PlayerKeys;
|
||||
import com.djrapitops.plan.data.store.keys.ServerKeys;
|
||||
import com.djrapitops.plan.data.store.mutators.SessionsMutator;
|
||||
import com.djrapitops.plan.data.store.mutators.TPSMutator;
|
||||
import com.djrapitops.plan.data.store.mutators.formatting.Formatters;
|
||||
import com.djrapitops.plan.data.time.WorldTimes;
|
||||
import com.djrapitops.plan.system.database.databases.Database;
|
||||
import com.djrapitops.plan.system.info.server.ServerInfo;
|
||||
import com.djrapitops.plan.system.info.server.ServerProperties;
|
||||
@ -13,12 +16,15 @@ 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.line.*;
|
||||
import com.djrapitops.plan.utilities.html.graphs.pie.WorldPie;
|
||||
import com.djrapitops.plan.utilities.html.structure.RecentLoginList;
|
||||
import com.djrapitops.plan.utilities.html.structure.SessionAccordion;
|
||||
import com.djrapitops.plan.utilities.html.tables.ServerSessionTable;
|
||||
import com.djrapitops.plugin.api.TimeAmount;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@ -56,10 +62,15 @@ public class AnalysisContainer extends DataContainer {
|
||||
putRawData(AnalysisKeys.TPS_MEDIUM, Settings.THEME_GRAPH_TPS_THRESHOLD_MED.getNumber());
|
||||
putRawData(AnalysisKeys.TPS_HIGH, Settings.THEME_GRAPH_TPS_THRESHOLD_HIGH.getNumber());
|
||||
|
||||
putSupplier(AnalysisKeys.SESSIONS_MUTATOR, () -> new SessionsMutator(serverContainer.getValue(ServerKeys.SESSIONS).orElse(new ArrayList<>())));
|
||||
putSupplier(AnalysisKeys.TPS_MUTATOR, () -> new TPSMutator(serverContainer.getValue(ServerKeys.TPS).orElse(new ArrayList<>())));
|
||||
|
||||
addServerProperties();
|
||||
addThemeColors();
|
||||
addPlayerSuppliers();
|
||||
addSessionSuppliers();
|
||||
addGraphSuppliers();
|
||||
addTPSAverageSuppliers();
|
||||
}
|
||||
|
||||
private void addServerProperties() {
|
||||
@ -124,7 +135,6 @@ public class AnalysisContainer extends DataContainer {
|
||||
putSupplier(AnalysisKeys.SESSION_ACCORDION_HTML, () -> getUnsafe(AnalysisKeys.SESSION_ACCORDION).toHtml());
|
||||
putSupplier(AnalysisKeys.SESSION_ACCORDION_FUNCTIONS, () -> getUnsafe(AnalysisKeys.SESSION_ACCORDION).toViewScript());
|
||||
|
||||
putSupplier(AnalysisKeys.SESSIONS_MUTATOR, () -> new SessionsMutator(serverContainer.getValue(ServerKeys.SESSIONS).orElse(new ArrayList<>())));
|
||||
putSupplier(AnalysisKeys.AVERAGE_SESSION_LENGTH_F, () -> Formatters.timeAmount()
|
||||
.apply(getUnsafe(AnalysisKeys.SESSIONS_MUTATOR).toAverageSessionLength())
|
||||
);
|
||||
@ -139,5 +149,58 @@ public class AnalysisContainer extends DataContainer {
|
||||
putSupplier(AnalysisKeys.AVERAGE_PLAYTIME_F, () -> Formatters.timeAmount()
|
||||
.apply(getUnsafe(AnalysisKeys.PLAYTIME_TOTAL) / (long) getUnsafe(AnalysisKeys.PLAYERS_TOTAL))
|
||||
);
|
||||
putSupplier(AnalysisKeys.AVERAGE_SESSION_LENGTH_F, () -> Formatters.timeAmount()
|
||||
.apply(getUnsafe(AnalysisKeys.SESSIONS_MUTATOR).toAverageSessionLength())
|
||||
);
|
||||
}
|
||||
|
||||
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(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()
|
||||
);
|
||||
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());
|
||||
}
|
||||
|
||||
private void addTPSAverageSuppliers() {
|
||||
Key<TPSMutator> tpsMonth = new Key<>(TPSMutator.class, "TPS_MONTH");
|
||||
Key<TPSMutator> tpsWeek = new Key<>(TPSMutator.class, "TPS_WEEK");
|
||||
Key<TPSMutator> tpsDay = new Key<>(TPSMutator.class, "TPS_DAY");
|
||||
|
||||
putSupplier(tpsMonth, () -> TPSMutator.copyOf(getUnsafe(AnalysisKeys.TPS_MUTATOR))
|
||||
.filterDataBetween(getUnsafe(AnalysisKeys.ANALYSIS_TIME_MONTH_AGO), getUnsafe(AnalysisKeys.ANALYSIS_TIME))
|
||||
);
|
||||
putSupplier(tpsWeek, () -> TPSMutator.copyOf(getUnsafe(AnalysisKeys.TPS_MUTATOR))
|
||||
.filterDataBetween(getUnsafe(AnalysisKeys.ANALYSIS_TIME_WEEK_AGO), getUnsafe(AnalysisKeys.ANALYSIS_TIME))
|
||||
);
|
||||
putSupplier(tpsDay, () -> TPSMutator.copyOf(getUnsafe(AnalysisKeys.TPS_MUTATOR))
|
||||
.filterDataBetween(getUnsafe(AnalysisKeys.ANALYSIS_TIME_DAY_AGO), getUnsafe(AnalysisKeys.ANALYSIS_TIME))
|
||||
);
|
||||
|
||||
putSupplier(AnalysisKeys.TPS_SPIKE_MONTH, () -> getUnsafe(tpsMonth).lowTpsSpikeCount());
|
||||
putSupplier(AnalysisKeys.AVG_TPS_MONTH, () -> getUnsafe(tpsMonth).averageTPS());
|
||||
putSupplier(AnalysisKeys.AVG_CPU_MONTH, () -> getUnsafe(tpsMonth).averageCPU());
|
||||
putSupplier(AnalysisKeys.AVG_RAM_MONTH, () -> getUnsafe(tpsMonth).averageRAM());
|
||||
putSupplier(AnalysisKeys.AVG_ENTITY_MONTH, () -> getUnsafe(tpsMonth).averageEntities());
|
||||
putSupplier(AnalysisKeys.AVG_CHUNK_MONTH, () -> getUnsafe(tpsMonth).averageChunks());
|
||||
putSupplier(AnalysisKeys.TPS_SPIKE_WEEK, () -> getUnsafe(tpsWeek).lowTpsSpikeCount());
|
||||
putSupplier(AnalysisKeys.AVG_TPS_WEEK, () -> getUnsafe(tpsWeek).averageTPS());
|
||||
putSupplier(AnalysisKeys.AVG_CPU_WEEK, () -> getUnsafe(tpsWeek).averageCPU());
|
||||
putSupplier(AnalysisKeys.AVG_RAM_WEEK, () -> getUnsafe(tpsWeek).averageRAM());
|
||||
putSupplier(AnalysisKeys.AVG_ENTITY_WEEK, () -> getUnsafe(tpsWeek).averageEntities());
|
||||
putSupplier(AnalysisKeys.AVG_CHUNK_WEEK, () -> getUnsafe(tpsWeek).averageChunks());
|
||||
putSupplier(AnalysisKeys.TPS_SPIKE_DAY, () -> getUnsafe(tpsDay).lowTpsSpikeCount());
|
||||
putSupplier(AnalysisKeys.AVG_TPS_DAY, () -> getUnsafe(tpsDay).averageTPS());
|
||||
putSupplier(AnalysisKeys.AVG_CPU_DAY, () -> getUnsafe(tpsDay).averageCPU());
|
||||
putSupplier(AnalysisKeys.AVG_RAM_DAY, () -> getUnsafe(tpsDay).averageRAM());
|
||||
putSupplier(AnalysisKeys.AVG_ENTITY_DAY, () -> getUnsafe(tpsDay).averageEntities());
|
||||
putSupplier(AnalysisKeys.AVG_CHUNK_DAY, () -> getUnsafe(tpsDay).averageChunks());
|
||||
}
|
||||
}
|
@ -4,6 +4,7 @@ import com.djrapitops.plan.data.store.Key;
|
||||
import com.djrapitops.plan.data.store.PlaceholderKey;
|
||||
import com.djrapitops.plan.data.store.Type;
|
||||
import com.djrapitops.plan.data.store.mutators.SessionsMutator;
|
||||
import com.djrapitops.plan.data.store.mutators.TPSMutator;
|
||||
import com.djrapitops.plan.utilities.html.structure.SessionAccordion;
|
||||
|
||||
import java.util.Map;
|
||||
@ -93,21 +94,21 @@ public class AnalysisKeys {
|
||||
public static final PlaceholderKey<Integer> TPS_SPIKE_MONTH = new PlaceholderKey<>(Integer.class, "tpsSpikeMonth");
|
||||
public static final PlaceholderKey<Integer> TPS_SPIKE_WEEK = new PlaceholderKey<>(Integer.class, "tpsSpikeWeek");
|
||||
public static final PlaceholderKey<Integer> TPS_SPIKE_DAY = new PlaceholderKey<>(Integer.class, "tpsSpikeDay");
|
||||
public static final PlaceholderKey<Integer> AVG_TPS_MONTH = new PlaceholderKey<>(Integer.class, "tpsAverageMonth");
|
||||
public static final PlaceholderKey<Integer> AVG_TPS_WEEK = new PlaceholderKey<>(Integer.class, "tpsAverageWeek");
|
||||
public static final PlaceholderKey<Integer> AVG_TPS_DAY = new PlaceholderKey<>(Integer.class, "tpsAverageDay");
|
||||
public static final PlaceholderKey<Integer> AVG_CPU_MONTH = new PlaceholderKey<>(Integer.class, "cpuAverageMonth");
|
||||
public static final PlaceholderKey<Integer> AVG_CPU_WEEK = new PlaceholderKey<>(Integer.class, "cpuAverageWeek");
|
||||
public static final PlaceholderKey<Integer> AVG_CPU_DAY = new PlaceholderKey<>(Integer.class, "cpuAverageDay");
|
||||
public static final PlaceholderKey<Integer> AVG_RAM_MONTH = new PlaceholderKey<>(Integer.class, "ramAverageMonth");
|
||||
public static final PlaceholderKey<Integer> AVG_RAM_WEEK = new PlaceholderKey<>(Integer.class, "ramAverageWeek");
|
||||
public static final PlaceholderKey<Integer> AVG_RAM_DAY = new PlaceholderKey<>(Integer.class, "ramAverageDay");
|
||||
public static final PlaceholderKey<Integer> AVG_ENTITY_MONTH = new PlaceholderKey<>(Integer.class, "entityAverageMonth");
|
||||
public static final PlaceholderKey<Integer> AVG_ENTITY_WEEK = new PlaceholderKey<>(Integer.class, "entityAverageWeek");
|
||||
public static final PlaceholderKey<Integer> AVG_ENTITY_DAY = new PlaceholderKey<>(Integer.class, "entityAverageDay");
|
||||
public static final PlaceholderKey<Integer> AVG_CHUNK_MONTH = new PlaceholderKey<>(Integer.class, "chunkAverageMonth");
|
||||
public static final PlaceholderKey<Integer> AVG_CHUNK_WEEK = new PlaceholderKey<>(Integer.class, "chunkAverageWeek");
|
||||
public static final PlaceholderKey<Integer> AVG_CHUNK_DAY = new PlaceholderKey<>(Integer.class, "chunkAverageDay");
|
||||
public static final PlaceholderKey<Double> AVG_TPS_MONTH = new PlaceholderKey<>(Double.class, "tpsAverageMonth");
|
||||
public static final PlaceholderKey<Double> AVG_TPS_WEEK = new PlaceholderKey<>(Double.class, "tpsAverageWeek");
|
||||
public static final PlaceholderKey<Double> AVG_TPS_DAY = new PlaceholderKey<>(Double.class, "tpsAverageDay");
|
||||
public static final PlaceholderKey<Double> AVG_CPU_MONTH = new PlaceholderKey<>(Double.class, "cpuAverageMonth");
|
||||
public static final PlaceholderKey<Double> AVG_CPU_WEEK = new PlaceholderKey<>(Double.class, "cpuAverageWeek");
|
||||
public static final PlaceholderKey<Double> AVG_CPU_DAY = new PlaceholderKey<>(Double.class, "cpuAverageDay");
|
||||
public static final PlaceholderKey<Double> AVG_RAM_MONTH = new PlaceholderKey<>(Double.class, "ramAverageMonth");
|
||||
public static final PlaceholderKey<Double> AVG_RAM_WEEK = new PlaceholderKey<>(Double.class, "ramAverageWeek");
|
||||
public static final PlaceholderKey<Double> AVG_RAM_DAY = new PlaceholderKey<>(Double.class, "ramAverageDay");
|
||||
public static final PlaceholderKey<Double> AVG_ENTITY_MONTH = new PlaceholderKey<>(Double.class, "entityAverageMonth");
|
||||
public static final PlaceholderKey<Double> AVG_ENTITY_WEEK = new PlaceholderKey<>(Double.class, "entityAverageWeek");
|
||||
public static final PlaceholderKey<Double> AVG_ENTITY_DAY = new PlaceholderKey<>(Double.class, "entityAverageDay");
|
||||
public static final PlaceholderKey<Double> AVG_CHUNK_MONTH = new PlaceholderKey<>(Double.class, "chunkAverageMonth");
|
||||
public static final PlaceholderKey<Double> AVG_CHUNK_WEEK = new PlaceholderKey<>(Double.class, "chunkAverageWeek");
|
||||
public static final PlaceholderKey<Double> AVG_CHUNK_DAY = new PlaceholderKey<>(Double.class, "chunkAverageDay");
|
||||
// Data for Charts
|
||||
public static final PlaceholderKey<String> WORLD_PIE_SERIES = new PlaceholderKey<>(String.class, "worldSeries");
|
||||
public static final PlaceholderKey<String> GM_PIE_SERIES = new PlaceholderKey<>(String.class, "gmSeries");
|
||||
@ -125,6 +126,7 @@ public class AnalysisKeys {
|
||||
public static final PlaceholderKey<String> CALENDAR_SERIES = new PlaceholderKey<>(String.class, "calendarSeries");
|
||||
// Variables used only during analysis
|
||||
public static final Key<SessionsMutator> SESSIONS_MUTATOR = new Key<>(SessionsMutator.class, "SESSIONS_MUTATOR");
|
||||
public static final Key<TPSMutator> TPS_MUTATOR = new Key<>(TPSMutator.class, "TPS_MUTATOR");
|
||||
public static final Key<Long> PLAYTIME_TOTAL = new Key<>(Long.class, "PLAYTIME_TOTAL");
|
||||
public static final Key<Long> ANALYSIS_TIME = new Key<>(Long.class, "ANALYSIS_TIME");
|
||||
public static final Key<Long> ANALYSIS_TIME_DAY_AGO = new Key<>(Long.class, "ANALYSIS_TIME_DAY_AGO");
|
||||
|
@ -28,7 +28,7 @@ public class SessionsMutator {
|
||||
}
|
||||
|
||||
public static SessionsMutator copyOf(SessionsMutator mutator) {
|
||||
return new SessionsMutator(mutator.sessions);
|
||||
return new SessionsMutator(new ArrayList<>(mutator.sessions));
|
||||
}
|
||||
|
||||
public SessionsMutator(List<Session> sessions) {
|
||||
|
@ -0,0 +1,225 @@
|
||||
package com.djrapitops.plan.data.store.mutators;
|
||||
|
||||
import com.djrapitops.plan.data.container.TPS;
|
||||
import com.djrapitops.plan.data.store.containers.DataContainer;
|
||||
import com.djrapitops.plan.data.store.keys.ServerKeys;
|
||||
import com.djrapitops.plan.system.settings.Settings;
|
||||
import com.djrapitops.plan.utilities.html.graphs.line.Point;
|
||||
import com.djrapitops.plugin.api.TimeAmount;
|
||||
import com.djrapitops.plugin.utilities.Verify;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.OptionalDouble;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Mutator for a list of TPS data.
|
||||
* <p>
|
||||
* Can be used to get properties of a large number of TPS entries easily.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class TPSMutator {
|
||||
|
||||
private List<TPS> tpsData;
|
||||
|
||||
public TPSMutator(List<TPS> tpsData) {
|
||||
this.tpsData = tpsData;
|
||||
}
|
||||
|
||||
public static TPSMutator forContainer(DataContainer dataContainer) {
|
||||
Verify.isTrue(dataContainer.supports(ServerKeys.TPS),
|
||||
() -> new IllegalArgumentException("Given DataContainer does not support SESSIONS-key"));
|
||||
return new TPSMutator(dataContainer.getValue(ServerKeys.TPS).orElse(new ArrayList<>()));
|
||||
}
|
||||
|
||||
public static TPSMutator copyOf(TPSMutator mutator) {
|
||||
return new TPSMutator(new ArrayList<>(mutator.tpsData));
|
||||
}
|
||||
|
||||
public TPSMutator filterDataBetween(long after, long before) {
|
||||
tpsData = tpsData.stream()
|
||||
.filter(tps -> tps.getDate() >= after && tps.getDate() <= before)
|
||||
.collect(Collectors.toList());
|
||||
return this;
|
||||
}
|
||||
|
||||
public List<TPS> all() {
|
||||
return tpsData;
|
||||
}
|
||||
|
||||
public List<Point> playersOnlinePoints() {
|
||||
return tpsData.stream()
|
||||
.map(tps -> new Point(tps.getDate(), tps.getPlayers()))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public List<Point> tpsPoints() {
|
||||
return tpsData.stream()
|
||||
.map(tps -> new Point(tps.getDate(), tps.getTicksPerSecond()))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public List<Point> cpuPoints() {
|
||||
return tpsData.stream()
|
||||
.map(tps -> new Point(tps.getDate(), tps.getCPUUsage()))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public List<Point> ramUsagePoints() {
|
||||
return tpsData.stream()
|
||||
.map(tps -> new Point(tps.getDate(), tps.getUsedMemory()))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public List<Point> entityPoints() {
|
||||
return tpsData.stream()
|
||||
.map(tps -> new Point(tps.getDate(), tps.getEntityCount()))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public List<Point> chunkPoints() {
|
||||
return tpsData.stream()
|
||||
.map(tps -> new Point(tps.getDate(), tps.getChunksLoaded()))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public long serverDownTime() {
|
||||
long lastDate = -1;
|
||||
long downTime = 0;
|
||||
for (TPS tps : tpsData) {
|
||||
long date = tps.getDate();
|
||||
if (lastDate == -1) {
|
||||
lastDate = date;
|
||||
continue;
|
||||
}
|
||||
|
||||
long diff = date - lastDate;
|
||||
if (diff > TimeAmount.MINUTE.ms() * 3L) {
|
||||
downTime += diff;
|
||||
}
|
||||
lastDate = date;
|
||||
}
|
||||
|
||||
return downTime;
|
||||
}
|
||||
|
||||
public long serverIdleTime() {
|
||||
long lastDate = -1;
|
||||
int lastPlayers = 0;
|
||||
long idleTime = 0;
|
||||
for (TPS tps : tpsData) {
|
||||
long date = tps.getDate();
|
||||
int players = tps.getPlayers();
|
||||
if (lastDate == -1) {
|
||||
lastDate = date;
|
||||
lastPlayers = players;
|
||||
continue;
|
||||
}
|
||||
|
||||
long diff = date - lastDate;
|
||||
if (lastPlayers == 0 && players == 0) {
|
||||
idleTime += diff;
|
||||
}
|
||||
|
||||
lastDate = date;
|
||||
lastPlayers = players;
|
||||
}
|
||||
|
||||
return idleTime;
|
||||
}
|
||||
|
||||
public double percentageTPSAboveLowThreshold() {
|
||||
if (tpsData.isEmpty()) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
int threshold = Settings.THEME_GRAPH_TPS_THRESHOLD_MED.getNumber();
|
||||
|
||||
long count = 0;
|
||||
for (TPS tps : tpsData) {
|
||||
if (tps.getTicksPerSecond() >= threshold) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
return count * 1.0 / tpsData.size();
|
||||
}
|
||||
|
||||
public int lowTpsSpikeCount() {
|
||||
int mediumThreshold = Settings.THEME_GRAPH_TPS_THRESHOLD_MED.getNumber();
|
||||
|
||||
boolean wasLow = false;
|
||||
int spikeCount = 0;
|
||||
|
||||
for (TPS tpsObj : tpsData) {
|
||||
double tps = tpsObj.getTicksPerSecond();
|
||||
if (tps < mediumThreshold) {
|
||||
if (!wasLow) {
|
||||
spikeCount++;
|
||||
wasLow = true;
|
||||
}
|
||||
} else {
|
||||
wasLow = false;
|
||||
}
|
||||
}
|
||||
|
||||
return spikeCount;
|
||||
}
|
||||
|
||||
public double averageTPS() {
|
||||
OptionalDouble average = tpsData.stream()
|
||||
.mapToDouble(TPS::getTicksPerSecond)
|
||||
.filter(num -> num >= 0)
|
||||
.average();
|
||||
if (average.isPresent()) {
|
||||
return average.getAsDouble();
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public double averageCPU() {
|
||||
OptionalDouble average = tpsData.stream()
|
||||
.mapToDouble(TPS::getCPUUsage)
|
||||
.filter(num -> num >= 0)
|
||||
.average();
|
||||
if (average.isPresent()) {
|
||||
return average.getAsDouble();
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public double averageRAM() {
|
||||
OptionalDouble average = tpsData.stream()
|
||||
.mapToDouble(TPS::getUsedMemory)
|
||||
.filter(num -> num >= 0)
|
||||
.average();
|
||||
if (average.isPresent()) {
|
||||
return average.getAsDouble();
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public double averageEntities() {
|
||||
OptionalDouble average = tpsData.stream()
|
||||
.mapToDouble(TPS::getEntityCount)
|
||||
.filter(num -> num >= 0)
|
||||
.average();
|
||||
if (average.isPresent()) {
|
||||
return average.getAsDouble();
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public double averageChunks() {
|
||||
OptionalDouble average = tpsData.stream()
|
||||
.mapToDouble(TPS::getChunksLoaded)
|
||||
.filter(num -> num >= 0)
|
||||
.average();
|
||||
if (average.isPresent()) {
|
||||
return average.getAsDouble();
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
}
|
@ -1,9 +1,9 @@
|
||||
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;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Graph about CPU Usage gathered by TPSCountTimer.
|
||||
@ -15,12 +15,10 @@ import java.util.stream.Collectors;
|
||||
public class CPUGraph extends AbstractLineGraph {
|
||||
|
||||
public CPUGraph(List<TPS> tpsData) {
|
||||
super(transformToPoints(tpsData));
|
||||
this(new TPSMutator(tpsData));
|
||||
}
|
||||
|
||||
private static List<Point> transformToPoints(List<TPS> tpsData) {
|
||||
return tpsData.stream()
|
||||
.map(tps -> new Point(tps.getDate(), tps.getCPUUsage()))
|
||||
.collect(Collectors.toList());
|
||||
public CPUGraph(TPSMutator mutator) {
|
||||
super(mutator.cpuPoints());
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
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;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Graph about Chunk Counts gathered by TPSCountTimer.
|
||||
@ -15,12 +15,10 @@ import java.util.stream.Collectors;
|
||||
public class ChunkGraph extends AbstractLineGraph {
|
||||
|
||||
public ChunkGraph(List<TPS> tpsData) {
|
||||
super(turnToPoints(tpsData));
|
||||
this(new TPSMutator(tpsData));
|
||||
}
|
||||
|
||||
private static List<Point> turnToPoints(List<TPS> tpsData) {
|
||||
return tpsData.stream()
|
||||
.map(tps -> new Point(tps.getDate(), tps.getChunksLoaded()))
|
||||
.collect(Collectors.toList());
|
||||
public ChunkGraph(TPSMutator mutator) {
|
||||
super(mutator.chunkPoints());
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
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;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Graph about Entity Counts gathered by TPSCountTimer.
|
||||
@ -15,12 +15,10 @@ import java.util.stream.Collectors;
|
||||
public class EntityGraph extends AbstractLineGraph {
|
||||
|
||||
public EntityGraph(List<TPS> tpsData) {
|
||||
super(turnToPoints(tpsData));
|
||||
this(new TPSMutator(tpsData));
|
||||
}
|
||||
|
||||
private static List<Point> turnToPoints(List<TPS> tpsData) {
|
||||
return tpsData.stream()
|
||||
.map(tps -> new Point(tps.getDate(), tps.getEntityCount()))
|
||||
.collect(Collectors.toList());
|
||||
public EntityGraph(TPSMutator mutator) {
|
||||
super(mutator.entityPoints());
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
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;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Graph about Player Counts gathered by TPSCountTimer.
|
||||
@ -15,12 +15,10 @@ import java.util.stream.Collectors;
|
||||
public class OnlineActivityGraph extends AbstractLineGraph {
|
||||
|
||||
public OnlineActivityGraph(List<TPS> tpsData) {
|
||||
super(turnToPoints(tpsData));
|
||||
this(new TPSMutator(tpsData));
|
||||
}
|
||||
|
||||
private static List<Point> turnToPoints(List<TPS> tpsData) {
|
||||
return tpsData.stream()
|
||||
.map(tps -> new Point(tps.getDate(), tps.getPlayers()))
|
||||
.collect(Collectors.toList());
|
||||
public OnlineActivityGraph(TPSMutator mutator) {
|
||||
super(mutator.playersOnlinePoints());
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
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;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Graph about RAM Usage gathered by TPSCountTimer.
|
||||
@ -15,12 +15,10 @@ import java.util.stream.Collectors;
|
||||
public class RamGraph extends AbstractLineGraph {
|
||||
|
||||
public RamGraph(List<TPS> tpsData) {
|
||||
super(turnToPoints(tpsData));
|
||||
this(new TPSMutator(tpsData));
|
||||
}
|
||||
|
||||
private static List<Point> turnToPoints(List<TPS> tpsData) {
|
||||
return tpsData.stream()
|
||||
.map(tps -> new Point(tps.getDate(), tps.getUsedMemory()))
|
||||
.collect(Collectors.toList());
|
||||
public RamGraph(TPSMutator mutator) {
|
||||
super(mutator.ramUsagePoints());
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
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;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Graph about TPS gathered by TPSCountTimer.
|
||||
@ -15,12 +15,10 @@ import java.util.stream.Collectors;
|
||||
public class TPSGraph extends AbstractLineGraph {
|
||||
|
||||
public TPSGraph(List<TPS> tpsData) {
|
||||
super(turnToPoints(tpsData));
|
||||
this(new TPSMutator(tpsData));
|
||||
}
|
||||
|
||||
private static List<Point> turnToPoints(List<TPS> tpsData) {
|
||||
return tpsData.stream()
|
||||
.map(tps -> new Point(tps.getDate(), tps.getTicksPerSecond()))
|
||||
.collect(Collectors.toList());
|
||||
public TPSGraph(TPSMutator mutator) {
|
||||
super(mutator.tpsPoints());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user