Skip to content

Commit

Permalink
Feature/scanned progress (#443)
Browse files Browse the repository at this point in the history
* Add ScannedCount to Attendence class

* Move calculating attendance from controller to service and repository

* Add attendance to model for event overview page

* Add Scanned Tickets progress bar to event overview page

* Fix alignment of text in progress bars

* Remove example value
  • Loading branch information
robertdijk authored Oct 2, 2023
1 parent 2c87a4e commit c815de5
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package ch.wisv.events.admin.controller;

import ch.wisv.events.core.admin.Attendence;
import ch.wisv.events.core.exception.normal.EventInvalidException;
import ch.wisv.events.core.exception.normal.EventNotFoundException;
import ch.wisv.events.core.model.event.Event;
Expand Down Expand Up @@ -247,7 +248,7 @@ public String overview(Model model, RedirectAttributes redirect, @PathVariable S

model.addAttribute(OBJ_EVENT, event);
model.addAttribute(OBJ_TICKETS, tickets);

model.addAttribute("attendance", eventService.getAttendance(event));
return "admin/events/overview";
} catch (EventNotFoundException e) {
redirect.addFlashAttribute(FLASH_ERROR, e.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,25 +115,6 @@ private double calculateChangePercentage(double previous, double current) {
return Math.round(((current - previous) / previous) * 100.d) / 100.d;
}

/**
* Method determineAttendanceRateEvent ...
*
* @param event of type Event
*
* @return double
*/
private double determineAttendanceRateEvent(Event event) {
List<Ticket> eventTickets = event.getProducts().stream().flatMap(product -> ticketService.getAllByProduct(product).stream()).collect(
Collectors.toList());
long numberTicketsScanned = eventTickets.stream().filter(ticket -> ticket.getStatus() == TicketStatus.SCANNED).count();

if (eventTickets.size() == 0) {
return 0.d;
}

return Math.round(numberTicketsScanned / (eventTickets.size() * 10000.d)) / 100.d;
}

/**
* Method determinePreviousEventAttendance ...
*
Expand All @@ -142,7 +123,7 @@ private double determineAttendanceRateEvent(Event event) {
private HashMap<Event, Double> determinePreviousEventAttendance() {
HashMap<Event, Double> events = new HashMap<>();

this.eventService.getPreviousEventsLastTwoWeeks().forEach(event -> events.put(event, this.determineAttendanceRateEvent(event)));
this.eventService.getPreviousEventsLastTwoWeeks().forEach(event -> events.put(event, eventService.getAttendance(event).getPercentageScanned()));

return events;
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/ch/wisv/events/core/admin/Attendence.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@

public interface Attendence {
long getTicketsCount();
long getScannedCount();
double getPercentageScanned();
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,20 @@ public interface EventRepository extends JpaRepository<Event, Integer> {
Optional<Event> findByProductsContaining(Product product);

@Query(value =
"select count(*) as ticketsCount, avg(status)*100 as percentageScanned " +
"select count(*) as ticketsCount, sum(status) as scannedCount, avg(status)*100 as percentageScanned " +
"from Ticket A INNER JOIN (Select distinct products_id FROM ticket T1 INNER JOIN (Select products_id from " +
"event_products EP INNER JOIN " +
"(Select id from event e where e.ending between :startDate and :endDate) E " +
"ON E.id=EP.event_id) T2 ON T1.product_id=T2.products_id) B " +
"ON A.product_id=B.products_id;", nativeQuery = true) //TODO fix proper date
Attendence getAttendenceFromEventsInDateRange(@Param("startDate") LocalDateTime start, @Param("endDate") LocalDateTime End);

@Query(value =
"select count(*) as ticketsCount, coalesce(sum(status), 0) as scannedCount, coalesce(avg(status),0 ) * 100 as percentageScanned " +
"from Ticket A INNER JOIN (Select distinct products_id FROM ticket T1 INNER JOIN (Select products_id from " +
"event_products EP INNER JOIN " +
"(Select :event_id as id) E " +
"ON E.id=EP.event_id) T2 ON T1.product_id=T2.products_id) B " +
"ON A.product_id=B.products_id;", nativeQuery = true)
Attendence getAttendanceFromEvent(@Param("event_id") Integer event_id);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package ch.wisv.events.core.service.event;

import ch.wisv.events.core.admin.Attendence;
import ch.wisv.events.core.exception.normal.EventInvalidException;
import ch.wisv.events.core.exception.normal.EventNotFoundException;
import ch.wisv.events.core.model.document.Document;
Expand Down Expand Up @@ -117,4 +118,11 @@ public interface EventService {
*/
void addDocumentImage(Event event, Document document);

/**
* Get attendance by Event
*
* @param event Event
* @return Attendance of event
*/
Attendence getAttendance(Event event);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package ch.wisv.events.core.service.event;

import ch.wisv.events.core.admin.Attendence;
import ch.wisv.events.core.exception.normal.EventInvalidException;
import ch.wisv.events.core.exception.normal.EventNotFoundException;
import ch.wisv.events.core.exception.normal.ProductInvalidException;
Expand Down Expand Up @@ -209,6 +210,17 @@ public void addDocumentImage(Event event, Document document) {
event.setImageUrl(this.imageLocation + document.getFileName() + ".png");
}

/**
* Get attendance by Event
*
* @param event Event
* @return Attendance of event
*/
@Override
public Attendence getAttendance(Event event) {
return eventRepository.getAttendanceFromEvent(event.getId());
}

/**
* Method assertIsValidEvent ...
*
Expand Down
1 change: 0 additions & 1 deletion src/main/resources/static/css/wisvch-dashboard.css
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,6 @@ h1 .badge-info {
}

.progress .progress-bar {
height: 30px;
background-color: #2AA1A9;
line-height: 30px;
padding-left: .25rem;
Expand Down
23 changes: 22 additions & 1 deletion src/main/resources/templates/admin/events/overview.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,33 @@ <h1>Ticket [[${event.getTitle()}]]</h1>

<div th:replace="fragments/messages :: messages"></div>

<div class="row my-2">
<div class="row mb-4">
<div class="col-auto">
<a th:href="@{'/administrator/events/overview/csv/' + ${event.getKey()} + '/'}" class="btn btn-secondary btn-block">export to csv</a>
</div>
</div>

<div class="row">
<div class="col">
<div class="card mb-4">
<h6 class="card-header">Scanned Tickets</h6>
<div class="card-body text-primary">
<h4 class="card-title">
[[${attendance.getScannedCount()}]] <small>out of [[${attendance.getTicketsCount()}]]</small>
</h4>
<div class="progress mb-2">
<div class="progress-bar" role="progressbar"
th:aria-valuenow="${attendance.getPercentageScanned()}"
aria-valuemin="0" aria-valuemax="100"
th:style="'width: ' + ${attendance.getPercentageScanned()} + '%;'"
th:text="${attendance.getPercentageScanned()} + '%'">
</div>
</div>
</div>
</div>
</div>
</div>

<div class="table-responsive">
<table id="soldProductTable" class="table table-hover">
<thead class="thead-dark bg-primary">
Expand Down

0 comments on commit c815de5

Please sign in to comment.