mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-10-29 23:09:42 +01:00
[Debt] Removed Settings getNumber method
Some threshold values are needed in mutators and tasks, but they are not yet available in the classes they are used. TODO was added. ActivityIndexTest was removed as it does not test proper stuff. Affected issues: none
This commit is contained in:
parent
b6cc713c01
commit
2b1cf4b3cb
@ -398,19 +398,21 @@ public class AnalysisContainer extends DataContainer {
|
|||||||
|
|
||||||
putSupplier(AnalysisKeys.PLAYERS_ONLINE_RESOLVER, () -> new PlayersOnlineResolver(getUnsafe(AnalysisKeys.TPS_MUTATOR)));
|
putSupplier(AnalysisKeys.PLAYERS_ONLINE_RESOLVER, () -> new PlayersOnlineResolver(getUnsafe(AnalysisKeys.TPS_MUTATOR)));
|
||||||
|
|
||||||
putSupplier(AnalysisKeys.TPS_SPIKE_MONTH, () -> getUnsafe(tpsMonth).lowTpsSpikeCount());
|
int threshold = 5; //TODO LOW TPS Threshold from Settings;
|
||||||
|
|
||||||
|
putSupplier(AnalysisKeys.TPS_SPIKE_MONTH, () -> getUnsafe(tpsMonth).lowTpsSpikeCount(threshold));
|
||||||
putSupplier(AnalysisKeys.AVG_TPS_MONTH, () -> getUnsafe(tpsMonth).averageTPS());
|
putSupplier(AnalysisKeys.AVG_TPS_MONTH, () -> getUnsafe(tpsMonth).averageTPS());
|
||||||
putSupplier(AnalysisKeys.AVG_CPU_MONTH, () -> getUnsafe(tpsMonth).averageCPU());
|
putSupplier(AnalysisKeys.AVG_CPU_MONTH, () -> getUnsafe(tpsMonth).averageCPU());
|
||||||
putSupplier(AnalysisKeys.AVG_RAM_MONTH, () -> getUnsafe(tpsMonth).averageRAM());
|
putSupplier(AnalysisKeys.AVG_RAM_MONTH, () -> getUnsafe(tpsMonth).averageRAM());
|
||||||
putSupplier(AnalysisKeys.AVG_ENTITY_MONTH, () -> getUnsafe(tpsMonth).averageEntities());
|
putSupplier(AnalysisKeys.AVG_ENTITY_MONTH, () -> getUnsafe(tpsMonth).averageEntities());
|
||||||
putSupplier(AnalysisKeys.AVG_CHUNK_MONTH, () -> getUnsafe(tpsMonth).averageChunks());
|
putSupplier(AnalysisKeys.AVG_CHUNK_MONTH, () -> getUnsafe(tpsMonth).averageChunks());
|
||||||
putSupplier(AnalysisKeys.TPS_SPIKE_WEEK, () -> getUnsafe(tpsWeek).lowTpsSpikeCount());
|
putSupplier(AnalysisKeys.TPS_SPIKE_WEEK, () -> getUnsafe(tpsWeek).lowTpsSpikeCount(threshold));
|
||||||
putSupplier(AnalysisKeys.AVG_TPS_WEEK, () -> getUnsafe(tpsWeek).averageTPS());
|
putSupplier(AnalysisKeys.AVG_TPS_WEEK, () -> getUnsafe(tpsWeek).averageTPS());
|
||||||
putSupplier(AnalysisKeys.AVG_CPU_WEEK, () -> getUnsafe(tpsWeek).averageCPU());
|
putSupplier(AnalysisKeys.AVG_CPU_WEEK, () -> getUnsafe(tpsWeek).averageCPU());
|
||||||
putSupplier(AnalysisKeys.AVG_RAM_WEEK, () -> getUnsafe(tpsWeek).averageRAM());
|
putSupplier(AnalysisKeys.AVG_RAM_WEEK, () -> getUnsafe(tpsWeek).averageRAM());
|
||||||
putSupplier(AnalysisKeys.AVG_ENTITY_WEEK, () -> getUnsafe(tpsWeek).averageEntities());
|
putSupplier(AnalysisKeys.AVG_ENTITY_WEEK, () -> getUnsafe(tpsWeek).averageEntities());
|
||||||
putSupplier(AnalysisKeys.AVG_CHUNK_WEEK, () -> getUnsafe(tpsWeek).averageChunks());
|
putSupplier(AnalysisKeys.AVG_CHUNK_WEEK, () -> getUnsafe(tpsWeek).averageChunks());
|
||||||
putSupplier(AnalysisKeys.TPS_SPIKE_DAY, () -> getUnsafe(tpsDay).lowTpsSpikeCount());
|
putSupplier(AnalysisKeys.TPS_SPIKE_DAY, () -> getUnsafe(tpsDay).lowTpsSpikeCount(threshold));
|
||||||
putSupplier(AnalysisKeys.AVG_TPS_DAY, () -> getUnsafe(tpsDay).averageTPS());
|
putSupplier(AnalysisKeys.AVG_TPS_DAY, () -> getUnsafe(tpsDay).averageTPS());
|
||||||
putSupplier(AnalysisKeys.AVG_CPU_DAY, () -> getUnsafe(tpsDay).averageCPU());
|
putSupplier(AnalysisKeys.AVG_CPU_DAY, () -> getUnsafe(tpsDay).averageCPU());
|
||||||
putSupplier(AnalysisKeys.AVG_RAM_DAY, () -> getUnsafe(tpsDay).averageRAM());
|
putSupplier(AnalysisKeys.AVG_RAM_DAY, () -> getUnsafe(tpsDay).averageRAM());
|
||||||
|
@ -23,7 +23,8 @@ public class PlayerContainer extends DataContainer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ActivityIndex getActivityIndex(long date) {
|
public ActivityIndex getActivityIndex(long date) {
|
||||||
return activityIndexCache.computeIfAbsent(date, time -> new ActivityIndex(this, time));
|
// TODO Thresholds from settings
|
||||||
|
return activityIndexCache.computeIfAbsent(date, time -> new ActivityIndex(this, time, 1, 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean playedBetween(long after, long before) {
|
public boolean playedBetween(long after, long before) {
|
||||||
|
@ -3,18 +3,27 @@ package com.djrapitops.plan.data.store.mutators;
|
|||||||
import com.djrapitops.plan.data.container.Session;
|
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.data.store.keys.PlayerKeys;
|
||||||
import com.djrapitops.plan.system.settings.Settings;
|
|
||||||
import com.djrapitops.plan.utilities.formatting.Formatter;
|
import com.djrapitops.plan.utilities.formatting.Formatter;
|
||||||
import com.djrapitops.plugin.api.TimeAmount;
|
import com.djrapitops.plugin.api.TimeAmount;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
public class ActivityIndex {
|
public class ActivityIndex {
|
||||||
|
|
||||||
private final double value;
|
private final double value;
|
||||||
|
|
||||||
public ActivityIndex(DataContainer container, long date) {
|
private final int playThreshold;
|
||||||
|
private final int loginThreshold;
|
||||||
|
|
||||||
|
public ActivityIndex(
|
||||||
|
DataContainer container, long date,
|
||||||
|
int playThreshold, int loginThreshold
|
||||||
|
) {
|
||||||
|
this.playThreshold = playThreshold;
|
||||||
|
this.loginThreshold = loginThreshold;
|
||||||
|
|
||||||
value = calculate(container, date);
|
value = calculate(container, date);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -22,22 +31,14 @@ public class ActivityIndex {
|
|||||||
return new String[]{"Very Active", "Active", "Regular", "Irregular", "Inactive"};
|
return new String[]{"Very Active", "Active", "Regular", "Irregular", "Inactive"};
|
||||||
}
|
}
|
||||||
|
|
||||||
private long loadSetting(long value) {
|
|
||||||
return value <= 0 ? 1 : value;
|
|
||||||
}
|
|
||||||
|
|
||||||
private int loadSetting(int value) {
|
|
||||||
return value <= 0 ? 1 : value;
|
|
||||||
}
|
|
||||||
|
|
||||||
private double calculate(DataContainer container, long date) {
|
private double calculate(DataContainer container, long date) {
|
||||||
long week = TimeAmount.WEEK.ms();
|
long week = TimeAmount.WEEK.ms();
|
||||||
long weekAgo = date - week;
|
long weekAgo = date - week;
|
||||||
long twoWeeksAgo = date - 2L * week;
|
long twoWeeksAgo = date - 2L * week;
|
||||||
long threeWeeksAgo = date - 3L * week;
|
long threeWeeksAgo = date - 3L * week;
|
||||||
|
|
||||||
long activePlayThreshold = loadSetting(Settings.ACTIVE_PLAY_THRESHOLD.getNumber() * TimeAmount.MINUTE.ms());
|
long activePlayThreshold = TimeUnit.MINUTES.toMillis(playThreshold);
|
||||||
int activeLoginThreshold = loadSetting(Settings.ACTIVE_LOGIN_THRESHOLD.getNumber());
|
int activeLoginThreshold = loginThreshold;
|
||||||
|
|
||||||
Optional<List<Session>> sessionsValue = container.getValue(PlayerKeys.SESSIONS);
|
Optional<List<Session>> sessionsValue = container.getValue(PlayerKeys.SESSIONS);
|
||||||
if (!sessionsValue.isPresent()) {
|
if (!sessionsValue.isPresent()) {
|
||||||
|
@ -48,7 +48,8 @@ public class RetentionData {
|
|||||||
public RetentionData(PlayerContainer player, PlayersOnlineResolver onlineOnJoin) {
|
public RetentionData(PlayerContainer player, PlayersOnlineResolver onlineOnJoin) {
|
||||||
Optional<Long> registeredValue = player.getValue(PlayerKeys.REGISTERED);
|
Optional<Long> registeredValue = player.getValue(PlayerKeys.REGISTERED);
|
||||||
activityIndex = registeredValue
|
activityIndex = registeredValue
|
||||||
.map(registered -> new ActivityIndex(player, registered + TimeAmount.DAY.ms()).getValue())
|
// TODO Thresholds from settings
|
||||||
|
.map(registered -> new ActivityIndex(player, registered + TimeAmount.DAY.ms(), 1, 1).getValue())
|
||||||
.orElse(0.0);
|
.orElse(0.0);
|
||||||
this.onlineOnJoin = registeredValue
|
this.onlineOnJoin = registeredValue
|
||||||
.map(registered -> onlineOnJoin.getOnlineOn(registered).orElse(-1))
|
.map(registered -> onlineOnJoin.getOnlineOn(registered).orElse(-1))
|
||||||
|
@ -3,7 +3,6 @@ package com.djrapitops.plan.data.store.mutators;
|
|||||||
import com.djrapitops.plan.data.container.TPS;
|
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.utilities.comparators.TPSComparator;
|
import com.djrapitops.plan.utilities.comparators.TPSComparator;
|
||||||
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;
|
||||||
@ -134,13 +133,11 @@ public class TPSMutator {
|
|||||||
return idleTime;
|
return idleTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double percentageTPSAboveLowThreshold() {
|
public double percentageTPSAboveThreshold(int threshold) {
|
||||||
if (tpsData.isEmpty()) {
|
if (tpsData.isEmpty()) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int threshold = Settings.THEME_GRAPH_TPS_THRESHOLD_MED.getNumber();
|
|
||||||
|
|
||||||
long count = 0;
|
long count = 0;
|
||||||
for (TPS tps : tpsData) {
|
for (TPS tps : tpsData) {
|
||||||
if (tps.getTicksPerSecond() >= threshold) {
|
if (tps.getTicksPerSecond() >= threshold) {
|
||||||
@ -151,15 +148,13 @@ public class TPSMutator {
|
|||||||
return count * 1.0 / tpsData.size();
|
return count * 1.0 / tpsData.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int lowTpsSpikeCount() {
|
public int lowTpsSpikeCount(int threshold) {
|
||||||
int mediumThreshold = Settings.THEME_GRAPH_TPS_THRESHOLD_MED.getNumber();
|
|
||||||
|
|
||||||
boolean wasLow = false;
|
boolean wasLow = false;
|
||||||
int spikeCount = 0;
|
int spikeCount = 0;
|
||||||
|
|
||||||
for (TPS tpsObj : tpsData) {
|
for (TPS tpsObj : tpsData) {
|
||||||
double tps = tpsObj.getTicksPerSecond();
|
double tps = tpsObj.getTicksPerSecond();
|
||||||
if (tps < mediumThreshold) {
|
if (tps < threshold) {
|
||||||
if (!wasLow) {
|
if (!wasLow) {
|
||||||
spikeCount++;
|
spikeCount++;
|
||||||
wasLow = true;
|
wasLow = true;
|
||||||
|
@ -10,7 +10,6 @@ import com.djrapitops.plan.data.store.keys.AnalysisKeys;
|
|||||||
import com.djrapitops.plan.data.store.mutators.PlayersMutator;
|
import com.djrapitops.plan.data.store.mutators.PlayersMutator;
|
||||||
import com.djrapitops.plan.data.store.mutators.PlayersOnlineResolver;
|
import com.djrapitops.plan.data.store.mutators.PlayersOnlineResolver;
|
||||||
import com.djrapitops.plan.data.store.mutators.TPSMutator;
|
import com.djrapitops.plan.data.store.mutators.TPSMutator;
|
||||||
import com.djrapitops.plan.system.settings.Settings;
|
|
||||||
import com.djrapitops.plan.utilities.html.icon.Icons;
|
import com.djrapitops.plan.utilities.html.icon.Icons;
|
||||||
import com.djrapitops.plugin.api.TimeAmount;
|
import com.djrapitops.plugin.api.TimeAmount;
|
||||||
|
|
||||||
@ -91,7 +90,10 @@ public class HealthInformation extends AbstractHealthInfo {
|
|||||||
Key<TPSMutator> tpsMonth = new Key<>(TPSMutator.class, "TPS_MONTH");
|
Key<TPSMutator> tpsMonth = new Key<>(TPSMutator.class, "TPS_MONTH");
|
||||||
TPSMutator tpsMutator = analysisContainer.getUnsafe(tpsMonth);
|
TPSMutator tpsMutator = analysisContainer.getUnsafe(tpsMonth);
|
||||||
long serverDownTime = tpsMutator.serverDownTime();
|
long serverDownTime = tpsMutator.serverDownTime();
|
||||||
double aboveThreshold = tpsMutator.percentageTPSAboveLowThreshold();
|
|
||||||
|
int threshold = 5; // TODO TPS THRESHOLD from settings
|
||||||
|
|
||||||
|
double aboveThreshold = tpsMutator.percentageTPSAboveThreshold(threshold);
|
||||||
long tpsSpikeMonth = analysisContainer.getValue(AnalysisKeys.TPS_SPIKE_MONTH).orElse(0);
|
long tpsSpikeMonth = analysisContainer.getValue(AnalysisKeys.TPS_SPIKE_MONTH).orElse(0);
|
||||||
|
|
||||||
String avgLowThresholdString = "<br> ";
|
String avgLowThresholdString = "<br> ";
|
||||||
@ -107,7 +109,6 @@ public class HealthInformation extends AbstractHealthInfo {
|
|||||||
avgLowThresholdString += " Average TPS was above Low Threshold "
|
avgLowThresholdString += " Average TPS was above Low Threshold "
|
||||||
+ decimalFormatter.apply(aboveThreshold * 100.0) + "% of the time";
|
+ decimalFormatter.apply(aboveThreshold * 100.0) + "% of the time";
|
||||||
|
|
||||||
int threshold = Settings.THEME_GRAPH_TPS_THRESHOLD_MED.getNumber();
|
|
||||||
if (tpsSpikeMonth <= 5) {
|
if (tpsSpikeMonth <= 5) {
|
||||||
addNote(Icons.GREEN_THUMB + " Average TPS dropped below Low Threshold (" + threshold + ")" +
|
addNote(Icons.GREEN_THUMB + " Average TPS dropped below Low Threshold (" + threshold + ")" +
|
||||||
" " + tpsSpikeMonth + " times" +
|
" " + tpsSpikeMonth + " times" +
|
||||||
|
@ -73,8 +73,10 @@ public class FileSystem implements SubSystem {
|
|||||||
Verify.isTrue((configFile.exists() && configFile.isFile()) || configFile.createNewFile(),
|
Verify.isTrue((configFile.exists() && configFile.isFile()) || configFile.createNewFile(),
|
||||||
() -> new EnableException("Could not create config file at " + configFile.getAbsolutePath()));
|
() -> new EnableException("Could not create config file at " + configFile.getAbsolutePath()));
|
||||||
|
|
||||||
|
// TODO Log Keep Day threshold from Settings
|
||||||
|
// TODO Move This task creation outside of FileSystem class
|
||||||
plugin.getRunnableFactory().create("Logs folder Clean Task",
|
plugin.getRunnableFactory().create("Logs folder Clean Task",
|
||||||
new LogsFolderCleanTask(getLogsFolder(), plugin.getPluginLogger())
|
new LogsFolderCleanTask(getLogsFolder(), 5, plugin.getPluginLogger())
|
||||||
).runTaskLaterAsynchronously(TimeAmount.toTicks(30L, TimeUnit.SECONDS));
|
).runTaskLaterAsynchronously(TimeAmount.toTicks(30L, TimeUnit.SECONDS));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new EnableException("Failed to create config.yml", e);
|
throw new EnableException("Failed to create config.yml", e);
|
||||||
|
@ -1,9 +1,6 @@
|
|||||||
package com.djrapitops.plan.system.settings;
|
package com.djrapitops.plan.system.settings;
|
||||||
|
|
||||||
import com.djrapitops.plan.system.settings.config.ConfigSystem;
|
|
||||||
import com.djrapitops.plan.system.settings.config.Setting;
|
import com.djrapitops.plan.system.settings.config.Setting;
|
||||||
import com.djrapitops.plugin.config.Config;
|
|
||||||
import com.djrapitops.plugin.utilities.Verify;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This enum contains all of the config settings used by the plugin for easier
|
* This enum contains all of the config settings used by the plugin for easier
|
||||||
@ -110,19 +107,6 @@ public enum Settings implements Setting {
|
|||||||
this.configPath = path;
|
this.configPath = path;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* If the settings is a number, this method should be used.
|
|
||||||
*
|
|
||||||
* @return Integer value of the config setting
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public int getNumber() {
|
|
||||||
if (tempValue != null) {
|
|
||||||
return (Integer) tempValue;
|
|
||||||
}
|
|
||||||
return getConfig().getInt(configPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used to get the String path of a the config setting eg.
|
* Used to get the String path of a the config setting eg.
|
||||||
* Settings.WebServer.Enabled
|
* Settings.WebServer.Enabled
|
||||||
@ -138,9 +122,4 @@ public enum Settings implements Setting {
|
|||||||
this.tempValue = value;
|
this.tempValue = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Config getConfig() {
|
|
||||||
Config config = ConfigSystem.getConfig_Old();
|
|
||||||
Verify.nullCheck(config, () -> new IllegalStateException("Settings are not supposed to be called before ConfigSystem is Enabled!"));
|
|
||||||
return config;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
package com.djrapitops.plan.system.tasks;
|
package com.djrapitops.plan.system.tasks;
|
||||||
|
|
||||||
import com.djrapitops.plan.system.settings.Settings;
|
|
||||||
import com.djrapitops.plugin.api.TimeAmount;
|
|
||||||
import com.djrapitops.plugin.logging.console.PluginLogger;
|
import com.djrapitops.plugin.logging.console.PluginLogger;
|
||||||
import com.djrapitops.plugin.task.AbsRunnable;
|
import com.djrapitops.plugin.task.AbsRunnable;
|
||||||
|
|
||||||
@ -9,6 +7,7 @@ import java.io.File;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Task in charge of removing old log files
|
* Task in charge of removing old log files
|
||||||
@ -17,11 +16,14 @@ import java.util.Objects;
|
|||||||
*/
|
*/
|
||||||
public class LogsFolderCleanTask extends AbsRunnable {
|
public class LogsFolderCleanTask extends AbsRunnable {
|
||||||
|
|
||||||
|
private final int keepLogDayThreshold;
|
||||||
|
|
||||||
private final File folder;
|
private final File folder;
|
||||||
private final PluginLogger logger;
|
private final PluginLogger logger;
|
||||||
|
|
||||||
public LogsFolderCleanTask(File folder, PluginLogger logger) {
|
public LogsFolderCleanTask(File folder, int keepLogDayThreshold, PluginLogger logger) {
|
||||||
this.folder = folder;
|
this.folder = folder;
|
||||||
|
this.keepLogDayThreshold = keepLogDayThreshold;
|
||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -42,8 +44,8 @@ public class LogsFolderCleanTask extends AbsRunnable {
|
|||||||
private void cleanFolder() {
|
private void cleanFolder() {
|
||||||
long now = System.currentTimeMillis();
|
long now = System.currentTimeMillis();
|
||||||
for (File file : Objects.requireNonNull(folder.listFiles())) {
|
for (File file : Objects.requireNonNull(folder.listFiles())) {
|
||||||
long forDaysMs = Settings.KEEP_LOGS_DAYS.getNumber() * TimeAmount.DAY.ms();
|
long forDaysMs = TimeUnit.DAYS.toMillis(keepLogDayThreshold);
|
||||||
if (now - file.lastModified() > (forDaysMs > 0 ? forDaysMs : TimeAmount.DAY.ms())) {
|
if (now - file.lastModified() > (forDaysMs > 0 ? forDaysMs : TimeUnit.DAYS.toMillis(1L))) {
|
||||||
try {
|
try {
|
||||||
Files.delete(file.toPath());
|
Files.delete(file.toPath());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
@ -1,125 +0,0 @@
|
|||||||
package com.djrapitops.plan.data.calculation;
|
|
||||||
|
|
||||||
import com.djrapitops.plan.data.container.Session;
|
|
||||||
import com.djrapitops.plan.data.store.containers.PlayerContainer;
|
|
||||||
import com.djrapitops.plan.data.store.keys.PlayerKeys;
|
|
||||||
import com.djrapitops.plan.data.store.mutators.ActivityIndex;
|
|
||||||
import com.djrapitops.plan.system.settings.Settings;
|
|
||||||
import com.djrapitops.plugin.api.TimeAmount;
|
|
||||||
import org.junit.BeforeClass;
|
|
||||||
import org.junit.ClassRule;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.rules.TemporaryFolder;
|
|
||||||
import utilities.TestConstants;
|
|
||||||
import utilities.mocks.SystemMockUtil;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import static junit.framework.TestCase.assertEquals;
|
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Test for ActivityIndex.
|
|
||||||
*
|
|
||||||
* @author Rsl1122
|
|
||||||
*/
|
|
||||||
public class ActivityIndexTest {
|
|
||||||
@ClassRule
|
|
||||||
public static TemporaryFolder temporaryFolder = new TemporaryFolder();
|
|
||||||
private static final UUID UUID = TestConstants.PLAYER_ONE_UUID;
|
|
||||||
private static final UUID SERVER_UUID = TestConstants.SERVER_UUID;
|
|
||||||
|
|
||||||
@BeforeClass
|
|
||||||
public static void setUpClass() throws Exception {
|
|
||||||
SystemMockUtil.setUp(temporaryFolder.getRoot()).enableConfigSystem();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testMaxActivityIndex() {
|
|
||||||
PlayerContainer container = new PlayerContainer();
|
|
||||||
List<Session> sessions = new ArrayList<>();
|
|
||||||
|
|
||||||
long date = System.currentTimeMillis();
|
|
||||||
long week = TimeAmount.WEEK.ms();
|
|
||||||
long weekAgo = date - week;
|
|
||||||
long twoWeeksAgo = date - 2L * week;
|
|
||||||
long threeWeeksAgo = date - 3L * week;
|
|
||||||
|
|
||||||
long requiredPlaytime = Settings.ACTIVE_PLAY_THRESHOLD.getNumber() * TimeAmount.MINUTE.ms();
|
|
||||||
int requiredLogins = Settings.ACTIVE_LOGIN_THRESHOLD.getNumber();
|
|
||||||
|
|
||||||
for (int i = 0; i < requiredLogins; i++) {
|
|
||||||
sessions.add(new Session(0, UUID, SERVER_UUID, weekAgo, weekAgo + requiredPlaytime * 4L, 0, 0, 0));
|
|
||||||
sessions.add(new Session(0, UUID, SERVER_UUID, twoWeeksAgo, twoWeeksAgo + requiredPlaytime * 4L, 0, 0, 0));
|
|
||||||
sessions.add(new Session(0, UUID, SERVER_UUID, threeWeeksAgo, threeWeeksAgo + requiredPlaytime * 4L, 0, 0, 0));
|
|
||||||
}
|
|
||||||
container.putRawData(PlayerKeys.SESSIONS, sessions);
|
|
||||||
|
|
||||||
assertEquals(5.0, new ActivityIndex(container, date).getValue());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testMaxActivityIndex2() {
|
|
||||||
PlayerContainer container = new PlayerContainer();
|
|
||||||
List<Session> sessions = new ArrayList<>();
|
|
||||||
|
|
||||||
long date = System.currentTimeMillis();
|
|
||||||
long week = TimeAmount.WEEK.ms();
|
|
||||||
long weekAgo = date - week;
|
|
||||||
long twoWeeksAgo = date - 2L * week;
|
|
||||||
long threeWeeksAgo = date - 3L * week;
|
|
||||||
|
|
||||||
long requiredPlaytime = Settings.ACTIVE_PLAY_THRESHOLD.getNumber() * TimeAmount.MINUTE.ms();
|
|
||||||
int requiredLogins = Settings.ACTIVE_LOGIN_THRESHOLD.getNumber();
|
|
||||||
|
|
||||||
for (int i = 0; i < requiredLogins * 2; i++) {
|
|
||||||
sessions.add(new Session(0, UUID, SERVER_UUID, weekAgo, weekAgo + requiredPlaytime * 3L, 0, 0, 0));
|
|
||||||
sessions.add(new Session(0, UUID, SERVER_UUID, twoWeeksAgo, twoWeeksAgo + requiredPlaytime * 3L, 0, 0, 0));
|
|
||||||
sessions.add(new Session(0, UUID, SERVER_UUID, threeWeeksAgo, threeWeeksAgo + requiredPlaytime * 3L, 0, 0, 0));
|
|
||||||
}
|
|
||||||
container.putRawData(PlayerKeys.SESSIONS, sessions);
|
|
||||||
assertTrue(container.supports(PlayerKeys.SESSIONS));
|
|
||||||
assertTrue(container.getValue(PlayerKeys.SESSIONS).isPresent());
|
|
||||||
|
|
||||||
assertEquals(5.0, new ActivityIndex(container, date).getValue());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testActivityIndexOne() {
|
|
||||||
PlayerContainer container = new PlayerContainer();
|
|
||||||
List<Session> sessions = new ArrayList<>();
|
|
||||||
|
|
||||||
long date = System.currentTimeMillis();
|
|
||||||
long week = TimeAmount.WEEK.ms();
|
|
||||||
long weekAgo = date - week;
|
|
||||||
long twoWeeksAgo = date - 2L * week;
|
|
||||||
long threeWeeksAgo = date - 3L * week;
|
|
||||||
|
|
||||||
int requiredLogins = Settings.ACTIVE_LOGIN_THRESHOLD.getNumber();
|
|
||||||
long requiredPlaytime = Settings.ACTIVE_PLAY_THRESHOLD.getNumber() * TimeAmount.MINUTE.ms() / requiredLogins;
|
|
||||||
|
|
||||||
for (int i = 0; i < requiredLogins; i++) {
|
|
||||||
sessions.add(new Session(i, UUID, SERVER_UUID, weekAgo, weekAgo + requiredPlaytime, 0, 0, 0));
|
|
||||||
sessions.add(new Session(i * 2, UUID, SERVER_UUID, twoWeeksAgo, twoWeeksAgo + requiredPlaytime, 0, 0, 0));
|
|
||||||
sessions.add(new Session(i * 3, UUID, SERVER_UUID, threeWeeksAgo, threeWeeksAgo + requiredPlaytime, 0, 0, 0));
|
|
||||||
}
|
|
||||||
container.putRawData(PlayerKeys.SESSIONS, sessions);
|
|
||||||
|
|
||||||
assertTrue(2.0 <= new ActivityIndex(container, date).getValue());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test(timeout = 500)
|
|
||||||
public void testTimeout() {
|
|
||||||
PlayerContainer container = new PlayerContainer();
|
|
||||||
List<Session> sessions = new ArrayList<>();
|
|
||||||
|
|
||||||
for (int i = 0; i < 5000; i++) {
|
|
||||||
sessions.add(new Session(0, UUID, SERVER_UUID, 0, 0, 0, 0, 0));
|
|
||||||
}
|
|
||||||
container.putRawData(PlayerKeys.SESSIONS, sessions);
|
|
||||||
|
|
||||||
new ActivityIndex(container, 0).getValue();
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user