Class: Decidim::Debates::Metrics::DebateFollowersMetricMeasure

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

Overview

Searches for unique Users following the next objects

- Debates

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
27
# File 'decidim-debates/app/queries/decidim/debates/metrics/debate_followers_metric_measure.rb', line 13

def calculate
  debates = Decidim::Debates::Debate.where(component: @resource).joins(:component)

  debates_followers = Decidim::Follow.where(followable: debates).joins(:user)
                                     .where("decidim_follows.created_at <= ?", end_time)
  cumulative_users = debates_followers.pluck(:decidim_user_id)

  debates_followers = debates_followers.where("decidim_follows.created_at >= ?", start_time)
  quantity_users = debates_followers.pluck(:decidim_user_id)

  {
    cumulative_users: cumulative_users.uniq,
    quantity_users: quantity_users.uniq
  }
end

#valid?Boolean

Returns:

  • (Boolean)

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

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