adds budget stats for final voting to admin stats
This commit is contained in:
committed by
Javi Martín
parent
5be54b57da
commit
110ee961e3
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
57
app/views/admin/stats/budget_balloting.html.erb
Normal file
57
app/views/admin/stats/budget_balloting.html.erb
Normal 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>
|
||||
@@ -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| %>
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -103,7 +103,7 @@ feature "Stats" do
|
||||
end
|
||||
|
||||
describe "Budget investments" do
|
||||
|
||||
context "Supporting phase" do
|
||||
background do
|
||||
@budget = create(:budget)
|
||||
@group_all_city = create(:budget_group, budget: @budget)
|
||||
@@ -127,7 +127,7 @@ feature "Stats" do
|
||||
expect(page).to have_content "Votes 3"
|
||||
end
|
||||
|
||||
scenario "Number of users that have voted a investment project" do
|
||||
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)
|
||||
@@ -149,7 +149,7 @@ feature "Stats" do
|
||||
expect(page).to have_content "Participants 2"
|
||||
end
|
||||
|
||||
scenario "Number of users that have voted a investment project per geozone" do
|
||||
scenario "Number of users that have supported investments projects per geozone" do
|
||||
budget = create(:budget)
|
||||
|
||||
group_all_city = create(:budget_group, budget: budget)
|
||||
@@ -190,6 +190,62 @@ feature "Stats" do
|
||||
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
|
||||
scenario "event graphs", :js do
|
||||
campaign = create(:campaign)
|
||||
|
||||
Reference in New Issue
Block a user