mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-12-15 05:41:51 +08:00
Cleaned up some session related stuff while attempting to find a bug
This commit is contained in:
parent
4d76671bc8
commit
097958c416
@ -85,10 +85,9 @@ public class ShutdownHook extends Thread {
|
||||
UUID uuid = entry.getKey();
|
||||
Session session = entry.getValue();
|
||||
long sessionEnd = session.getSessionEnd();
|
||||
if (sessionEnd != -1) {
|
||||
continue;
|
||||
if (sessionEnd == -1) {
|
||||
session.endSession(now);
|
||||
}
|
||||
session.endSession(now);
|
||||
try {
|
||||
Log.debug("Shutdown: Saving a session: " + session.getSessionStart());
|
||||
db.save().session(uuid, session);
|
||||
|
@ -80,15 +80,11 @@ public class PlayerProfile implements OfflinePlayer {
|
||||
}
|
||||
|
||||
public static long getPlaytime(Stream<Session> s) {
|
||||
return s.map(Session::getLength)
|
||||
.mapToLong(i -> i)
|
||||
.sum();
|
||||
return s.mapToLong(Session::getLength).sum();
|
||||
}
|
||||
|
||||
public static long getLongestSession(Stream<Session> s) {
|
||||
OptionalLong longestSession = s.map(Session::getLength)
|
||||
.mapToLong(i -> i)
|
||||
.max();
|
||||
OptionalLong longestSession = s.mapToLong(Session::getLength).max();
|
||||
if (longestSession.isPresent()) {
|
||||
return longestSession.getAsLong();
|
||||
}
|
||||
|
@ -67,18 +67,6 @@ public class Session {
|
||||
this.deaths = deaths;
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts a new Session.
|
||||
*
|
||||
* @param time Time the session started.
|
||||
* @param world World the session started in.
|
||||
* @param gm GameMode the session started in.
|
||||
* @return a new Session object.
|
||||
*/
|
||||
public static Session start(long time, String world, String gm) {
|
||||
return new Session(time, world, gm);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ends the session with given end point.
|
||||
* <p>
|
||||
|
@ -17,8 +17,12 @@ public class ActivityIndex {
|
||||
value = calculate(player, date);
|
||||
}
|
||||
|
||||
private static long loadSetting(long value) {
|
||||
return value < 0 ? 1 : value;
|
||||
private long loadSetting(long value) {
|
||||
return value <= 0 ? 1 : value;
|
||||
}
|
||||
|
||||
private int loadSetting(int value) {
|
||||
return value <= 0 ? 1 : value;
|
||||
}
|
||||
|
||||
public static String[] getGroups() {
|
||||
@ -31,14 +35,8 @@ public class ActivityIndex {
|
||||
long twoWeeksAgo = date - 2L * week;
|
||||
long threeWeeksAgo = date - 3L * week;
|
||||
|
||||
long activePlayThreshold = Settings.ACTIVE_PLAY_THRESHOLD.getNumber() * TimeAmount.MINUTE.ms();
|
||||
if (activePlayThreshold <= 0) {
|
||||
activePlayThreshold = 1;
|
||||
}
|
||||
int activeLoginThreshold = Settings.ACTIVE_LOGIN_THRESHOLD.getNumber();
|
||||
if (activeLoginThreshold <= 0) {
|
||||
activeLoginThreshold = 1;
|
||||
}
|
||||
long activePlayThreshold = loadSetting(Settings.ACTIVE_PLAY_THRESHOLD.getNumber() * TimeAmount.MINUTE.ms());
|
||||
int activeLoginThreshold = loadSetting(Settings.ACTIVE_LOGIN_THRESHOLD.getNumber());
|
||||
|
||||
List<Session> sessionsWeek = player.getSessions(weekAgo, date).collect(Collectors.toList());
|
||||
List<Session> sessionsWeek2 = player.getSessions(twoWeeksAgo, weekAgo).collect(Collectors.toList());
|
||||
|
@ -94,7 +94,7 @@ public class PlayerOnlineListener implements Listener {
|
||||
|
||||
int playersOnline = TaskSystem.getInstance().getTpsCountTimer().getLatestPlayersOnline();
|
||||
|
||||
SessionCache.getInstance().cacheSession(uuid, Session.start(time, world, gm));
|
||||
SessionCache.getInstance().cacheSession(uuid, new Session(time, world, gm));
|
||||
|
||||
Processor.queueMany(
|
||||
new RegisterProcessor(uuid, player.getFirstPlayed(), time, playerName, playersOnline,
|
||||
|
@ -35,7 +35,6 @@ public class PlayersPageResponse extends Response {
|
||||
super.setHeader("HTTP/1.1 200 OK");
|
||||
try {
|
||||
PlanSystem system = PlanSystem.getInstance();
|
||||
|
||||
PlanPlugin plugin = PlanPlugin.getInstance();
|
||||
Database db = system.getDatabaseSystem().getActiveDatabase();
|
||||
List<String> names = new ArrayList<>(db.fetch().getPlayerNames().values());
|
||||
@ -101,8 +100,8 @@ public class PlayersPageResponse extends Response {
|
||||
|
||||
List<Session> sessions = sessionsByUser.getOrDefault(uuid, new ArrayList<>());
|
||||
int sessionCount = sessions.size();
|
||||
long playtime = sessionCount != 0 ? sessions.stream().map(Session::getLength)
|
||||
.mapToLong(p -> p)
|
||||
long playtime = sessionCount != 0 ? sessions.stream()
|
||||
.mapToLong(Session::getLength)
|
||||
.sum() : 0L;
|
||||
long registered = userInfo.getRegistered();
|
||||
long lastSeen = lastSeenForAllPlayers.getOrDefault(uuid, 0L);
|
||||
|
Loading…
Reference in New Issue
Block a user