Sha256: 79187ce4ea655a0de0e86c928f0ce86daf97b3e5e3f4e76b0408d368c10b3b5d

Contents?: true

Size: 1003 Bytes

Versions: 13

Compression:

Stored size: 1003 Bytes

Contents

# frozen_string_literal: true

module Decidim
  module Budgets
    module Metrics
      # Searches for unique Users following the next objects
      #  - Budgets
      class BudgetFollowersMetricMeasure < Decidim::MetricMeasure
        def valid?
          super && @resource.is_a?(Decidim::Component)
        end

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

          budgets_followers = Decidim::Follow.where(followable: budgets).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
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
decidim-budgets-0.22.0 app/queries/decidim/budgets/metrics/budget_followers_metric_measure.rb
decidim-budgets-0.21.0 app/queries/decidim/budgets/metrics/budget_followers_metric_measure.rb
decidim-budgets-0.20.1 app/queries/decidim/budgets/metrics/budget_followers_metric_measure.rb
decidim-budgets-0.20.0 app/queries/decidim/budgets/metrics/budget_followers_metric_measure.rb
decidim-budgets-0.19.1 app/queries/decidim/budgets/metrics/budget_followers_metric_measure.rb
decidim-budgets-0.18.1 app/queries/decidim/budgets/metrics/budget_followers_metric_measure.rb
decidim-budgets-0.19.0 app/queries/decidim/budgets/metrics/budget_followers_metric_measure.rb
decidim-budgets-0.17.2 app/queries/decidim/budgets/metrics/budget_followers_metric_measure.rb
decidim-budgets-0.18.0 app/queries/decidim/budgets/metrics/budget_followers_metric_measure.rb
decidim-budgets-0.17.1 app/queries/decidim/budgets/metrics/budget_followers_metric_measure.rb
decidim-budgets-0.16.1 app/queries/decidim/budgets/metrics/budget_followers_metric_measure.rb
decidim-budgets-0.17.0 app/queries/decidim/budgets/metrics/budget_followers_metric_measure.rb
decidim-budgets-0.16.0 app/queries/decidim/budgets/metrics/budget_followers_metric_measure.rb