Fixed regression bugs, reduced list copying

This commit is contained in:
Rsl1122 2018-06-22 12:40:14 +03:00
parent 5dba6ac27c
commit 4e254cb42e
18 changed files with 116 additions and 67 deletions

View File

@ -106,7 +106,7 @@ public class QInspectCommand extends CommandNode {
sender.sendMessage(Locale.get(Msg.CMD_HEADER_INSPECT).toString() + ": " + colT + container.getValue(PlayerKeys.NAME).orElse("Unknown")); sender.sendMessage(Locale.get(Msg.CMD_HEADER_INSPECT).toString() + ": " + colT + container.getValue(PlayerKeys.NAME).orElse("Unknown"));
ActivityIndex activityIndex = new ActivityIndex(container, now); ActivityIndex activityIndex = container.getActivityIndex(now);
Long registered = container.getValue(PlayerKeys.REGISTERED).orElse(0L); Long registered = container.getValue(PlayerKeys.REGISTERED).orElse(0L);
Long lastSeen = container.getValue(PlayerKeys.LAST_SEEN).orElse(0L); Long lastSeen = container.getValue(PlayerKeys.LAST_SEEN).orElse(0L);
List<GeoInfo> geoInfo = container.getValue(PlayerKeys.GEO_INFO).orElse(new ArrayList<>()); List<GeoInfo> geoInfo = container.getValue(PlayerKeys.GEO_INFO).orElse(new ArrayList<>());

View File

@ -34,13 +34,13 @@ public class TableContainer {
*/ */
public TableContainer(String... header) { public TableContainer(String... header) {
this.header = header; this.header = header;
this.formatters = new Formatter[header.length]; this.formatters = new Formatter[this.header.length];
values = new ArrayList<>(); values = new ArrayList<>();
} }
public TableContainer(boolean players, String... header) { public TableContainer(boolean players, String... header) {
this.header = FormatUtils.mergeArrays(new String[]{Html.FONT_AWESOME_ICON.parse("user") + " Player"}, header); this.header = FormatUtils.mergeArrays(new String[]{Html.FONT_AWESOME_ICON.parse("user") + " Player"}, header);
this.formatters = new Formatter[header.length]; this.formatters = new Formatter[this.header.length];
values = new ArrayList<>(); values = new ArrayList<>();
} }

View File

@ -149,22 +149,22 @@ public class AnalysisContainer extends DataContainer {
Key<PlayersMutator> uniqueDay = new Key<>(PlayersMutator.class, "UNIQUE_DAY"); Key<PlayersMutator> uniqueDay = new Key<>(PlayersMutator.class, "UNIQUE_DAY");
Key<PlayersMutator> uniqueWeek = new Key<>(PlayersMutator.class, "UNIQUE_WEEK"); Key<PlayersMutator> uniqueWeek = new Key<>(PlayersMutator.class, "UNIQUE_WEEK");
Key<PlayersMutator> uniqueMonth = new Key<>(PlayersMutator.class, "UNIQUE_MONTH"); Key<PlayersMutator> uniqueMonth = new Key<>(PlayersMutator.class, "UNIQUE_MONTH");
putSupplier(newDay, () -> PlayersMutator.copyOf(getUnsafe(AnalysisKeys.PLAYERS_MUTATOR)) putSupplier(newDay, () -> getUnsafe(AnalysisKeys.PLAYERS_MUTATOR)
.filterRegisteredBetween(getUnsafe(AnalysisKeys.ANALYSIS_TIME_DAY_AGO), getUnsafe(AnalysisKeys.ANALYSIS_TIME)) .filterRegisteredBetween(getUnsafe(AnalysisKeys.ANALYSIS_TIME_DAY_AGO), getUnsafe(AnalysisKeys.ANALYSIS_TIME))
); );
putSupplier(newWeek, () -> PlayersMutator.copyOf(getUnsafe(AnalysisKeys.PLAYERS_MUTATOR)) putSupplier(newWeek, () -> getUnsafe(AnalysisKeys.PLAYERS_MUTATOR)
.filterRegisteredBetween(getUnsafe(AnalysisKeys.ANALYSIS_TIME_WEEK_AGO), getUnsafe(AnalysisKeys.ANALYSIS_TIME)) .filterRegisteredBetween(getUnsafe(AnalysisKeys.ANALYSIS_TIME_WEEK_AGO), getUnsafe(AnalysisKeys.ANALYSIS_TIME))
); );
putSupplier(newMonth, () -> PlayersMutator.copyOf(getUnsafe(AnalysisKeys.PLAYERS_MUTATOR)) putSupplier(newMonth, () -> getUnsafe(AnalysisKeys.PLAYERS_MUTATOR)
.filterRegisteredBetween(getUnsafe(AnalysisKeys.ANALYSIS_TIME_MONTH_AGO), getUnsafe(AnalysisKeys.ANALYSIS_TIME)) .filterRegisteredBetween(getUnsafe(AnalysisKeys.ANALYSIS_TIME_MONTH_AGO), getUnsafe(AnalysisKeys.ANALYSIS_TIME))
); );
putSupplier(uniqueDay, () -> PlayersMutator.copyOf(getUnsafe(AnalysisKeys.PLAYERS_MUTATOR)) putSupplier(uniqueDay, () -> getUnsafe(AnalysisKeys.PLAYERS_MUTATOR)
.filterRegisteredBetween(getUnsafe(AnalysisKeys.ANALYSIS_TIME_DAY_AGO), getUnsafe(AnalysisKeys.ANALYSIS_TIME)) .filterRegisteredBetween(getUnsafe(AnalysisKeys.ANALYSIS_TIME_DAY_AGO), getUnsafe(AnalysisKeys.ANALYSIS_TIME))
); );
putSupplier(uniqueWeek, () -> PlayersMutator.copyOf(getUnsafe(AnalysisKeys.PLAYERS_MUTATOR)) putSupplier(uniqueWeek, () -> getUnsafe(AnalysisKeys.PLAYERS_MUTATOR)
.filterRegisteredBetween(getUnsafe(AnalysisKeys.ANALYSIS_TIME_WEEK_AGO), getUnsafe(AnalysisKeys.ANALYSIS_TIME)) .filterRegisteredBetween(getUnsafe(AnalysisKeys.ANALYSIS_TIME_WEEK_AGO), getUnsafe(AnalysisKeys.ANALYSIS_TIME))
); );
putSupplier(uniqueMonth, () -> PlayersMutator.copyOf(getUnsafe(AnalysisKeys.PLAYERS_MUTATOR)) putSupplier(uniqueMonth, () -> getUnsafe(AnalysisKeys.PLAYERS_MUTATOR)
.filterRegisteredBetween(getUnsafe(AnalysisKeys.ANALYSIS_TIME_MONTH_AGO), getUnsafe(AnalysisKeys.ANALYSIS_TIME)) .filterRegisteredBetween(getUnsafe(AnalysisKeys.ANALYSIS_TIME_MONTH_AGO), getUnsafe(AnalysisKeys.ANALYSIS_TIME))
); );
@ -246,13 +246,13 @@ public class AnalysisContainer extends DataContainer {
Key<SessionsMutator> sessionsDay = new Key<>(SessionsMutator.class, "SESSIONS_DAY"); Key<SessionsMutator> sessionsDay = new Key<>(SessionsMutator.class, "SESSIONS_DAY");
Key<SessionsMutator> sessionsWeek = new Key<>(SessionsMutator.class, "SESSIONS_WEEK"); Key<SessionsMutator> sessionsWeek = new Key<>(SessionsMutator.class, "SESSIONS_WEEK");
Key<SessionsMutator> sessionsMonth = new Key<>(SessionsMutator.class, "SESSIONS_MONTH"); Key<SessionsMutator> sessionsMonth = new Key<>(SessionsMutator.class, "SESSIONS_MONTH");
putSupplier(sessionsDay, () -> SessionsMutator.copyOf(getUnsafe(AnalysisKeys.SESSIONS_MUTATOR)) putSupplier(sessionsDay, () -> getUnsafe(AnalysisKeys.SESSIONS_MUTATOR)
.filterSessionsBetween(getUnsafe(AnalysisKeys.ANALYSIS_TIME_DAY_AGO), getUnsafe(AnalysisKeys.ANALYSIS_TIME)) .filterSessionsBetween(getUnsafe(AnalysisKeys.ANALYSIS_TIME_DAY_AGO), getUnsafe(AnalysisKeys.ANALYSIS_TIME))
); );
putSupplier(sessionsWeek, () -> SessionsMutator.copyOf(getUnsafe(AnalysisKeys.SESSIONS_MUTATOR)) putSupplier(sessionsWeek, () -> getUnsafe(AnalysisKeys.SESSIONS_MUTATOR)
.filterSessionsBetween(getUnsafe(AnalysisKeys.ANALYSIS_TIME_WEEK_AGO), getUnsafe(AnalysisKeys.ANALYSIS_TIME)) .filterSessionsBetween(getUnsafe(AnalysisKeys.ANALYSIS_TIME_WEEK_AGO), getUnsafe(AnalysisKeys.ANALYSIS_TIME))
); );
putSupplier(sessionsMonth, () -> SessionsMutator.copyOf(getUnsafe(AnalysisKeys.SESSIONS_MUTATOR)) putSupplier(sessionsMonth, () -> getUnsafe(AnalysisKeys.SESSIONS_MUTATOR)
.filterSessionsBetween(getUnsafe(AnalysisKeys.ANALYSIS_TIME_MONTH_AGO), getUnsafe(AnalysisKeys.ANALYSIS_TIME)) .filterSessionsBetween(getUnsafe(AnalysisKeys.ANALYSIS_TIME_MONTH_AGO), getUnsafe(AnalysisKeys.ANALYSIS_TIME))
); );
@ -262,13 +262,13 @@ public class AnalysisContainer extends DataContainer {
putSupplier(AnalysisKeys.AVG_PLAYERS_WEEK, () -> getUnsafe(sessionsWeek).toUniqueJoinsPerDay()); putSupplier(AnalysisKeys.AVG_PLAYERS_WEEK, () -> getUnsafe(sessionsWeek).toUniqueJoinsPerDay());
putSupplier(AnalysisKeys.AVG_PLAYERS_MONTH, () -> getUnsafe(sessionsMonth).toUniqueJoinsPerDay()); putSupplier(AnalysisKeys.AVG_PLAYERS_MONTH, () -> getUnsafe(sessionsMonth).toUniqueJoinsPerDay());
putSupplier(AnalysisKeys.PLAYERS_RETAINED_WEEK, () -> putSupplier(AnalysisKeys.PLAYERS_RETAINED_WEEK, () ->
PlayersMutator.copyOf(getUnsafe(AnalysisKeys.PLAYERS_MUTATOR)).filterRetained( getUnsafe(AnalysisKeys.PLAYERS_MUTATOR).filterRetained(
getUnsafe(AnalysisKeys.ANALYSIS_TIME_WEEK_AGO), getUnsafe(AnalysisKeys.ANALYSIS_TIME_WEEK_AGO),
getUnsafe(AnalysisKeys.ANALYSIS_TIME) getUnsafe(AnalysisKeys.ANALYSIS_TIME)
).count() ).count()
); );
putSupplier(AnalysisKeys.PLAYERS_RETAINED_MONTH, () -> putSupplier(AnalysisKeys.PLAYERS_RETAINED_MONTH, () ->
PlayersMutator.copyOf(getUnsafe(AnalysisKeys.PLAYERS_MUTATOR)).filterRetained( getUnsafe(AnalysisKeys.PLAYERS_MUTATOR).filterRetained(
getUnsafe(AnalysisKeys.ANALYSIS_TIME_MONTH_AGO), getUnsafe(AnalysisKeys.ANALYSIS_TIME_MONTH_AGO),
getUnsafe(AnalysisKeys.ANALYSIS_TIME) getUnsafe(AnalysisKeys.ANALYSIS_TIME)
).count() ).count()
@ -328,13 +328,13 @@ public class AnalysisContainer extends DataContainer {
Key<TPSMutator> tpsWeek = new Key<>(TPSMutator.class, "TPS_WEEK"); Key<TPSMutator> tpsWeek = new Key<>(TPSMutator.class, "TPS_WEEK");
Key<TPSMutator> tpsDay = new Key<>(TPSMutator.class, "TPS_DAY"); Key<TPSMutator> tpsDay = new Key<>(TPSMutator.class, "TPS_DAY");
putSupplier(tpsMonth, () -> TPSMutator.copyOf(getUnsafe(AnalysisKeys.TPS_MUTATOR)) putSupplier(tpsMonth, () -> getUnsafe(AnalysisKeys.TPS_MUTATOR)
.filterDataBetween(getUnsafe(AnalysisKeys.ANALYSIS_TIME_MONTH_AGO), getUnsafe(AnalysisKeys.ANALYSIS_TIME)) .filterDataBetween(getUnsafe(AnalysisKeys.ANALYSIS_TIME_MONTH_AGO), getUnsafe(AnalysisKeys.ANALYSIS_TIME))
); );
putSupplier(tpsWeek, () -> TPSMutator.copyOf(getUnsafe(AnalysisKeys.TPS_MUTATOR)) putSupplier(tpsWeek, () -> getUnsafe(AnalysisKeys.TPS_MUTATOR)
.filterDataBetween(getUnsafe(AnalysisKeys.ANALYSIS_TIME_WEEK_AGO), getUnsafe(AnalysisKeys.ANALYSIS_TIME)) .filterDataBetween(getUnsafe(AnalysisKeys.ANALYSIS_TIME_WEEK_AGO), getUnsafe(AnalysisKeys.ANALYSIS_TIME))
); );
putSupplier(tpsDay, () -> TPSMutator.copyOf(getUnsafe(AnalysisKeys.TPS_MUTATOR)) putSupplier(tpsDay, () -> getUnsafe(AnalysisKeys.TPS_MUTATOR)
.filterDataBetween(getUnsafe(AnalysisKeys.ANALYSIS_TIME_DAY_AGO), getUnsafe(AnalysisKeys.ANALYSIS_TIME)) .filterDataBetween(getUnsafe(AnalysisKeys.ANALYSIS_TIME_DAY_AGO), getUnsafe(AnalysisKeys.ANALYSIS_TIME))
); );

View File

@ -110,22 +110,22 @@ public class NetworkContainer extends DataContainer {
Key<PlayersMutator> uniqueDay = new Key<>(PlayersMutator.class, "UNIQUE_DAY"); Key<PlayersMutator> uniqueDay = new Key<>(PlayersMutator.class, "UNIQUE_DAY");
Key<PlayersMutator> uniqueWeek = new Key<>(PlayersMutator.class, "UNIQUE_WEEK"); Key<PlayersMutator> uniqueWeek = new Key<>(PlayersMutator.class, "UNIQUE_WEEK");
Key<PlayersMutator> uniqueMonth = new Key<>(PlayersMutator.class, "UNIQUE_MONTH"); Key<PlayersMutator> uniqueMonth = new Key<>(PlayersMutator.class, "UNIQUE_MONTH");
putSupplier(newDay, () -> PlayersMutator.copyOf(getUnsafe(NetworkKeys.PLAYERS_MUTATOR)) putSupplier(newDay, () -> getUnsafe(NetworkKeys.PLAYERS_MUTATOR)
.filterRegisteredBetween(getUnsafe(NetworkKeys.REFRESH_TIME_DAY_AGO), getUnsafe(NetworkKeys.REFRESH_TIME)) .filterRegisteredBetween(getUnsafe(NetworkKeys.REFRESH_TIME_DAY_AGO), getUnsafe(NetworkKeys.REFRESH_TIME))
); );
putSupplier(newWeek, () -> PlayersMutator.copyOf(getUnsafe(NetworkKeys.PLAYERS_MUTATOR)) putSupplier(newWeek, () -> getUnsafe(NetworkKeys.PLAYERS_MUTATOR)
.filterRegisteredBetween(getUnsafe(NetworkKeys.REFRESH_TIME_WEEK_AGO), getUnsafe(NetworkKeys.REFRESH_TIME)) .filterRegisteredBetween(getUnsafe(NetworkKeys.REFRESH_TIME_WEEK_AGO), getUnsafe(NetworkKeys.REFRESH_TIME))
); );
putSupplier(newMonth, () -> PlayersMutator.copyOf(getUnsafe(NetworkKeys.PLAYERS_MUTATOR)) putSupplier(newMonth, () -> getUnsafe(NetworkKeys.PLAYERS_MUTATOR)
.filterRegisteredBetween(getUnsafe(NetworkKeys.REFRESH_TIME_MONTH_AGO), getUnsafe(NetworkKeys.REFRESH_TIME)) .filterRegisteredBetween(getUnsafe(NetworkKeys.REFRESH_TIME_MONTH_AGO), getUnsafe(NetworkKeys.REFRESH_TIME))
); );
putSupplier(uniqueDay, () -> PlayersMutator.copyOf(getUnsafe(NetworkKeys.PLAYERS_MUTATOR)) putSupplier(uniqueDay, () -> getUnsafe(NetworkKeys.PLAYERS_MUTATOR)
.filterRegisteredBetween(getUnsafe(NetworkKeys.REFRESH_TIME_DAY_AGO), getUnsafe(NetworkKeys.REFRESH_TIME)) .filterRegisteredBetween(getUnsafe(NetworkKeys.REFRESH_TIME_DAY_AGO), getUnsafe(NetworkKeys.REFRESH_TIME))
); );
putSupplier(uniqueWeek, () -> PlayersMutator.copyOf(getUnsafe(NetworkKeys.PLAYERS_MUTATOR)) putSupplier(uniqueWeek, () -> getUnsafe(NetworkKeys.PLAYERS_MUTATOR)
.filterRegisteredBetween(getUnsafe(NetworkKeys.REFRESH_TIME_WEEK_AGO), getUnsafe(NetworkKeys.REFRESH_TIME)) .filterRegisteredBetween(getUnsafe(NetworkKeys.REFRESH_TIME_WEEK_AGO), getUnsafe(NetworkKeys.REFRESH_TIME))
); );
putSupplier(uniqueMonth, () -> PlayersMutator.copyOf(getUnsafe(NetworkKeys.PLAYERS_MUTATOR)) putSupplier(uniqueMonth, () -> getUnsafe(NetworkKeys.PLAYERS_MUTATOR)
.filterRegisteredBetween(getUnsafe(NetworkKeys.REFRESH_TIME_MONTH_AGO), getUnsafe(NetworkKeys.REFRESH_TIME)) .filterRegisteredBetween(getUnsafe(NetworkKeys.REFRESH_TIME_MONTH_AGO), getUnsafe(NetworkKeys.REFRESH_TIME))
); );

View File

@ -1,7 +1,11 @@
package com.djrapitops.plan.data.store.containers; package com.djrapitops.plan.data.store.containers;
import com.djrapitops.plan.data.store.mutators.ActivityIndex;
import com.djrapitops.plan.data.store.mutators.SessionsMutator; import com.djrapitops.plan.data.store.mutators.SessionsMutator;
import java.util.HashMap;
import java.util.Map;
/** /**
* DataContainer about a Player. * DataContainer about a Player.
* <p> * <p>
@ -12,6 +16,21 @@ import com.djrapitops.plan.data.store.mutators.SessionsMutator;
*/ */
public class PlayerContainer extends DataContainer { public class PlayerContainer extends DataContainer {
private Map<Long, ActivityIndex> activityIndexCache;
public PlayerContainer() {
activityIndexCache = new HashMap<>();
}
public ActivityIndex getActivityIndex(long date) {
ActivityIndex index = activityIndexCache.get(date);
if (index == null) {
index = new ActivityIndex(this, date);
activityIndexCache.put(date, index);
}
return index;
}
public boolean playedBetween(long after, long before) { public boolean playedBetween(long after, long before) {
return SessionsMutator.forContainer(this).playedBetween(after, before); return SessionsMutator.forContainer(this).playedBetween(after, before);
} }

View File

@ -51,8 +51,8 @@ public class AnalysisKeys {
public static final PlaceholderKey<String> RECENT_LOGINS = new PlaceholderKey<>(String.class, "listRecentLogins"); public static final PlaceholderKey<String> RECENT_LOGINS = new PlaceholderKey<>(String.class, "listRecentLogins");
public static final PlaceholderKey<String> COMMAND_USAGE_TABLE = new PlaceholderKey<>(String.class, "tableBodyCommands"); public static final PlaceholderKey<String> COMMAND_USAGE_TABLE = new PlaceholderKey<>(String.class, "tableBodyCommands");
public static final PlaceholderKey<String> HEALTH_NOTES = new PlaceholderKey<>(String.class, "healthNotes"); public static final PlaceholderKey<String> HEALTH_NOTES = new PlaceholderKey<>(String.class, "healthNotes");
public static final PlaceholderKey<String> PLUGINS_TAB = new PlaceholderKey<>(String.class, "navPluginsTabs"); public static final PlaceholderKey<String> PLUGINS_TAB = new PlaceholderKey<>(String.class, "tabsPlugins");
public static final PlaceholderKey<String> PLUGINS_TAB_NAV = new PlaceholderKey<>(String.class, "tabsPlugins"); public static final PlaceholderKey<String> PLUGINS_TAB_NAV = new PlaceholderKey<>(String.class, "navPluginsTabs");
// Formatted time values // Formatted time values
public static final PlaceholderKey<String> REFRESH_TIME_F = CommonPlaceholderKeys.REFRESH_TIME_F; public static final PlaceholderKey<String> REFRESH_TIME_F = CommonPlaceholderKeys.REFRESH_TIME_F;
public static final PlaceholderKey<String> LAST_PEAK_TIME_F = CommonPlaceholderKeys.LAST_PEAK_TIME_F; public static final PlaceholderKey<String> LAST_PEAK_TIME_F = CommonPlaceholderKeys.LAST_PEAK_TIME_F;

View File

@ -1,10 +1,15 @@
package com.djrapitops.plan.data.store.mutators; package com.djrapitops.plan.data.store.mutators;
import com.djrapitops.plan.data.container.Session;
import com.djrapitops.plan.data.store.containers.DataContainer; import com.djrapitops.plan.data.store.containers.DataContainer;
import com.djrapitops.plan.data.store.keys.PlayerKeys;
import com.djrapitops.plan.system.settings.Settings; import com.djrapitops.plan.system.settings.Settings;
import com.djrapitops.plan.utilities.FormatUtils; import com.djrapitops.plan.utilities.FormatUtils;
import com.djrapitops.plugin.api.TimeAmount; import com.djrapitops.plugin.api.TimeAmount;
import java.util.List;
import java.util.Optional;
public class ActivityIndex { public class ActivityIndex {
private final double value; private final double value;
@ -34,10 +39,18 @@ public class ActivityIndex {
long activePlayThreshold = loadSetting(Settings.ACTIVE_PLAY_THRESHOLD.getNumber() * TimeAmount.MINUTE.ms()); long activePlayThreshold = loadSetting(Settings.ACTIVE_PLAY_THRESHOLD.getNumber() * TimeAmount.MINUTE.ms());
int activeLoginThreshold = loadSetting(Settings.ACTIVE_LOGIN_THRESHOLD.getNumber()); int activeLoginThreshold = loadSetting(Settings.ACTIVE_LOGIN_THRESHOLD.getNumber());
SessionsMutator sessionsMutator = SessionsMutator.forContainer(container); Optional<List<Session>> sessionsValue = container.getValue(PlayerKeys.SESSIONS);
SessionsMutator weekOne = SessionsMutator.copyOf(sessionsMutator).filterSessionsBetween(weekAgo, date); if (!sessionsValue.isPresent()) {
SessionsMutator weekTwo = SessionsMutator.copyOf(sessionsMutator).filterSessionsBetween(twoWeeksAgo, weekAgo); return 0.0;
SessionsMutator weekThree = SessionsMutator.copyOf(sessionsMutator).filterSessionsBetween(threeWeeksAgo, twoWeeksAgo); }
SessionsMutator sessionsMutator = new SessionsMutator(sessionsValue.get());
if (sessionsMutator.all().isEmpty()) {
return 0.0;
}
SessionsMutator weekOne = sessionsMutator.filterSessionsBetween(weekAgo, date);
SessionsMutator weekTwo = sessionsMutator.filterSessionsBetween(twoWeeksAgo, weekAgo);
SessionsMutator weekThree = sessionsMutator.filterSessionsBetween(threeWeeksAgo, twoWeeksAgo);
// Playtime per week multipliers, max out to avoid too high values. // Playtime per week multipliers, max out to avoid too high values.
double max = 4.0; double max = 4.0;

View File

@ -29,10 +29,12 @@ public class HealthInformation {
public HealthInformation(AnalysisContainer analysisContainer) { public HealthInformation(AnalysisContainer analysisContainer) {
this.analysisContainer = analysisContainer; this.analysisContainer = analysisContainer;
this.notes = new ArrayList<>(); this.notes = new ArrayList<>();
calculate();
now = analysisContainer.getUnsafe(AnalysisKeys.ANALYSIS_TIME); now = analysisContainer.getUnsafe(AnalysisKeys.ANALYSIS_TIME);
fourWeeksAgo = analysisContainer.getUnsafe(AnalysisKeys.ANALYSIS_TIME_MONTH_AGO); fourWeeksAgo = analysisContainer.getUnsafe(AnalysisKeys.ANALYSIS_TIME_MONTH_AGO);
serverHealth = 100.0;
calculate();
} }
public String toHtml() { public String toHtml() {
@ -153,7 +155,7 @@ public class HealthInformation {
} }
private void activePlayerPlaytimeChange() { private void activePlayerPlaytimeChange() {
PlayersMutator currentlyActive = PlayersMutator.copyOf(analysisContainer.getUnsafe(AnalysisKeys.PLAYERS_MUTATOR)).filterActive(now, 1.75); PlayersMutator currentlyActive = analysisContainer.getUnsafe(AnalysisKeys.PLAYERS_MUTATOR).filterActive(now, 1.75);
long twoWeeksAgo = (now - (now - fourWeeksAgo)) / 2L; long twoWeeksAgo = (now - (now - fourWeeksAgo)) / 2L;
long totalFourToTwoWeeks = 0; long totalFourToTwoWeeks = 0;

View File

@ -37,42 +37,37 @@ public class PlayersMutator {
} }
public PlayersMutator filterPlayedBetween(long after, long before) { public PlayersMutator filterPlayedBetween(long after, long before) {
players = players.stream().filter(player -> return new PlayersMutator(players.stream().filter(player ->
player.getValue(PlayerKeys.SESSIONS) player.getValue(PlayerKeys.SESSIONS)
.map(sessions -> sessions.stream().anyMatch(session -> { .map(sessions -> sessions.stream().anyMatch(session -> {
long start = session.getValue(SessionKeys.START).orElse(-1L); long start = session.getValue(SessionKeys.START).orElse(-1L);
long end = session.getValue(SessionKeys.END).orElse(-1L); long end = session.getValue(SessionKeys.END).orElse(-1L);
return (after <= start && start <= before) || (after <= end && end <= before); return (after <= start && start <= before) || (after <= end && end <= before);
})).orElse(false) })).orElse(false)
).collect(Collectors.toList()); ).collect(Collectors.toList()));
return this;
} }
public PlayersMutator filterRegisteredBetween(long after, long before) { public PlayersMutator filterRegisteredBetween(long after, long before) {
players = players.stream().filter(player -> return new PlayersMutator(players.stream().filter(player ->
player.getValue(PlayerKeys.REGISTERED).map(date -> after <= date && date <= before).orElse(false) player.getValue(PlayerKeys.REGISTERED).map(date -> after <= date && date <= before).orElse(false)
).collect(Collectors.toList()); ).collect(Collectors.toList()));
return this;
} }
public PlayersMutator filterRetained(long after, long before) { public PlayersMutator filterRetained(long after, long before) {
players = players.stream() return new PlayersMutator(players.stream()
.filter(player -> { .filter(player -> {
long backLimit = Math.max(after, player.getValue(PlayerKeys.REGISTERED).orElse(0L)); long backLimit = Math.max(after, player.getValue(PlayerKeys.REGISTERED).orElse(0L));
long half = backLimit + ((before - backLimit) / 2L); long half = backLimit + ((before - backLimit) / 2L);
SessionsMutator firstHalf = SessionsMutator.forContainer(player); SessionsMutator sessionsMutator = SessionsMutator.forContainer(player);
SessionsMutator secondHalf = SessionsMutator.copyOf(firstHalf); return !sessionsMutator.playedBetween(backLimit, half) && !sessionsMutator.playedBetween(half, before);
return !firstHalf.playedBetween(backLimit, half) && !secondHalf.playedBetween(half, before);
}) })
.collect(Collectors.toList()); .collect(Collectors.toList()));
return this;
} }
public PlayersMutator filterActive(long date, double limit) { public PlayersMutator filterActive(long date, double limit) {
players = players.stream() return new PlayersMutator(players.stream()
.filter(player -> new ActivityIndex(player, date).getValue() >= limit) .filter(player -> player.getActivityIndex(date).getValue() >= limit)
.collect(Collectors.toList()); .collect(Collectors.toList()));
return this;
} }
public List<PlayerContainer> all() { public List<PlayerContainer> all() {
@ -102,8 +97,8 @@ public class PlayersMutator {
TreeMap<Long, Map<String, Set<UUID>>> activityData = new TreeMap<>(); TreeMap<Long, Map<String, Set<UUID>>> activityData = new TreeMap<>();
if (!players.isEmpty()) { if (!players.isEmpty()) {
for (PlayerContainer player : players) { for (PlayerContainer player : players) {
for (long time = date; time >= time - TimeAmount.MONTH.ms() * 2L; time -= TimeAmount.WEEK.ms()) { for (long time = date; time >= date - TimeAmount.MONTH.ms() * 2L; time -= TimeAmount.WEEK.ms()) {
ActivityIndex activityIndex = new ActivityIndex(player, time); ActivityIndex activityIndex = player.getActivityIndex(time);
String activityGroup = activityIndex.getGroup(); String activityGroup = activityIndex.getGroup();
Map<String, Set<UUID>> map = activityData.getOrDefault(time, new HashMap<>()); Map<String, Set<UUID>> map = activityData.getOrDefault(time, new HashMap<>());

View File

@ -41,10 +41,9 @@ public class SessionsMutator {
} }
public SessionsMutator filterSessionsBetween(long after, long before) { public SessionsMutator filterSessionsBetween(long after, long before) {
sessions = sessions.stream() return new SessionsMutator(sessions.stream()
.filter(getBetweenPredicate(after, before)) .filter(getBetweenPredicate(after, before))
.collect(Collectors.toList()); .collect(Collectors.toList()));
return this;
} }
public WorldTimes toTotalWorldTimes() { public WorldTimes toTotalWorldTimes() {

View File

@ -4,6 +4,7 @@ import com.djrapitops.plan.data.container.TPS;
import com.djrapitops.plan.data.store.containers.DataContainer; import com.djrapitops.plan.data.store.containers.DataContainer;
import com.djrapitops.plan.data.store.keys.ServerKeys; import com.djrapitops.plan.data.store.keys.ServerKeys;
import com.djrapitops.plan.system.settings.Settings; import com.djrapitops.plan.system.settings.Settings;
import com.djrapitops.plan.utilities.FormatUtils;
import com.djrapitops.plan.utilities.html.graphs.line.Point; import com.djrapitops.plan.utilities.html.graphs.line.Point;
import com.djrapitops.plugin.api.TimeAmount; import com.djrapitops.plugin.api.TimeAmount;
@ -36,10 +37,9 @@ public class TPSMutator {
} }
public TPSMutator filterDataBetween(long after, long before) { public TPSMutator filterDataBetween(long after, long before) {
tpsData = tpsData.stream() return new TPSMutator(tpsData.stream()
.filter(tps -> tps.getDate() >= after && tps.getDate() <= before) .filter(tps -> tps.getDate() >= after && tps.getDate() <= before)
.collect(Collectors.toList()); .collect(Collectors.toList()));
return this;
} }
public List<TPS> all() { public List<TPS> all() {
@ -171,7 +171,7 @@ public class TPSMutator {
.filter(num -> num >= 0) .filter(num -> num >= 0)
.average(); .average();
if (average.isPresent()) { if (average.isPresent()) {
return average.getAsDouble(); return Double.parseDouble(FormatUtils.cutDecimals(average.getAsDouble()));
} }
return -1; return -1;
} }
@ -182,7 +182,7 @@ public class TPSMutator {
.filter(num -> num >= 0) .filter(num -> num >= 0)
.average(); .average();
if (average.isPresent()) { if (average.isPresent()) {
return average.getAsDouble(); return Double.parseDouble(FormatUtils.cutDecimals(average.getAsDouble()));
} }
return -1; return -1;
} }
@ -193,7 +193,7 @@ public class TPSMutator {
.filter(num -> num >= 0) .filter(num -> num >= 0)
.average(); .average();
if (average.isPresent()) { if (average.isPresent()) {
return average.getAsDouble(); return Double.parseDouble(FormatUtils.cutDecimals(average.getAsDouble()));
} }
return -1; return -1;
} }
@ -204,7 +204,7 @@ public class TPSMutator {
.filter(num -> num >= 0) .filter(num -> num >= 0)
.average(); .average();
if (average.isPresent()) { if (average.isPresent()) {
return average.getAsDouble(); return Double.parseDouble(FormatUtils.cutDecimals(average.getAsDouble()));
} }
return -1; return -1;
} }
@ -215,7 +215,7 @@ public class TPSMutator {
.filter(num -> num >= 0) .filter(num -> num >= 0)
.average(); .average();
if (average.isPresent()) { if (average.isPresent()) {
return average.getAsDouble(); return Double.parseDouble(FormatUtils.cutDecimals(average.getAsDouble()));
} }
return -1; return -1;
} }

View File

@ -2,6 +2,7 @@ package com.djrapitops.plan.data.store.mutators.formatting;
import com.djrapitops.plan.data.store.objects.DateHolder; import com.djrapitops.plan.data.store.objects.DateHolder;
import com.djrapitops.plan.utilities.FormatUtils; import com.djrapitops.plan.utilities.FormatUtils;
import com.djrapitops.plugin.api.TimeAmount;
import java.util.Calendar; import java.util.Calendar;
import java.util.function.Function; import java.util.function.Function;
@ -68,4 +69,14 @@ public class Formatters {
public static Formatter<Double> percentage() { public static Formatter<Double> percentage() {
return value -> value >= 0 ? FormatUtils.cutDecimals(value * 100.0) + "%" : "-"; return value -> value >= 0 ? FormatUtils.cutDecimals(value * 100.0) + "%" : "-";
} }
public static Formatter<Long> benchmark() {
return ns -> {
if (ns > TimeAmount.MILLISECOND.ns() * 5L) {
return (ns / TimeAmount.MILLISECOND.ns()) + "ms";
} else {
return 1.0 * ns / TimeAmount.MILLISECOND.ns() + "ms";
}
};
}
} }

View File

@ -2,6 +2,7 @@ package com.djrapitops.plan.data.store.mutators.formatting;
import com.djrapitops.plan.data.store.PlaceholderKey; import com.djrapitops.plan.data.store.PlaceholderKey;
import com.djrapitops.plan.data.store.containers.DataContainer; import com.djrapitops.plan.data.store.containers.DataContainer;
import com.djrapitops.plugin.api.utility.log.Log;
import org.apache.commons.text.StringSubstitutor; import org.apache.commons.text.StringSubstitutor;
import java.io.Serializable; import java.io.Serializable;
@ -18,7 +19,11 @@ public class PlaceholderReplacer extends HashMap<String, Serializable> implement
if (!container.supports(key)) { if (!container.supports(key)) {
return; return;
} }
long ns = System.nanoTime();
Log.debug(key.getPlaceholder());
put(key.getPlaceholder(), container.getSupplier(key).get().toString()); put(key.getPlaceholder(), container.getSupplier(key).get().toString());
ns = System.nanoTime() - ns;
Log.debug(key.getPlaceholder() + ": " + Formatters.benchmark().apply(ns));
} }
public void addAllPlaceholdersFrom(DataContainer container, PlaceholderKey... keys) { public void addAllPlaceholdersFrom(DataContainer container, PlaceholderKey... keys) {

View File

@ -127,6 +127,8 @@ public class SQLFetchOps extends SQLOps implements FetchOperations {
container.putSupplier(PlayerKeys.PLAYER_KILL_COUNT, container.getUnsafe(PlayerKeys.PLAYER_KILLS)::size); container.putSupplier(PlayerKeys.PLAYER_KILL_COUNT, container.getUnsafe(PlayerKeys.PLAYER_KILLS)::size);
container.putSupplier(PlayerKeys.MOB_KILL_COUNT, SessionsMutator.forContainer(container)::toMobKillCount); container.putSupplier(PlayerKeys.MOB_KILL_COUNT, SessionsMutator.forContainer(container)::toMobKillCount);
container.putSupplier(PlayerKeys.DEATH_COUNT, SessionsMutator.forContainer(container)::toDeathCount); container.putSupplier(PlayerKeys.DEATH_COUNT, SessionsMutator.forContainer(container)::toDeathCount);
containers.add(container);
} }
return containers; return containers;

View File

@ -71,6 +71,10 @@ public class NicknamesTable extends UserIDTable {
RunnableFactory.createNew(new AbsRunnable("DB version 18->19") { RunnableFactory.createNew(new AbsRunnable("DB version 18->19") {
@Override @Override
public void run() { public void run() {
// Create actions table if version 18 transfer is run concurrently.
execute("CREATE TABLE IF NOT EXISTS plan_actions " +
"(action_id integer, date bigint, server_id integer, user_id integer, additional_info varchar(1))");
Map<Integer, UUID> serverUUIDsByID = serverTable.getServerUUIDsByID(); Map<Integer, UUID> serverUUIDsByID = serverTable.getServerUUIDsByID();
Map<UUID, Integer> serverIDsByUUID = new HashMap<>(); Map<UUID, Integer> serverIDsByUUID = new HashMap<>();
for (Map.Entry<Integer, UUID> entry : serverUUIDsByID.entrySet()) { for (Map.Entry<Integer, UUID> entry : serverUUIDsByID.entrySet()) {
@ -125,7 +129,7 @@ public class NicknamesTable extends UserIDTable {
}); });
db.setVersion(19); db.setVersion(19);
execute("DROP TABLE plan_actions"); executeUnsafe("DROP TABLE plan_actions");
} }
}).runTaskAsynchronously(); }).runTaskAsynchronously();
} }

View File

@ -48,7 +48,6 @@ public class Version8TransferTable extends TransferTable {
db.getWorldTable().createTable(); db.getWorldTable().createTable();
db.getWorldTimesTable().createTable(); db.getWorldTimesTable().createTable();
dropTable("plan_actions");
dropTable("plan_gamemodetimes"); dropTable("plan_gamemodetimes");
dropTable("temp_nicks"); dropTable("temp_nicks");
dropTable("temp_kills"); dropTable("temp_kills");

View File

@ -160,9 +160,9 @@ public class InspectPage extends Page {
long weekAgo = now - TimeAmount.WEEK.ms(); long weekAgo = now - TimeAmount.WEEK.ms();
long monthAgo = now - TimeAmount.MONTH.ms(); long monthAgo = now - TimeAmount.MONTH.ms();
SessionsMutator daySessionsMutator = SessionsMutator.copyOf(sessionsMutator).filterSessionsBetween(dayAgo, now); SessionsMutator daySessionsMutator = sessionsMutator.filterSessionsBetween(dayAgo, now);
SessionsMutator weekSessionsMutator = SessionsMutator.copyOf(sessionsMutator).filterSessionsBetween(weekAgo, now); SessionsMutator weekSessionsMutator = sessionsMutator.filterSessionsBetween(weekAgo, now);
SessionsMutator monthSessionsMutator = SessionsMutator.copyOf(sessionsMutator).filterSessionsBetween(monthAgo, now); SessionsMutator monthSessionsMutator = sessionsMutator.filterSessionsBetween(monthAgo, now);
long playtime = sessionsMutator.toPlaytime(); long playtime = sessionsMutator.toPlaytime();
long playtimeDay = daySessionsMutator.toPlaytime(); long playtimeDay = daySessionsMutator.toPlaytime();
@ -247,7 +247,7 @@ public class InspectPage extends Page {
addValue("mobKillCount", mobKillCount); addValue("mobKillCount", mobKillCount);
addValue("deathCount", deathCount); addValue("deathCount", deathCount);
ActivityIndex activityIndex = new ActivityIndex(container, now); ActivityIndex activityIndex = container.getActivityIndex(now);
addValue("activityIndexNumber", activityIndex.getFormattedValue()); addValue("activityIndexNumber", activityIndex.getFormattedValue());
addValue("activityIndexColor", activityIndex.getColor()); addValue("activityIndexColor", activityIndex.getColor());

View File

@ -70,7 +70,7 @@ public class PlayersTable extends TableContainer {
long registered = player.getValue(PlayerKeys.REGISTERED).orElse(0L); long registered = player.getValue(PlayerKeys.REGISTERED).orElse(0L);
long lastSeen = sessionsMutator.toLastSeen(); long lastSeen = sessionsMutator.toLastSeen();
ActivityIndex activityIndex = new ActivityIndex(player, now); ActivityIndex activityIndex = player.getActivityIndex(now);
boolean isBanned = player.getValue(PlayerKeys.BANNED).orElse(false); boolean isBanned = player.getValue(PlayerKeys.BANNED).orElse(false);
String activityString = activityIndex.getFormattedValue() String activityString = activityIndex.getFormattedValue()
+ (isBanned ? " (<b>Banned</b>)" : " (" + activityIndex.getGroup() + ")"); + (isBanned ? " (<b>Banned</b>)" : " (" + activityIndex.getGroup() + ")");