diff --git a/app/controllers/admin/stats_controller.rb b/app/controllers/admin/stats_controller.rb
index 75d79b57b..b6a926792 100644
--- a/app/controllers/admin/stats_controller.rb
+++ b/app/controllers/admin/stats_controller.rb
@@ -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)
diff --git a/app/models/budget.rb b/app/models/budget.rb
index 8c34e030d..8cc5c9b8f 100644
--- a/app/models/budget.rb
+++ b/app/models/budget.rb
@@ -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
diff --git a/app/views/admin/stats/budget_balloting.html.erb b/app/views/admin/stats/budget_balloting.html.erb
new file mode 100644
index 000000000..72d1d6a54
--- /dev/null
+++ b/app/views/admin/stats/budget_balloting.html.erb
@@ -0,0 +1,57 @@
+<%= back_link_to budgets_admin_stats_path %>
+
+
<%= @budget.name %> - <%= t("admin.stats.budget_balloting.title") %>
+
+
+
+
+
+ <%= t("admin.stats.budget_balloting.vote_count") %>
+
+
+ <%= @vote_count %>
+
+
+
+
+
+
+ <%= t("admin.stats.budget_balloting.participant_count") %>
+
+
+ <%= @user_count %>
+
+
+
+
+
+
+
+ | <%= t("admin.stats.budget_balloting.votes_per_heading") %> |
+
+ <% @vote_count_by_heading.each do |heading_name, count| %>
+
+ |
+ <%= heading_name %>
+ |
+
+ <%= number_with_delimiter count %>
+ |
+
+ <% end %>
+
+
+
+ | <%= t("admin.stats.budget_balloting.participants_per_district") %> |
+
+ <% @user_count_by_district.each do |heading_name, count| %>
+
+ |
+ <%= heading_name %>
+ |
+
+ <%= number_with_delimiter count %>
+ |
+
+ <% end %>
+
diff --git a/app/views/admin/stats/budget_supporting.html.erb b/app/views/admin/stats/budget_supporting.html.erb
index ba079c1c8..6eb995a15 100644
--- a/app/views/admin/stats/budget_supporting.html.erb
+++ b/app/views/admin/stats/budget_supporting.html.erb
@@ -33,7 +33,7 @@
<%= render "graph", name: "user_supported_budgets", event: "", count: @user_count %>
- | <%= t("admin.stats.budget_supporting.groups") %> |
+ <%= t("admin.stats.budget_supporting.headings") %> |
<%= t("admin.stats.budget_supporting.users") %> |
<% @voters_in_heading.each do |heading, count| %>
diff --git a/app/views/admin/stats/budgets.html.erb b/app/views/admin/stats/budgets.html.erb
index 8976884ec..2c12b6b37 100644
--- a/app/views/admin/stats/budgets.html.erb
+++ b/app/views/admin/stats/budgets.html.erb
@@ -10,6 +10,7 @@
<%= 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" %>
|
diff --git a/config/locales/en/admin.yml b/config/locales/en/admin.yml
index 8dfc1ac7a..f47b0eb19 100644
--- a/config/locales/en/admin.yml
+++ b/config/locales/en/admin.yml
@@ -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
diff --git a/config/locales/es/admin.yml b/config/locales/es/admin.yml
index d26806ecf..c78902915 100644
--- a/config/locales/es/admin.yml
+++ b/config/locales/es/admin.yml
@@ -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
diff --git a/config/routes/admin.rb b/config/routes/admin.rb
index 378758c24..917f1447c 100644
--- a/config/routes/admin.rb
+++ b/config/routes/admin.rb
@@ -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
diff --git a/spec/features/admin/stats_spec.rb b/spec/features/admin/stats_spec.rb
index 0d5d33223..d4117879e 100644
--- a/spec/features/admin/stats_spec.rb
+++ b/spec/features/admin/stats_spec.rb
@@ -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