add budget investment stats

This commit is contained in:
rgarcia
2017-03-13 20:43:24 +01:00
committed by Javi Martín
parent 135984d535
commit 11437a1d40
9 changed files with 163 additions and 1 deletions

View File

@@ -52,9 +52,29 @@ class Admin::StatsController < Admin::BaseController
@users_who_have_sent_message = DirectMessage.select(:sender_id).distinct.count
end
def budget_investments
votes = Vote.for_budget_investments(Budget::Investment.all)
@vote_count = votes.count
@participant_count = votes.select(:voter_id).distinct.count
@voters_in_heading = {}
budget = Budget.last
budget.headings.each do |heading|
@voters_in_heading[heading] = voters_in_heading(heading)
end
end
def polls
@polls = ::Poll.current
@participants = ::Poll::Voter.where(poll: @polls)
end
private
def voters_in_heading(heading)
Vote.where(votable_type: "Budget::Investment").
includes(:budget_investment).
where(budget_investments: { heading_id: heading.id }).
select("votes.voter_id").distinct.count
end
end