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 class Admin::Api::StatsController < Admin::Api::BaseController
def show def show
unless params[:events].present? || unless params[:events].present? ||
params[:visits].present? || params[:visits].present? ||
params[:spending_proposals].present? params[:spending_proposals].present? ||
params[:budget_investments].present?
return render json: {}, status: :bad_request return render json: {}, status: :bad_request
end end
@@ -24,6 +25,10 @@ class Admin::Api::StatsController < Admin::Api::BaseController
ds.add "Spending proposals", SpendingProposal.group_by_day(:created_at).count ds.add "Spending proposals", SpendingProposal.group_by_day(:created_at).count
end end
if params[:budget_investments].present?
ds.add "Budget Investments", Budget::Investment.group_by_day(:created_at).count
end
render json: ds.build render json: ds.build
end end
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_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 @user_ids_who_didnt_vote_proposals = @verified_users - @user_ids_who_voted_proposals
@spending_proposals = SpendingProposal.count @spending_proposals = SpendingProposal.count
@budgets = Budget.where.not(phase: 'finished').count
@investments = Budget.where.not(phase: 'finished').collect(&:investments).flatten.count
end end
def proposal_notifications def proposal_notifications

View File

@@ -21,4 +21,11 @@ module StatsHelper
content_tag :div, "", opt content_tag :div, "", opt
end 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 end

View File

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

View File

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

View File

@@ -612,6 +612,8 @@ es:
debates: Debates debates: Debates
proposal_votes: Votos en propuestas proposal_votes: Votos en propuestas
proposals: Propuestas proposals: Propuestas
budgets: Presupuestos abiertos
budget_investments: Propuestas de inversión
spending_proposals: Propuestas de inversión spending_proposals: Propuestas de inversión
unverified_users: Usuarios sin verificar unverified_users: Usuarios sin verificar
user_level_three: Usuarios de nivel tres user_level_three: Usuarios de nivel tres
@@ -622,6 +624,7 @@ es:
visits: Visitas visits: Visitas
votes: Votos votes: Votos
spending_proposals_title: Propuestas de inversión spending_proposals_title: Propuestas de inversión
budgets_title: Presupuestos participativos
visits_title: Visitas visits_title: Visitas
direct_messages: Mensajes directos direct_messages: Mensajes directos
proposal_notifications: Notificaciones de propuestas 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] expect(data).to eq "x"=>["2015-01-01", "2015-01-02"], "Foo"=>[1, 2], "Visits"=>[2, 1]
end end
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
end end