adds budget stats for final voting to admin stats

This commit is contained in:
Juanjo Bazán
2017-05-24 14:26:36 +02:00
committed by Javi Martín
parent 5be54b57da
commit 110ee961e3
9 changed files with 209 additions and 70 deletions

View File

@@ -74,6 +74,17 @@ class Admin::StatsController < Admin::BaseController
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
@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)

View File

@@ -31,6 +31,7 @@ class Budget < ApplicationRecord
has_many :ballots, dependent: :destroy
has_many :groups, dependent: :destroy
has_many :headings, through: :groups
has_many :lines, through: :ballots, class_name: "Budget::Ballot::Line"
has_many :phases, class_name: Budget::Phase
has_one :poll

View File

@@ -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>

View File

@@ -33,7 +33,7 @@
<%= render "graph", name: "user_supported_budgets", event: "", count: @user_count %>
<table class="investment-projects-summary">
<th><%= t("admin.stats.budget_supporting.groups") %></th>
<th><%= t("admin.stats.budget_supporting.headings") %></th>
<th><%= t("admin.stats.budget_supporting.users") %></th>
<% @voters_in_heading.each do |heading, count| %>

View File

@@ -10,6 +10,7 @@
</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>

View File

@@ -1467,9 +1467,15 @@ en:
title: "Participatory Budgets - Participation stats"
supporting_phase: Supporting phase
balloting_phase: Final voting
budget_balloting:
title: "Final voting stats"
vote_count: Votes
participant_count: Participants
votes_per_heading: Votes per heading
participants_per_district: Participants per district
budget_supporting:
title: "Supporting phase stats"
groups: Group
headings: Headings
users: Users
vote_count: Votes
participant_count: Participants

View File

@@ -1466,9 +1466,15 @@ es:
title: "Presupuestos participativos - Estadisticas de participación"
supporting_phase: Fase de apoyos
balloting_phase: Votación final
budget_balloting:
title: "Estadísticas votación final"
vote_count: Votos
participant_count: Participantes
votes_per_heading: Votos por partida
participants_per_district: Participantes por distrito
budget_supporting:
title: "Estadísticas fase de apoyos"
groups: Grupo
headings: Partidas
users: Usuarios
vote_count: Votos
participant_count: Participantes

View File

@@ -197,6 +197,7 @@ namespace :admin do
get :graph, on: :member
get :budgets, on: :collection
get :budget_supporting, on: :member
get :budget_balloting, on: :member
get :proposal_notifications, on: :collection
get :direct_messages, on: :collection
get :polls, on: :collection

View File

