Sha256: 0ed044e007bf95ada513af63af58163182ffaf63217ae0c996386a07a67b9f80

Contents?: true

Size: 790 Bytes

Versions: 63

Compression:

Stored size: 790 Bytes

Contents

# frozen_string_literal: true

module Decidim
  module Accountability
    # This class handles the calculation of progress for a set of results
    class ResultsCalculator
      # Public: Initializes the service.
      def initialize(component, scope_id, category_id)
        @component = component
        @scope_id = scope_id
        @category_id = category_id
      end

      delegate :count, to: :results

      def progress
        results.average("COALESCE(progress, 0)")
      end

      private

      attr_reader :component, :scope_id, :category_id

      def results
        @results ||= ResultSearch.new(
          component: component,
          scope_id: scope_id,
          category_id: category_id,
          deep_search: false
        ).results
      end
    end
  end
end

Version data entries

63 entries across 63 versions & 1 rubygems

Version Path
decidim-accountability-0.17.2 app/services/decidim/accountability/results_calculator.rb
decidim-accountability-0.18.0 app/services/decidim/accountability/results_calculator.rb
decidim-accountability-0.17.1 app/services/decidim/accountability/results_calculator.rb
decidim-accountability-0.16.1 app/services/decidim/accountability/results_calculator.rb
decidim-accountability-0.17.0 app/services/decidim/accountability/results_calculator.rb
decidim-accountability-0.16.0 app/services/decidim/accountability/results_calculator.rb
decidim-accountability-0.15.2 app/services/decidim/accountability/results_calculator.rb
decidim-accountability-0.15.1 app/services/decidim/accountability/results_calculator.rb
decidim-accountability-0.15.0 app/services/decidim/accountability/results_calculator.rb
decidim-accountability-0.14.4 app/services/decidim/accountability/results_calculator.rb
decidim-accountability-0.14.3 app/services/decidim/accountability/results_calculator.rb
decidim-accountability-0.14.2 app/services/decidim/accountability/results_calculator.rb
decidim-accountability-0.14.1 app/services/decidim/accountability/results_calculator.rb
decidim-accountability-0.13.1 app/services/decidim/accountability/results_calculator.rb
decidim-accountability-0.12.2 app/services/decidim/accountability/results_calculator.rb
decidim-accountability-0.13.0 app/services/decidim/accountability/results_calculator.rb
decidim-accountability-0.12.1 app/services/decidim/accountability/results_calculator.rb
decidim-accountability-0.13.0.pre1 app/services/decidim/accountability/results_calculator.rb
decidim-accountability-0.12.0 app/services/decidim/accountability/results_calculator.rb
decidim-accountability-0.11.2 app/services/decidim/accountability/results_calculator.rb