-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathmeeting_poll.rb
More file actions
122 lines (95 loc) · 2.71 KB
/
meeting_poll.rb
File metadata and controls
122 lines (95 loc) · 2.71 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
#!/usr/bin/ruby -w
require 'rexml/document'
require 'json'
include REXML
xmlFileName = ARGV.first
puts "Parsing: " + xmlFileName
begin
xmlfile = File.new(xmlFileName)
rescue
print "Failed to open #{xmlFileName}\n"
print "Please specifcy events.xml for the BBB meeting for which you want to extract polling data\n"
exit
end
xmldoc = Document.new(xmlfile)
# Now get the root element
root = xmldoc.root
class User
def initialize(userId, name, role, externaluserId)
@userId = userId
@name = name
@role = role
@externaluserId = externaluserId
@polls = Array.new
end
def to_s
"User: #{@userId} #{@name} #{@role} #{@externaluserId} #{@polls}"
end
def as_json(options={})
{
userId: @userId,
name: @name,
role: @role,
externaluserId: @externaluserId,
pollAnswer: @polls.to_json
}
end
def to_json(*options)
as_json(*options).to_json(*options)
end
attr_accessor :userId, :name, :polls
end
class Poll
def initialize(pollId, pollTime, pollAnswer)
@pollId = pollId
@pollTime = pollTime
@pollAnswer = pollAnswer
end
def as_json(options={})
{
pollId: @pollId,
pollTime: @pollTime,
pollAnswer: @pollAnswer
}
end
def to_json(*options)
as_json(*options).to_json(*options)
end
end
puts "BigBlueButton Poll Analytics"
puts "Meeting Id : " + root.attributes["meeting_id"]
answerArray = Array.new
users = Array.new
xmldoc.elements.each("recording/event") do |e|
if(e.attributes["eventname"] == "ParticipantJoinEvent")
user = User.new(e.elements["userId"].text(),
e.elements["name"].text(),
e.elements["role"].text(),
e.elements["externalUserId"].text()
)
users.push(user)
elsif(e.attributes["eventname"] == "PollStartedRecordEvent")
# create answerArray to find answer key from given answer id when UserRespondedToPollRecordEvent is parsed
answerArray = JSON.parse(e.elements["answers"].text())
elsif(e.attributes["eventname"] == "UserRespondedToPollRecordEvent")
# answerArray would get populated when PollStartedRecordEvent element is parsed in the earlier if-else
if answerArray.length > 0
for answerElement in answerArray
if(answerElement["id"].to_s == e.elements["answerId"].text())
poll = Poll.new(e.elements["pollId"].text(),
e.elements["date"].text(),
answerElement["key"])
for u in users
if(u.userId == e.elements["userId"].text())
u.polls.push(poll)
end
end
end
end
end
end
end
# print all users with poll data
for u in users
puts u.to_json
end