Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/get rush analytics #98

Merged
merged 2 commits into from
Aug 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
Loading