handle outlier cases where the number of join/leave events dont match

This commit is contained in:
Josh 2017-08-01 16:41:28 -04:00
parent 949fce701c
commit 9135898f1d
1 changed files with 24 additions and 6 deletions

View File

@ -48,29 +48,47 @@ def getParticipantsInfo(events_xml)
participants_info participants_info
end 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. # Gets the join and leave times for each user, as well as total duration of stay.
def get_duration_info(events_xml) def get_duration_info(events_xml)
BigBlueButton.logger.info("Task: Getting duration information.") BigBlueButton.logger.info("Task: Getting duration information.")
doc = Nokogiri::XML(File.open(events_xml)) doc = Nokogiri::XML(File.open(events_xml))
user_data = {}
first_event_time = BigBlueButton::Events.first_event_timestamp(events_xml) 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 timestamp = doc.at_xpath('/recording')['meeting_id'].split('-')[1].to_i
joinEvents = doc.xpath('/recording/event[@module="PARTICIPANT" and @eventname="ParticipantJoinEvent"]') joinEvents = doc.xpath('/recording/event[@module="PARTICIPANT" and @eventname="ParticipantJoinEvent"]')
leftEvents = doc.xpath('/recording/event[@module="PARTICIPANT" and @eventname="ParticipantLeftEvent"]') 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| joinEvents.each do |join|
uID = join.xpath('externalUserId').text uID = get_id_from_event(join)
uIDs << uID
user_data[uID] = {} user_data[uID] = {}
user_data[uID]['name'] = join.xpath('name').text 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]['role'] = join.xpath('role').text
user_data[uID]['join'] = join['timestamp'].to_i - first_event_time + timestamp
end end
leftEvents.each do |left| 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]['left'] = left['timestamp'].to_i - first_event_time + timestamp
user_data[uID]['duration'] = user_data[uID]['left'] - user_data[uID]['join'] user_data[uID]['duration'] = user_data[uID]['left'] - user_data[uID]['join']
end 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 user_data
end end