-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add admin budget stats #3499
Add admin budget stats #3499
Changes from all commits
cfe3f95
a31b625
94a3e7e
1f8d19c
73d35e2
0d9ff07
b628631
be757f7
5121c9b
135984d
11437a1
5be54b5
110ee96
f22a974
d5c7858
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,18 @@ | ||
class Admin::Api::StatsController < Admin::Api::BaseController | ||
|
||
def show | ||
unless params[:events].present? || | ||
unless params[:event].present? || | ||
params[:visits].present? || | ||
params[:spending_proposals].present? || | ||
params[:budget_investments].present? | ||
params[:budget_investments].present? || | ||
params[:user_supported_budgets].present? | ||
return render json: {}, status: :bad_request | ||
end | ||
|
||
ds = Ahoy::DataSource.new | ||
|
||
if params[:events].present? | ||
event_types = params[:events].split "," | ||
event_types.each do |event| | ||
ds.add event.titleize, Ahoy::Event.where(name: event).group_by_day(:time).count | ||
end | ||
if params[:event].present? | ||
ds.add params[:event].titleize, Ahoy::Event.where(name: params[:event]).group_by_day(:time).count | ||
end | ||
|
||
if params[:visits].present? | ||
|
@@ -29,6 +27,9 @@ def show | |
ds.add "Budget Investments", Budget::Investment.group_by_day(:created_at).count | ||
end | ||
|
||
if params[:user_supported_budgets].present? | ||
ds.add "User supported budgets", Vote.where(votable_type: "Budget::Investment").group_by_day(:updated_at).count | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Metrics/LineLength: Line is too long. [117/100] (https://github.com/bbatsov/ruby-style-guide#80-character-limits) |
||
end | ||
render json: ds.build | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
class Admin::StatsController < Admin::BaseController | ||
|
||
def show | ||
@event_types = Ahoy::Event.group(:name).count | ||
@event_types = Ahoy::Event.pluck(:name).uniq.sort | ||
|
||
@visits = Visit.count | ||
@debates = Debate.with_hidden.count | ||
|
@@ -31,6 +31,17 @@ def show | |
@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 | ||
|
@@ -41,9 +52,50 @@ def direct_messages | |
@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]) | ||
@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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Metrics/LineLength: Line is too long. [122/100] (https://github.com/bbatsov/ruby-style-guide#80-character-limits) |
||
|
||
@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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Metrics/LineLength: Line is too long. [159/100] (https://github.com/bbatsov/ruby-style-guide#80-character-limits) |
||
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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<%= back_link_to %> | ||
|
||
<div id="graph" class="small-12 column"> | ||
<h2><%= t "admin.stats.graph.#{name || event}" %> (<%= count %>)</h2> | ||
<%= chart_tag id: name, event: event %> | ||
</div> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<%= back_link_to budgets_admin_stats_path %> | ||
|
||
<h2><%= @budget.name %> - <%= t("admin.stats.budget_balloting.title") %></h2> | ||
|
||
<div class="stats"> | ||
<div class="row stats-numbers"> | ||
<div class="small-12 medium-3 column"> | ||
<p class="featured"> | ||
<%= t("admin.stats.budget_balloting.vote_count") %> | ||
<br> | ||
<span id="total_votes_count" class="number"> | ||
<%= @vote_count %> | ||
</span> | ||
</p> | ||
</div> | ||
|
||
<div class="small-12 medium-6 column end"> | ||
<p> | ||
<%= t("admin.stats.budget_balloting.participant_count") %> | ||
<br> | ||
<span id="total_participants_count" class="number"> | ||
<%= @user_count %> | ||
</span> | ||
</p> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<table class="investment-projects-summary"> | ||
<th colspan="2"><%= t("admin.stats.budget_balloting.votes_per_heading") %></th> | ||
|
||
<% @vote_count_by_heading.each do |heading_name, count| %> | ||
<tr id="vote_count_<%= heading_name.parameterize %>"> | ||
<td class="name"> | ||
<%= heading_name %> | ||
</td> | ||
<td class="name"> | ||
<%= number_with_delimiter count %> | ||
</td> | ||
</tr> | ||
<% end %> | ||
</table> | ||
|
||
<table class="investment-projects-summary"> | ||
<th colspan="2"><%= t("admin.stats.budget_balloting.participants_per_district") %></th> | ||
|
||
<% @user_count_by_district.each do |heading_name, count| %> | ||
<tr id="user_count_<%= heading_name.parameterize %>"> | ||
<td class="name"> | ||
<%= heading_name %> | ||
</td> | ||
<td class="name"> | ||
<%= number_with_delimiter count %> | ||
</td> | ||
</tr> | ||
<% end %> | ||
</table> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<% content_for :head do %> | ||
<%= javascript_include_tag "stat_graphs", "data-turbolinks-track" => true %> | ||
<% end %> | ||
|
||
<%= back_link_to budgets_admin_stats_path %> | ||
|
||
<h2><%= @budget.name %> - <%= t("admin.stats.budget_supporting.title") %></h2> | ||
|
||
<div class="stats"> | ||
<div class="row stats-numbers"> | ||
<div class="small-12 medium-3 column"> | ||
<p class="featured"> | ||
<%= t("admin.stats.budget_supporting.vote_count") %> | ||
<br> | ||
<span id="total_votes_count" class="number"> | ||
<%= @vote_count %> | ||
</span> | ||
</p> | ||
</div> | ||
|
||
<div class="small-12 medium-6 column end"> | ||
<p> | ||
<%= t("admin.stats.budget_supporting.participant_count") %> | ||
<br> | ||
<span id="total_participants_count" class="number"> | ||
<%= @user_count %> | ||
</span> | ||
</p> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<%= render "graph", name: "user_supported_budgets", event: "", count: @user_count %> | ||
|
||
<table class="investment-projects-summary"> | ||
<th><%= t("admin.stats.budget_supporting.headings") %></th> | ||
<th><%= t("admin.stats.budget_supporting.users") %></th> | ||
|
||
<% @voters_in_heading.each do |heading, count| %> | ||
<tr id="<%= dom_id(heading) %>"> | ||
<td class="name"> | ||
<%= heading.name %> | ||
</td> | ||
<td class="name"> | ||
<%= number_with_delimiter count %> | ||
</td> | ||
</tr> | ||
<% end %> | ||
</table> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<%= back_link_to admin_stats_path %> | ||
|
||
<h2><%= t("admin.stats.budgets.title") %></h2> | ||
|
||
<% @budgets.each do |budget| %> | ||
<table> | ||
<tr id="<%= dom_id(budget) %>"> | ||
<td> | ||
<strong><%= budget.name %></strong> | ||
</td> | ||
<td> | ||
<%= link_to t("admin.stats.budgets.supporting_phase"), budget_supporting_admin_stats_path(budget_id: budget.id), class: "button hollow" %> | ||
<%= link_to t("admin.stats.budgets.balloting_phase"), budget_balloting_admin_stats_path(budget_id: budget.id), class: "button hollow" %> | ||
</td> | ||
</tr> | ||
</table> | ||
<% end %> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<% content_for :head do %> | ||
<%= javascript_include_tag "stat_graphs", 'data-turbolinks-track' => true %> | ||
<% end %> | ||
|
||
<%= render 'graph', name: @name, event: @event, count: @count %> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,4 +8,8 @@ def track_event(name, properties, options) | |
event.ip = request.ip | ||
end | ||
end | ||
|
||
def exclude? | ||
false | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Metrics/LineLength: Line is too long. [103/100] (https://github.com/bbatsov/ruby-style-guide#80-character-limits)