Sha256: 92ff84ea9df1e083d4784e8559234abed10848946de3421fa4e6caaa7dd8c097

Contents?: true

Size: 1.05 KB

Versions: 58

Compression:

Stored size: 1.05 KB

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::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
      end
    end
  end
end

Version data entries

58 entries across 58 versions & 1 rubygems

Version Path
decidim-budgets-0.29.1 app/queries/decidim/budgets/metrics/budget_followers_metric_measure.rb
decidim-budgets-0.28.4 app/queries/decidim/budgets/metrics/budget_followers_metric_measure.rb
decidim-budgets-0.27.9 app/queries/decidim/budgets/metrics/budget_followers_metric_measure.rb
decidim-budgets-0.29.0 app/queries/decidim/budgets/metrics/budget_followers_metric_measure.rb
decidim-budgets-0.28.3 app/queries/decidim/budgets/metrics/budget_followers_metric_measure.rb
decidim-budgets-0.27.8 app/queries/decidim/budgets/metrics/budget_followers_metric_measure.rb
decidim-budgets-0.29.0.rc4 app/queries/decidim/budgets/metrics/budget_followers_metric_measure.rb
decidim-budgets-0.29.0.rc3 app/queries/decidim/budgets/metrics/budget_followers_metric_measure.rb
decidim-budgets-0.29.0.rc2 app/queries/decidim/budgets/metrics/budget_followers_metric_measure.rb
decidim-budgets-0.29.0.rc1 app/queries/decidim/budgets/metrics/budget_followers_metric_measure.rb
decidim-budgets-0.28.2 app/queries/decidim/budgets/metrics/budget_followers_metric_measure.rb
decidim-budgets-0.27.7 app/queries/decidim/budgets/metrics/budget_followers_metric_measure.rb
decidim-budgets-0.28.1 app/queries/decidim/budgets/metrics/budget_followers_metric_measure.rb
decidim-budgets-0.27.6 app/queries/decidim/budgets/metrics/budget_followers_metric_measure.rb
decidim-budgets-0.26.10 app/queries/decidim/budgets/metrics/budget_followers_metric_measure.rb
decidim-budgets-0.26.9 app/queries/decidim/budgets/metrics/budget_followers_metric_measure.rb
decidim-budgets-0.28.0 app/queries/decidim/budgets/metrics/budget_followers_metric_measure.rb
decidim-budgets-0.27.5 app/queries/decidim/budgets/metrics/budget_followers_metric_measure.rb
decidim-budgets-0.28.0.rc5 app/queries/decidim/budgets/metrics/budget_followers_metric_measure.rb
decidim-budgets-0.28.0.rc4 app/queries/decidim/budgets/metrics/budget_followers_metric_measure.rb