13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File '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
|