Class: ThinkFeelDoEngine::Reports::SiteSession
- Inherits:
-
Object
- Object
- ThinkFeelDoEngine::Reports::SiteSession
- Defined in:
- app/models/think_feel_do_engine/reports/site_session.rb
Overview
Scenario: a Participant is active on the site for a period of time.
Constant Summary collapse
- THRESHOLD =
5.minutes
Class Method Summary collapse
- .all ⇒ Object
- .click_times(participant_id) ⇒ Object
- .columns ⇒ Object
-
.preceding_sign_in(participant_id, time) ⇒ Object
Returns the sign in for the Participant closest to the given time.
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 34 35 36 37 38 39 40 41 42 43 |
# File 'app/models/think_feel_do_engine/reports/site_session.rb', line 12 def self.all Participant.not_moderator.select(:id, :study_id).map do |participant| earliest_click_time = latest_click_time = nil times = click_times(participant.id) times.map do |click_time| earliest_click_time ||= click_time latest_click_time ||= earliest_click_time if click_time - latest_click_time < THRESHOLD && click_time != times.last # this click is part of the current session latest_click_time = click_time nil else # this click is part of the next session or # it's the last click sign_in = preceding_sign_in(participant.id, earliest_click_time) session = { participant_id: participant.study_id, sign_in_at: sign_in.try(:iso8601), first_action_at: earliest_click_time.iso8601, last_action_at: latest_click_time.iso8601 } earliest_click_time = latest_click_time = nil session end end.compact end.flatten end |
.click_times(participant_id) ⇒ Object
45 46 47 48 49 50 51 |
# File 'app/models/think_feel_do_engine/reports/site_session.rb', line 45 def self.click_times(participant_id) EventCapture::Event .where(participant_id: participant_id, kind: "click") .order(:emitted_at) .select(:emitted_at) .map(&:emitted_at) end |
.columns ⇒ Object
8 9 10 |
# File 'app/models/think_feel_do_engine/reports/site_session.rb', line 8 def self.columns %w( participant_id sign_in_at first_action_at last_action_at ) end |
.preceding_sign_in(participant_id, time) ⇒ Object
Returns the sign in for the Participant closest to the given time.
54 55 56 57 58 59 60 61 |
# File 'app/models/think_feel_do_engine/reports/site_session.rb', line 54 def self.preceding_sign_in(participant_id, time) ParticipantLoginEvent .where(participant_id: participant_id) .order(:created_at) .where("created_at < ?", time) .last .try(:created_at) end |