Skip to content
Snippets Groups Projects

Fix waiting times

Merged
Taico Aertsrequested to merge
fix-waiting-time into development
All threads resolved!
6 files
+ 121
31
Compare changes
  • Side-by-side
  • Inline

Files

@@ -95,14 +95,26 @@ public abstract class AbstractSlottedLab<TS extends TimeSlot> extends Lab {
@@ -95,14 +95,26 @@ public abstract class AbstractSlottedLab<TS extends TimeSlot> extends Lab {
@Override
@Override
public OptionalDouble currentWaitingTime() {
public OptionalDouble currentWaitingTime() {
 
var labEndTime = getSessionDto().getEndTime();
 
var slots = getTimeSlots().stream();
 
OptionalDouble baseWaitTime;
 
LocalDateTime effectiveEndTime;
 
 
if (labEndTime.isBefore(now())) {
 
effectiveEndTime = labEndTime;
 
baseWaitTime = OptionalDouble.of(0);
 
} else {
 
slots = slots.filter(ts -> ts.getSlot().getOpensAt().isBefore(now()));
 
effectiveEndTime = now();
 
baseWaitTime = OptionalDouble.empty();
 
}
 
// Find the last started timeslot with pending requests, if any.
// Find the last started timeslot with pending requests, if any.
// Otherwise, find the last started timeslot with requests.
// Otherwise, find the last started timeslot with requests.
// Then pick the first created pending request, if any. Otherwise, pick the first created request.
// Then pick the first created pending request, if any. Otherwise, pick the first created request.
return getTimeSlots().stream()
return slots.max(Comparator.<TimeSlot>comparingInt(ts -> ts.hasPendingRequests() ? 1 : -1)
.filter(ts -> ts.getSlot().getOpensAt().isBefore(now()))
.thenComparingInt(ts -> ts.getRequests().size() > 0 ? 1 : -1)
.max(Comparator.<TimeSlot>comparingInt(ts -> ts.hasPendingRequests() ? 1 : -1)
.thenComparing(ts -> ts.getSlot().getOpensAt()))
.thenComparingInt(ts -> ts.getRequests().size() > 0 ? 1 : -1)
.thenComparing(ts -> ts.getSlot().getOpensAt()))
.stream()
.stream()
.flatMap(ts -> ts.getRequests().stream())
.flatMap(ts -> ts.getRequests().stream())
.max(Comparator
.max(Comparator
@@ -110,7 +122,8 @@ public abstract class AbstractSlottedLab<TS extends TimeSlot> extends Lab {
@@ -110,7 +122,8 @@ public abstract class AbstractSlottedLab<TS extends TimeSlot> extends Lab {
.thenComparing(Comparator.nullsFirst(Comparator
.thenComparing(Comparator.nullsFirst(Comparator
.<LabRequest, LocalDateTime>comparing(Request::getCreatedAt)
.<LabRequest, LocalDateTime>comparing(Request::getCreatedAt)
.reversed())))
.reversed())))
.map(LabRequest::sensibleWaitingTime)
.map(r -> r.sensibleWaitingTime(effectiveEndTime))
.orElse(OptionalDouble.empty());
.orElse(baseWaitTime);
 
}
}
}
}
Loading