From 0776b49fa15849f4a45dc0c46a4f2f4e19862ab0 Mon Sep 17 00:00:00 2001 From: Maxime Boissonneault Date: Mon, 19 Aug 2024 14:32:54 -0400 Subject: [PATCH 1/2] calculate zoom attendance duration considering overlapping records --- zoom_attendance_to_eventbrite.py | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/zoom_attendance_to_eventbrite.py b/zoom_attendance_to_eventbrite.py index 9425644..1dafc39 100755 --- a/zoom_attendance_to_eventbrite.py +++ b/zoom_attendance_to_eventbrite.py @@ -49,8 +49,29 @@ zoom_participants = {p['user_email']: {'user_email': p['user_email'], 'name': p['name'], 'duration': 0} for p in participants_records} # calculating the total attendance duration for each attendee -for r in participants_records: - zoom_participants[r['user_email']]['duration'] += r['duration'] +for email in zoom_participants.keys(): + records = [r for r in participants_records if r['user_email'] == email] + # the participant joined multiple times, we need to combine them + if len(records) >= 1: + # Algorithm from https://medium.com/@saraswatp/solving-overlapping-intervals-with-python-the-merged-interval-problem-dcf16ad09190 + # first, sort the records by join_time + records.sort(key=lambda x: x['join_time']) + merged_records = [] + for record in records: + # If the list of merged records is empty or if the current record does not overlap with the previous one, + # simply add it to the merged list + if not merged_records or record['join_time'] > merged_records[-1]['leave_time']: + merged_records.append(record) + else: + # If the current interval overlaps with previous one, merge them + merged_records[-1]['leave_time'] = max(merged_records[-1]['leave_time'], record['leave_time']) + merged_records[-1]['duration'] = merged_records[-1]['leave_time'] - merged_records[-1]['join_time'] + + records = merged_records + + # sum the duration of each records + zoom_participants[email]['duration'] = sum([r['duration'] for r in records]) + # retrieve the maximum duration mean_duration = mean([v['duration'] for k,v in zoom_participants.items()]) From 5ba4688a20a405c12d1f05314037f0f12c1d57e9 Mon Sep 17 00:00:00 2001 From: Maxime Boissonneault Date: Tue, 1 Oct 2024 14:22:56 -0400 Subject: [PATCH 2/2] update to use CQORCcalendar --- zoom_attendance_to_eventbrite.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/zoom_attendance_to_eventbrite.py b/zoom_attendance_to_eventbrite.py index 1dafc39..b311bdd 100755 --- a/zoom_attendance_to_eventbrite.py +++ b/zoom_attendance_to_eventbrite.py @@ -23,6 +23,12 @@ # read configuration files global_config = get_config(args) +# get the events from the working calendar in the Google spreadsheets +calendar = CQORCcalendar.Calendar(global_config, args) +course = None +if args.course_id: + course = calendar[args.course_id] + # initialize Zoom interface zoom_user = global_config['zoom']['user'] zoom = ZoomInterface.ZoomInterface(global_config['zoom']['account_id'], global_config['zoom']['client_id'], global_config['zoom']['client_secret'], global_config['global']['timezone'], zoom_user) @@ -30,6 +36,8 @@ webinars = [] if args.zoom_id: webinars = zoom.get_webinars(ids = [int(args.zoom_id)]) +elif course: + webinars = zoom.get_webinars(ids = [int(course['sessions'][0]['zoom_id'])]) elif args.date: webinars = zoom.get_webinars(date = to_iso8061(args.date).date()) @@ -99,6 +107,8 @@ eb_event = None if args.eventbrite_id: eb_event = eb.get_event(args.eventbrite_id) +elif course: + eb_event = eb.get_event(course['sessions'][0]['eventbrite_id']) else: eb_events = eb.get_events(global_config['eventbrite']['organization_id'], time_filter="past", flattened=True, order_by="start_desc") todays_events = []