From 9135898f1d92d7ee1757f6585c0d61de46c5833c Mon Sep 17 00:00:00 2001 From: Josh Date: Tue, 1 Aug 2017 16:41:28 -0400 Subject: [PATCH] handle outlier cases where the number of join/leave events dont match --- scripts/greenlight_recording_notify.rb | 30 ++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/scripts/greenlight_recording_notify.rb b/scripts/greenlight_recording_notify.rb index a17335bb..470bfa0e 100755 --- a/scripts/greenlight_recording_notify.rb +++ b/scripts/greenlight_recording_notify.rb @@ -48,29 +48,47 @@ def getParticipantsInfo(events_xml) participants_info end +def get_id_from_event(event) + (event.xpath('externalUserId').empty?) ? event.xpath('userId').text.split('_')[0] : event.xpath('externalUserId').text +end + # Gets the join and leave times for each user, as well as total duration of stay. def get_duration_info(events_xml) BigBlueButton.logger.info("Task: Getting duration information.") doc = Nokogiri::XML(File.open(events_xml)) - user_data = {} + first_event_time = BigBlueButton::Events.first_event_timestamp(events_xml) + last_event_time = BigBlueButton::Events.last_event_timestamp(events_xml) timestamp = doc.at_xpath('/recording')['meeting_id'].split('-')[1].to_i joinEvents = doc.xpath('/recording/event[@module="PARTICIPANT" and @eventname="ParticipantJoinEvent"]') leftEvents = doc.xpath('/recording/event[@module="PARTICIPANT" and @eventname="ParticipantLeftEvent"]') - # This should never occur, but just in case. - return {'error' => 'inequal number of join/left events.'} if joinEvents.length != leftEvents.length + + user_data = {} + uIDs = [] + joinEvents.each do |join| - uID = join.xpath('externalUserId').text + uID = get_id_from_event(join) + uIDs << uID user_data[uID] = {} user_data[uID]['name'] = join.xpath('name').text - user_data[uID]['join'] = join['timestamp'].to_i - first_event_time + timestamp user_data[uID]['role'] = join.xpath('role').text + user_data[uID]['join'] = join['timestamp'].to_i - first_event_time + timestamp end + leftEvents.each do |left| - uID = left.xpath('userId').text.split('_')[0] + uID = get_id_from_event(left) user_data[uID]['left'] = left['timestamp'].to_i - first_event_time + timestamp user_data[uID]['duration'] = user_data[uID]['left'] - user_data[uID]['join'] end + + # Sometimes leftEvents are missing... + uIDs.each do |id| + unless user_data[id].has_key?('left') + user_data[id]['left'] = last_event_time - first_event_time + timestamp + user_data[id]['duration'] = user_data[id]['left'] - user_data[id]['join'] + end + end + user_data end