diff options
Autocommit at 08.05.2022 @ 08:27
3 files changed, 10 insertions, 8 deletions
| -rw-r--r-- | src/Services/EventService.cpp | 14 | ||||
| -rw-r--r-- | src/Services/EventService.h | 2 | ||||
| -rw-r--r-- | src/UserInterface/VenueConsoleUI.cpp | 2 |
diff --git a/src/Services/EventService.cpp b/src/Services/EventService.cpp index eb57f41..5b79faa 100644 --- a/src/Services/EventService.cpp +++ b/src/Services/EventService.cpp @@ -161,20 +161,22 @@ String EventService::createSeatingString(const char* name, const Date& date, uns unsigned indexToInsertWhenTicketSort(const List<Event>& elem, unsigned topN, unsigned ticketCount) { for (unsigned i = 0; i < elem.get_count() && i < topN; i++) { - if (elem[i].get_tickets().get_count() < ticketCount) + if (elem[i].get_tickets().get_count() <= ticketCount) return i; } return topN; } -StatusCode EventService::queryMostWatched(unsigned topN) { +List<Event> EventService::queryMostWatched(unsigned topN) { List<Event> result; for (unsigned i = 0; i < events.get_count(); i++) { - if (result.get_count() > 10 && result[10].get_tickets().get_count() > events[i].get_tickets().get_count()) - continue; - - + unsigned ind = indexToInsertWhenTicketSort(result, topN, events[i].get_tickets().get_count()); + if (ind < topN) + result.insertAt(events[i], ind); + if (result.get_count() == topN) + result.removeAt(topN); } + return result; } template <typename T> diff --git a/src/Services/EventService.h b/src/Services/EventService.h index 371aaf2..1914c02 100644 --- a/src/Services/EventService.h +++ b/src/Services/EventService.h @@ -34,7 +34,7 @@ public: String createSeatingString(const char* name, const Date& date, unsigned* seatsPerRow); - StatusCode queryMostWatched(); + List<Event> queryMostWatched(unsigned topN); void queryInsufficientlyVisited(); StatusCode reportReservations(const char* name, const Date& date); diff --git a/src/UserInterface/VenueConsoleUI.cpp b/src/UserInterface/VenueConsoleUI.cpp index 4e90192..71f302e 100644 --- a/src/UserInterface/VenueConsoleUI.cpp +++ b/src/UserInterface/VenueConsoleUI.cpp @@ -145,7 +145,7 @@ void command_cancelEvent() { } void command_mostWatched() { - + List<Event> top = es->queryMostWatched(10); } void command_belowWatchers() { |
