mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-12-23 01:27:42 +01:00
[3.0.1] Fix #83
This commit is contained in:
parent
617d4f580c
commit
7f7e4e925a
@ -3,7 +3,7 @@ package main.java.com.djrapitops.plan.ui.graphs;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.stream.Collectors;
|
||||
import main.java.com.djrapitops.plan.data.SessionData;
|
||||
import main.java.com.djrapitops.plan.utilities.FormatUtils;
|
||||
|
||||
@ -23,17 +23,10 @@ public class PlayerActivityGraphCreator {
|
||||
public static String[] generateDataArray(List<SessionData> sessionData, long scale, int maxPlayers) {
|
||||
long now = new Date().toInstant().getEpochSecond() * (long) 1000;
|
||||
long nowMinusScale = now - scale;
|
||||
CopyOnWriteArrayList<Long> sessionStarts = new CopyOnWriteArrayList<>();
|
||||
CopyOnWriteArrayList<Long> sessionEnds = new CopyOnWriteArrayList<>();
|
||||
CopyOnWriteArrayList<SessionData> s = new CopyOnWriteArrayList(sessionData);
|
||||
s.parallelStream()
|
||||
.filter(session -> (session != null))
|
||||
.filter((session) -> (session.getSessionStart() > nowMinusScale || session.getSessionEnd() > nowMinusScale))
|
||||
.forEach((session) -> {
|
||||
sessionEnds.add(session.getSessionEnd());
|
||||
sessionStarts.add(session.getSessionStart());
|
||||
});
|
||||
List<Integer> playersOnline = new ArrayList<>();
|
||||
List<List<Long>> s = filterSessions(sessionData, nowMinusScale);
|
||||
List<Long> sessionStarts = s.get(0);
|
||||
List<Long> sessionEnds = s.get(1);
|
||||
List<Long> playersOnline = new ArrayList<>();
|
||||
List<String> labels = new ArrayList<>();
|
||||
|
||||
for (Long start : sessionStarts) {
|
||||
@ -41,27 +34,16 @@ public class PlayerActivityGraphCreator {
|
||||
sessionStarts.add(nowMinusScale);
|
||||
}
|
||||
}
|
||||
|
||||
int lastPValue = 0;
|
||||
int lastSavedPValue = -1;
|
||||
|
||||
long lastPValue = 0;
|
||||
long lastSavedPValue = -1;
|
||||
long lastSaveI = 0;
|
||||
for (long i = nowMinusScale; i <= now; i += 1000) {
|
||||
final long j = i;
|
||||
if (sessionStarts.contains(i)) {
|
||||
int amount = 0;
|
||||
amount = sessionStarts.parallelStream()
|
||||
.filter((start) -> (start == j))
|
||||
.map((item) -> 1)
|
||||
.reduce(amount, Integer::sum);
|
||||
lastPValue += amount;
|
||||
lastPValue += getCount(sessionStarts, i);
|
||||
}
|
||||
if (sessionEnds.contains(i)) {
|
||||
int amount = 0;
|
||||
amount = sessionEnds.parallelStream()
|
||||
.filter((end) -> (end == j))
|
||||
.map((item) -> 1)
|
||||
.reduce(amount, Integer::sum);
|
||||
lastPValue -= amount;
|
||||
lastPValue -= getCount(sessionEnds, i);
|
||||
}
|
||||
|
||||
if (lastSavedPValue != lastPValue || i - lastSaveI > (scale / (long) 75)) {
|
||||
@ -71,9 +53,36 @@ public class PlayerActivityGraphCreator {
|
||||
playersOnline.add(lastPValue);
|
||||
}
|
||||
}
|
||||
playersOnline.add(0);
|
||||
playersOnline.add(maxPlayers);
|
||||
playersOnline.add(0L);
|
||||
playersOnline.add((long) maxPlayers);
|
||||
return new String[]{playersOnline.toString(), labels.toString()};
|
||||
}
|
||||
|
||||
public static long getCount(List<Long> values, long lookFor) {
|
||||
return values.stream()
|
||||
.filter((start) -> (start == lookFor))
|
||||
.count();
|
||||
}
|
||||
|
||||
public static List<List<Long>> filterSessions(List<SessionData> sessionData, long nowMinusScale) {
|
||||
List<Long[]> values = sessionData.parallelStream()
|
||||
.filter(session -> (session != null))
|
||||
.filter((session) -> (session.getSessionStart() >= nowMinusScale || session.getSessionEnd() >= nowMinusScale))
|
||||
.map(session -> new Long[]{session.getSessionStart(), session.getSessionEnd()})
|
||||
.collect(Collectors.toList());
|
||||
List<Long> sessionStarts = new ArrayList<>();
|
||||
List<Long> sessionEnds = new ArrayList<>();
|
||||
for (Long[] startAndEnd : values) {
|
||||
sessionStarts.add(getSecond(startAndEnd[0]));
|
||||
sessionEnds.add(getSecond(startAndEnd[1]));
|
||||
}
|
||||
List<List<Long>> r = new ArrayList<>();
|
||||
r.add(sessionStarts);
|
||||
r.add(sessionEnds);
|
||||
return r;
|
||||
}
|
||||
|
||||
public static long getSecond(long ms) {
|
||||
return ms - (ms % 1000);
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
name: Plan
|
||||
author: Rsl1122
|
||||
main: main.java.com.djrapitops.plan.Plan
|
||||
version: 3.0.0
|
||||
version: 3.0.1
|
||||
|
||||
softdepend:
|
||||
- OnTime
|
||||
|
Loading…
Reference in New Issue
Block a user