Files
nairobi/app/components/admin/stats/budget_supporting_component.rb
Javi Martín e51e034468 Use budget stats model to calculate admin stats
This way we reduce duplication.
2023-02-20 14:21:22 +01:00

32 lines
595 B
Ruby

class Admin::Stats::BudgetSupportingComponent < ApplicationComponent
attr_reader :budget
def initialize(budget)
@budget = budget
end
private
def stats
@stats ||= Budget::Stats.new(budget)
end
def headings_stats
@headings_stats ||= stats.headings
end
def vote_count
stats.total_supports
end
def user_count
stats.total_participants_support_phase
end
def user_count_by_heading
budget.headings.map do |heading|
[heading, headings_stats[heading.id][:total_participants_support_phase]]
end
end
end