Class: Decidim::Metrics::FollowersMetricManage

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

Overview

Metric manager for Followers’s registries Searches for unique Followers for registered MetricOperations

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



8
9
10
# File 'app/queries/decidim/metrics/followers_metric_manage.rb', line 8

def metric_name
  "followers"
end

#saveObject



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

def save
  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)
    record.save!
  end
end