Fixed some minor code smells

This commit is contained in:
Rsl1122 2019-07-13 10:50:21 +03:00
parent 27e5436785
commit 524e598664
17 changed files with 38 additions and 40 deletions

View File

@ -38,7 +38,15 @@ public class PlayerContainer {
this.container = container;
}
/**
* @deprecated loginThreshold no longer used for activity index.
*/
@Deprecated
public double getActivityIndex(long date, long playtimeMsThreshold, int loginThreshold) {
return getActivityIndex(date, playtimeMsThreshold);
}
public double getActivityIndex(long date, long playtimeMsThreshold) {
return container.getActivityIndex(date, playtimeMsThreshold).getValue();
}

View File

@ -66,7 +66,8 @@ public class AnalyzeCommand extends CommandNode {
Processing processing,
HtmlExport export,
ServerInfo serverInfo,
ConnectionSystem connectionSystem, WebServer webServer,
ConnectionSystem connectionSystem,
WebServer webServer,
DBSystem dbSystem,
ErrorHandler errorHandler
) {

View File

@ -255,8 +255,7 @@ public class AnalysisContainer extends DynamicDataContainer {
putCachingSupplier(retentionDay, () -> getUnsafe(AnalysisKeys.PLAYERS_MUTATOR).compareAndFindThoseLikelyToBeRetained(
getUnsafe(newDay).all(), getUnsafe(AnalysisKeys.ANALYSIS_TIME_MONTH_AGO),
getUnsafe(AnalysisKeys.PLAYERS_ONLINE_RESOLVER),
config.get(TimeSettings.ACTIVE_PLAY_THRESHOLD),
config.get(TimeSettings.ACTIVE_LOGIN_THRESHOLD)
config.get(TimeSettings.ACTIVE_PLAY_THRESHOLD)
).count()
);
putSupplier(AnalysisKeys.PLAYERS_RETAINED_DAY, () -> {

View File

@ -109,11 +109,11 @@ public class ActivityIndex {
long playtime2 = weekTwo.toActivePlaytime();
long playtime3 = weekThree.toActivePlaytime();
double A1 = 1.0 / (Math.PI / 2.0 * (playtime1 * 1.0 / playtimeMsThreshold) + 1.0);
double A2 = 1.0 / (Math.PI / 2.0 * (playtime2 * 1.0 / playtimeMsThreshold) + 1.0);
double A3 = 1.0 / (Math.PI / 2.0 * (playtime3 * 1.0 / playtimeMsThreshold) + 1.0);
double indexW1 = 1.0 / (Math.PI / 2.0 * (playtime1 * 1.0 / playtimeMsThreshold) + 1.0);
double indexW2 = 1.0 / (Math.PI / 2.0 * (playtime2 * 1.0 / playtimeMsThreshold) + 1.0);
double indexW3 = 1.0 / (Math.PI / 2.0 * (playtime3 * 1.0 / playtimeMsThreshold) + 1.0);
double average = (A1 + A2 + A3) / 3.0;
double average = (indexW1 + indexW2 + indexW3) / 3.0;
return 5.0 - (5.0 * average);
}

View File

@ -86,7 +86,7 @@ public class PlayersMutator {
);
}
public PlayersMutator filterActive(long date, long msThreshold, int loginThreshold, double limit) {
public PlayersMutator filterActive(long date, long msThreshold, double limit) {
return filterBy(player -> player.getActivityIndex(date, msThreshold).getValue() >= limit);
}
@ -199,8 +199,7 @@ public class PlayersMutator {
Iterable<PlayerContainer> compareTo,
long dateLimit,
PlayersOnlineResolver onlineResolver,
long activityMsThreshold,
int activityLoginThreshold
long activityMsThreshold
) {
Collection<PlayerContainer> retainedAfterMonth = new ArrayList<>();
Collection<PlayerContainer> notRetainedAfterMonth = new ArrayList<>();

View File

@ -140,7 +140,7 @@ public abstract class AbstractHealthInfo {
}
protected void activePlayerPlaytimeChange(PlayersMutator playersMutator) {
PlayersMutator currentlyActive = playersMutator.filterActive(now, activeMsThreshold, activeLoginThreshold, 1.75);
PlayersMutator currentlyActive = playersMutator.filterActive(now, activeMsThreshold, 1.75);
long twoWeeksAgo = now - ((now - monthAgo) / 2L);
long totalFourToTwoWeeks = 0;

View File

@ -16,6 +16,7 @@
*/
package com.djrapitops.plan.data.store.objects;
import java.util.Map;
import java.util.TreeMap;
/**
@ -29,7 +30,7 @@ public class DateMap<T> extends TreeMap<Long, T> {
super(Long::compareTo);
}
public DateMap(TreeMap<Long, T> map) {
public DateMap(Map<Long, T> map) {
putAll(map);
}

View File

@ -66,6 +66,10 @@ import static com.djrapitops.plan.db.sql.parsing.Sql.*;
*/
public class ActivityIndexQueries {
private ActivityIndexQueries() {
// Static method class
}
public static Query<Integer> fetchRegularPlayerCount(long date, UUID serverUUID, long playtimeThreshold) {
return fetchActivityGroupCount(date, serverUUID, playtimeThreshold, ActivityIndex.REGULAR, 5.1);
}

View File

@ -21,7 +21,6 @@ import com.djrapitops.plan.system.export.HtmlExport;
import com.djrapitops.plan.system.export.JSONExport;
import com.djrapitops.plan.system.info.InfoSystem;
import com.djrapitops.plan.system.info.connection.ConnectionSystem;
import com.djrapitops.plan.system.info.connection.WebExceptionLogger;
import com.djrapitops.plan.system.info.server.ServerInfo;
import com.djrapitops.plan.system.processing.Processing;
import com.djrapitops.plan.system.settings.config.PlanConfig;
@ -48,7 +47,6 @@ public class InfoRequestFactory {
private final Lazy<Processing> processing;
private final Lazy<InfoSystem> infoSystem;
private final Lazy<ConnectionSystem> connectionSystem;
private final Lazy<WebExceptionLogger> webExceptionLogger;
private final Lazy<ServerInfo> serverInfo;
private final Lazy<ResponseFactory> responseFactory;
private final Lazy<PageFactory> pageFactory;
@ -64,7 +62,6 @@ public class InfoRequestFactory {
Lazy<Processing> processing,
Lazy<InfoSystem> infoSystem,
Lazy<ConnectionSystem> connectionSystem,
Lazy<WebExceptionLogger> webExceptionLogger,
Lazy<ServerInfo> serverInfo,
Lazy<ResponseFactory> responseFactory,
Lazy<PageFactory> pageFactory,
@ -78,7 +75,6 @@ public class InfoRequestFactory {
this.processing = processing;
this.infoSystem = infoSystem;
this.connectionSystem = connectionSystem;
this.webExceptionLogger = webExceptionLogger;
this.serverInfo = serverInfo;
this.responseFactory = responseFactory;
this.pageFactory = pageFactory;

View File

@ -66,7 +66,6 @@ public class JSONFactory {
public String serverPlayersTableJSON(UUID serverUUID) {
Integer xMostRecentPlayers = config.get(DisplaySettings.PLAYERS_PER_SERVER_PAGE);
Integer loginThreshold = config.get(TimeSettings.ACTIVE_LOGIN_THRESHOLD);
Long playtimeThreshold = config.get(TimeSettings.ACTIVE_PLAY_THRESHOLD);
Boolean openPlayerLinksInNewTab = config.get(DisplaySettings.OPEN_PLAYER_LINKS_IN_NEW_TAB);
@ -75,7 +74,7 @@ public class JSONFactory {
return new PlayersTableJSONParser(
database.query(new ServerPlayersTableContainersQuery(serverUUID)),
database.query(new ExtensionServerPlayerDataTableQuery(serverUUID, xMostRecentPlayers)),
xMostRecentPlayers, playtimeThreshold, loginThreshold, openPlayerLinksInNewTab,
xMostRecentPlayers, playtimeThreshold, openPlayerLinksInNewTab,
formatters
).toJSONString();
}

View File

@ -50,7 +50,6 @@ public class PlayersTableJSONParser {
private final int maxPlayers;
private final long activeMsThreshold;
private final int activeLoginThreshold;
private final boolean openPlayerPageInNewTab;
private Map<FormatType, Formatter<Long>> numberFormatters;
@ -62,7 +61,7 @@ public class PlayersTableJSONParser {
List<PlayerContainer> players,
Map<UUID, ExtensionTabData> extensionData,
// Settings
int maxPlayers, long activeMsThreshold, int activeLoginThreshold, boolean openPlayerPageInNewTab,
int maxPlayers, long activeMsThreshold, boolean openPlayerPageInNewTab,
// Formatters
Formatters formatters
) {
@ -77,7 +76,6 @@ public class PlayersTableJSONParser {
// Settings
this.maxPlayers = maxPlayers;
this.activeMsThreshold = activeMsThreshold;
this.activeLoginThreshold = activeLoginThreshold;
this.openPlayerPageInNewTab = openPlayerPageInNewTab;
// Formatters
numberFormatters = new EnumMap<>(FormatType.class);

View File

@ -64,4 +64,15 @@ public class Trend {
return null;
}
public String getText() {
return text;
}
public String getDirection() {
return direction;
}
public boolean isReversed() {
return reversed;
}
}

View File

@ -22,10 +22,8 @@ import com.djrapitops.plan.api.exceptions.connection.WebException;
import com.djrapitops.plan.db.Database;
import com.djrapitops.plan.db.access.queries.objects.ServerQueries;
import com.djrapitops.plan.system.database.DBSystem;
import com.djrapitops.plan.system.info.InfoSystem;
import com.djrapitops.plan.system.info.server.Server;
import com.djrapitops.plan.system.info.server.ServerInfo;
import com.djrapitops.plan.system.processing.Processing;
import com.djrapitops.plan.system.webserver.Request;
import com.djrapitops.plan.system.webserver.RequestTarget;
import com.djrapitops.plan.system.webserver.auth.Authentication;
@ -47,25 +45,19 @@ import java.util.UUID;
@Singleton
public class ServerPageHandler implements PageHandler {
private final Processing processing;
private final ResponseFactory responseFactory;
private final DBSystem dbSystem;
private final ServerInfo serverInfo;
private final InfoSystem infoSystem;
@Inject
public ServerPageHandler(
Processing processing,
ResponseFactory responseFactory,
DBSystem dbSystem,
ServerInfo serverInfo,
InfoSystem infoSystem
ServerInfo serverInfo
) {
this.processing = processing;
this.responseFactory = responseFactory;
this.dbSystem = dbSystem;
this.serverInfo = serverInfo;
this.infoSystem = infoSystem;
}
@Override

View File

@ -18,7 +18,6 @@ package com.djrapitops.plan.utilities.html.pages;
import com.djrapitops.plan.api.exceptions.connection.NotFoundException;
import com.djrapitops.plan.data.plugin.HookHandler;
import com.djrapitops.plan.data.store.containers.AnalysisContainer;
import com.djrapitops.plan.data.store.containers.NetworkContainer;
import com.djrapitops.plan.data.store.containers.PlayerContainer;
import com.djrapitops.plan.db.Database;
@ -68,7 +67,6 @@ public class PageFactory {
private final Lazy<HtmlTables> tables;
private final Lazy<Accordions> accordions;
private final Lazy<Formatters> formatters;
private final Lazy<AnalysisContainer.Factory> analysisContainerFactory;
private final Lazy<AnalysisPluginsTabContentCreator> analysisPluginsTabContentCreator;
private final Lazy<HookHandler> hookHandler;
private final Lazy<DebugLogger> debugLogger;
@ -88,7 +86,6 @@ public class PageFactory {
Lazy<HtmlTables> tables,
Lazy<Accordions> accordions,
Lazy<Formatters> formatters,
Lazy<AnalysisContainer.Factory> analysisContainerFactory,
Lazy<AnalysisPluginsTabContentCreator> analysisPluginsTabContentCreator,
Lazy<HookHandler> hookHandler,
Lazy<DebugLogger> debugLogger,
@ -106,7 +103,6 @@ public class PageFactory {
this.tables = tables;
this.accordions = accordions;
this.formatters = formatters;
this.analysisContainerFactory = analysisContainerFactory;
this.analysisPluginsTabContentCreator = analysisPluginsTabContentCreator;
this.hookHandler = hookHandler;
this.debugLogger = debugLogger;

View File

@ -156,7 +156,6 @@ public class HtmlTables {
players,
config.get(DisplaySettings.PLAYERS_PER_SERVER_PAGE),
config.get(TimeSettings.ACTIVE_PLAY_THRESHOLD),
config.get(TimeSettings.ACTIVE_LOGIN_THRESHOLD),
config.get(DisplaySettings.OPEN_PLAYER_LINKS_IN_NEW_TAB),
formatters.timeAmount(), formatters.yearLong(), formatters.decimals()
);
@ -172,7 +171,6 @@ public class HtmlTables {
return new PlayersTable(
players, config.get(DisplaySettings.PLAYERS_PER_PLAYERS_PAGE),
config.get(TimeSettings.ACTIVE_PLAY_THRESHOLD),
config.get(TimeSettings.ACTIVE_LOGIN_THRESHOLD),
config.get(DisplaySettings.OPEN_PLAYER_LINKS_IN_NEW_TAB),
formatters.timeAmount(), formatters.yearLong(), formatters.decimals()
);

View File

@ -42,7 +42,6 @@ class PlayersTable extends TableContainer {
private final List<PlayerContainer> players;
private final int maxPlayers;
private final long activeMsThreshold;
private final int activeLoginThreshold;
private final boolean openPlayerPageInNewTab;
private final Formatter<Double> decimalFormatter;
@ -51,7 +50,6 @@ class PlayersTable extends TableContainer {
List<PlayerContainer> players,
int maxPlayers,
long activeMsThreshold,
int activeLoginThreshold,
boolean openPlayerPageInNewTab,
Formatter<Long> timeAmountFormatter,
Formatter<Long> yearLongFormatter,
@ -69,7 +67,6 @@ class PlayersTable extends TableContainer {
this.players = players;
this.maxPlayers = maxPlayers;
this.activeMsThreshold = activeMsThreshold;
this.activeLoginThreshold = activeLoginThreshold;
this.openPlayerPageInNewTab = openPlayerPageInNewTab;
this.decimalFormatter = decimalFormatter;
useJqueryDataTables("player-table");

View File

@ -66,7 +66,6 @@ class PlayersTableTest {
players,
50, // maxPlayers
TimeUnit.MINUTES.toMillis(60), // activeMsThreshold
5, // activeLoginThreshold
false,
l -> "",
l -> "",