Skip to content

Commit

Permalink
Merge pull request #98 from whyphi/feat/get-rush-analytics
Browse files Browse the repository at this point in the history
Feat/get rush analytics
  • Loading branch information
wderocco8 authored Aug 3, 2024
2 parents f4a7523 + c416c19 commit e6bbc00
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
8 changes: 7 additions & 1 deletion chalicelib/api/events_rush.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
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)
24 changes: 24 additions & 0 deletions chalicelib/services/EventsRushService.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,4 +334,28 @@ 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] }

result = { "categoryName": category["name"], "attendees": attendees }

return json.dumps(result, cls=self.BSONEncoder)

events_rush_service = EventsRushService()

0 comments on commit e6bbc00

Please sign in to comment.