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

Inherits:
MetricMeasure
  • Object
show all
Defined in:
app/queries/decidim/lausanne/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



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

def calculate
  budgets = Decidim::Lausanne::Budgets::LausanneBudget.where(component: @resource)
  projects = Decidim::Lausanne::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(:loz_user_record_id)

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

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

#valid?Boolean

Returns:

  • (Boolean)


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

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