Class: Decidim::StatsPresenter
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- Decidim::StatsPresenter
- Defined in:
- decidim-core/app/presenters/decidim/stats_presenter.rb
Overview
A general presenter to render statistics in participatory spaces.
Direct Known Subclasses
Admin::DashboardStatisticChartsPresenter, Assemblies::AssemblyStatsPresenter, Conferences::ConferenceStatsPresenter, HomeStatsPresenter, ParticipatoryProcesses::ParticipatoryProcessGroupStatsPresenter, ParticipatoryProcesses::ParticipatoryProcessStatsPresenter
Instance Method Summary collapse
- #all_stats(conditions) ⇒ Object
-
#collection(priority: StatsRegistry::MEDIUM_PRIORITY) ⇒ Object
Public: returns a collection of stats (Hash) for the Participatory Space Home.
-
#scope_entity ⇒ Object
Public: returns the entity where to limit the stats on.
Instance Method Details
#all_stats(conditions) ⇒ Object
23 24 25 26 |
# File 'decidim-core/app/presenters/decidim/stats_presenter.rb', line 23 def all_stats(conditions) @global_stats ||= {} @global_stats[conditions] ||= global_stats(**conditions).concat(component_stats(**conditions)) end |
#collection(priority: StatsRegistry::MEDIUM_PRIORITY) ⇒ Object
Public: returns a collection of stats (Hash) for the Participatory Space Home.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'decidim-core/app/presenters/decidim/stats_presenter.rb', line 7 def collection(priority: StatsRegistry::MEDIUM_PRIORITY) stats = all_stats(priority:).reject(&:empty?) stats = stats.reject { |stat| stat[:data].blank? || stat[:data][0].zero? } stats.each_with_object({}) do |stat, hash| name = stat[:name] if hash[name] stat[:data].each_with_index do |value, idx| hash[name][:data][idx] ||= 0 hash[name][:data][idx] += value end else hash[name] = stat end end.values end |
#scope_entity ⇒ Object
Public: returns the entity where to limit the stats on. Usually, this is a Participatory Space or an Organization.
30 |
# File 'decidim-core/app/presenters/decidim/stats_presenter.rb', line 30 def scope_entity = raise NotImplementedError |