mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-01-08 09:27:45 +01:00
[Debt] Added thresholds to ActivityIndex methods
This required addition of PlanConfig in some places to obtain the values
This commit is contained in:
parent
6bb24c3903
commit
51e2d6fe91
@ -16,6 +16,8 @@ import com.djrapitops.plan.system.locale.lang.DeepHelpLang;
|
||||
import com.djrapitops.plan.system.locale.lang.GenericLang;
|
||||
import com.djrapitops.plan.system.processing.Processing;
|
||||
import com.djrapitops.plan.system.settings.Permissions;
|
||||
import com.djrapitops.plan.system.settings.Settings;
|
||||
import com.djrapitops.plan.system.settings.config.PlanConfig;
|
||||
import com.djrapitops.plan.utilities.MiscUtils;
|
||||
import com.djrapitops.plan.utilities.formatting.Formatter;
|
||||
import com.djrapitops.plan.utilities.formatting.Formatters;
|
||||
@ -44,6 +46,7 @@ public class QInspectCommand extends CommandNode {
|
||||
|
||||
private final Locale locale;
|
||||
private final Database database;
|
||||
private final PlanConfig config;
|
||||
private final Processing processing;
|
||||
private final Formatters formatters;
|
||||
private final UUIDUtility uuidUtility;
|
||||
@ -51,6 +54,7 @@ public class QInspectCommand extends CommandNode {
|
||||
|
||||
@Inject
|
||||
public QInspectCommand(
|
||||
PlanConfig config,
|
||||
Locale locale,
|
||||
Processing processing,
|
||||
Database database,
|
||||
@ -59,6 +63,7 @@ public class QInspectCommand extends CommandNode {
|
||||
ErrorHandler errorHandler
|
||||
) {
|
||||
super("qinspect", Permissions.QUICK_INSPECT.getPermission(), CommandType.PLAYER_OR_ARGS);
|
||||
this.config = config;
|
||||
this.processing = processing;
|
||||
this.formatters = formatters;
|
||||
setArguments("<player>");
|
||||
@ -115,7 +120,11 @@ public class QInspectCommand extends CommandNode {
|
||||
|
||||
String playerName = player.getValue(PlayerKeys.NAME).orElse(locale.getString(GenericLang.UNKNOWN));
|
||||
|
||||
ActivityIndex activityIndex = player.getActivityIndex(now);
|
||||
ActivityIndex activityIndex = player.getActivityIndex(
|
||||
now,
|
||||
config.getNumber(Settings.ACTIVE_PLAY_THRESHOLD),
|
||||
config.getNumber(Settings.ACTIVE_LOGIN_THRESHOLD)
|
||||
);
|
||||
Long registered = player.getValue(PlayerKeys.REGISTERED).orElse(0L);
|
||||
Long lastSeen = player.getValue(PlayerKeys.LAST_SEEN).orElse(0L);
|
||||
List<GeoInfo> geoInfo = player.getValue(PlayerKeys.GEO_INFO).orElse(new ArrayList<>());
|
||||
|
@ -358,7 +358,7 @@ public class AnalysisContainer extends DataContainer {
|
||||
getUnsafe(AnalysisKeys.NEW_PLAYERS_PER_DAY)
|
||||
).toCalendarSeries());
|
||||
|
||||
putSupplier(AnalysisKeys.ACTIVITY_DATA, () -> getUnsafe(AnalysisKeys.PLAYERS_MUTATOR).toActivityDataMap(getUnsafe(AnalysisKeys.ANALYSIS_TIME)));
|
||||
putSupplier(AnalysisKeys.ACTIVITY_DATA, () -> getUnsafe(AnalysisKeys.PLAYERS_MUTATOR).toActivityDataMap(getUnsafe(AnalysisKeys.ANALYSIS_TIME), config.getNumber(Settings.ACTIVE_PLAY_THRESHOLD), config.getNumber(Settings.ACTIVE_LOGIN_THRESHOLD)));
|
||||
Key<StackGraph> activityStackGraph = new Key<>(StackGraph.class, "ACTIVITY_STACK_GRAPH");
|
||||
putSupplier(activityStackGraph, () -> graphs.stack().activityStackGraph(getUnsafe(AnalysisKeys.ACTIVITY_DATA)));
|
||||
putSupplier(AnalysisKeys.ACTIVITY_STACK_CATEGORIES, () -> getUnsafe(activityStackGraph).toHighChartsLabels());
|
||||
|
@ -117,7 +117,7 @@ public class NetworkContainer extends DataContainer {
|
||||
graphs.line().playersOnlineGraph(TPSMutator.forContainer(bungeeContainer)).toHighChartsSeries()
|
||||
);
|
||||
Key<StackGraph> activityStackGraph = new Key<>(StackGraph.class, "ACTIVITY_STACK_GRAPH");
|
||||
putSupplier(NetworkKeys.ACTIVITY_DATA, () -> getUnsafe(NetworkKeys.PLAYERS_MUTATOR).toActivityDataMap(getUnsafe(NetworkKeys.REFRESH_TIME)));
|
||||
putSupplier(NetworkKeys.ACTIVITY_DATA, () -> getUnsafe(NetworkKeys.PLAYERS_MUTATOR).toActivityDataMap(getUnsafe(NetworkKeys.REFRESH_TIME), config.getNumber(Settings.ACTIVE_PLAY_THRESHOLD), config.getNumber(Settings.ACTIVE_LOGIN_THRESHOLD)));
|
||||
putSupplier(activityStackGraph, () -> graphs.stack().activityStackGraph(getUnsafe(NetworkKeys.ACTIVITY_DATA)));
|
||||
putSupplier(NetworkKeys.ACTIVITY_STACK_CATEGORIES, () -> getUnsafe(activityStackGraph).toHighChartsLabels());
|
||||
putSupplier(NetworkKeys.ACTIVITY_STACK_SERIES, () -> getUnsafe(activityStackGraph).toHighChartsSeries());
|
||||
|
@ -22,9 +22,8 @@ public class PlayerContainer extends DataContainer {
|
||||
activityIndexCache = new HashMap<>();
|
||||
}
|
||||
|
||||
public ActivityIndex getActivityIndex(long date) {
|
||||
// TODO Thresholds from settings
|
||||
return activityIndexCache.computeIfAbsent(date, time -> new ActivityIndex(this, time, 1, 1));
|
||||
public ActivityIndex getActivityIndex(long date, int minuteThreshold, int loginThreshold) {
|
||||
return activityIndexCache.computeIfAbsent(date, time -> new ActivityIndex(this, time, minuteThreshold, loginThreshold));
|
||||
}
|
||||
|
||||
public boolean playedBetween(long after, long before) {
|
||||
|
@ -19,9 +19,9 @@ public class ActivityIndex {
|
||||
|
||||
public ActivityIndex(
|
||||
DataContainer container, long date,
|
||||
int playThreshold, int loginThreshold
|
||||
int minuteThreshold, int loginThreshold
|
||||
) {
|
||||
this.playThreshold = playThreshold;
|
||||
this.playThreshold = minuteThreshold;
|
||||
this.loginThreshold = loginThreshold;
|
||||
|
||||
value = calculate(container, date);
|
||||
|
@ -70,8 +70,8 @@ public class PlayersMutator {
|
||||
);
|
||||
}
|
||||
|
||||
public PlayersMutator filterActive(long date, double limit) {
|
||||
return filterBy(player -> player.getActivityIndex(date).getValue() >= limit);
|
||||
public PlayersMutator filterActive(long date, int minuteThreshold, int loginThreshold, double limit) {
|
||||
return filterBy(player -> player.getActivityIndex(date, minuteThreshold, loginThreshold).getValue() >= limit);
|
||||
}
|
||||
|
||||
public PlayersMutator filterPlayedOnServer(UUID serverUUID) {
|
||||
@ -123,7 +123,7 @@ public class PlayersMutator {
|
||||
return pingPerCountry;
|
||||
}
|
||||
|
||||
public TreeMap<Long, Map<String, Set<UUID>>> toActivityDataMap(long date) {
|
||||
public TreeMap<Long, Map<String, Set<UUID>>> toActivityDataMap(long date, int minuteThreshold, int loginThreshold) {
|
||||
TreeMap<Long, Map<String, Set<UUID>>> activityData = new TreeMap<>();
|
||||
for (long time = date; time >= date - TimeAmount.MONTH.toMillis(2L); time -= TimeAmount.WEEK.toMillis(1L)) {
|
||||
Map<String, Set<UUID>> map = activityData.getOrDefault(time, new HashMap<>());
|
||||
@ -132,7 +132,7 @@ public class PlayersMutator {
|
||||
if (player.getValue(PlayerKeys.REGISTERED).orElse(0L) > time) {
|
||||
continue;
|
||||
}
|
||||
ActivityIndex activityIndex = player.getActivityIndex(time);
|
||||
ActivityIndex activityIndex = player.getActivityIndex(time, minuteThreshold, loginThreshold);
|
||||
String activityGroup = activityIndex.getGroup();
|
||||
|
||||
Set<UUID> uuids = map.getOrDefault(activityGroup, new HashSet<>());
|
||||
|
@ -20,6 +20,8 @@ public abstract class AbstractHealthInfo {
|
||||
protected double serverHealth;
|
||||
|
||||
// TODO
|
||||
protected int activeMinuteThreshold;
|
||||
protected int activeLoginThreshold;
|
||||
protected Formatter<Long> timeAmountFormatter;
|
||||
protected Formatter<Double> decimalFormatter;
|
||||
protected Formatter<Double> percentageFormatter;
|
||||
@ -102,7 +104,7 @@ public abstract class AbstractHealthInfo {
|
||||
}
|
||||
|
||||
protected void activePlayerPlaytimeChange(PlayersMutator playersMutator) {
|
||||
PlayersMutator currentlyActive = playersMutator.filterActive(now, 1.75);
|
||||
PlayersMutator currentlyActive = playersMutator.filterActive(now, activeMinuteThreshold, activeLoginThreshold, 1.75);
|
||||
long twoWeeksAgo = (now - (now - monthAgo)) / 2L;
|
||||
|
||||
long totalFourToTwoWeeks = 0;
|
||||
|
@ -7,6 +7,7 @@ package com.djrapitops.plan.system.settings.config;
|
||||
import com.djrapitops.plan.api.exceptions.EnableException;
|
||||
import com.djrapitops.plan.system.file.PlanFiles;
|
||||
import com.djrapitops.plan.system.settings.theme.Theme;
|
||||
import com.djrapitops.plugin.logging.console.PluginLogger;
|
||||
import com.djrapitops.plugin.logging.error.ErrorHandler;
|
||||
|
||||
import javax.inject.Inject;
|
||||
@ -28,9 +29,10 @@ public class BukkitConfigSystem extends ConfigSystem {
|
||||
PlanFiles files,
|
||||
PlanConfig config,
|
||||
Theme theme,
|
||||
PluginLogger logger,
|
||||
ErrorHandler errorHandler
|
||||
) {
|
||||
super(files, config, theme, errorHandler);
|
||||
super(files, config, theme, logger, errorHandler);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -7,6 +7,7 @@ package com.djrapitops.plan.system.settings.config;
|
||||
import com.djrapitops.plan.api.exceptions.EnableException;
|
||||
import com.djrapitops.plan.system.file.PlanFiles;
|
||||
import com.djrapitops.plan.system.settings.theme.Theme;
|
||||
import com.djrapitops.plugin.logging.console.PluginLogger;
|
||||
import com.djrapitops.plugin.logging.error.ErrorHandler;
|
||||
|
||||
import javax.inject.Inject;
|
||||
@ -28,9 +29,10 @@ public class BungeeConfigSystem extends ConfigSystem {
|
||||
PlanFiles files,
|
||||
PlanConfig config,
|
||||
Theme theme,
|
||||
PluginLogger logger,
|
||||
ErrorHandler errorHandler
|
||||
) {
|
||||
super(files, config, theme, errorHandler);
|
||||
super(files, config, theme, logger, errorHandler);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -31,7 +31,7 @@ public abstract class ConfigSystem implements SubSystem {
|
||||
protected final PlanFiles files;
|
||||
protected final PlanConfig config;
|
||||
protected final Theme theme;
|
||||
private final PluginLogger logger;
|
||||
protected final PluginLogger logger;
|
||||
protected final ErrorHandler errorHandler;
|
||||
|
||||
public ConfigSystem(
|
||||
|
@ -19,8 +19,6 @@ import java.io.IOException;
|
||||
@Singleton
|
||||
public class SpongeConfigSystem extends BukkitConfigSystem {
|
||||
|
||||
private final PluginLogger logger;
|
||||
|
||||
private boolean firstInstall;
|
||||
|
||||
@Inject
|
||||
@ -31,8 +29,7 @@ public class SpongeConfigSystem extends BukkitConfigSystem {
|
||||
PluginLogger logger,
|
||||
ErrorHandler errorHandler
|
||||
) {
|
||||
super(files, config, theme, errorHandler);
|
||||
this.logger = logger;
|
||||
super(files, config, theme, logger, errorHandler);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -214,7 +214,9 @@ public class InspectPage implements Page {
|
||||
|
||||
pvpAndPve(replacer, sessionsMutator, weekSessionsMutator, monthSessionsMutator);
|
||||
|
||||
ActivityIndex activityIndex = player.getActivityIndex(now);
|
||||
ActivityIndex activityIndex = player.getActivityIndex(
|
||||
now, config.getNumber(Settings.ACTIVE_PLAY_THRESHOLD), config.getNumber(Settings.ACTIVE_LOGIN_THRESHOLD)
|
||||
);
|
||||
|
||||
replacer.put("activityIndexNumber", activityIndex.getFormattedValue(decimalFormatter));
|
||||
replacer.put("activityIndexColor", activityIndex.getColor());
|
||||
|
@ -136,7 +136,10 @@ public class HtmlTables {
|
||||
*/
|
||||
public TableContainer playerTableForServerPage(List<PlayerContainer> players) {
|
||||
return new PlayersTable(
|
||||
players, config.getNumber(Settings.MAX_PLAYERS),
|
||||
players,
|
||||
config.getNumber(Settings.MAX_PLAYERS),
|
||||
config.getNumber(Settings.ACTIVE_PLAY_THRESHOLD),
|
||||
config.getNumber(Settings.ACTIVE_LOGIN_THRESHOLD),
|
||||
formatters.timeAmount(), formatters.yearLong(), formatters.decimals()
|
||||
);
|
||||
}
|
||||
@ -150,7 +153,7 @@ public class HtmlTables {
|
||||
public TableContainer playerTableForPlayersPage(List<PlayerContainer> players) {
|
||||
return new PlayersTable(
|
||||
players, config.getNumber(Settings.MAX_PLAYERS_PLAYERS_PAGE),
|
||||
formatters.timeAmount(), formatters.yearLong(), formatters.decimals()
|
||||
config.getNumber(Settings.ACTIVE_PLAY_THRESHOLD), config.getNumber(Settings.ACTIVE_LOGIN_THRESHOLD), formatters.timeAmount(), formatters.yearLong(), formatters.decimals()
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -25,11 +25,16 @@ class PlayersTable extends TableContainer {
|
||||
|
||||
private final List<PlayerContainer> players;
|
||||
private final int maxPlayers;
|
||||
private final int activeMinuteThreshold;
|
||||
private final int activeLoginThreshold;
|
||||
|
||||
private final Formatter<Double> decimalFormatter;
|
||||
|
||||
PlayersTable(
|
||||
List<PlayerContainer> players,
|
||||
int maxPlayers,
|
||||
int activeMinuteThreshold,
|
||||
int activeLoginThreshold,
|
||||
Formatter<Long> timeAmountFormatter,
|
||||
Formatter<Long> yearLongFormatter,
|
||||
Formatter<Double> decimalFormatter
|
||||
@ -45,6 +50,8 @@ class PlayersTable extends TableContainer {
|
||||
);
|
||||
this.players = players;
|
||||
this.maxPlayers = maxPlayers;
|
||||
this.activeMinuteThreshold = activeMinuteThreshold;
|
||||
this.activeLoginThreshold = activeLoginThreshold;
|
||||
this.decimalFormatter = decimalFormatter;
|
||||
useJqueryDataTables("player-table");
|
||||
|
||||
@ -74,7 +81,7 @@ class PlayersTable extends TableContainer {
|
||||
long registered = player.getValue(PlayerKeys.REGISTERED).orElse(0L);
|
||||
long lastSeen = sessionsMutator.toLastSeen();
|
||||
|
||||
ActivityIndex activityIndex = player.getActivityIndex(now);
|
||||
ActivityIndex activityIndex = player.getActivityIndex(now, activeMinuteThreshold, activeLoginThreshold);
|
||||
boolean isBanned = player.getValue(PlayerKeys.BANNED).orElse(false);
|
||||
String activityString = activityIndex.getFormattedValue(decimalFormatter)
|
||||
+ (isBanned ? " (<b>Banned</b>)" : " (" + activityIndex.getGroup() + ")");
|
||||
|
@ -36,7 +36,7 @@ public class PlayersTableTest {
|
||||
PlayerContainer container = new PlayerContainer();
|
||||
container.putRawData(PlayerKeys.SESSIONS, new ArrayList<>());
|
||||
List<PlayerContainer> players = Collections.singletonList(container);
|
||||
String html = new PlayersTable(players, 50, l -> "", l -> "", d -> "").parseHtml();
|
||||
String html = new PlayersTable(players, 50, 60, 5, l -> "", l -> "", d -> "").parseHtml();
|
||||
|
||||
testHtmlValidity(html);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user