Class: Decidim::Surveys::Metrics::SurveyParticipantsMetricMeasure

Inherits:
MetricMeasure
  • Object
show all
Defined in:
decidim-surveys/app/queries/decidim/surveys/metrics/survey_participants_metric_measure.rb

Overview

Searches for Participants in the following actions

- Answer a survey (Surveys)

Instance Method Summary collapse

Methods inherited from MetricMeasure

#initialize

Constructor Details

This class inherits a constructor from Decidim::MetricMeasure

Instance Method Details

#calculateObject


13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'decidim-surveys/app/queries/decidim/surveys/metrics/survey_participants_metric_measure.rb', line 13

def calculate
  surveys = Decidim::Surveys::Survey.joins(:component, :questionnaire).where(component: @resource)
  questionnaires = Decidim::Forms::Questionnaire.includes(:questionnaire_for)
                                                .where(questionnaire_for_type: Decidim::Surveys::Survey.name, questionnaire_for_id: surveys.pluck(:id))

  answers = Decidim::Forms::Answer.joins(:questionnaire)
                                  .where(questionnaire: questionnaires)
                                  .where("decidim_forms_answers.created_at <= ?", end_time)

  {
    cumulative_users: answers.pluck(:decidim_user_id).uniq,
    quantity_users: answers.where("decidim_forms_answers.created_at >= ?", start_time).pluck(:decidim_user_id).uniq
  }
end

#valid?Boolean

Returns:

  • (Boolean)

9
10
11
# File 'decidim-surveys/app/queries/decidim/surveys/metrics/survey_participants_metric_measure.rb', line 9

def valid?
  super && @resource.is_a?(Decidim::Component)
end