Class: Decidim::Metrics::ParticipantsMetricManage

Inherits:
Decidim::MetricManage show all
Defined in:
app/queries/decidim/metrics/participants_metric_manage.rb

Overview

Metric manager for Participant’s registries Searches for Participants for registered MetricOperations

Constant Summary collapse

AVAILABLE_COMPONENTS =

This list limits the number of components involved in this Metric

%w(proposals debates surveys budgets).freeze

Instance Method Summary collapse

Methods inherited from Decidim::MetricManage

for, #initialize, #valid?

Constructor Details

This class inherits a constructor from Decidim::MetricManage

Instance Method Details

#metric_nameObject



11
12
13
# File 'app/queries/decidim/metrics/participants_metric_manage.rb', line 11

def metric_name
  "participants"
end

#saveObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/queries/decidim/metrics/participants_metric_manage.rb', line 15

def save
  return @registry if @registry

  @registry = []
  query.each do |key, results|
    cumulative_value = results[:cumulative_users].count
    next if cumulative_value.zero?

    quantity_value = results[:quantity_users].count || 0
    space_type, space_id = key
    record = Decidim::Metric.find_or_initialize_by(day: @day.to_s, metric_type: @metric_name,
                                                   participatory_space_type: space_type, participatory_space_id: space_id,
                                                   organization: @organization)
    record.assign_attributes(cumulative: cumulative_value, quantity: quantity_value)
    @registry << record
  end
  @registry.each(&:save!)
  @registry
end