-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdescribe.rb
More file actions
177 lines (161 loc) · 5.69 KB
/
describe.rb
File metadata and controls
177 lines (161 loc) · 5.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# encoding: UTF-8
require 'nokogiri'
require 'date'
require 'json'
require 'optimist'
require 'logger'
require 'pp'
require 'tz'
require 'terminal-table'
Encoding.default_external = Encoding::UTF_8
Encoding.default_internal = Encoding::UTF_8
def timestamp_to_date(ms)
DateTime.strptime(ms.to_s,'%Q')
end
def format_date_time(d, timezone_s = nil)
timezone_s ||= $timezone
timezone = TZInfo::Timezone.get(timezone_s)
local_date = timezone.utc_to_local(d)
local_date.strftime("%d/%m/%Y %H:%M:%S")
end
def seconds_to_duration(t)
Time.at(t).utc.strftime("%H:%M:%S")
end
opts = Optimist::options do
opt :events_xml, "Path to events.xml", :type => String, :required => true
opt :timezone, "Timezone", :type => String, :required => false, :default => "America/Sao_Paulo"
end
events_xml = opts[:events_xml]
$timezone = opts[:timezone]
doc = Nokogiri::XML(File.open(events_xml)) { |x| x.noblanks }
user_id_to_name = {}
events = []
record_duration_sec = 0
record_last_segment = 0
start_recording = nil
participants = 0
talking = {}
doc.xpath("/recording/event").sort_by{ |node| node.at_xpath("@timestamp").text.to_i }.each do |node|
event_module = node.at_xpath("@module").text
event_name = node.at_xpath("@eventname").text
timestamp = node.at_xpath("@timestamp").text.to_i
timestamp_utc = node.at_xpath("timestampUTC").text.to_i
date_utc = timestamp_to_date(timestamp_utc)
record_duration_sec = events.empty? ? 0 : events.last[:record_duration_sec]
if ! start_recording.nil?
record_duration_sec = record_last_segment + ((date_utc - start_recording) * 24 * 60 * 60).to_i
end
event = {
:timestamp => timestamp,
:timestamp_utc => timestamp_utc,
:date => date_utc,
:record_duration_sec => record_duration_sec,
:record_duration => seconds_to_duration(record_duration_sec),
:participants => participants
}
if event_module == "PARTICIPANT"
case event_name
when "ParticipantJoinEvent"
user_id = node.at_xpath("userId").text
user_name = node.at_xpath("name").text
user_id_to_name[user_id] = user_name
participants += 1
event.merge!({
:user => user_name,
:event => "Joined the session",
:participants => participants
})
events << event
when "ParticipantLeftEvent"
user_id = node.at_xpath("userId").text
user_name = user_id_to_name[user_id]
participants -= 1
event.merge!({
:user => user_name,
:event => "Left the session",
:participants => participants
})
events << event
when "RecordStatusEvent"
user_id = node.at_xpath("userId").text
user_name = user_id_to_name[user_id]
status = node.at_xpath("status").text == "true"
if status
start_recording = date_utc
else
start_recording = nil
record_last_segment = record_duration_sec
end
event.merge!({
:user => user_name,
:event => "** Session #{status ? 'started' : 'stopped'} being recorded"
})
events << event
end
elsif event_module == "VOICE"
case event_name
when "ParticipantJoinedEvent"
user_id = node.at_xpath("participant").text
user_name = user_id_to_name[user_id]
message = node.at_xpath("muted").text == "true" ? "Enabled to listen" : "Enabled microphone"
event.merge!({
:user => user_name,
:event => message
})
events << event
when "ParticipantLeftEvent"
user_id = node.at_xpath("participant").text
user_name = user_id_to_name[user_id]
event.merge!({
:user => user_name,
:event => "Disabled audio"
})
events << event
when "ParticipantTalkingEvent"
user_id = node.at_xpath("participant").text
user_name = user_id_to_name[user_id]
status = node.at_xpath("talking").text == "true"
event[:user] = user_name
if ! talking.has_key?(user_id)
event[:event] = "First talking event"
talking[user_id] = []
else
talking[user_id].pop if talking[user_id].length == 2
event[:event] = "Last talking event"
end
talking[user_id] << event
end
elsif event_module == "bbb-webrtc-sfu"
filename = node.at_xpath("filename").text
match = /.*\w+-\d+\/\w+-(?<user_id>\w_\w+)-\d+.\w+/.match filename
if ! match.nil?
user_id = match[:user_id]
user_name = user_id_to_name[user_id]
case event_name
when "StartWebRTCShareEvent"
event.merge!({
:user => user_name,
:event => "Enabled camera"
})
events << event
when "StopWebRTCShareEvent"
event.merge!({
:user => user_name,
:event => "Disabled camera"
})
events << event
end
end
end
end
talking.values.each do |entry|
entry.each do |event|
events << event
end
end
exit 0 if events.length == 0
events.each do |event|
event[:date] = format_date_time(event[:date])
end
events.sort_by! { |event| event[:timestamp] }
puts Terminal::Table.new :headings => events.first.keys.map{ |entry| entry.to_s }, :rows => events.map{ |entry| entry.values }