Sha256: 0397681dee9d2234749e77908192a2c76e58eca452594522139a93b92872a86b

Contents?: true

Size: 1.47 KB

Versions: 44

Compression:

Stored size: 1.47 KB

Contents

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.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

44 entries across 44 versions & 1 rubygems

Version Path
think_feel_do_engine-3.17.2 app/models/think_feel_do_engine/reports/tool_access.rb
think_feel_do_engine-3.17.1 app/models/think_feel_do_engine/reports/tool_access.rb
think_feel_do_engine-3.17.0 app/models/think_feel_do_engine/reports/tool_access.rb
think_feel_do_engine-3.16.3 app/models/think_feel_do_engine/reports/tool_access.rb
think_feel_do_engine-3.16.2 app/models/think_feel_do_engine/reports/tool_access.rb
think_feel_do_engine-3.16.1 app/models/think_feel_do_engine/reports/tool_access.rb
think_feel_do_engine-3.15.7 app/models/think_feel_do_engine/reports/tool_access.rb
think_feel_do_engine-3.16.0 app/models/think_feel_do_engine/reports/tool_access.rb
think_feel_do_engine-3.15.6 app/models/think_feel_do_engine/reports/tool_access.rb
think_feel_do_engine-3.15.5 app/models/think_feel_do_engine/reports/tool_access.rb
think_feel_do_engine-3.15.4 app/models/think_feel_do_engine/reports/tool_access.rb
think_feel_do_engine-3.15.3 app/models/think_feel_do_engine/reports/tool_access.rb
think_feel_do_engine-3.15.2 app/models/think_feel_do_engine/reports/tool_access.rb
think_feel_do_engine-3.15.1 app/models/think_feel_do_engine/reports/tool_access.rb
think_feel_do_engine-3.15.0 app/models/think_feel_do_engine/reports/tool_access.rb
think_feel_do_engine-3.14.9 app/models/think_feel_do_engine/reports/tool_access.rb
think_feel_do_engine-3.14.8 app/models/think_feel_do_engine/reports/tool_access.rb
think_feel_do_engine-3.14.7 app/models/think_feel_do_engine/reports/tool_access.rb
think_feel_do_engine-3.14.6 app/models/think_feel_do_engine/reports/tool_access.rb
think_feel_do_engine-3.14.5 app/models/think_feel_do_engine/reports/tool_access.rb