reduces current admin budget stats as supporting phase

This commit is contained in:
Juanjo Bazán
2017-05-24 12:48:44 +02:00
committed by Javi Martín
parent 11437a1d40
commit 5be54b57da
8 changed files with 75 additions and 23 deletions

View File

@@ -52,14 +52,24 @@ class Admin::StatsController < Admin::BaseController
@users_who_have_sent_message = DirectMessage.select(:sender_id).distinct.count @users_who_have_sent_message = DirectMessage.select(:sender_id).distinct.count
end end
def budget_investments
votes = Vote.for_budget_investments(Budget::Investment.all) 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 @vote_count = votes.count
@participant_count = votes.select(:voter_id).distinct.count @user_count = votes.select(:voter_id).distinct.count
@voters_in_heading = {} @voters_in_heading = {}
budget = Budget.last @budget.headings.each do |heading|
budget.headings.each do |heading|
@voters_in_heading[heading] = voters_in_heading(heading) @voters_in_heading[heading] = voters_in_heading(heading)
end end
end end

View File

@@ -2,11 +2,15 @@
<%= javascript_include_tag "stat_graphs", "data-turbolinks-track" => true %> <%= javascript_include_tag "stat_graphs", "data-turbolinks-track" => true %>
<% end %> <% end %>
<%= back_link_to budgets_admin_stats_path %>
<h2><%= @budget.name %> - <%= t("admin.stats.budget_supporting.title") %></h2>
<div class="stats"> <div class="stats">
<div class="row stats-numbers"> <div class="row stats-numbers">
<div class="small-12 medium-3 column"> <div class="small-12 medium-3 column">
<p class="featured"> <p class="featured">
<%= t("admin.stats.budget_investments.vote_count") %> <%= t("admin.stats.budget_supporting.vote_count") %>
<br> <br>
<span id="total_votes_count" class="number"> <span id="total_votes_count" class="number">
<%= @vote_count %> <%= @vote_count %>
@@ -16,21 +20,21 @@
<div class="small-12 medium-6 column end"> <div class="small-12 medium-6 column end">
<p> <p>
<%= t("admin.stats.budget_investments.participant_count") %> <%= t("admin.stats.budget_supporting.participant_count") %>
<br> <br>
<span id="total_participants_count" class="number"> <span id="total_participants_count" class="number">
<%= @participant_count %> <%= @user_count %>
</span> </span>
</p> </p>
</div> </div>
</div> </div>
</div> </div>
<%= render "graph", name: "user_supported_budgets", event: "", count: @participant_count %> <%= render "graph", name: "user_supported_budgets", event: "", count: @user_count %>
<table class="investment-projects-summary"> <table class="investment-projects-summary">
<th><%= t("admin.stats.budget_investments.groups") %></th> <th><%= t("admin.stats.budget_supporting.groups") %></th>
<th><%= t("admin.stats.budget_investments.users") %></th> <th><%= t("admin.stats.budget_supporting.users") %></th>
<% @voters_in_heading.each do |heading, count| %> <% @voters_in_heading.each do |heading, count| %>
<tr id="<%= dom_id(heading) %>"> <tr id="<%= dom_id(heading) %>">

View File

@@ -0,0 +1,16 @@
<%= 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" %>
</td>
</tr>
</table>
<% end %>

View File

@@ -7,7 +7,7 @@
<%= link_to t("admin.stats.show.polls"), <%= link_to t("admin.stats.show.polls"),
polls_admin_stats_path, class: "button hollow" %> polls_admin_stats_path, class: "button hollow" %>
<%= link_to t("admin.stats.show.participatory_budgets"), <%= link_to t("admin.stats.show.participatory_budgets"),
budget_investments_admin_stats_path, class: "button hollow" %> budgets_admin_stats_path, class: "button hollow" %>
<%= link_to t("admin.stats.show.direct_messages"), <%= link_to t("admin.stats.show.direct_messages"),
direct_messages_admin_stats_path, class: "button hollow" %> direct_messages_admin_stats_path, class: "button hollow" %>
<%= link_to t("admin.stats.show.proposal_notifications"), <%= link_to t("admin.stats.show.proposal_notifications"),

View File

