use of com.djrapitops.plan.delivery.domain.TimeSegment in project Plan by plan-player-analytics.
the class TimeSegmentsMutator method sessionClockSegments.
public static TimeSegmentsMutator<Integer> sessionClockSegments(List<FinishedSession> sessions) {
List<DateObj<Integer>> changes = new ArrayList<>();
for (FinishedSession session : sessions) {
long startTime = (session.getStart()) % TimeUnit.DAYS.toMillis(1);
long endTime = (session.getEnd()) % TimeUnit.DAYS.toMillis(1);
changes.add(new DateObj<>(startTime, 1));
changes.add(new DateObj<>(endTime, -1));
}
changes.sort(new DateHolderOldestComparator());
int count = 0;
long previousTime = 0L;
List<TimeSegment<Integer>> segments = new ArrayList<>();
for (DateObj<Integer> change : changes) {
segments.add(new TimeSegment<>(previousTime, change.getDate(), count));
count += change.getValue();
previousTime = change.getDate();
}
return new TimeSegmentsMutator<>(segments);
}
Aggregations