Class: BBBEvents::Attendee

Inherits:
Object
  • Object
show all
Defined in:
lib/bbbevents/attendee.rb

Constant Summary collapse

MODERATOR_ROLE =
"MODERATOR"
VIEWER_ROLE =
"VIEWER"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(join_event) ⇒ Attendee

Returns a new instance of Attendee.



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
# File 'lib/bbbevents/attendee.rb', line 8

def initialize(join_event)
  @id        = join_event["userId"]
  @ext_user_id = join_event["externalUserId"]
  @name      = join_event["name"]
  @moderator = (join_event["role"] == MODERATOR_ROLE)

  @joins    = []
  @leaves   = []
  @duration = 0

  @recent_talking_time = 0

  @engagement = {
    chats: 0,
    talks: 0,
    raisehand: 0,
    emojis: 0,
    poll_votes: 0,
    talk_time: 0,
  }

  # A hash of join and lefts arrays for each internal user id
  # { "w_5lmcgjboagjc" => { :joins => [], :lefts => []}}
  @sessions = Hash.new
end

Instance Attribute Details

#durationObject

Returns the value of attribute duration.



3
4
5
# File 'lib/bbbevents/attendee.rb', line 3

def duration
  @duration
end

#engagementObject

Returns the value of attribute engagement.



3
4
5
# File 'lib/bbbevents/attendee.rb', line 3

def engagement
  @engagement
end

#ext_user_idObject

Returns the value of attribute ext_user_id.



3
4
5
# File 'lib/bbbevents/attendee.rb', line 3

def ext_user_id
  @ext_user_id
end

#idObject

Returns the value of attribute id.



3
4
5
# File 'lib/bbbevents/attendee.rb', line 3

def id
  @id
end

#joinsObject

Returns the value of attribute joins.



3
4
5
# File 'lib/bbbevents/attendee.rb', line 3

def joins
  @joins
end

#leavesObject

Returns the value of attribute leaves.



3
4
5
# File 'lib/bbbevents/attendee.rb', line 3

def leaves
  @leaves
end

#moderatorObject

Returns the value of attribute moderator.



3
4
5
# File 'lib/bbbevents/attendee.rb', line 3

def moderator
  @moderator
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/bbbevents/attendee.rb', line 3

def name
  @name
end

#recent_talking_timeObject

Returns the value of attribute recent_talking_time.



3
4
5
# File 'lib/bbbevents/attendee.rb', line 3

def recent_talking_time
  @recent_talking_time
end

#sessionsObject

Returns the value of attribute sessions.



3
4
5
# File 'lib/bbbevents/attendee.rb', line 3

def sessions
  @sessions
end

Instance Method Details

#as_jsonObject



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/bbbevents/attendee.rb', line 80

def as_json
  {
    id: @id,
    ext_user_id: @ext_user_id,
    name: @name,
    moderator: @moderator,
    joins: @joins.map { |join| BBBEvents.format_datetime(join) },
    leaves: @leaves.map { |leave| BBBEvents.format_datetime(leave) },
    duration: @duration,
    recent_talking_time: @recent_talking_time > 0 ? BBBEvents.format_datetime(Time.at(@recent_talking_time)) : '',
    engagement: @engagement,
    sessions: @sessions.map { |key, session| {
        joins: session[:joins].map { |join| join.merge({ timestamp: BBBEvents.format_datetime(join[:timestamp])}) },
        lefts: session[:lefts].map { |leave| leave.merge({ timestamp: BBBEvents.format_datetime(leave[:timestamp])}) }
      }
    }
  }
end

#csv_rowObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/bbbevents/attendee.rb', line 48

def csv_row
  e = @engagement
  [
    @name,
    @moderator,
    e[:chats],
    e[:talks],
    e[:emojis],
    e[:poll_votes],
    e[:raisehand],
    seconds_to_time(@engagement[:talk_time]),
    joined.strftime(DATE_FORMAT),
    left.strftime(DATE_FORMAT),
    seconds_to_time(@duration),
  ].map(&:to_s)
end

#joinedObject

Grab the initial join.



39
40
41
# File 'lib/bbbevents/attendee.rb', line 39

def joined
  @joins.first
end

#leftObject

Grab the last leave.



44
45
46
# File 'lib/bbbevents/attendee.rb', line 44

def left
  @leaves.last
end

#moderator?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/bbbevents/attendee.rb', line 34

def moderator?
  moderator
end

#to_hObject



65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/bbbevents/attendee.rb', line 65

def to_h
  {
    id: @id,
    ext_user_id: @ext_user_id,
    name: @name,
    moderator: @moderator,
    joins: @joins,
    leaves: @leaves,
    duration: @duration,
    recent_talking_time: @recent_talking_time > 0 ? Time.at(@recent_talking_time) : '',
    engagement: @engagement,
    sessions: @sessions,
  }
end

#to_jsonObject



99
100
101
# File 'lib/bbbevents/attendee.rb', line 99

def to_json
  JSON.generate(as_json)
end