Sha256: d6bfc7ca0f0490a037dcada31f43bb2d205bb7ed85d4d065694ce8c37a63c587

Contents?: true

Size: 1.08 KB

Versions: 13

Compression:

Stored size: 1.08 KB

Contents

# frozen_string_literal: true

module Decidim
  # A general presenter to render statistics in participatory spaces.
  class StatsPresenter < Rectify::Presenter
    def comments_stats(name)
      comments = Decidim.component_manifests.map do |component_manifest|
        component_manifest.stats.only([:comments_count])
                          .filter({ tag: :comments })
                          .with_context(published_components)
                          .map { |_name, value| value }.sum
      end
      comments_count = comments.inject(0, :+) { |sum, value| sum + value }
      [[name, :comments_count, comments_count]]
    end

    def statistics(grouped_stats)
      statistics = []
      grouped_stats.each do |_manifest_name, stats|
        stats.each_with_index.each do |stat, _index|
          stat.each_with_index.map do |_item, subindex|
            next unless (subindex % 3).zero?
            next if stat[subindex + 2].zero?

            statistics << { stat_title: stat[subindex + 1], stat_number: stat[subindex + 2] }
          end
        end
      end
      statistics
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
decidim-core-0.26.3 app/presenters/decidim/stats_presenter.rb
decidim-core-0.26.2 app/presenters/decidim/stats_presenter.rb
decidim-core-0.26.1 app/presenters/decidim/stats_presenter.rb
decidim-core-0.26.0 app/presenters/decidim/stats_presenter.rb
decidim-core-0.26.0.rc2 app/presenters/decidim/stats_presenter.rb
decidim-core-0.26.0.rc1 app/presenters/decidim/stats_presenter.rb
decidim-core-0.25.2 app/presenters/decidim/stats_presenter.rb
decidim-core-0.25.1 app/presenters/decidim/stats_presenter.rb
decidim-core-0.25.0 app/presenters/decidim/stats_presenter.rb
decidim-core-0.25.0.rc4 app/presenters/decidim/stats_presenter.rb
decidim-core-0.25.0.rc3 app/presenters/decidim/stats_presenter.rb
decidim-core-0.25.0.rc2 app/presenters/decidim/stats_presenter.rb
decidim-core-0.25.0.rc1 app/presenters/decidim/stats_presenter.rb