Skip to content
Snippets Groups Projects

Fix and refactor lab statistic page

6 files
+ 178
77
Compare changes
  • Side-by-side
  • Inline

Files

@@ -17,12 +17,14 @@
*/
package nl.tudelft.ewi.queue.controller;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeSet;
import java.util.stream.Collectors;
import nl.tudelft.ewi.queue.dto.view.LabStatisticsViewDto;
import nl.tudelft.ewi.queue.dto.view.RequestFrequencyViewDto;
import nl.tudelft.ewi.queue.dto.view.RequestStatusViewDto;
import nl.tudelft.ewi.queue.model.Assignment;
import nl.tudelft.ewi.queue.model.Lab;
import nl.tudelft.ewi.queue.model.Request;
@@ -44,21 +46,6 @@ public class CourseStatusController {
@Autowired
private LabStatusService lss;
/**
* A data class to be sent over a network. This class distinguishes buckets and data. Buckets are the
* start positions of each bucket in a histogram and the data is what is to be displayed in each bucket.
*/
public static class MultiFrequencies {
public List<Long> buckets;
public Map<String, List<Long>> data;
MultiFrequencies(List<Long> buckets, Map<String, List<Long>> data) {
this.buckets = buckets;
this.data = data;
}
}
/**
* Creates and returns the data for a histogram regarding the status of requests over time. The data for
* requests can be filtered on labs, assignments and rooms to only selectively count.
@@ -68,13 +55,13 @@ public class CourseStatusController {
* @param assignments The assignments to filter on.
* @param rooms The rooms to filter on.
* @param nBuckets The number of buckets to create. 4 by default (for 4 hours of lab).
* @return A MultiFrequencies object representing the buckets into which the lab was divided
* and the number of requests created, open, and handled during each of the created
* timeframes.
* @return A RequestFrequencyViewDto object representing the buckets into which the lab was
* divided and the number of requests created, open, and handled during each of the
* created time frames.
*/
@GetMapping("/course/{id}/status/freq/request")
@PreAuthorize("@permissionService.canViewStatus(principal, #id)")
public MultiFrequencies getRequestFrequencies(@PathVariable Long id,
public RequestFrequencyViewDto getRequestFrequencies(@PathVariable Long id,
@RequestParam(required = false, defaultValue = "") List<Lab> labs,
@RequestParam(required = false, defaultValue = "") List<Assignment> assignments,
@RequestParam(required = false, defaultValue = "") List<Room> rooms,
@@ -82,15 +69,11 @@ public class CourseStatusController {
List<Request> requests = lss.getFilteredRequests(labs, assignments, rooms);
TreeSet<Long> buckets = lss.createBucketsOverCourse(labs, nBuckets);
return new MultiFrequencies(
return new RequestFrequencyViewDto(
buckets.stream().sorted().collect(Collectors.toList()),
new HashMap<>() {
{
put("created", lss.countCreatedRequestsInBuckets(buckets, requests));
put("open", lss.countOpenRequestsInBuckets(buckets, requests));
put("handled", lss.countHandledRequestsInBuckets(buckets, requests));
}
});
lss.countCreatedRequestsInBuckets(buckets, requests),
lss.countOpenRequestsInBuckets(buckets, requests),
lss.countHandledRequestsInBuckets(buckets, requests));
}
/**
@@ -101,27 +84,23 @@ public class CourseStatusController {
* @param labs The labs to filter on.
* @param assignments The assignments to filter on.
* @param rooms The rooms to filter on.
* @return The data in the form of a mapping from names of statuses to the number of requests
* counted with that status.
* @return The data in the form of a StatusViewDto.
*/
@GetMapping("/course/{id}/status/freq/status")
@PreAuthorize("@permissionService.canViewStatus(principal, #id)")
public Map<String, Long> getRequestStatusFrequencies(@PathVariable Long id,
public RequestStatusViewDto getRequestStatusFrequencies(@PathVariable Long id,
@RequestParam(required = false, defaultValue = "") List<Lab> labs,
@RequestParam(required = false, defaultValue = "") List<Assignment> assignments,
@RequestParam(required = false, defaultValue = "") List<Room> rooms) {
List<Request> requests = lss.getFilteredRequests(labs, assignments, rooms);
return new HashMap<>() {
{
put("pending", lss.countWhere(requests, Request::isPending));
put("processing", lss.countWhere(requests, Request::isProcessing));
put("approved", lss.countWhere(requests, Request::isApproved));
put("rejected", lss.countWhere(requests, Request::isRejected));
put("not_found", lss.countWhere(requests, Request::isNotFound));
put("revoked", lss.countWhere(requests, Request::isRevoked));
}
};
return new RequestStatusViewDto(
lss.countWhere(requests, Request::isPending),
lss.countWhere(requests, Request::isProcessing),
lss.countWhere(requests, Request::isApproved),
lss.countWhere(requests, Request::isRejected),
lss.countWhere(requests, Request::isNotFound),
lss.countWhere(requests, Request::isRevoked));
}
/**
@@ -134,29 +113,25 @@ public class CourseStatusController {
* @param labs The labs to filter on.
* @param assignments The assignments to filter on.
* @param rooms The rooms to filter on.
* @return The data in the form of a mapping from names to the measured data.
* @return The data in the form of a LabStatisticsViewDto.
*/
@GetMapping("/course/{id}/status/lab/info")
@PreAuthorize("@permissionService.canViewStatus(principal, #id)")
public Map<String, Object> getGenericLabInformation(@PathVariable Long id,
public LabStatisticsViewDto getGenericLabInformation(@PathVariable Long id,
@RequestParam(required = false, defaultValue = "") List<Lab> labs,
@RequestParam(required = false, defaultValue = "") List<Assignment> assignments,
@RequestParam(required = false, defaultValue = "") List<Room> rooms) {
List<Request> requests = lss.getFilteredRequests(labs, assignments, rooms);
return new HashMap<>() {
{
put("lab-static-noStudents", lss.countDistinctUsers(requests));
put("lab-static-noAssistants", lss.countDistinctAssistants(requests));
put("lab-static-nOpen", lss.countWhere(requests, Request::isPending));
put("lab-static-nHandled", lss.countWhere(requests, Request::isHandled));
put("lab-static-assignment",
lss.mostCountedName(lss.countRequestsPerAssignment(assignments, requests)));
put("lab-static-room", lss.mostCountedName(lss.countRequestsPerRoom(rooms, requests)));
put("lab-static-avgWaitingTime", lss.averageWaitingTime(requests));
put("lab-static-avgProcessingTime", lss.averageProcessingTime(requests));
}
};
return new LabStatisticsViewDto(
lss.countDistinctUsers(requests),
lss.countDistinctAssistants(requests),
lss.countWhere(requests, Request::isPending),
lss.countWhere(requests, Request::isHandled),
lss.mostCountedName(lss.countRequestsPerAssignment(assignments, requests)),
lss.mostCountedName(lss.countRequestsPerRoom(rooms, requests)),
lss.averageWaitingTime(requests),
lss.averageProcessingTime(requests));
}
/**
Loading