@@ -1463,7 +1463,12 @@ en:
visit: Visits visit: Visits
level_2_user: Level 2 users level_2_user: Level 2 users
proposal_created: Citizen proposals proposal_created: Citizen proposals
budget_investments: budgets:
title: "Participatory Budgets - Participation stats"
supporting_phase: Supporting phase
balloting_phase: Final voting
budget_supporting:
title: "Supporting phase stats"
groups: Group groups: Group
users: Users users: Users
vote_count: Votes vote_count: Votes

View File

@@ -1462,7 +1462,12 @@ es:
visit: Visitas visit: Visitas
level_2_user: Usuarios nivel 2 level_2_user: Usuarios nivel 2
proposal_created: Propuestas Ciudadanas proposal_created: Propuestas Ciudadanas
budget_investments: budgets:
title: "Presupuestos participativos - Estadisticas de participación"
supporting_phase: Fase de apoyos
balloting_phase: Votación final
budget_supporting:
title: "Estadísticas fase de apoyos"
groups: Grupo groups: Grupo
users: Usuarios users: Usuarios
vote_count: Votos vote_count: Votos

View File

@@ -195,7 +195,8 @@ namespace :admin do
resource :stats, only: :show do resource :stats, only: :show do
get :graph, on: :member get :graph, on: :member
get :budget_investments, on: :collection get :budgets, on: :collection
get :budget_supporting, on: :member
get :proposal_notifications, on: :collection get :proposal_notifications, on: :collection
get :direct_messages, on: :collection get :direct_messages, on: :collection
get :polls, on: :collection get :polls, on: :collection

View File

@@ -105,20 +105,24 @@ feature "Stats" do
describe "Budget investments" do describe "Budget investments" do
background do background do
budget = create(:budget) @budget = create(:budget)
group_all_city = create(:budget_group, budget: budget) @group_all_city = create(:budget_group, budget: @budget)
heading_all_city = create(:budget_heading, group: group_all_city) @heading_all_city = create(:budget_heading, group: @group_all_city)
end end
scenario "Number of supports in investment projects" do scenario "Number of supports in investment projects" do
investment1 = create(:budget_investment) group_2 = create(:budget_group, budget: @budget)
investment2 = create(:budget_investment) investment1 = create(:budget_investment, heading: create(:budget_heading, group: group_2))
investment2 = create(:budget_investment, heading: @heading_all_city)
1.times { create(:vote, votable: investment1) } 1.times { create(:vote, votable: investment1) }
2.times { create(:vote, votable: investment2) } 2.times { create(:vote, votable: investment2) }
visit admin_stats_path visit admin_stats_path
click_link "Participatory Budgets" click_link "Participatory Budgets"
within("#budget_#{@budget.id}") do
click_link "Supporting phase"
end
expect(page).to have_content "Votes 3" expect(page).to have_content "Votes 3"
end end
@@ -128,8 +132,9 @@ feature "Stats" do
user2 = create(:user, :level_two) user2 = create(:user, :level_two)
user3 = create(:user, :level_two) user3 = create(:user, :level_two)
investment1 = create(:budget_investment) group_2 = create(:budget_group, budget: @budget)
investment2 = create(:budget_investment) investment1 = create(:budget_investment, heading: create(:budget_heading, group: group_2))
investment2 = create(:budget_investment, heading: @heading_all_city)
create(:vote, votable: investment1, voter: user1) create(:vote, votable: investment1, voter: user1)
create(:vote, votable: investment1, voter: user2) create(:vote, votable: investment1, voter: user2)
@@ -137,6 +142,9 @@ feature "Stats" do
visit admin_stats_path visit admin_stats_path
click_link "Participatory Budgets" click_link "Participatory Budgets"
within("#budget_#{@budget.id}") do
click_link "Supporting phase"
end
expect(page).to have_content "Participants 2" expect(page).to have_content "Participants 2"
end end
@@ -161,6 +169,9 @@ feature "Stats" do
visit admin_stats_path visit admin_stats_path
click_link "Participatory Budgets" click_link "Participatory Budgets"
within("#budget_#{budget.id}") do
click_link "Supporting phase"
end
within("#budget_heading_#{all_city.id}") do within("#budget_heading_#{all_city.id}") do
expect(page).to have_content all_city.name expect(page).to have_content all_city.name