Sha256: 0283406bc38116ceeafa28f235e4a316523688e441f027231b81ddf909f14859

Contents?: true

Size: 1.51 KB

Versions: 13

Compression:

Stored size: 1.51 KB

Contents

# frozen_string_literal: true
module ThinkFeelDoEngine
  module Reports
    # Scenario: a Participant accesses a Tool Module.
    class ToolAccess
      def self.columns
        %w( participant_id module_title came_from occurred_at )
      end

      def self.all
        Participant.not_moderator.select(:id, :study_id).map do |participant|
          tool_access_events(participant).map do |tool_access|
            {
              participant_id: participant.study_id,
              module_title: tool_access[:title],
              came_from: tool_access[:source],
              occurred_at: tool_access[:time].iso8601
            }
          end
        end.flatten
      end

      def self.tool_access_events(participant)
        sources = {
          "list-group left" => "Tool home",
          "list-group right" => "Tool home",
          "<li>" => "Nav menu",
          '<li class="list-group-item' => "To do list"
        }
        module_titles = BitCore::ContentModule.all.map(&:title)

        EventCapture::Event
          .where(kind: "click", participant_id: participant.id).map do |e|
            title = module_titles.find do |t|
              e.payload["buttonHtml"].include?(t)
            end
            source = sources.keys.find do |s|
              e.payload["parentHtml"].try(:include?, s)
            end

            next unless title && source

            {
              title: title,
              source: sources[source],
              time: e.emitted_at
            }
          end.compact
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
think_feel_do_engine-3.22.9 app/models/think_feel_do_engine/reports/tool_access.rb
think_feel_do_engine-3.22.8 app/models/think_feel_do_engine/reports/tool_access.rb
think_feel_do_engine-3.22.7 app/models/think_feel_do_engine/reports/tool_access.rb
think_feel_do_engine-3.22.6 app/models/think_feel_do_engine/reports/tool_access.rb
think_feel_do_engine-3.22.5 app/models/think_feel_do_engine/reports/tool_access.rb
think_feel_do_engine-3.22.4 app/models/think_feel_do_engine/reports/tool_access.rb
think_feel_do_engine-3.22.2 app/models/think_feel_do_engine/reports/tool_access.rb
think_feel_do_engine-3.22.1 app/models/think_feel_do_engine/reports/tool_access.rb
think_feel_do_engine-3.22.0 app/models/think_feel_do_engine/reports/tool_access.rb
think_feel_do_engine-3.21.2 app/models/think_feel_do_engine/reports/tool_access.rb
think_feel_do_engine-3.21.1 app/models/think_feel_do_engine/reports/tool_access.rb
think_feel_do_engine-3.21.0 app/models/think_feel_do_engine/reports/tool_access.rb
think_feel_do_engine-3.20.1 app/models/think_feel_do_engine/reports/tool_access.rb