mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-02-03 14:01:47 +01:00
Ping grouping for graphing purposes to PingMutator
This commit is contained in:
parent
ab768c3f4b
commit
ead8024ca5
@ -15,22 +15,31 @@ public class DateHoldersMutator<T extends DateHolder> {
|
|||||||
this.dateHolders = dateHolders;
|
this.dateHolders = dateHolders;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TreeMap<Long, List<T>> groupByStartOfDay() {
|
public TreeMap<Long, List<T>> groupByStartOfMinute() {
|
||||||
|
return groupByStartOfSections(TimeAmount.MINUTE.ms());
|
||||||
|
}
|
||||||
|
|
||||||
|
private TreeMap<Long, List<T>> groupByStartOfSections(long sectionLength) {
|
||||||
TreeMap<Long, List<T>> map = new TreeMap<>();
|
TreeMap<Long, List<T>> map = new TreeMap<>();
|
||||||
|
|
||||||
if (dateHolders.isEmpty()) {
|
if (dateHolders.isEmpty()) {
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
long twentyFourHours = 24L * TimeAmount.HOUR.ms();
|
|
||||||
for (T holder : dateHolders) {
|
for (T holder : dateHolders) {
|
||||||
long date = holder.getDate();
|
long date = holder.getDate();
|
||||||
long startOfDate = date - (date % twentyFourHours);
|
long startOfMinute = date - (date % sectionLength);
|
||||||
|
|
||||||
List<T> list = map.getOrDefault(startOfDate, new ArrayList<>());
|
List<T> list = map.getOrDefault(startOfMinute, new ArrayList<>());
|
||||||
list.add(holder);
|
list.add(holder);
|
||||||
map.put(startOfDate, list);
|
map.put(startOfMinute, list);
|
||||||
}
|
}
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
|
||||||
|
public TreeMap<Long, List<T>> groupByStartOfDay() {
|
||||||
|
long twentyFourHours = 24L * TimeAmount.HOUR.ms();
|
||||||
|
TreeMap<Long, List<T>> map = groupByStartOfSections(twentyFourHours);
|
||||||
|
|
||||||
// Empty map firstKey attempt causes NPE if not checked.
|
// Empty map firstKey attempt causes NPE if not checked.
|
||||||
if (!map.isEmpty()) {
|
if (!map.isEmpty()) {
|
||||||
|
@ -6,7 +6,10 @@ import com.djrapitops.plan.data.store.keys.CommonKeys;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.TreeMap;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.function.Predicate;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class PingMutator {
|
public class PingMutator {
|
||||||
|
|
||||||
@ -20,18 +23,53 @@ public class PingMutator {
|
|||||||
return new PingMutator(container.getValue(CommonKeys.PING).orElse(new ArrayList<>()));
|
return new PingMutator(container.getValue(CommonKeys.PING).orElse(new ArrayList<>()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public Optional<Ping> max() {
|
public PingMutator filterBy(Predicate<Ping> predicate) {
|
||||||
Ping maxPing = null;
|
return new PingMutator(pings.stream().filter(predicate).collect(Collectors.toList()));
|
||||||
int max = 0;
|
}
|
||||||
|
|
||||||
|
public PingMutator filterByServer(UUID serverUUID) {
|
||||||
|
return filterBy(ping -> serverUUID.equals(ping.getServerUUID()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public PingMutator mutateToByMinutePings() {
|
||||||
|
DateHoldersMutator<Ping> dateMutator = new DateHoldersMutator<>(pings);
|
||||||
|
TreeMap<Long, List<Ping>> byStartOfMinute = dateMutator.groupByStartOfMinute();
|
||||||
|
|
||||||
|
return new PingMutator(byStartOfMinute.entrySet().stream()
|
||||||
|
.map(entry -> {
|
||||||
|
PingMutator mutator = new PingMutator(entry.getValue());
|
||||||
|
|
||||||
|
return new Ping(entry.getKey(), null,
|
||||||
|
mutator.min(), mutator.max(), mutator.average());
|
||||||
|
}).collect(Collectors.toList()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Ping> all() {
|
||||||
|
return pings;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int max() {
|
||||||
|
int max = -1;
|
||||||
for (Ping ping : pings) {
|
for (Ping ping : pings) {
|
||||||
Integer value = ping.getMax();
|
Integer value = ping.getMax();
|
||||||
if (value > max) {
|
if (value > max) {
|
||||||
max = value;
|
max = value;
|
||||||
maxPing = ping;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return Optional.ofNullable(maxPing);
|
return max;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int min() {
|
||||||
|
int min = -1;
|
||||||
|
for (Ping ping : pings) {
|
||||||
|
Integer value = ping.getMin();
|
||||||
|
if (value < min || min == -1) {
|
||||||
|
min = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return min;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double average() {
|
public double average() {
|
||||||
|
Loading…
Reference in New Issue
Block a user