Class: ThinkFeelDoEngine::Reports::LessonSlideView
- Inherits:
-
Object
- Object
- ThinkFeelDoEngine::Reports::LessonSlideView
- Includes:
- LessonModule
- Defined in:
- app/models/think_feel_do_engine/reports/lesson_slide_view.rb
Overview
Scenario: a Participant starts viewing a Slide.
Constant Summary
Constants included from LessonModule
ThinkFeelDoEngine::Reports::LessonModule::URL_ROOT_RE
Class Method Summary collapse
- .all ⇒ Object
- .all_slide_interactions ⇒ Object
- .columns ⇒ Object
- .find_slide_by_url(slides, url) ⇒ Object
-
.next_event_at(event) ⇒ Object
Return the time of the Event immediately following if one exists, nil otherwise.
-
.slide_view_events(lessons, participant_id) ⇒ Object
Events for a Participant in which a Lesson Slide is viewed.
Methods included from LessonModule
Class Method Details
.all ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'app/models/think_feel_do_engine/reports/lesson_slide_view.rb', line 12 def self.all interactions = # condense adjacent interactions filtered_interactions = [] interactions.each_with_index do |interaction, i| previous_interaction = i > 0 ? interactions[i - 1] : {} next if previous_interaction[:slide_id] == interaction[:slide_id] next_interaction = interactions[i + 1] || {} filtered_interaction = interaction.clone if next_interaction[:slide_id] == interaction[:slide_id] filtered_interaction[:slide_exited_at] = next_interaction[:slide_exited_at] end filtered_interactions << filtered_interaction end filtered_interactions end |
.all_slide_interactions ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'app/models/think_feel_do_engine/reports/lesson_slide_view.rb', line 35 def self. lessons = lessons_map Participant.select(:id, :study_id).map do |participant| (lessons, participant.id).map do |lesson_event| e = lesson_event[1] lesson_id = lesson_event[0] = ContentModules::LessonModule.find(lesson_id). = (, e.current_url) { participant_id: participant.study_id, lesson_id: lesson_id, slide_id: .try(:id), slide_title: .try(:title), slide_selected_at: e.emitted_at.try(:iso8601), slide_exited_at: next_event_at(e).try(:iso8601) } end end.flatten end |
.columns ⇒ Object
7 8 9 10 |
# File 'app/models/think_feel_do_engine/reports/lesson_slide_view.rb', line 7 def self.columns %w( participant_id lesson_id slide_id slide_title slide_selected_at slide_exited_at ) end |
.find_slide_by_url(slides, url) ⇒ Object
83 84 85 86 87 88 89 90 91 |
# File 'app/models/think_feel_do_engine/reports/lesson_slide_view.rb', line 83 def self.(, url) = 1 if url.match(/modules\/\d+$/).nil? = url[/\d+$/].to_i end .find_by_position() end |
.next_event_at(event) ⇒ Object
Return the time of the Event immediately following if one exists, nil otherwise.
74 75 76 77 78 79 80 81 |
# File 'app/models/think_feel_do_engine/reports/lesson_slide_view.rb', line 74 def self.next_event_at(event) EventCapture::Event .where("participant_id = ? AND emitted_at > ?", event.participant_id, event.emitted_at) .select(:participant_id, :emitted_at) .limit(1) .first.try(:emitted_at) end |
.slide_view_events(lessons, participant_id) ⇒ Object
Events for a Participant in which a Lesson Slide is viewed.
58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'app/models/think_feel_do_engine/reports/lesson_slide_view.rb', line 58 def self.(lessons, participant_id) EventCapture::Event .where(participant_id: participant_id, kind: %w( click render )) .select(:participant_id, :emitted_at, :payload) .order(:emitted_at) .to_a.map do |e| key = lessons.keys.find do |l| !e.current_url.match(/#{ l }(\/.*)?$/).nil? end key ? [lessons[key], e] : nil end.compact end |