adds budget investments numbers and chart on admin stats

This commit is contained in:
Alberto Garcia Cabeza
2017-04-25 16:46:20 +02:00
parent 79f147ec00
commit 45af9ce5aa
7 changed files with 72 additions and 13 deletions

View File

@@ -1,9 +1,10 @@
class Admin::Api::StatsController < Admin::Api::BaseController
def show
unless params[:events].present? ||
params[:visits].present? ||
params[:spending_proposals].present?
unless params[:events].present? ||
params[:visits].present? ||
params[:spending_proposals].present? ||
params[:budget_investments].present?
return render json: {}, status: :bad_request
end
@@ -24,6 +25,10 @@ class Admin::Api::StatsController < Admin::Api::BaseController
ds.add "Spending proposals", SpendingProposal.group_by_day(:created_at).count
end
if params[:budget_investments].present?
ds.add "Budget Investments", Budget::Investment.group_by_day(:created_at).count
end
render json: ds.build
end
end

View File

@@ -21,6 +21,8 @@ class Admin::StatsController < Admin::BaseController
@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
@spending_proposals = SpendingProposal.count
@budgets = Budget.where.not(phase: 'finished').count
@investments = Budget.where.not(phase: 'finished').collect(&:investments).flatten.count
end
def proposal_notifications

View File

@@ -21,4 +21,11 @@ module StatsHelper
content_tag :div, "", opt
end
def budget_investments_chart_tag(opt={})
events = events.join(',') if events.is_a? Array
opt[:data] ||= {}
opt[:data][:graph] = admin_api_stats_path(budget_investments: true)
content_tag :div, "", opt
end
end

View File

@@ -36,6 +36,16 @@
<%= t "admin.stats.show.summary.comments" %><br>
<span class="number"><%= number_with_delimiter(@comments) %></span>
</p>
<% if feature?(:polls) %>
<p>
<%= t "admin.stats.show.summary.budgets" %><br>
<span class="number"><%= number_with_delimiter(@budgets) %></span>
</p>
<p class="featured">
<%= t "admin.stats.show.summary.budget_investments" %><br>
<span class="number"><%= number_with_delimiter(@investments) %></span>
</p>
<% end %>
</div>
<div class="small-12 medium-3 column">
@@ -96,12 +106,14 @@
</p>
</div>
<div class="small-12 medium-3 column">
<p class="featured">
<%= t "admin.stats.show.summary.spending_proposals" %><br>
<span class="number"><%= number_with_delimiter(@spending_proposals) %></span>
</p>
</div>
<% if feature?(:spending_proposals) %>
<div class="small-12 medium-3 column">
<p class="featured">
<%= t "admin.stats.show.summary.spending_proposals" %><br>
<span class="number"><%= number_with_delimiter(@spending_proposals) %></span>
</p>
</div>
<% end %>
</div>
<div class="small-12 column">
@@ -116,11 +128,19 @@
<% end %>
</div>
<div class="small-12 column">
<h2><%= t "admin.stats.show.spending_proposals_title" %></h2>
<%= spending_proposals_chart_tag id: "spending_proposals" %>
</div>
<% if feature?(:spending_proposals) %>
<div class="small-12 column">
<h2><%= t "admin.stats.show.spending_proposals_title" %></h2>
<%= spending_proposals_chart_tag id: "spending_proposals" %>
</div>
<% end %>
<% if feature?(:polls) %>
<div class="small-12 column">
<h2><%= t "admin.stats.show.budgets_title" %></h2>
<%= budget_investments_chart_tag id: "budget_investments" %>
</div>
<% end %>
</div>
</div>
</div>

View File

@@ -612,6 +612,8 @@ en:
debates: Debates
proposal_votes: Proposal votes
proposals: Proposals
budgets: Open budgets
budget_investments: Investment projects
spending_proposals: Spending Proposals
unverified_users: Unverified users
user_level_three: Level three users
@@ -622,6 +624,7 @@ en:
visits: Visits
votes: Total votes
spending_proposals_title: Spending Proposals
budgets_title: Participatory budgeting
visits_title: Visits
direct_messages: Direct messages
proposal_notifications: Proposal notifications

View File

@@ -612,6 +612,8 @@ es:
debates: Debates
proposal_votes: Votos en propuestas
proposals: Propuestas
budgets: Presupuestos abiertos
budget_investments: Propuestas de inversión
spending_proposals: Propuestas de inversión
unverified_users: Usuarios sin verificar
user_level_three: Usuarios de nivel tres
@@ -622,6 +624,7 @@ es:
visits: Visitas
votes: Votos
spending_proposals_title: Propuestas de inversión
budgets_title: Presupuestos participativos
visits_title: Visitas
direct_messages: Mensajes directos
proposal_notifications: Notificaciones de propuestas

View File

@@ -91,5 +91,24 @@ describe Admin::Api::StatsController do
expect(data).to eq "x"=>["2015-01-01", "2015-01-02"], "Foo"=>[1, 2], "Visits"=>[2, 1]
end
end
context 'budget investments present' do
it 'should return budget investments formated for working with c3.js' do
time_1 = DateTime.parse("2017-04-01")
time_2 = DateTime.parse("2017-04-02")
budget_investment1 = create(:budget_investment, budget: @budget, created_at: time_1)
budget_investment2 = create(:budget_investment, budget: @budget, created_at: time_2)
budget_investment3 = create(:budget_investment, budget: @budget, created_at: time_2)
sign_in user
get :show, budget_investments: true
expect(response).to be_ok
data = JSON.parse(response.body)
expect(data).to eq "x"=>["2017-04-01", "2017-04-02"], "Budget Investments"=>[1, 2]
end
end
end
end