Search in sources :

Example 1 with TimeSegment

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);
}
Also used : TimeSegment(com.djrapitops.plan.delivery.domain.TimeSegment) ArrayList(java.util.ArrayList) FinishedSession(com.djrapitops.plan.gathering.domain.FinishedSession) DateObj(com.djrapitops.plan.delivery.domain.DateObj) DateHolderOldestComparator(com.djrapitops.plan.utilities.comparators.DateHolderOldestComparator)

Aggregations

DateObj (com.djrapitops.plan.delivery.domain.DateObj)1 TimeSegment (com.djrapitops.plan.delivery.domain.TimeSegment)1 FinishedSession (com.djrapitops.plan.gathering.domain.FinishedSession)1 DateHolderOldestComparator (com.djrapitops.plan.utilities.comparators.DateHolderOldestComparator)1 ArrayList (java.util.ArrayList)1