Skip to content
Snippets Groups Projects
Commit 414d5ce8 authored by Ruben Backx's avatar Ruben Backx :coffee:
Browse files

Merge branch...

Merge branch '767-time-slot-shows-wrong-numbers-if-people-retracted-their-request' into 'development'

Resolve "Time slot shows wrong numbers if people retracted their request"

Closes #761 and #767

See merge request !839
parents 8750bfc8 c1395dbf
Branches
Tags
2 merge requests!8412425.0.0 release,!839Resolve "Time slot shows wrong numbers if people retracted their request"
...@@ -53,7 +53,7 @@ public class ExamTimeSlotViewDTO extends View<ClosableTimeSlot> { ...@@ -53,7 +53,7 @@ public class ExamTimeSlotViewDTO extends View<ClosableTimeSlot> {
public void postApply(DTOConverter converter) { public void postApply(DTOConverter converter) {
super.postApply(); super.postApply();
occupied = data.countSlotsOccupied(); occupied = data.getNumberOfSlotsOccupied();
handled = data.countHandledRequests(); handled = data.countHandledRequests();
examRequests = converter.convert(new ArrayList<>(data.getRequests()), ExamRequestViewDTO.class); examRequests = converter.convert(new ArrayList<>(data.getRequests()), ExamRequestViewDTO.class);
......
...@@ -79,7 +79,7 @@ public class QueueSessionSummaryDTO extends View<QueueSession<?>> { ...@@ -79,7 +79,7 @@ public class QueueSessionSummaryDTO extends View<QueueSession<?>> {
*/ */
private String slotOccupationString(SlottedLab lab) { private String slotOccupationString(SlottedLab lab) {
long slotsTotal = lab.getTimeSlots().stream().mapToInt(TimeSlot::getCapacity).sum(); long slotsTotal = lab.getTimeSlots().stream().mapToInt(TimeSlot::getCapacity).sum();
long slotsTaken = lab.getTimeSlots().stream().mapToInt(TimeSlot::countSlotsOccupied).sum(); long slotsTaken = lab.getTimeSlots().stream().mapToInt(TimeSlot::getNumberOfSlotsOccupied).sum();
return "(" + slotsTaken + "/" + slotsTotal + " slots taken)"; return "(" + slotsTaken + "/" + slotsTotal + " slots taken)";
} }
...@@ -91,7 +91,7 @@ public class QueueSessionSummaryDTO extends View<QueueSession<?>> { ...@@ -91,7 +91,7 @@ public class QueueSessionSummaryDTO extends View<QueueSession<?>> {
* @return The number of slots in this lab that are currently occupied. * @return The number of slots in this lab that are currently occupied.
*/ */
private Integer slotsOccupied(SlottedLab lab) { private Integer slotsOccupied(SlottedLab lab) {
return lab.getTimeSlots().stream().mapToInt(TimeSlot::countSlotsOccupied).sum(); return lab.getTimeSlots().stream().mapToInt(TimeSlot::getNumberOfSlotsOccupied).sum();
} }
public QueueSession<?> getData() { public QueueSession<?> getData() {
......
...@@ -97,6 +97,6 @@ public class AbstractSlottedLabViewDTO<D extends AbstractSlottedLab<?>> extends ...@@ -97,6 +97,6 @@ public class AbstractSlottedLabViewDTO<D extends AbstractSlottedLab<?>> extends
public void postApply() { public void postApply() {
super.postApply(); super.postApply();
maxSlots = this.data.getTimeSlots().stream().mapToInt(TimeSlot::getCapacity).sum(); maxSlots = this.data.getTimeSlots().stream().mapToInt(TimeSlot::getCapacity).sum();
slotsOccupied = this.data.getTimeSlots().stream().mapToInt(TimeSlot::countSlotsOccupied).sum(); slotsOccupied = this.data.getTimeSlots().stream().mapToInt(TimeSlot::getNumberOfSlotsOccupied).sum();
} }
} }
...@@ -133,7 +133,7 @@ public class TimeSlot { ...@@ -133,7 +133,7 @@ public class TimeSlot {
* @return Whether the time slot is filled or not. * @return Whether the time slot is filled or not.
*/ */
public boolean isFull() { public boolean isFull() {
return countSlotsOccupied() >= capacity; return getNumberOfSlotsOccupied() >= capacity;
} }
/** /**
...@@ -152,7 +152,7 @@ public class TimeSlot { ...@@ -152,7 +152,7 @@ public class TimeSlot {
* *
* @return The count of how many requests are active within this time slot. * @return The count of how many requests are active within this time slot.
*/ */
public int countSlotsOccupied() { public int getNumberOfSlotsOccupied() {
return (int) requests.stream() return (int) requests.stream()
.filter(r -> r.getEventInfo().getStatus() != RequestStatus.REVOKED) .filter(r -> r.getEventInfo().getStatus() != RequestStatus.REVOKED)
.count(); .count();
...@@ -178,7 +178,7 @@ public class TimeSlot { ...@@ -178,7 +178,7 @@ public class TimeSlot {
*/ */
protected boolean isFullAccordingToPercentage() { protected boolean isFullAccordingToPercentage() {
var labConfig = ((AbstractSlottedLab<?>) lab).getSlottedLabConfig(); var labConfig = ((AbstractSlottedLab<?>) lab).getSlottedLabConfig();
return isFull() || ((int) ((countSlotsOccupied() * 100.0) / this.capacity) >= labConfig return isFull() || ((int) ((getNumberOfSlotsOccupied() * 100.0) / this.capacity) >= labConfig
.getConsideredFullPercentage()); .getConsideredFullPercentage());
} }
......
...@@ -265,7 +265,7 @@ class TimeSlot { ...@@ -265,7 +265,7 @@ class TimeSlot {
}) })
: []; : [];
let id = dto.id === undefined ? undefined : dto.id.toString(); let id = dto.id === undefined ? undefined : dto.id.toString();
return new TimeSlot(id, moment(dto.slot.opensAt), moment(dto.slot.closesAt), dto.capacity, requests, {}); return new TimeSlot(id, moment(dto.slot.opensAt), moment(dto.slot.closesAt), dto.numberOfSlotsOccupied, dto.capacity, requests, {});
} }
/** /**
...@@ -282,15 +282,17 @@ class TimeSlot { ...@@ -282,15 +282,17 @@ class TimeSlot {
* @param id The ID of the timeslot, if undefined, generates an ID * @param id The ID of the timeslot, if undefined, generates an ID
* @param start The start of the timeslot * @param start The start of the timeslot
* @param end The end of the timeslot * @param end The end of the timeslot
* @param occupancy The number of non-revoked requests in the timeslot
* @param capacity The capacity of the timeslot * @param capacity The capacity of the timeslot
* @param requests The requests in the timeslot * @param requests The requests in the timeslot
* @param options Optional configuration. * @param options Optional configuration.
*/ */
constructor(id, start, end, capacity, requests, options) { constructor(id, start, end, occupancy, capacity, requests, options) {
this.id = id === undefined ? (TimeSlot.nextId++).toString() : id; this.id = id === undefined ? (TimeSlot.nextId++).toString() : id;
this.start = start; this.start = start;
this.end = end; this.end = end;
this._capacity = capacity; this._capacity = capacity;
this.occupancy = occupancy;
this.requests = requests; this.requests = requests;
this.selected = false; this.selected = false;
this.timeSlots = undefined; this.timeSlots = undefined;
...@@ -310,7 +312,7 @@ class TimeSlot { ...@@ -310,7 +312,7 @@ class TimeSlot {
toEvent() { toEvent() {
let title = "Time slot"; let title = "Time slot";
if (this.showRequests && this.showCapacity) { if (this.showRequests && this.showCapacity) {
title += ` (${this.requests.length}/${this.capacity})`; title += ` (${this.occupancy}/${this.capacity})`;
} else if (this.showCapacity) { } else if (this.showCapacity) {
title += ` (${this.capacity})`; title += ` (${this.capacity})`;
} }
......
...@@ -148,13 +148,13 @@ public class TimeSlotTest { ...@@ -148,13 +148,13 @@ public class TimeSlotTest {
@Test @Test
void countSlotsTakenDoesNotIncludeRevoked() { void countSlotsTakenDoesNotIncludeRevoked() {
assertThat(timeSlot3.countSlotsOccupied()) assertThat(timeSlot3.getNumberOfSlotsOccupied())
.isEqualTo(0); .isEqualTo(0);
} }
@Test @Test
void countSlotsTakenDoesIncludeOtherRequestStatuses() { void countSlotsTakenDoesIncludeOtherRequestStatuses() {
assertThat(timeSlot1.countSlotsOccupied()) assertThat(timeSlot1.getNumberOfSlotsOccupied())
.isEqualTo(2); .isEqualTo(2);
} }
......
...@@ -101,7 +101,7 @@ public class SessionStatusServiceTest { ...@@ -101,7 +101,7 @@ public class SessionStatusServiceTest {
.flatMap(req -> req.getEventInfo().getEvents().stream()) .flatMap(req -> req.getEventInfo().getEvents().stream())
.map(event -> event.getTimestamp().until(LocalDateTime.now(), ChronoUnit.MILLIS)) .map(event -> event.getTimestamp().until(LocalDateTime.now(), ChronoUnit.MILLIS))
.max(Long::compare); .max(Long::compare);
assertThat(res.get(oopTeacher1.getId())).isCloseTo(lastTime.get(), Assertions.within(1000L)); assertThat(res.get(oopTeacher1.getId())).isCloseTo(lastTime.get(), Assertions.within(10000L));
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment