-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
stats_controller.rb
102 lines (77 loc) · 3.26 KB
/
stats_controller.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
class Admin::StatsController < Admin::BaseController
def show
@event_types = Ahoy::Event.pluck(:name).uniq.sort
@visits = Visit.count
@debates = Debate.with_hidden.count
@proposals = Proposal.with_hidden.count
@comments = Comment.not_valuations.with_hidden.count
@debate_votes = Vote.where(votable_type: "Debate").count
@proposal_votes = Vote.where(votable_type: "Proposal").count
@comment_votes = Vote.where(votable_type: "Comment").count
@votes = Vote.count
@user_level_two = User.active.level_two_verified.count
@user_level_three = User.active.level_three_verified.count
@verified_users = User.active.level_two_or_three_verified.count
@unverified_users = User.active.unverified.count
@users = User.active.count
@user_ids_who_voted_proposals = ActsAsVotable::Vote.where(votable_type: "Proposal")
.distinct
.count(:voter_id)
@user_ids_who_didnt_vote_proposals = @verified_users - @user_ids_who_voted_proposals
budgets_ids = Budget.where.not(phase: "finished").pluck(:id)
@budgets = budgets_ids.size
@investments = Budget::Investment.where(budget_id: budgets_ids).count
end
def graph
@name = params[:id]
@event = params[:event]
if params[:event]
@count = Ahoy::Event.where(name: params[:event]).count
else
@count = params[:count]
end
end
def proposal_notifications
@proposal_notifications = ProposalNotification.all
@proposals_with_notifications = @proposal_notifications.select(:proposal_id).distinct.count
end
def direct_messages
@direct_messages = DirectMessage.count
@users_who_have_sent_message = DirectMessage.select(:sender_id).distinct.count
end
def budgets
@budgets = Budget.all
end
def budget_supporting
@budget = Budget.find(params[:budget_id])
heading_ids = @budget.heading_ids
votes = Vote.where(votable_type: "Budget::Investment").
includes(:budget_investment).
where(budget_investments: { heading_id: heading_ids })
@vote_count = votes.count
@user_count = votes.select(:voter_id).distinct.count
@voters_in_heading = {}
@budget.headings.each do |heading|
@voters_in_heading[heading] = voters_in_heading(heading)
end
end
def budget_balloting
@budget = Budget.find(params[:budget_id])
authorize! :read_admin_stats, @budget, message: t("admin.stats.budgets.no_data_before_balloting_phase")
@user_count = @budget.ballots.select { |ballot| ballot.lines.any? }.count
@vote_count = @budget.lines.count
@vote_count_by_heading = @budget.lines.group(:heading_id).count.collect { |k, v| [Budget::Heading.find(k).name, v] }.sort
@user_count_by_district = User.where.not(balloted_heading_id: nil).group(:balloted_heading_id).count.collect { |k, v| [Budget::Heading.find(k).name, v] }.sort
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