@@ -103,91 +103,147 @@ feature "Stats" do
end
describe "Budget investments" do
background do
@budget = create(:budget)
@group_all_city = create(:budget_group, budget: @budget)
@heading_all_city = create(:budget_heading, group: @group_all_city)
end
scenario "Number of supports in investment projects" do
group_2 = create(:budget_group, budget: @budget)
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) }
2.times { create(:vote, votable: investment2) }
visit admin_stats_path
click_link "Participatory Budgets"
within("#budget_#{@budget.id}") do
click_link "Supporting phase"
context "Supporting phase" do
background do
@budget = create(:budget)
@group_all_city = create(:budget_group, budget: @budget)
@heading_all_city = create(:budget_heading, group: @group_all_city)
end
expect(page).to have_content "Votes 3"
end
scenario "Number of supports in investment projects" do
group_2 = create(:budget_group, budget: @budget)
investment1 = create(:budget_investment, heading: create(:budget_heading, group: group_2))
investment2 = create(:budget_investment, heading: @heading_all_city)
scenario "Number of users that have voted a investment project" do
user1 = create(:user, :level_two)
user2 = create(:user, :level_two)
user3 = create(:user, :level_two)
1.times { create(:vote, votable: investment1) }
2.times { create(:vote, votable: investment2) }
group_2 = create(:budget_group, budget: @budget)
investment1 = create(:budget_investment, heading: create(:budget_heading, group: group_2))
investment2 = create(:budget_investment, heading: @heading_all_city)
visit admin_stats_path
click_link "Participatory Budgets"
within("#budget_#{@budget.id}") do
click_link "Supporting phase"
end
create(:vote, votable: investment1, voter: user1)
create(:vote, votable: investment1, voter: user2)
create(:vote, votable: investment2, voter: user1)
visit admin_stats_path
click_link "Participatory Budgets"
within("#budget_#{@budget.id}") do
click_link "Supporting phase"
expect(page).to have_content "Votes 3"
end
expect(page).to have_content "Participants 2"
end
scenario "Number of users that have supported an investment project" do
user1 = create(:user, :level_two)
user2 = create(:user, :level_two)
user3 = create(:user, :level_two)
scenario "Number of users that have voted a investment project per geozone" do
budget = create(:budget)
group_2 = create(:budget_group, budget: @budget)
investment1 = create(:budget_investment, heading: create(:budget_heading, group: group_2))
investment2 = create(:budget_investment, heading: @heading_all_city)
group_all_city = create(:budget_group, budget: budget)
group_districts = create(:budget_group, budget: budget)
create(:vote, votable: investment1, voter: user1)
create(:vote, votable: investment1, voter: user2)
create(:vote, votable: investment2, voter: user1)
all_city = create(:budget_heading, group: group_all_city)
carabanchel = create(:budget_heading, group: group_districts)
barajas = create(:budget_heading, group: group_districts)
visit admin_stats_path
click_link "Participatory Budgets"
within("#budget_#{@budget.id}") do
click_link "Supporting phase"
end
all_city_investment = create(:budget_investment, heading: all_city)
carabanchel_investment = create(:budget_investment, heading: carabanchel)
carabanchel_investment = create(:budget_investment, heading: carabanchel)
Budget::Investment.all.each do |investment|
create(:vote, votable: investment)
expect(page).to have_content "Participants 2"
end
visit admin_stats_path
click_link "Participatory Budgets"
within("#budget_#{budget.id}") do
click_link "Supporting phase"
end
scenario "Number of users that have supported investments projects per geozone" do
budget = create(:budget)
within("#budget_heading_#{all_city.id}") do
expect(page).to have_content all_city.name
expect(page).to have_content 1
end
group_all_city = create(:budget_group, budget: budget)
group_districts = create(:budget_group, budget: budget)
within("#budget_heading_#{carabanchel.id}") do
expect(page).to have_content carabanchel.name
expect(page).to have_content 2
end
all_city = create(:budget_heading, group: group_all_city)
carabanchel = create(:budget_heading, group: group_districts)
barajas = create(:budget_heading, group: group_districts)
within("#budget_heading_#{barajas.id}") do
expect(page).to have_content barajas.name
expect(page).to have_content 0
all_city_investment = create(:budget_investment, heading: all_city)
carabanchel_investment = create(:budget_investment, heading: carabanchel)
carabanchel_investment = create(:budget_investment, heading: carabanchel)
Budget::Investment.all.each do |investment|
create(:vote, votable: investment)
end
visit admin_stats_path
click_link "Participatory Budgets"
within("#budget_#{budget.id}") do
click_link "Supporting phase"
end
within("#budget_heading_#{all_city.id}") do
expect(page).to have_content all_city.name
expect(page).to have_content 1
end
within("#budget_heading_#{carabanchel.id}") do
expect(page).to have_content carabanchel.name
expect(page).to have_content 2
end
within("#budget_heading_#{barajas.id}") do
expect(page).to have_content barajas.name
expect(page).to have_content 0
end
end
end
context "Balloting phase" do
scenario "Number of votes in investment projects" do
budget = create(:budget, :balloting)
ballot_1 = create(:budget_ballot, budget: budget)
ballot_2 = create(:budget_ballot, budget: budget)
group_1 = create(:budget_group, budget: budget)
heading_1 = create(:budget_heading, group: group_1)
investment_1 = create(:budget_investment, :feasible, :selected, heading: heading_1)
group_2 = create(:budget_group, budget: budget)
heading_2 = create(:budget_heading, group: group_2)
investment_2 = create(:budget_investment, :feasible, :selected, heading: heading_2)
create(:budget_ballot_line, ballot: ballot_1, investment: investment_1)
create(:budget_ballot_line, ballot: ballot_1, investment: investment_2)
create(:budget_ballot_line, ballot: ballot_2, investment: investment_2)
visit admin_stats_path
click_link "Participatory Budgets"
within("#budget_#{budget.id}") do
click_link "Final voting"
end
expect(page).to have_content "Votes 3"
end
scenario "Number of users that have voted a investment project" do
user_1 = create(:user, :level_two)
user_2 = create(:user, :level_two)
user_3 = create(:user, :level_two)
budget = create(:budget, :balloting)
ballot_1 = create(:budget_ballot, budget: budget, user: user_1)
ballot_2 = create(:budget_ballot, budget: budget, user: user_2)
ballot_3 = create(:budget_ballot, budget: budget, user: user_3)
group = create(:budget_group, budget: budget)
heading = create(:budget_heading, group: group)
investment = create(:budget_investment, :feasible, :selected, heading: heading)
create(:budget_ballot_line, ballot: ballot_1, investment: investment)
create(:budget_ballot_line, ballot: ballot_2, investment: investment)
visit admin_stats_path
click_link "Participatory Budgets"
within("#budget_#{budget.id}") do
click_link "Final voting"
end
expect(page).to have_content "Participants 2"
end
end
end
context "graphs" do