From 0c02bc27bf388b21fd1bfab300223bc435539115 Mon Sep 17 00:00:00 2001 From: William De Rocco <93288641+wderocco8@users.noreply.github.com> Date: Sun, 28 Jul 2024 13:20:33 -0400 Subject: [PATCH 1/2] added function to return rush event analytics --- chalicelib/api/events_rush.py | 8 +++++++- chalicelib/services/EventsRushService.py | 23 +++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/chalicelib/api/events_rush.py b/chalicelib/api/events_rush.py index d15c645..8159289 100644 --- a/chalicelib/api/events_rush.py +++ b/chalicelib/api/events_rush.py @@ -57,4 +57,10 @@ def get_rush_events_default_category(): @events_rush_api.route("/events/rush/{event_id}", methods=["DELETE"], cors=True) def delete_rush_event(event_id): - return events_rush_service.delete_rush_event(event_id) \ No newline at end of file + return events_rush_service.delete_rush_event(event_id) + + +@events_rush_api.route("/events/rush/{category_id}/analytics", methods=["GET"], cors=True) +@auth(events_rush_api, roles=["admin"]) +def get_rush_category_analytics(category_id): + return events_rush_service.get_rush_category_analytics(category_id=category_id) \ No newline at end of file diff --git a/chalicelib/services/EventsRushService.py b/chalicelib/services/EventsRushService.py index 71933de..a934afd 100644 --- a/chalicelib/services/EventsRushService.py +++ b/chalicelib/services/EventsRushService.py @@ -334,4 +334,27 @@ def delete_rush_event(self, event_id: str): except Exception as e: raise BadRequestError(e) + def get_rush_category_analytics(self, category_id: str): + category = self.mongo_module.get_document_by_id( + f"{self.collection_prefix}rush", category_id + ) + + # attendees : dict of all users (user: { name, email, eventsAttended: list of objects }) + attendees = {} + + for event in category["events"]: + for attendee in event["attendees"]: + email =attendee["email"] + new_event = { + "eventId": event["_id"], + "eventName": event["name"] + } + if email in attendees: + attendees[email]["eventsAttended"].append(new_event) + else: + attendees[email] = { **attendee, "eventsAttended": [new_event] } + + + return json.dumps(attendees, cls=self.BSONEncoder) + events_rush_service = EventsRushService() \ No newline at end of file From c416c192d9553061044a48f0cc6d48fc56ab62a7 Mon Sep 17 00:00:00 2001 From: William De Rocco <93288641+wderocco8@users.noreply.github.com> Date: Sat, 3 Aug 2024 09:42:16 -0400 Subject: [PATCH 2/2] returned categoryName in API --- chalicelib/services/EventsRushService.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/chalicelib/services/EventsRushService.py b/chalicelib/services/EventsRushService.py index a934afd..952c063 100644 --- a/chalicelib/services/EventsRushService.py +++ b/chalicelib/services/EventsRushService.py @@ -354,7 +354,8 @@ def get_rush_category_analytics(self, category_id: str): else: attendees[email] = { **attendee, "eventsAttended": [new_event] } + result = { "categoryName": category["name"], "attendees": attendees } - return json.dumps(attendees, cls=self.BSONEncoder) + return json.dumps(result, cls=self.BSONEncoder) events_rush_service = EventsRushService() \ No newline at end of file