mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-01-13 11:41:34 +01:00
Players Table Creator
This commit is contained in:
parent
0fd0cd38b9
commit
04eb62974f
@ -513,4 +513,31 @@ public class SessionsTable extends UserIDTable {
|
||||
close(set, statement);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Map<UUID, Long> getLastSeenForAllPlayers() throws SQLException {
|
||||
PreparedStatement statement = null;
|
||||
ResultSet set = null;
|
||||
try {
|
||||
String usersIDColumn = usersTable + "." + usersTable.getColumnID();
|
||||
String usersUUIDColumn = usersTable + "." + usersTable.getColumnUUID() + " as uuid";
|
||||
|
||||
statement = prepareStatement("SELECT" +
|
||||
" MAX(" + columnSessionEnd + ") as last_seen, " +
|
||||
usersUUIDColumn +
|
||||
" FROM " + tableName +
|
||||
" JOIN " + usersTable + " on " + usersIDColumn + "=" + columnUserID);
|
||||
statement.setFetchSize(5000);
|
||||
set = statement.executeQuery();
|
||||
Map<UUID, Long> lastSeenMap = new HashMap<>();
|
||||
while (set.next()) {
|
||||
UUID uuid = UUID.fromString(set.getString("uuid"));
|
||||
long lastSeen = set.getLong("last_seen");
|
||||
lastSeenMap.put(uuid, lastSeen);
|
||||
}
|
||||
return lastSeenMap;
|
||||
} finally {
|
||||
endTransaction(statement);
|
||||
close(set, statement);
|
||||
}
|
||||
}
|
||||
}
|
@ -25,11 +25,14 @@ import main.java.com.djrapitops.plan.systems.webserver.response.PlayersPageRespo
|
||||
import main.java.com.djrapitops.plan.systems.webserver.response.api.JsonResponse;
|
||||
import main.java.com.djrapitops.plan.utilities.Benchmark;
|
||||
import main.java.com.djrapitops.plan.utilities.MiscUtils;
|
||||
import main.java.com.djrapitops.plan.utilities.comparators.UserInfoLastPlayedComparator;
|
||||
import main.java.com.djrapitops.plan.utilities.html.HtmlUtils;
|
||||
import main.java.com.djrapitops.plan.utilities.html.tables.PlayersTableCreator;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.sql.SQLException;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@ -106,7 +109,7 @@ public class Analysis {
|
||||
*/
|
||||
public boolean analyzeData(List<TPS> tpsData, InformationManager infoManager, Database db) {
|
||||
try {
|
||||
// rawData.sort(new UserDataLastPlayedComparator());
|
||||
// rawData.sort(new UserInfoLastPlayedComparator());
|
||||
// List<UUID> uuids = rawData.stream().map(UserInfo::getUuid).collect(Collectors.toList());
|
||||
Benchmark.start("Create Empty dataset");
|
||||
DataCache dataCache = plugin.getDataCache();
|
||||
@ -131,10 +134,6 @@ public class Analysis {
|
||||
//TODO Fetch Size
|
||||
log(Locale.get(Msg.ANALYSIS_PHASE_START).parse(0, fetchPhaseLength));
|
||||
|
||||
// TODO Create playersTable
|
||||
// String playersTable = PlayersTableCreator.createSortablePlayersTable(rawData);
|
||||
// analysisData.setPlayersTable(playersTable);
|
||||
|
||||
fillDataset(analysisData, db);
|
||||
// Analyze
|
||||
analysisData.analyseData();
|
||||
@ -253,6 +252,19 @@ public class Analysis {
|
||||
Benchmark.start("Fetch Phase");
|
||||
try {
|
||||
List<UserInfo> userInfo = db.getUserInfoTable().getAllUserInfo();
|
||||
Map<UUID, UserInfo> mappedUserInfo = userInfo.stream().collect(Collectors.toMap(UserInfo::getUuid, Function.identity()));
|
||||
Map<UUID, Long> lastSeen = db.getSessionsTable().getLastSeenForAllPlayers();
|
||||
for (Map.Entry<UUID, Long> entry : lastSeen.entrySet()) {
|
||||
UserInfo user = mappedUserInfo.get(entry.getKey());
|
||||
if (user == null) {
|
||||
continue;
|
||||
}
|
||||
user.setLastSeen(entry.getValue());
|
||||
}
|
||||
userInfo.sort(new UserInfoLastPlayedComparator());
|
||||
|
||||
analysisData.setPlayersTable(PlayersTableCreator.createSortablePlayersTable(userInfo, joinInfo, geolocPart));
|
||||
|
||||
playerCount.addPlayers(userInfo.stream().map(UserInfo::getUuid).collect(Collectors.toSet()));
|
||||
|
||||
Map<UUID, Long> registered = userInfo.stream().collect(Collectors.toMap(UserInfo::getUuid, UserInfo::getRegistered));
|
||||
|
@ -327,4 +327,12 @@ public class AnalysisUtils {
|
||||
Optional<Session> longest = sessions.stream().sorted(new SessionLengthComparator()).findFirst();
|
||||
return longest.map(Session::getLength).orElse(0L);
|
||||
}
|
||||
|
||||
public static long getLastSeen(List<Session> userSessions) {
|
||||
OptionalLong max = userSessions.stream().mapToLong(Session::getSessionEnd).max();
|
||||
if (max.isPresent()) {
|
||||
return max.getAsLong();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ import java.util.Comparator;
|
||||
/**
|
||||
* @author Risto
|
||||
*/
|
||||
public class UserDataLastPlayedComparator implements Comparator<UserInfo> {
|
||||
public class UserInfoLastPlayedComparator implements Comparator<UserInfo> {
|
||||
|
||||
@Override
|
||||
public int compare(UserInfo u1, UserInfo u2) {
|
@ -1,14 +1,22 @@
|
||||
package main.java.com.djrapitops.plan.utilities.html.tables;
|
||||
|
||||
import main.java.com.djrapitops.plan.data.Session;
|
||||
import main.java.com.djrapitops.plan.data.UserInfo;
|
||||
import main.java.com.djrapitops.plan.data.analysis.GeolocationPart;
|
||||
import main.java.com.djrapitops.plan.data.analysis.JoinInfoPart;
|
||||
import main.java.com.djrapitops.plan.utilities.FormatUtils;
|
||||
import main.java.com.djrapitops.plan.utilities.MiscUtils;
|
||||
import main.java.com.djrapitops.plan.utilities.analysis.AnalysisUtils;
|
||||
import main.java.com.djrapitops.plan.utilities.html.Html;
|
||||
import main.java.com.djrapitops.plan.utilities.html.HtmlUtils;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @author Rsl1122
|
||||
*/
|
||||
// TODO Rewrite!
|
||||
public class PlayersTableCreator {
|
||||
|
||||
/**
|
||||
@ -18,37 +26,52 @@ public class PlayersTableCreator {
|
||||
throw new IllegalStateException("Utility class");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param data The list of the {@link UserInfo} Objects from which the players table should be created
|
||||
* @return The created players table
|
||||
*/
|
||||
public static String createSortablePlayersTable(List<UserInfo> data) {
|
||||
public static String createSortablePlayersTable(List<UserInfo> userInfo, JoinInfoPart joinInfoPart, GeolocationPart geolocationPart) {
|
||||
StringBuilder html = new StringBuilder();
|
||||
|
||||
Map<UUID, List<Session>> sessions = joinInfoPart.getSessions();
|
||||
Map<UUID, String> geoLocations = geolocationPart.getMostCommonGeoLocations();
|
||||
|
||||
long now = MiscUtils.getTime();
|
||||
|
||||
int i = 0;
|
||||
for (UserInfo uData : data) {
|
||||
for (UserInfo user : userInfo) {
|
||||
if (i >= 750) {
|
||||
break;
|
||||
}
|
||||
|
||||
try {
|
||||
// boolean isBanned = uData.isBanned();
|
||||
// boolean isUnknown = uData.getLoginTimes() == 1;
|
||||
// boolean isActive = AnalysisUtils.isActive(now, uData.getLastPlayed(), uData.getPlayTime(), uData.getLoginTimes());
|
||||
//
|
||||
// String activityString = getActivityString(isBanned, isUnknown, isActive);
|
||||
//
|
||||
// html.append(Html.TABLELINE_PLAYERS.parse(
|
||||
// Html.LINK.parse(HtmlUtils.getRelativeInspectUrl(uData.getName()), uData.getName()),
|
||||
// activityString,
|
||||
// String.valueOf(uData.getPlayTime()), FormatUtils.formatTimeAmount(uData.getPlayTime()),
|
||||
// String.valueOf(uData.getLoginTimes()),
|
||||
// String.valueOf(uData.getRegistered()), FormatUtils.formatTimeStampYear(uData.getRegistered()),
|
||||
// String.valueOf(uData.getLastPlayed()), FormatUtils.formatTimeStamp(uData.getLastPlayed()),
|
||||
// String.valueOf(uData.getGeolocations()) //TODO get last Geoloc
|
||||
// ));
|
||||
UUID uuid = user.getUuid();
|
||||
boolean isBanned = user.isBanned();
|
||||
List<Session> userSessions = sessions.get(uuid);
|
||||
int loginTimes = 0;
|
||||
if (userSessions != null) {
|
||||
loginTimes = userSessions.size();
|
||||
}
|
||||
boolean isUnknown = loginTimes == 1;
|
||||
long registered = user.getRegistered();
|
||||
long playtime = AnalysisUtils.getTotalPlaytime(userSessions);
|
||||
|
||||
boolean isActive = AnalysisUtils.isActive(now, user.getLastSeen(), playtime, loginTimes);
|
||||
|
||||
long lastSeen = AnalysisUtils.getLastSeen(userSessions);
|
||||
|
||||
String activityString = getActivityString(isBanned, isUnknown, isActive);
|
||||
|
||||
|
||||
String geoLocation = geoLocations.get(uuid);
|
||||
if (geoLocation == null) {
|
||||
geoLocation = "Not Known";
|
||||
}
|
||||
html.append(Html.TABLELINE_PLAYERS.parse(
|
||||
Html.LINK.parse(HtmlUtils.getRelativeInspectUrl(user.getName()), user.getName()),
|
||||
activityString,
|
||||
String.valueOf(playtime), FormatUtils.formatTimeAmount(playtime),
|
||||
String.valueOf(loginTimes),
|
||||
String.valueOf(registered), FormatUtils.formatTimeStampYear(registered),
|
||||
String.valueOf(lastSeen), FormatUtils.formatTimeStamp(lastSeen),
|
||||
String.valueOf(geoLocation)
|
||||
));
|
||||
} catch (NullPointerException ignored) {
|
||||
}
|
||||
|
||||
|
@ -57,7 +57,7 @@ public class ComparatorTest {
|
||||
List<Long> longValues = test.stream().map(UserInfo::getLastSeen).collect(Collectors.toList());
|
||||
longValues.sort(Long::compare);
|
||||
Collections.reverse(longValues);
|
||||
test.sort(new UserDataLastPlayedComparator());
|
||||
test.sort(new UserInfoLastPlayedComparator());
|
||||
List<Long> afterSort = test.stream().map(UserInfo::getLastSeen).collect(Collectors.toList());
|
||||
assertEquals(longValues, afterSort);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user