Class: Decidim::Budgets::Metrics::BudgetFollowersMetricMeasure

Inherits:
MetricMeasure
  • Object
show all
Defined in:
app/queries/decidim/budgets/metrics/budget_followers_metric_measure.rb

Overview

Searches for unique Users following the next objects

- Budgets

Instance Method Summary collapse

Instance Method Details

#calculateObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/queries/decidim/budgets/metrics/budget_followers_metric_measure.rb', line 13

def calculate
  budgets = Decidim::Budgets::Budget.where(component: @resource)
  projects = Decidim::Budgets::Project.where(budget: budgets)

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

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

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

#valid?Boolean

Returns:

  • (Boolean)


9
10
11
# File 'app/queries/decidim/budgets/metrics/budget_followers_metric_measure.rb', line 9

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