From 71fd3657d3b5fa802da48fba223c130efcbbca72 Mon Sep 17 00:00:00 2001 From: kikito Date: Mon, 6 Feb 2017 17:06:38 +0100 Subject: [PATCH 01/42] makes all users old enough to vote by default when created for the specs --- spec/factories/users.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/spec/factories/users.rb b/spec/factories/users.rb index c4a70a94b..f074d525c 100644 --- a/spec/factories/users.rb +++ b/spec/factories/users.rb @@ -6,6 +6,7 @@ FactoryBot.define do password "judgmentday" terms_of_service "1" confirmed_at { Time.current } + date_of_birth { 20.years.ago } public_activity true trait :incomplete_verification do From 63631f29a88f949d2a916008f8e3336871c928ec Mon Sep 17 00:00:00 2001 From: Bertocq Date: Wed, 28 Jun 2017 23:50:28 +0200 Subject: [PATCH 02/42] Add ballot_lines_count counter_cache to ballot -> ballot line relationship --- app/models/budget/ballot/line.rb | 2 +- ...547_add_ballot_line_counter_cached_to_budget_ballots.rb | 5 +++++ db/schema.rb | 7 ++++--- 3 files changed, 10 insertions(+), 4 deletions(-) create mode 100644 db/migrate/20170628211547_add_ballot_line_counter_cached_to_budget_ballots.rb diff --git a/app/models/budget/ballot/line.rb b/app/models/budget/ballot/line.rb index 54b26f4b4..c64ed39c0 100644 --- a/app/models/budget/ballot/line.rb +++ b/app/models/budget/ballot/line.rb @@ -1,7 +1,7 @@ class Budget class Ballot class Line < ApplicationRecord - belongs_to :ballot + belongs_to :ballot, counter_cache: :ballot_lines_count belongs_to :investment, counter_cache: :ballot_lines_count belongs_to :heading belongs_to :group diff --git a/db/migrate/20170628211547_add_ballot_line_counter_cached_to_budget_ballots.rb b/db/migrate/20170628211547_add_ballot_line_counter_cached_to_budget_ballots.rb new file mode 100644 index 000000000..b67649341 --- /dev/null +++ b/db/migrate/20170628211547_add_ballot_line_counter_cached_to_budget_ballots.rb @@ -0,0 +1,5 @@ +class AddBallotLineCounterCachedToBudgetBallots < ActiveRecord::Migration + def change + add_column :budget_ballots, :ballot_lines_count, :integer, default: 0 + end +end diff --git a/db/schema.rb b/db/schema.rb index e5bf875af..4430a4980 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -131,9 +131,10 @@ ActiveRecord::Schema.define(version: 20190411090023) do create_table "budget_ballots", force: :cascade do |t| t.integer "user_id" t.integer "budget_id" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.boolean "physical", default: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.integer "ballot_lines_count", default: 0 + t.boolean "physical", default: false t.integer "poll_ballot_id" end From e0e02b47c054d177b75f59d4da1b603b424744ef Mon Sep 17 00:00:00 2001 From: Bertocq Date: Wed, 28 Jun 2017 23:54:05 +0200 Subject: [PATCH 03/42] Add Budgets Stats Controller, route and ability on reviewing ballots and finished budget --- app/controllers/budgets/stats_controller.rb | 18 ++++++++++++++++++ app/models/abilities/everyone.rb | 1 + config/routes/budget.rb | 1 + 3 files changed, 20 insertions(+) create mode 100644 app/controllers/budgets/stats_controller.rb diff --git a/app/controllers/budgets/stats_controller.rb b/app/controllers/budgets/stats_controller.rb new file mode 100644 index 000000000..48a93c5e7 --- /dev/null +++ b/app/controllers/budgets/stats_controller.rb @@ -0,0 +1,18 @@ +module Budgets + class StatsController < ApplicationController + + load_and_authorize_resource :budget + + def show + authorize! :read_stats, @budget + @stats = load_stats + end + + private + + def load_stats + Budget::Stats.new(@budget).generate + end + + end +end diff --git a/app/models/abilities/everyone.rb b/app/models/abilities/everyone.rb index a20a119fe..90d4161c2 100644 --- a/app/models/abilities/everyone.rb +++ b/app/models/abilities/everyone.rb @@ -21,6 +21,7 @@ module Abilities can [:read], Budget::Group can [:read, :print, :json_data], Budget::Investment can [:read_results, :read_executions], Budget, phase: "finished" + can :read_stats, Budget, phase: ["reviewing_ballots", "finished"] can :new, DirectMessage can [:read, :debate, :draft_publication, :allegations, :result_publication, :proposals, :milestones], Legislation::Process, published: true diff --git a/config/routes/budget.rb b/config/routes/budget.rb index 215b0bc75..a72a71dfb 100644 --- a/config/routes/budget.rb +++ b/config/routes/budget.rb @@ -15,6 +15,7 @@ resources :budgets, only: [:show, :index] do end resource :results, only: :show, controller: "budgets/results" + resource :stats, only: :show, controller: "budgets/stats" resource :executions, only: :show, controller: "budgets/executions" end From 132397b610ac1b396129c32c0892f7df6810a4d4 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Wed, 28 Jun 2017 23:59:39 +0200 Subject: [PATCH 04/42] Add Budget Stats class --- app/models/budget/stats.rb | 198 +++++++++++++++++++++++++++++++++++++ 1 file changed, 198 insertions(+) create mode 100644 app/models/budget/stats.rb diff --git a/app/models/budget/stats.rb b/app/models/budget/stats.rb new file mode 100644 index 000000000..3a497bc95 --- /dev/null +++ b/app/models/budget/stats.rb @@ -0,0 +1,198 @@ +class Budget + class Stats + + def initialize(budget) + @budget = budget + end + + def generate + stats = %w[total_participants total_participants_support_phase total_participants_vote_phase total_budget_investments total_votes + total_feasible_investments total_unfeasible_investments total_male_participants total_female_participants total_supports + total_unknown_gender_or_age age_groups male_percentage female_percentage headings] + stats.map { |stat_name| [stat_name.to_sym, send(stat_name)] }.to_h + end + + private + + def total_participants + stats_cache("total_participants") { participants.distinct.count } + end + + def total_participants_support_phase + stats_cache("total_participants_support_phase") { voters.uniq.count } + end + + def total_participants_vote_phase + stats_cache("total_participants_vote_phase") { balloters.uniq.count } + end + + def total_budget_investments + stats_cache("total_budget_investments") { @budget.investments.count } + end + + def total_votes + stats_cache("total_votes") { @budget.ballots.count } + end + + def total_feasible_investments + stats_cache("total_feasible_investments") { @budget.investments.feasible.count } + end + + def total_unfeasible_investments + stats_cache("total_unfeasible_investments") { @budget.investments.unfeasible.count } + end + + def total_male_participants + stats_cache("total_male_participants") { participants.where(gender: "male").count } + end + + def total_female_participants + stats_cache("total_female_participants") { participants.where(gender: "female").count } + end + + def total_supports + stats_cache("total_supports") { supports(@budget).count } + end + + def total_unknown_gender_or_age + stats_cache("total_unknown_gender_or_age") do + participants.where("gender IS NULL OR date_of_birth is NULL").uniq.count + end + end + + def age_groups + stats_cache("age_groups") do + groups = Hash.new(0) + ["16 - 19", + "20 - 24", + "25 - 29", + "30 - 34", + "35 - 39", + "40 - 44", + "45 - 49", + "50 - 54", + "55 - 59", + "60 - 64", + "65 - 69", + "70 - 140"].each do |group| + start, finish = group.split(" - ") + group_name = (group == "70 - 140" ? "+ 70" : group) + groups[group_name] = User.where(id: participants) + .where("date_of_birth > ? AND date_of_birth < ?", + finish.to_i.years.ago.beginning_of_year, + start.to_i.years.ago.end_of_year).count + end + groups + end + end + + def male_percentage + stats_cache("male_percentage") { total_male_participants / total_participants_with_gender.to_f * 100 } + end + + def female_percentage + stats_cache("female_percentage") { total_female_participants / total_participants_with_gender.to_f * 100 } + end + + def participants + stats_cache("participants") { User.where(id: (authors + voters + balloters).uniq) } + end + + def authors + stats_cache("authors") { @budget.investments.pluck(:author_id) } + end + + def voters + stats_cache("voters") { supports(@budget).pluck(:voter_id) } + end + + def balloters + stats_cache("balloters") { @budget.ballots.where("ballot_lines_count > ?", 0).pluck(:user_id) } + end + + def total_participants_with_gender + stats_cache("total_participants_with_gender") { participants.where.not(gender: nil).distinct.count } + end + + def balloters_by_heading(heading_id) + stats_cache("balloters_by_heading_#{heading_id}") do + @budget.ballots.joins(:lines).where(budget_ballot_lines: {heading_id: heading_id}).pluck(:user_id) + end + end + + def voters_by_heading(heading) + stats_cache("voters_by_heading_#{heading.id}") do + supports(heading).pluck(:voter_id) + end + end + + def headings + stats_cache("headings") do + groups = Hash.new(0) + @budget.headings.each do |heading| + groups[heading.id] = Hash.new(0).merge(calculate_heading_totals(heading)) + end + + groups[:total] = Hash.new(0) + groups[:total][:total_participants_support_phase] = groups.collect {|_k, v| v[:total_participants_support_phase]}.sum + groups[:total][:total_participants_vote_phase] = groups.collect {|_k, v| v[:total_participants_vote_phase]}.sum + groups[:total][:total_participants_all_phase] = groups.collect {|_k, v| v[:total_participants_all_phase]}.sum + + @budget.headings.each do |heading| + groups[heading.id].merge!(calculate_heading_stats_with_totals(groups[heading.id], groups[:total], heading.population)) + end + + groups[:total][:percentage_participants_support_phase] = groups.collect {|_k, v| v[:percentage_participants_support_phase]}.sum + groups[:total][:percentage_participants_vote_phase] = groups.collect {|_k, v| v[:percentage_participants_vote_phase]}.sum + groups[:total][:percentage_participants_all_phase] = groups.collect {|_k, v| v[:percentage_participants_all_phase]}.sum + + groups + end + end + + def calculate_heading_totals(heading) + { + total_participants_support_phase: voters_by_heading(heading).uniq.count, + total_participants_vote_phase: balloters_by_heading(heading.id).uniq.count, + total_participants_all_phase: voters_and_balloters_by_heading(heading) + } + end + + def calculate_heading_stats_with_totals(heading_totals, groups_totals, population) + { + percentage_participants_support_phase: participants_percent(heading_totals, groups_totals, :total_participants_support_phase), + percentage_district_population_support_phase: population_percent(population, heading_totals[:total_participants_support_phase]), + percentage_participants_vote_phase: participants_percent(heading_totals, groups_totals, :total_participants_vote_phase), + percentage_district_population_vote_phase: population_percent(population, heading_totals[:total_participants_vote_phase]), + percentage_participants_all_phase: participants_percent(heading_totals, groups_totals, :total_participants_all_phase), + percentage_district_population_all_phase: population_percent(population, heading_totals[:total_participants_all_phase]) + } + end + + def voters_and_balloters_by_heading(heading) + (voters_by_heading(heading) + balloters_by_heading(heading.id)).uniq.count + end + + def participants_percent(heading_totals, groups_totals, phase) + calculate_percentage(heading_totals[phase], groups_totals[phase]) + end + + def population_percent(population, participants) + return "N/A" unless population.to_f.positive? + calculate_percentage(participants, population) + end + + def calculate_percentage(fraction, total) + percent = fraction / total.to_f + percent.nan? ? 0.0 : (percent * 100).round(2) + end + + def supports(supportable) + ActsAsVotable::Vote.where(votable_type: "Budget::Investment", votable_id: supportable.investments.pluck(:id)) + end + + def stats_cache(key, &block) + Rails.cache.fetch("budgets_stats/#{@budget.id}/#{key}", &block) + end + end +end From 0c73d571181a34c3c25f50c7a22de198b50bad19 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Wed, 28 Jun 2017 23:59:57 +0200 Subject: [PATCH 05/42] Add budget stats view, pending some work and style --- app/views/budgets/stats/show.html.erb | 260 ++++++++++++++++++++++++++ 1 file changed, 260 insertions(+) create mode 100644 app/views/budgets/stats/show.html.erb diff --git a/app/views/budgets/stats/show.html.erb b/app/views/budgets/stats/show.html.erb new file mode 100644 index 000000000..269e0f20f --- /dev/null +++ b/app/views/budgets/stats/show.html.erb @@ -0,0 +1,260 @@ +<% cache [@stats] do %> + <% provide :title, t("spending_proposals.stats.page_title") %> + <% provide :social_media_meta_tags do %> + <%= render "shared/social_media_meta_tags_participatory_budget" %> + <% end %> + + <%= javascript_include_tag "chart", "data-turbolinks-track" => true %> + <%= javascript_include_tag "participatory-budget-charts", "data-turbolinks-track" => true %> + +
+
+
+ <%= link_to participatory_budget_path, class: "left back" do %> + + <%= t("pages.processes.back") %> + <% end %> + +

<%= t("spending_proposals.stats.heading") %>

+
+
+
+ +
+
+
    +
  • + <%= link_to t("spending_proposals.stats.results_link"), participatory_budget_results_path %> +
  • +
  • + <%= t("shared.you_are_in") %> + <%= link_to t("spending_proposals.stats.stats_link"), participatory_budget_stats_path, class: "is-active" %> +
  • +
+
+
+ +
+ +
+
+
+

TOTAL PARTICIPANTES

+

+ <%= @stats[:total_participants] %> +

+
+
+
+ +
+ +
+
+
+

TOTAL PROPUESTAS ENVIADAS

+

+ <%= @stats[:total_spending_proposals] + @stats[:paper_spending_proposals] %> +

+
+
+ +
+

+   + + PROPUESTAS EN LA FASE FINAL: + <%= @stats[:total_feasible_spending_proposals] %>
+
+ +   + + PROPUESTAS INVIABLES: + <%= @stats[:total_unfeasible_spending_proposals] %>
+
+ +
+ +   + FASE DE APOYOS: + + <%= @stats[:total_participants_support_phase] %> Participantes, + + + <%= @stats[:total_supports] %> Apoyos
+
+ +   + FASE DE VOTACIÓN: + + <%= @stats[:total_participants_vote_phase] %> Participantes, + + + <%= @stats[:total_votes] %> Votos
+
+

+
+
+ +
+
+ +
+ + +
+

Participación
por sexo

+
+ +
+ +
+
+ <%= image_tag ("participatory_budget_stats/sex.png") %> +
+
+ +
+
+
+ +
+
+
+

+ +  HOMBRES + (<%= number_to_percentage(@stats[:male_percentage], + strip_insignificant_zeros: true, + precision: 2) %>) +

+

+ <%= @stats[:total_male_participants] %> +

+
+
+ +
+
+

+ +  MUJERES + (<%= number_to_percentage(@stats[:female_percentage], + strip_insignificant_zeros: true, + precision: 2) %>) +

+

+ <%= @stats[:total_female_participants] %> +

+
+
+
+
+ +
+ +
+

Participación por
grupos de edad

+
+ +
+ + <%= render "spending_proposals_results_age" %> +
+ +
+ +
+ +
+

Participación por
distritos

+
+ +
+ +
+ <%= image_tag("map.jpg", usemap: "#html_map", alt: "Mapa de distritos de Madrid") %> +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + <% @stats.headings.each do |heading| %> + + + + + <% ["support", "vote", "all"].each do |phase| %> + + + + <% end %> + + <% end %> + +
DISTRITOPROPUESTAS ENVIADASPARTICIPACIÓN FASE APOYOSPARTICIPACIÓN FASE VOTACIÓNPARTICIPACIÓN TOTAL
TOTAL%
TOTAL
PARTICIPANTES
%
CENSO
DISTRITO
TOTAL%
TOTAL
PARTICIPANTES
%
CENSO
DISTRITO
TOTAL%
TOTAL
PARTICIPANTES
%
CENSO
DISTRITO
+ <%= heading.name %> + + <%= heading.spending_proposals.count %> + + <%= @stats[:headings][heading.id]["total_participants_#{phase}_phase".to_sym] %> + + <%= number_to_percentage(@stats[:headings][heading.id]["percentage_participants_#{phase}_phase".to_sym], + strip_insignificant_zeros: true, + precision: 2) %> + + <%= number_to_percentage(@stats[:headings][heading.id]["percentage_district_population_#{phase}_phase".to_sym], + strip_insignificant_zeros: true, + precision: 2) %> +
+ +
+
+

+ + * No se dispone de los datos demográficos de + <%= @stats[:total_unknown_gender_or_age] %> + participantes. + +
+ + ** Las cifras de participación total se refieren a personas que han creado, apoyado o votado propuestas. + +
+ + *** Los datos de distrito se refieren al distrito en el que el usuario ha votado, no necesariamente en el que está empadronado. + +

+
+
+ +
+ +
+
+<% end %> From 0993aaf5d15e41e16e5785a45cc3e2c49624ced8 Mon Sep 17 00:00:00 2001 From: decabeza Date: Thu, 29 Jun 2017 19:25:20 +0200 Subject: [PATCH 06/42] changes budgets stats html --- app/views/budgets/stats/show.html.erb | 115 ++++++++++++-------------- 1 file changed, 54 insertions(+), 61 deletions(-) diff --git a/app/views/budgets/stats/show.html.erb b/app/views/budgets/stats/show.html.erb index 269e0f20f..a1e723be4 100644 --- a/app/views/budgets/stats/show.html.erb +++ b/app/views/budgets/stats/show.html.erb @@ -7,14 +7,11 @@ <%= javascript_include_tag "chart", "data-turbolinks-track" => true %> <%= javascript_include_tag "participatory-budget-charts", "data-turbolinks-track" => true %> -
+
+
-
- <%= link_to participatory_budget_path, class: "left back" do %> - - <%= t("pages.processes.back") %> - <% end %> - +
+ <%= back_link_to participatory_budget_path %>

<%= t("spending_proposals.stats.heading") %>

@@ -34,66 +31,63 @@
-
+
+
+
+

TOTAL PARTICIPANTES

+

+ <%= @stats[:total_participants] %> +

+
+
+
-
-
-
-

TOTAL PARTICIPANTES

-

- <%= @stats[:total_participants] %> -

-
+
+ +
+
+
+

TOTAL PROPUESTAS ENVIADAS

+

+ <%= @stats[:total_spending_proposals] + @stats[:paper_spending_proposals] %> +

-
+
+

+   + + PROPUESTAS EN LA FASE FINAL: + <%= @stats[:total_feasible_spending_proposals] %>
+
-

-
-
-

TOTAL PROPUESTAS ENVIADAS

-

- <%= @stats[:total_spending_proposals] + @stats[:paper_spending_proposals] %> -

-
-
+   + + PROPUESTAS INVIABLES: + <%= @stats[:total_unfeasible_spending_proposals] %>
+
-
-

-   - - PROPUESTAS EN LA FASE FINAL: - <%= @stats[:total_feasible_spending_proposals] %>
-
+
-   - - PROPUESTAS INVIABLES: - <%= @stats[:total_unfeasible_spending_proposals] %>
-
+   + FASE DE APOYOS: + + <%= @stats[:total_participants_support_phase] %> Participantes, + + + <%= @stats[:total_supports] %> Apoyos
+
-
- -   - FASE DE APOYOS: - - <%= @stats[:total_participants_support_phase] %> Participantes, - - - <%= @stats[:total_supports] %> Apoyos
-
- -   - FASE DE VOTACIÓN: - - <%= @stats[:total_participants_vote_phase] %> Participantes, - - - <%= @stats[:total_votes] %> Votos
-
-

-
+   + FASE DE VOTACIÓN: + + <%= @stats[:total_participants_vote_phase] %> Participantes, + + + <%= @stats[:total_votes] %> Votos
+
+

@@ -252,9 +246,8 @@

-
-
+
<% end %> From 6899ba9a9f5ce76d4442bfdc033a741ffa517220 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Fri, 30 Jun 2017 12:08:44 +0200 Subject: [PATCH 07/42] Complete Budget Stats view with translations --- app/assets/images/budgets/stats/gender.png | Bin 0 -> 4133 bytes app/views/budgets/stats/show.html.erb | 142 ++++++++++++--------- config/locales/en/budgets.yml | 31 +++++ config/locales/es/budgets.yml | 31 +++++ 4 files changed, 147 insertions(+), 57 deletions(-) create mode 100644 app/assets/images/budgets/stats/gender.png diff --git a/app/assets/images/budgets/stats/gender.png b/app/assets/images/budgets/stats/gender.png new file mode 100644 index 0000000000000000000000000000000000000000..e4179354caaca1fec82a09bd98b3867a8f7f71a8 GIT binary patch literal 4133 zcmaJ@c|2788b7uciM;KTm_}*EU>GxuZ6<4$WQ)RJFlNR~3}Xzbv`A&iR+dy`C&E;S z@|GpxO^jhIud+m0Qns?(bKL6QKi+%ik2B}|KF{-gw(s*izpGXjMjORp;s5|_G%+Sv z1Awp-`0lz+7<@js1Sf)jJDEovm?!9-Ocv3P1n7Iv-AHf~8qtenO(J@*&oq*>0YKyc z*~WqCV15kiPNyjmAsMA08Uxe@0BzkM2GN~DV#3`>USwY!VzROZ0VjLl5ccZkNOK0B z>%1ZUx8F{YY?iB@IP)qy`#}#we+%qtPhz5x6Q+MO_)GrmTikR8_;GkXV!|{O1n= zTJ!Vp#99*!f7$}Sa0qWElYv!MX0cdGEHx#%pO>-<27^&Xsw%6hDuNP<{%l_+F-XzZ zU;Y;Yf#mP*M`kd|bYD1xNOYqIFmVXb(|?CRW0;%&2KM#;nJ6%2%0WbivWgN?nMQ-+ zT9x)^T9f|c#y?8?+prlVWowc@J;2W$tcR!kFJ&-y|KAWK2zrAh(A@)QBwwZp0fzuj zlsw2DSPis>zJ?(ZrDll6sHhy(z~GU1yc$YhU0oHWhSpU5rEB8r&m{V~lYZ%v|D&t+ ze|52VKN68i_p_nXslTdcgk-)D00obv^ze`k%V`|5H~P zbVeB}?|+s1*Ad7e==C>w!H?hcC;5V$_XEj&MSOY%03_l}2>Lcb-JjDq44V$2D`6+6 z`4>G(*_(Kq@DVCm#?raMZPycC9Jk5yR>W)Zu(U#p(D-g2xep>*X(a(i9P94!h-CpX zF5?b|Ut4VvyVqb<7;y{XMz{puWbk}bIH8Smqg*4-eD+N11g^3ly%4^4u4my~Z~tUp z%Qqz-n+b^>wq-|(%kw=mXu3}J zxdG1{UD}s-Pdwflkf&>2Z_cV&l$vh%Vc6#(e=}U+BR?mxa;7hCjJ(n>6>baDGWzh) zHb|S>WI?f--rDlCi+2V>_RRCV4kmV~`u+FmxS+Ue!}J-D26BkFc;tb1|uF~Qk8r*jf& zcIm)$Hbm@xm{(<|zO2c`%d%@;bAmhCO%k`3UbfseSHN}f(oGpoE@=u}xZOQ-s$f?% z#>`8xUPFzxdzSi+mYr9rR(+`IeeR4=INrYUhtRQZeOb0#6Q?s`@GfT7H=?}i$LKh(Z-(!A zm!_MNv`=%YJo}v-twDa$ojnPQl|j|7Ej%MN%D)KWjKwt>EumfaJ&!VSR2 zqpKDS_pWU|uCb?j+(=a22gcp${V8U!pyq-bgc}0k?(nw@scotIvMg3oUdy`|d?B*- zs_eSN!)+ITL!S=`{j%n9g8Pw46Y?{AQK!kh^9&x(!51F9pOQ0tqrcjjTUqfMN)`5Yu9S1iItu0osAGNQb^uILA zGI{LHm3@I=wZp zYb@@EULY=eDMjaLzUp18@Iwj*{Vp%A=U#SLrmzy8ICv&%y+zJh%pKUp9*nibgZTjt z{=HCH{%zatu^m1sjB=&#H?o{BfSJjDC@lmR``k6WhR`HFcdt%l-BD)SLUO2C@_und zbQNwIg*dmwCiHD_KPEuo|p1XUJ??jcn3Y=V1n7Wzep~d8WoGi6gyiW7^ zxYUs5JvU`LQE{fEn3JElWJ*g3mBy?xSh+hEkL zUnR_X*&O3xS`R8;EbQf`ho#qi&*b&4kd+9@%q7@Xdr9@o{L`!!ru`qS8!FVkWQCgT zZ!vB4FaSIKSx6hmtmF?1PrH|sJXmetMA8D$+(5ys3{xt`Wj?&G@9*V>ubT9Exk4M? z<-bLuzj+Txlozek$X!NEror&cB*&IPC*0P@yH07dL{Tx>vRj2Y{=E1d@4kwV}3ulEJ6`DAf>?zAB zp2!&gR%BF3LtvAe6heS=8*8JmTq*hE%ex)RgL1qX{P~NrPd#JOb%QQ(;&Gytj%D9v zp?=E%n{ngYuJ<}#9f!N^J~GyF?Yf6wPD$e0GRn<*uE4|Y)bwV~NJ*?58?4;~5_$3{ z)S&#*mhscAMFwS*{+i_`XXMti)1pp5!z?si zVz;;1%UXAdN(HL>M0#px>FI!B37^{y&4hgq9o|iz>3m@7xBtZUgE5rFfQyQNM*tXB zR&H`p!%ma&d%i`2{#+ptYzzc5_kX{bd08&(q^XNJUs%r$s#<(xqqv=dCKq{s`YPWu zLJ{D)w4ie`J)YbWpYuHvnCI;Ni&u!Vj%mQLo+;7Ni!cQuo;^Xjr^?6ZNO)5X!I)g=S*-jXN$v1oll-CoZ$klMqq@O`4xM+rYEvV zv3+MHoUYM?o<~9TA4t7gRKrV&JMOigQj@`wt>>BkG~mC;DM{+|KYsgpKfqc0$p)17M2^^@hl(49#k`c%zs6xI2)o7s~EtI1Gd+p{Xiycz_bm` z?RHCn335iQq~~Hp6%^pnA&HG6H^a}CE!B32be?&${^Rq+TXy$gXv+sTMAGG4tgjR% zaNp(>M01Q|>Gz=qIFwF+TFbk_FGenqdcARWFvYezzRms+*De!JCg=$LmN}S}gUzBv z=7oNle#I+bEN*`PZsv_NIKhqjKDC0W_upc32-VY`doy_GQgJiG>56NrLd%!(Fr~0P z(N!)(&mb1cV1%|x%*koDq0v%AN_=fhrJKbm!N_WYa%rHzXNudCruUa@`JR_(`e#C- zr`BDD?i}%}^q;=^=L~Bj_ayO?)$#51b^C0gZHk5F{``eos5fg!n@gI-on9?yORi|M zMZsIz5&GR#$D~*hgK->@VsoJZl`~Y(323K5%pBhF{Y0zPpHth-@Mq%XTrkc8$z!%1QJ&C(+=>c%X*#Mg;D zSWo2>C=jLw0<$jW!iOO%!rFd0pOi&JKQ4CbD%H&L0KTcS)rTza5l^xE$JS{Eqj <% provide :title, t("spending_proposals.stats.page_title") %> <% provide :social_media_meta_tags do %> - <%= render "shared/social_media_meta_tags_participatory_budget" %> + <%= render "shared/social_media_meta_tags", + social_url: budget_url(@budget), + social_title: @budget.name, + social_description: @budget.description_finished %> <% end %> <%= javascript_include_tag "chart", "data-turbolinks-track" => true %> - <%= javascript_include_tag "participatory-budget-charts", "data-turbolinks-track" => true %> + <%= javascript_include_tag "budgets-stats-charts", "data-turbolinks-track" => true %>
- <%= back_link_to participatory_budget_path %> + <%= back_link_to budgets_path %>

<%= t("spending_proposals.stats.heading") %>

@@ -21,11 +24,11 @@
  • - <%= link_to t("spending_proposals.stats.results_link"), participatory_budget_results_path %> + <%= link_to t("budget.results.link"), budget_results_path(@budget) %>
  • <%= t("shared.you_are_in") %> - <%= link_to t("spending_proposals.stats.stats_link"), participatory_budget_stats_path, class: "is-active" %> + <%= link_to t("budgets.stats.link"), budget_stats_path(@budget), class: "is-active" %>
@@ -34,7 +37,7 @@
-

TOTAL PARTICIPANTES

+

<%= t("budgets.stats.total_participants").upcase %>

<%= @stats[:total_participants] %>

@@ -47,9 +50,9 @@
-

TOTAL PROPUESTAS ENVIADAS

+

<%= t("budgets.stats.total_budget_investments").upcase %>

- <%= @stats[:total_spending_proposals] + @stats[:paper_spending_proposals] %> + <%= @stats[:total_budget_investments] %>

@@ -58,34 +61,34 @@

  - PROPUESTAS EN LA FASE FINAL: - <%= @stats[:total_feasible_spending_proposals] %>
+ <%= t("budgets.stats.total_feasible_investments").upcase %>: + <%= @stats[:total_feasible_investments] %>
  - PROPUESTAS INVIABLES: - <%= @stats[:total_unfeasible_spending_proposals] %>
+ <%= t("budgets.stats.total_unfeasible_investments").upcase %>: + <%= @stats[:total_unfeasible_investments] %>

  - FASE DE APOYOS: + <%= t("budgets.stats.total_participants_support_phase").upcase %>: - <%= @stats[:total_participants_support_phase] %> Participantes, + <%= @stats[:total_participants_support_phase] %> <%= t("budgets.stats.participants") %>, - <%= @stats[:total_supports] %> Apoyos
+ <%= @stats[:total_supports] %> <%= t("budgets.stats.supports") %>
  - FASE DE VOTACIÓN: + <%= t("budgets.stats.total_participants_vote_phase").upcase %>: - <%= @stats[:total_participants_vote_phase] %> Participantes, + <%= @stats[:total_participants_vote_phase] %> <%= t("budgets.stats.participants") %>, - <%= @stats[:total_votes] %> Votos
+ <%= @stats[:total_votes] %> <%= t("budgets.stats.votes") %>

@@ -95,19 +98,18 @@
-
-

Participación
por sexo

+

<%= t("budgets.stats.by_gender") %>


- <%= image_tag ("participatory_budget_stats/sex.png") %> + <%= image_tag ("budgets/stats/gender.png") %>
- +
@@ -117,7 +119,7 @@

-  HOMBRES +  <%= t("budgets.stats.total_male_participants").upcase %> (<%= number_to_percentage(@stats[:male_percentage], strip_insignificant_zeros: true, precision: 2) %>) @@ -132,7 +134,7 @@

-  MUJERES +  <%= t("budgets.stats.total_female_participants").upcase %> (<%= number_to_percentage(@stats[:female_percentage], strip_insignificant_zeros: true, precision: 2) %>) @@ -148,12 +150,46 @@

-

Participación por
grupos de edad

+

<%= t("budgets.stats.by_age") %>


- <%= render "spending_proposals_results_age" %> + + + + + + + + + <% all_ages_count = @stats[:age_groups].values.sum.to_f %> + <% @stats[:age_groups].each do |age_group, count| %> + "> + + + + <% end %> + +
<%= t("budgets.stats.age").upcase %><%= t("budgets.stats.total").upcase %>
+ <%= age_group.gsub("+", t("budgets.stats.more_than")) + t("budgets.stats.years") %> + + + <% + percentage_age_count = all_ages_count == 0 ? 0 : (count / all_ages_count * 100) + formatted_percentage_age_count = number_to_percentage(percentage_age_count, + strip_insignificant_zeros: true, + precision: 2) + %> + <%= count %> + (<%= formatted_percentage_age_count %>) + +
+ +
+

@@ -161,62 +197,56 @@
-

Participación por
distritos

-
- -
- -
- <%= image_tag("map.jpg", usemap: "#html_map", alt: "Mapa de distritos de Madrid") %> +

<%= t("budgets.stats.by_heading") %>

- - - - - + + + + + - - - - - - - - - + + + + + + + + + - <% @stats.headings.each do |heading| %> + <% @budget.headings.each do |heading| %> <% ["support", "vote", "all"].each do |phase| %> - - + + - - + + - - + + @@ -261,7 +261,7 @@

- <%= t("budgets.stats.no_demographic_data", total: @stats[:total_unknown_gender_or_age]) %> + <%= t("budgets.stats.no_demographic_data_html", total: @stats[:total_unknown_gender_or_age]) %>
diff --git a/config/locales/en/budgets.yml b/config/locales/en/budgets.yml index 2002d54ea..299ae7c49 100644 --- a/config/locales/en/budgets.yml +++ b/config/locales/en/budgets.yml @@ -203,22 +203,22 @@ en: supports: Supports votes: Votes total_participants_vote_phase: Voting Phase - by_gender: "Participants
by sex" + by_gender_html: "Participants
by sex" total_male_participants: Mens total_female_participants: Women - by_age: "Participants by
age groups" + by_age_html: "Participants by
age groups" age: Age total: Total more_than: More than years: years - by_heading: "Participants by
heading" + by_heading_html: "Participants by
heading" heading: Heading investments_sent: Investment proposals sent participants_support_phase: Participants support phase participants_voting_phase: Participants voting phase participants_total: Total Participants - percent_total_participants: "%
Total
Participants" - percent_heading_census: "%
Heading
Census" - no_demographic_data: "* There is no demographic data for
%{total}
participants." + percent_total_participants_html: "%
Total
Participants" + percent_heading_census_html: "%
Heading
Census" + no_demographic_data_html: "* There is no demographic data for
%{total}
participants." participatory_disclaimer: "** The numbers of total participation refer to persons that created, supported or voted investment proposals." heading_disclaimer: "*** Data about headings refer to the heading where each user voted, not necessarily the one that person is registered on." diff --git a/config/locales/es/budgets.yml b/config/locales/es/budgets.yml index 5fefc3430..5c1be0866 100644 --- a/config/locales/es/budgets.yml +++ b/config/locales/es/budgets.yml @@ -204,21 +204,21 @@ es: votes: Votos total_participants_vote_phase: Fase de votación total: Total - by_gender: "Participación
por sexo" + by_gender_html: "Participación
por sexo" total_male_participants: Hombres total_female_participants: Mujeres - by_age: "Participación por
grupos de edad" + by_age_html: "Participación por
grupos de edad" age: Edad more_than: Más de years: años - by_heading: "Participación por
distritos" + by_heading_html: "Participación por
distritos" heading: Distrito investments_sent: Propuestas enviadas participants_support_phase: Participación fase apoyos participants_voting_phase: Participación fase apoyos participants_total: Participación fase apoyos - percent_total_participants: "%
Total
Participantes" - percent_heading_census: "%
Censo
Distrito" - no_demographic_data: "* No se dispone de los datos demográficos de
%{total}
participantes." + percent_total_participants_html: "%
Total
Participantes" + percent_heading_census_html: "%
Censo
Distrito" + no_demographic_data_html: "* No se dispone de los datos demográficos de
%{total}
participantes." participatory_disclaimer: "** Las cifras de participación total se refieren a personas que han creado, apoyado o votado propuestas." heading_disclaimer: "*** Los datos de distrito se refieren al distrito en el que el usuario ha votado, no necesariamente en el que está empadronado." From 1c0c55c0fb3aac4f492fa7c7726b2e1cff76e5b0 Mon Sep 17 00:00:00 2001 From: decabeza Date: Fri, 30 Jun 2017 14:20:44 +0200 Subject: [PATCH 09/42] improves texts and styles for budgets stats --- app/views/budgets/stats/show.html.erb | 391 ++++++++++++-------------- config/locales/en/budgets.yml | 9 +- config/locales/es/budgets.yml | 13 +- 3 files changed, 189 insertions(+), 224 deletions(-) diff --git a/app/views/budgets/stats/show.html.erb b/app/views/budgets/stats/show.html.erb index f95311022..89666053f 100644 --- a/app/views/budgets/stats/show.html.erb +++ b/app/views/budgets/stats/show.html.erb @@ -1,5 +1,7 @@ <% cache [@stats] do %> - <% provide :title, t("spending_proposals.stats.page_title") %> + <% provide :title do %> + <%= t("budgets.stats.title") %> - <%= @budget.name %> + <% end %> <% provide :social_media_meta_tags do %> <%= render "shared/social_media_meta_tags", social_url: budget_url(@budget), @@ -7,246 +9,210 @@ social_description: @budget.description_finished %> <% end %> - <%= javascript_include_tag "chart", "data-turbolinks-track" => true %> - <%= javascript_include_tag "budgets-stats-charts", "data-turbolinks-track" => true %> - -

-
-
-
- <%= back_link_to budgets_path %> -

<%= t("spending_proposals.stats.heading") %>

-
-
-
- -
-
-
    -
  • - <%= link_to t("budget.results.link"), budget_results_path(@budget) %> -
  • -
  • - <%= t("shared.you_are_in") %> - <%= link_to t("budgets.stats.link"), budget_stats_path(@budget), class: "is-active" %> -
  • -
-
-
- -
-
-
-

<%= t("budgets.stats.total_participants").upcase %>

-

- <%= @stats[:total_participants] %> -

-
-
-
- -
- -
-
-
-

<%= t("budgets.stats.total_budget_investments").upcase %>

-

- <%= @stats[:total_budget_investments] %> -

+
+
+
+
+ <%= back_link_to budgets_path %> +

<%= t("budgets.stats.title") %>
<%= @budget.name %>

+
-
-

-   - - <%= t("budgets.stats.total_feasible_investments").upcase %>: - <%= @stats[:total_feasible_investments] %>
-
- -   - - <%= t("budgets.stats.total_unfeasible_investments").upcase %>: - <%= @stats[:total_unfeasible_investments] %>
-
- -
- -   - <%= t("budgets.stats.total_participants_support_phase").upcase %>: - - <%= @stats[:total_participants_support_phase] %> <%= t("budgets.stats.participants") %>, - - - <%= @stats[:total_supports] %> <%= t("budgets.stats.supports") %>
-
- -   - <%= t("budgets.stats.total_participants_vote_phase").upcase %>: - - <%= @stats[:total_participants_vote_phase] %> <%= t("budgets.stats.participants") %>, - - - <%= @stats[:total_votes] %> <%= t("budgets.stats.votes") %>
-
-

-
- -
-
- -
- +
-

<%= t("budgets.stats.by_gender_html") %>

+
    + +
  • + <%= t("shared.you_are_in") %> + <%= link_to t("budgets.stats.link"), budget_stats_path(@budget), class: "is-active" %> +
  • +
+
+
+ +
+
+
+ <%= t("budgets.stats.total_participants") %> +

+ <%= @stats[:total_participants] %> +

+ + <%= t("budgets.stats.total_budget_investments") %> +

+ <%= @stats[:total_budget_investments] %> +

+
-
+
+

+   + + <%= t("budgets.stats.total_feasible_investments") %>: + <%= @stats[:total_feasible_investments] %>
+
+ +   + + <%= t("budgets.stats.total_unfeasible_investments") %>: + <%= @stats[:total_unfeasible_investments] %>
+
-

-
- <%= image_tag ("budgets/stats/gender.png") %>
-
- -
-
+ +   + <%= t("budgets.stats.total_participants_support_phase") %>: + + <%= @stats[:total_participants_support_phase] %> <%= t("budgets.stats.participants") %>, + <%= @stats[:total_supports] %> <%= t("budgets.stats.supports") %>
+
+ +   + <%= t("budgets.stats.total_participants_vote_phase") %>: + + <%= @stats[:total_participants_vote_phase] %> <%= t("budgets.stats.participants") %>, + <%= @stats[:total_votes] %> <%= t("budgets.stats.votes") %>
+
+

+
+
+ +
+
+

<%= t("budgets.stats.by_gender") %>

-
-
-
-

- -  <%= t("budgets.stats.total_male_participants").upcase %> - (<%= number_to_percentage(@stats[:male_percentage], - strip_insignificant_zeros: true, - precision: 2) %>) -

-

- <%= @stats[:total_male_participants] %> -

-
+
+ <%= image_tag ("budgets/stats/gender.png") %> +
+ +
+
+

+ +  <%= t("budgets.stats.total_male_participants").upcase %> + (<%= number_to_percentage(@stats[:male_percentage], + strip_insignificant_zeros: true, + precision: 2) %>) +

+

+ <%= @stats[:total_male_participants] %> +

-
-
-

- -  <%= t("budgets.stats.total_female_participants").upcase %> - (<%= number_to_percentage(@stats[:female_percentage], - strip_insignificant_zeros: true, - precision: 2) %>) -

-

- <%= @stats[:total_female_participants] %> -

-
+
+

+ +  <%= t("budgets.stats.total_female_participants").upcase %> + (<%= number_to_percentage(@stats[:female_percentage], + strip_insignificant_zeros: true, + precision: 2) %>) +

+

+ <%= @stats[:total_female_participants] %> +

-
- -
-

<%= t("budgets.stats.by_age_html") %>

-
- -
- -
DISTRITOPROPUESTAS ENVIADASPARTICIPACIÓN FASE APOYOSPARTICIPACIÓN FASE VOTACIÓNPARTICIPACIÓN TOTAL<% t("budgets.stats.heading").upcase %><% t("budgets.stats.investments_sent").upcase %><% t("budgets.stats.participants_support_phase").upcase %><% t("budgets.stats.participants_voting_phase").upcase %><% t("budgets.stats.participants_total").upcase %>
TOTAL%
TOTAL
PARTICIPANTES
%
CENSO
DISTRITO
TOTAL%
TOTAL
PARTICIPANTES
%
CENSO
DISTRITO
TOTAL%
TOTAL
PARTICIPANTES
%
CENSO
DISTRITO
<%= t("budgets.stats.total").upcase %><%= t("budgets.stats.percent_total_participants").upcase %><%= t("budgets.stats.percent_heading_census").upcase %><%= t("budgets.stats.total").upcase %><%= t("budgets.stats.percent_total_participants").upcase %><%= t("budgets.stats.percent_heading_census").upcase %><%= t("budgets.stats.total").upcase %><%= t("budgets.stats.percent_total_participants").upcase %><%= t("budgets.stats.percent_heading_census").upcase %>
<%= heading.name %> - <%= heading.spending_proposals.count %> + <%= heading.investments.count %> + class="border-left text-center <%= phase == "all" ? "success" : "" %>"> <%= @stats[:headings][heading.id]["total_participants_#{phase}_phase".to_sym] %> + class="border-left border-right text-center <%= phase == "all" ? "success" : "" %>"> <%= number_to_percentage(@stats[:headings][heading.id]["percentage_participants_#{phase}_phase".to_sym], strip_insignificant_zeros: true, precision: 2) %> + class="text-center <%= phase == "all" ? "success" : "" %>"> <%= number_to_percentage(@stats[:headings][heading.id]["percentage_district_population_#{phase}_phase".to_sym], strip_insignificant_zeros: true, precision: 2) %> @@ -231,17 +261,15 @@

- * No se dispone de los datos demográficos de - <%= @stats[:total_unknown_gender_or_age] %> - participantes. + <%= t("budgets.stats.no_demographic_data", total: @stats[:total_unknown_gender_or_age]) %>
- ** Las cifras de participación total se refieren a personas que han creado, apoyado o votado propuestas. + <%= t("budgets.stats.participatory_disclaimer") %>
- *** Los datos de distrito se refieren al distrito en el que el usuario ha votado, no necesariamente en el que está empadronado. + <%= t("budgets.stats.heading_disclaimer") %>

diff --git a/config/locales/en/budgets.yml b/config/locales/en/budgets.yml index d7bd7235d..2002d54ea 100644 --- a/config/locales/en/budgets.yml +++ b/config/locales/en/budgets.yml @@ -191,3 +191,34 @@ en: dates_range_invalid: "Start date can't be equal or later than End date" prev_phase_dates_invalid: "Start date must be later than the start date of the previous enabled phase (%{phase_name})" next_phase_dates_invalid: "End date must be earlier than the end date of the next enabled phase (%{phase_name})" + stats: + link: Stats + page_title: "%{budget} - Stats" + total_participants: Total Participants + total_budget_investments: Total Proposed Investments + total_feasible_investments: Proposals on final phase + total_unfeasible_investments: Unfeasible proposals + total_participants_support_phase: Support phase + participants: Participants + supports: Supports + votes: Votes + total_participants_vote_phase: Voting Phase + by_gender: "Participants
by sex" + total_male_participants: Mens + total_female_participants: Women + by_age: "Participants by
age groups" + age: Age + total: Total + more_than: More than + years: years + by_heading: "Participants by
heading" + heading: Heading + investments_sent: Investment proposals sent + participants_support_phase: Participants support phase + participants_voting_phase: Participants voting phase + participants_total: Total Participants + percent_total_participants: "%
Total
Participants" + percent_heading_census: "%
Heading
Census" + no_demographic_data: "* There is no demographic data for
%{total}
participants." + participatory_disclaimer: "** The numbers of total participation refer to persons that created, supported or voted investment proposals." + heading_disclaimer: "*** Data about headings refer to the heading where each user voted, not necessarily the one that person is registered on." diff --git a/config/locales/es/budgets.yml b/config/locales/es/budgets.yml index 982149b5a..5fefc3430 100644 --- a/config/locales/es/budgets.yml +++ b/config/locales/es/budgets.yml @@ -191,3 +191,34 @@ es: dates_range_invalid: "La fecha de comienzo no puede ser igual o superior a la de finalización" prev_phase_dates_invalid: "La fecha de inicio debe ser posterior a la fecha de inicio de la anterior fase habilitada (%{phase_name})" next_phase_dates_invalid: "La fecha de fin debe ser anterior a la fecha de fin de la siguiente fase habilitada (%{phase_name})" + stats: + link: Estadísticas + page_title: "%{budget} - Estadísticas" + total_participants: Total participantes + total_budget_investments: Total propuestas enviadas + total_feasible_investments: Propuestas en la fase final + total_unfeasible_investments: Propuestas inviables + total_participants_support_phase: Fase de apoyos + participants: Participantess + supports: Apoyos + votes: Votos + total_participants_vote_phase: Fase de votación + total: Total + by_gender: "Participación
por sexo" + total_male_participants: Hombres + total_female_participants: Mujeres + by_age: "Participación por
grupos de edad" + age: Edad + more_than: Más de + years: años + by_heading: "Participación por
distritos" + heading: Distrito + investments_sent: Propuestas enviadas + participants_support_phase: Participación fase apoyos + participants_voting_phase: Participación fase apoyos + participants_total: Participación fase apoyos + percent_total_participants: "%
Total
Participantes" + percent_heading_census: "%
Censo
Distrito" + no_demographic_data: "* No se dispone de los datos demográficos de
%{total}
participantes." + participatory_disclaimer: "** Las cifras de participación total se refieren a personas que han creado, apoyado o votado propuestas." + heading_disclaimer: "*** Los datos de distrito se refieren al distrito en el que el usuario ha votado, no necesariamente en el que está empadronado." From fd4ea312c3c4910aa757139c0b093bf7d1c1ceaa Mon Sep 17 00:00:00 2001 From: Bertocq Date: Fri, 30 Jun 2017 12:15:11 +0200 Subject: [PATCH 08/42] Fix budget stats translations with line breaks --- app/views/budgets/stats/show.html.erb | 20 ++++++++++---------- config/locales/en/budgets.yml | 12 ++++++------ config/locales/es/budgets.yml | 12 ++++++------ 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/app/views/budgets/stats/show.html.erb b/app/views/budgets/stats/show.html.erb index 5570cc13e..f95311022 100644 --- a/app/views/budgets/stats/show.html.erb +++ b/app/views/budgets/stats/show.html.erb @@ -99,7 +99,7 @@
-

<%= t("budgets.stats.by_gender") %>

+

<%= t("budgets.stats.by_gender_html") %>


@@ -150,7 +150,7 @@
-

<%= t("budgets.stats.by_age") %>

+

<%= t("budgets.stats.by_age_html") %>


@@ -197,7 +197,7 @@
-

<%= t("budgets.stats.by_heading") %>

+

<%= t("budgets.stats.by_heading_html") %>

@@ -212,14 +212,14 @@
<%= t("budgets.stats.total").upcase %><%= t("budgets.stats.percent_total_participants").upcase %><%= t("budgets.stats.percent_heading_census").upcase %><%= t("budgets.stats.percent_total_participants_html") %><%= t("budgets.stats.percent_heading_census_html") %> <%= t("budgets.stats.total").upcase %><%= t("budgets.stats.percent_total_participants").upcase %><%= t("budgets.stats.percent_heading_census").upcase %><%= t("budgets.stats.percent_total_participants_html") %><%= t("budgets.stats.percent_heading_census_html") %> <%= t("budgets.stats.total").upcase %><%= t("budgets.stats.percent_total_participants").upcase %><%= t("budgets.stats.percent_heading_census").upcase %><%= t("budgets.stats.percent_total_participants_html") %><%= t("budgets.stats.percent_heading_census_html") %>
- - - - - - - - <% all_ages_count = @stats[:age_groups].values.sum.to_f %> - <% @stats[:age_groups].each do |age_group, count| %> - "> - - - - <% end %> - -
<%= t("budgets.stats.age").upcase %><%= t("budgets.stats.total").upcase %>
- <%= age_group.gsub("+", t("budgets.stats.more_than")) + t("budgets.stats.years") %> - - - <% - percentage_age_count = all_ages_count == 0 ? 0 : (count / all_ages_count * 100) - formatted_percentage_age_count = number_to_percentage(percentage_age_count, - strip_insignificant_zeros: true, - precision: 2) - %> - <%= count %> - (<%= formatted_percentage_age_count %>) - -
- -
-
-
- -
- -
- +
-

<%= t("budgets.stats.by_heading_html") %>

-
+

<%= t("budgets.stats.by_age") %>

-
- +
- - - - - + + + + + + <% all_ages_count = @stats[:age_groups].values.sum.to_f %> + <% @stats[:age_groups].each do |age_group, count| %> + "> + + + + <% end %> + +
<% t("budgets.stats.heading").upcase %><% t("budgets.stats.investments_sent").upcase %><% t("budgets.stats.participants_support_phase").upcase %><% t("budgets.stats.participants_voting_phase").upcase %><% t("budgets.stats.participants_total").upcase %><%= t("budgets.stats.age").upcase %><%= t("budgets.stats.total").upcase %>
+ <%= age_group.gsub("+", t("budgets.stats.more_than")) + t("budgets.stats.years") %> + + + <% + percentage_age_count = all_ages_count == 0 ? 0 : (count / all_ages_count * 100) + formatted_percentage_age_count = number_to_percentage(percentage_age_count, + strip_insignificant_zeros: true, + precision: 2) + %> + <%= count %> + (<%= formatted_percentage_age_count %>) + +
+ +
+
+
+
+ +
+
+

<%= t("budgets.stats.by_heading") %>

+ + + + + + + + + - - - - - - - - - + + + + + + + + + <% @budget.headings.each do |heading| %> - <% ["support", "vote", "all"].each do |phase| %>
<%= t("budgets.stats.heading") %><%= t("budgets.stats.investments_sent") %><%= t("budgets.stats.participants_support_phase") %><%= t("budgets.stats.participants_voting_phase") %><%= t("budgets.stats.participants_total") %>
<%= t("budgets.stats.total").upcase %><%= t("budgets.stats.percent_total_participants_html") %><%= t("budgets.stats.percent_heading_census_html") %><%= t("budgets.stats.total").upcase %><%= t("budgets.stats.percent_total_participants_html") %><%= t("budgets.stats.percent_heading_census_html") %><%= t("budgets.stats.total").upcase %><%= t("budgets.stats.percent_total_participants_html") %><%= t("budgets.stats.percent_heading_census_html") %><%= t("budgets.stats.total") %><%= t("budgets.stats.percent_total_participants_html") %><%= t("budgets.stats.percent_heading_census_html") %><%= t("budgets.stats.total") %><%= t("budgets.stats.percent_total_participants_html") %><%= t("budgets.stats.percent_heading_census_html") %><%= t("budgets.stats.total") %><%= t("budgets.stats.percent_total_participants_html") %><%= t("budgets.stats.percent_heading_census_html") %>
+ <%= heading.name %> + class="text-center border-left border-right"> <%= heading.investments.count %> "> + class="border-left text-center"> <%= @stats[:headings][heading.id]["total_participants_#{phase}_phase".to_sym] %> "> + class="border-left border-right text-center %>"> <%= number_to_percentage(@stats[:headings][heading.id]["percentage_participants_#{phase}_phase".to_sym], strip_insignificant_zeros: true, precision: 2) %> "> + class="text-center border-right"> <%= number_to_percentage(@stats[:headings][heading.id]["percentage_district_population_#{phase}_phase".to_sym], strip_insignificant_zeros: true, precision: 2) %> @@ -256,26 +222,23 @@ <% end %>
+
+
-
-
-

- - <%= t("budgets.stats.no_demographic_data_html", total: @stats[:total_unknown_gender_or_age]) %> - -
- - <%= t("budgets.stats.participatory_disclaimer") %> - -
- - <%= t("budgets.stats.heading_disclaimer") %> - -

-
+
+
+
+

+ <%= t("budgets.stats.no_demographic_data", total: @stats[:total_unknown_gender_or_age]) %> +

+

+ <%= t("budgets.stats.participatory_disclaimer") %> +

+

+ <%= t("budgets.stats.heading_disclaimer") %> +

-
<% end %> diff --git a/config/locales/en/budgets.yml b/config/locales/en/budgets.yml index 299ae7c49..bdfa3c3cf 100644 --- a/config/locales/en/budgets.yml +++ b/config/locales/en/budgets.yml @@ -192,6 +192,7 @@ en: prev_phase_dates_invalid: "Start date must be later than the start date of the previous enabled phase (%{phase_name})" next_phase_dates_invalid: "End date must be earlier than the end date of the next enabled phase (%{phase_name})" stats: + title: Participation stats link: Stats page_title: "%{budget} - Stats" total_participants: Total Participants @@ -203,15 +204,15 @@ en: supports: Supports votes: Votes total_participants_vote_phase: Voting Phase - by_gender_html: "Participants
by sex" + by_gender: "Participants by gender" total_male_participants: Mens total_female_participants: Women - by_age_html: "Participants by
age groups" + by_age: "Participants by age groups" age: Age total: Total more_than: More than years: years - by_heading_html: "Participants by
heading" + by_heading: "Participants by heading" heading: Heading investments_sent: Investment proposals sent participants_support_phase: Participants support phase @@ -219,6 +220,6 @@ en: participants_total: Total Participants percent_total_participants_html: "%
Total
Participants" percent_heading_census_html: "%
Heading
Census" - no_demographic_data_html: "* There is no demographic data for
%{total}
participants." + no_demographic_data: "* There is no demographic data for %{total} participants." participatory_disclaimer: "** The numbers of total participation refer to persons that created, supported or voted investment proposals." heading_disclaimer: "*** Data about headings refer to the heading where each user voted, not necessarily the one that person is registered on." diff --git a/config/locales/es/budgets.yml b/config/locales/es/budgets.yml index 5c1be0866..23f0ab491 100644 --- a/config/locales/es/budgets.yml +++ b/config/locales/es/budgets.yml @@ -192,6 +192,7 @@ es: prev_phase_dates_invalid: "La fecha de inicio debe ser posterior a la fecha de inicio de la anterior fase habilitada (%{phase_name})" next_phase_dates_invalid: "La fecha de fin debe ser anterior a la fecha de fin de la siguiente fase habilitada (%{phase_name})" stats: + title: Estadísticas de participación link: Estadísticas page_title: "%{budget} - Estadísticas" total_participants: Total participantes @@ -204,21 +205,21 @@ es: votes: Votos total_participants_vote_phase: Fase de votación total: Total - by_gender_html: "Participación
por sexo" + by_gender: "Participación por género" total_male_participants: Hombres total_female_participants: Mujeres - by_age_html: "Participación por
grupos de edad" + by_age: "Participación por grupos de edad" age: Edad more_than: Más de years: años - by_heading_html: "Participación por
distritos" + by_heading: "Participación por distritos" heading: Distrito investments_sent: Propuestas enviadas participants_support_phase: Participación fase apoyos - participants_voting_phase: Participación fase apoyos - participants_total: Participación fase apoyos + participants_voting_phase: Participación fase votación + participants_total: Participación total percent_total_participants_html: "%
Total
Participantes" percent_heading_census_html: "%
Censo
Distrito" - no_demographic_data_html: "* No se dispone de los datos demográficos de
%{total}
participantes." + no_demographic_data: "* No se dispone de los datos demográficos de %{total} participantes." participatory_disclaimer: "** Las cifras de participación total se refieren a personas que han creado, apoyado o votado propuestas." heading_disclaimer: "*** Los datos de distrito se refieren al distrito en el que el usuario ha votado, no necesariamente en el que está empadronado." From 895c8292abdefb4e2b71134ea0f01b338e580b0c Mon Sep 17 00:00:00 2001 From: decabeza Date: Fri, 30 Jun 2017 14:24:11 +0200 Subject: [PATCH 10/42] updates page title --- app/views/budgets/stats/show.html.erb | 2 +- config/locales/en/budgets.yml | 2 +- config/locales/es/budgets.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/views/budgets/stats/show.html.erb b/app/views/budgets/stats/show.html.erb index 89666053f..bdfd72803 100644 --- a/app/views/budgets/stats/show.html.erb +++ b/app/views/budgets/stats/show.html.erb @@ -1,6 +1,6 @@ <% cache [@stats] do %> <% provide :title do %> - <%= t("budgets.stats.title") %> - <%= @budget.name %> + <%= t("budgets.stats.page_title", budget: @budget.name) %> <% end %> <% provide :social_media_meta_tags do %> <%= render "shared/social_media_meta_tags", diff --git a/config/locales/en/budgets.yml b/config/locales/en/budgets.yml index bdfa3c3cf..fff10aa1c 100644 --- a/config/locales/en/budgets.yml +++ b/config/locales/en/budgets.yml @@ -194,7 +194,7 @@ en: stats: title: Participation stats link: Stats - page_title: "%{budget} - Stats" + page_title: "%{budget} - Participation stats" total_participants: Total Participants total_budget_investments: Total Proposed Investments total_feasible_investments: Proposals on final phase diff --git a/config/locales/es/budgets.yml b/config/locales/es/budgets.yml index 23f0ab491..0e6423c93 100644 --- a/config/locales/es/budgets.yml +++ b/config/locales/es/budgets.yml @@ -194,7 +194,7 @@ es: stats: title: Estadísticas de participación link: Estadísticas - page_title: "%{budget} - Estadísticas" + page_title: "%{budget} - Estadísticas de participación" total_participants: Total participantes total_budget_investments: Total propuestas enviadas total_feasible_investments: Propuestas en la fase final From 88ac17cc1bd6d58812da8816cf51d0772ef28980 Mon Sep 17 00:00:00 2001 From: decabeza Date: Fri, 30 Jun 2017 14:34:53 +0200 Subject: [PATCH 11/42] removes progress meter multiplier --- app/views/budgets/stats/show.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/budgets/stats/show.html.erb b/app/views/budgets/stats/show.html.erb index bdfd72803..5aa5f7c72 100644 --- a/app/views/budgets/stats/show.html.erb +++ b/app/views/budgets/stats/show.html.erb @@ -151,7 +151,7 @@ (<%= formatted_percentage_age_count %>)
-
From 6c214c266f4f124d09a674eb5bd982bcf620b62b Mon Sep 17 00:00:00 2001 From: Bertocq Date: Fri, 30 Jun 2017 15:32:30 +0200 Subject: [PATCH 12/42] Correct budget stats age group id's and labels --- app/views/budgets/stats/show.html.erb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/budgets/stats/show.html.erb b/app/views/budgets/stats/show.html.erb index 5aa5f7c72..7f0811414 100644 --- a/app/views/budgets/stats/show.html.erb +++ b/app/views/budgets/stats/show.html.erb @@ -135,9 +135,9 @@ <% all_ages_count = @stats[:age_groups].values.sum.to_f %> <% @stats[:age_groups].each do |age_group, count| %> - "> + "> - <%= age_group.gsub("+", t("budgets.stats.more_than")) + t("budgets.stats.years") %> + <%= age_group.gsub("+", t("budgets.stats.more_than")) + " " + t("budgets.stats.years") %> From 51ab4a430e1a62dc854aaff82fe6eca19e8d7cba Mon Sep 17 00:00:00 2001 From: rgarcia Date: Fri, 30 Jun 2017 21:41:47 +0200 Subject: [PATCH 13/42] Load budget in stats controller --- app/controllers/budgets/stats_controller.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/controllers/budgets/stats_controller.rb b/app/controllers/budgets/stats_controller.rb index 48a93c5e7..558a00865 100644 --- a/app/controllers/budgets/stats_controller.rb +++ b/app/controllers/budgets/stats_controller.rb @@ -1,6 +1,7 @@ module Budgets class StatsController < ApplicationController + before_action :load_budget load_and_authorize_resource :budget def show @@ -14,5 +15,9 @@ module Budgets Budget::Stats.new(@budget).generate end + def load_budget + @budget = Budget.find_by(slug: params[:budget_id]) || Budget.find_by(id: params[:budget_id]) + end + end end From eb57b5c3756dcbff37520bd550c3ddc0200e41d3 Mon Sep 17 00:00:00 2001 From: decabeza Date: Fri, 30 Jun 2017 21:51:27 +0200 Subject: [PATCH 14/42] adds multiplier on progress meter stats age table --- app/views/budgets/stats/show.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/budgets/stats/show.html.erb b/app/views/budgets/stats/show.html.erb index 7f0811414..af2eec87b 100644 --- a/app/views/budgets/stats/show.html.erb +++ b/app/views/budgets/stats/show.html.erb @@ -151,7 +151,7 @@ (<%= formatted_percentage_age_count %>)
-
From 75dfa4c66336114c0b055927dd015a16ae69f409 Mon Sep 17 00:00:00 2001 From: decabeza Date: Fri, 30 Jun 2017 22:32:06 +0200 Subject: [PATCH 15/42] fixes typo --- config/locales/es/budgets.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/locales/es/budgets.yml b/config/locales/es/budgets.yml index 0e6423c93..7e29f0367 100644 --- a/config/locales/es/budgets.yml +++ b/config/locales/es/budgets.yml @@ -200,7 +200,7 @@ es: total_feasible_investments: Propuestas en la fase final total_unfeasible_investments: Propuestas inviables total_participants_support_phase: Fase de apoyos - participants: Participantess + participants: Participantes supports: Apoyos votes: Votos total_participants_vote_phase: Fase de votación From ef958aae59055b5f325bd75d5c1574d132e06703 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Fri, 30 Jun 2017 22:58:25 +0200 Subject: [PATCH 16/42] adds version to cache --- app/models/budget/stats.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/budget/stats.rb b/app/models/budget/stats.rb index 3a497bc95..1ec2ca65d 100644 --- a/app/models/budget/stats.rb +++ b/app/models/budget/stats.rb @@ -192,7 +192,7 @@ class Budget end def stats_cache(key, &block) - Rails.cache.fetch("budgets_stats/#{@budget.id}/#{key}", &block) + Rails.cache.fetch("budgets_stats/#{@budget.id}/#{key}/v10", &block) end end end From f9e45dc2e25533f4eef79404b30e0d7bd153ae8c Mon Sep 17 00:00:00 2001 From: rgarcia Date: Fri, 30 Jun 2017 23:04:54 +0200 Subject: [PATCH 17/42] displays selected instead of feasible investments --- app/models/budget/stats.rb | 4 ++-- app/views/budgets/stats/show.html.erb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/models/budget/stats.rb b/app/models/budget/stats.rb index 1ec2ca65d..832007020 100644 --- a/app/models/budget/stats.rb +++ b/app/models/budget/stats.rb @@ -34,8 +34,8 @@ class Budget stats_cache("total_votes") { @budget.ballots.count } end - def total_feasible_investments - stats_cache("total_feasible_investments") { @budget.investments.feasible.count } + def total_selected_investments + stats_cache("total_selected_investments") { @budget.investments.selected.count } end def total_unfeasible_investments diff --git a/app/views/budgets/stats/show.html.erb b/app/views/budgets/stats/show.html.erb index af2eec87b..cb3bf6169 100644 --- a/app/views/budgets/stats/show.html.erb +++ b/app/views/budgets/stats/show.html.erb @@ -54,7 +54,7 @@

  - <%= t("budgets.stats.total_feasible_investments") %>: + <%= t("budgets.stats.total_selected_investments") %>: <%= @stats[:total_feasible_investments] %>
From 1f3bc2c8d9f717c8553b03e05b9734897166e06c Mon Sep 17 00:00:00 2001 From: Bertocq Date: Fri, 30 Jun 2017 23:08:57 +0200 Subject: [PATCH 18/42] Switch from feasible to selected investments on budget stats --- app/models/budget/stats.rb | 2 +- app/views/budgets/stats/show.html.erb | 4 ++-- config/locales/en/budgets.yml | 2 +- config/locales/es/budgets.yml | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/models/budget/stats.rb b/app/models/budget/stats.rb index 832007020..de07b7040 100644 --- a/app/models/budget/stats.rb +++ b/app/models/budget/stats.rb @@ -7,7 +7,7 @@ class Budget def generate stats = %w[total_participants total_participants_support_phase total_participants_vote_phase total_budget_investments total_votes - total_feasible_investments total_unfeasible_investments total_male_participants total_female_participants total_supports + total_selected_investments total_unfeasible_investments total_male_participants total_female_participants total_supports total_unknown_gender_or_age age_groups male_percentage female_percentage headings] stats.map { |stat_name| [stat_name.to_sym, send(stat_name)] }.to_h end diff --git a/app/views/budgets/stats/show.html.erb b/app/views/budgets/stats/show.html.erb index cb3bf6169..919ae5d52 100644 --- a/app/views/budgets/stats/show.html.erb +++ b/app/views/budgets/stats/show.html.erb @@ -53,9 +53,9 @@

  - + <%= t("budgets.stats.total_selected_investments") %>: - <%= @stats[:total_feasible_investments] %>
+ <%= @stats[:total_selected_investments] %>
  diff --git a/config/locales/en/budgets.yml b/config/locales/en/budgets.yml index fff10aa1c..2b41cee5d 100644 --- a/config/locales/en/budgets.yml +++ b/config/locales/en/budgets.yml @@ -197,7 +197,7 @@ en: page_title: "%{budget} - Participation stats" total_participants: Total Participants total_budget_investments: Total Proposed Investments - total_feasible_investments: Proposals on final phase + total_selected_investments: Proposals on final phase total_unfeasible_investments: Unfeasible proposals total_participants_support_phase: Support phase participants: Participants diff --git a/config/locales/es/budgets.yml b/config/locales/es/budgets.yml index 7e29f0367..c72e8b85d 100644 --- a/config/locales/es/budgets.yml +++ b/config/locales/es/budgets.yml @@ -197,7 +197,7 @@ es: page_title: "%{budget} - Estadísticas de participación" total_participants: Total participantes total_budget_investments: Total propuestas enviadas - total_feasible_investments: Propuestas en la fase final + total_selected_investments: Propuestas en la fase final total_unfeasible_investments: Propuestas inviables total_participants_support_phase: Fase de apoyos participants: Participantes From 427781a253940235f6db5b6c5e3506c3c7090a2d Mon Sep 17 00:00:00 2001 From: Bertocq Date: Fri, 30 Jun 2017 23:29:25 +0200 Subject: [PATCH 19/42] Reorder gender statistics to match gender image --- app/views/budgets/stats/show.html.erb | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/app/views/budgets/stats/show.html.erb b/app/views/budgets/stats/show.html.erb index 919ae5d52..9b5d62b46 100644 --- a/app/views/budgets/stats/show.html.erb +++ b/app/views/budgets/stats/show.html.erb @@ -93,19 +93,6 @@

-
-

- -  <%= t("budgets.stats.total_male_participants").upcase %> - (<%= number_to_percentage(@stats[:male_percentage], - strip_insignificant_zeros: true, - precision: 2) %>) -

-

- <%= @stats[:total_male_participants] %> -

-
-

@@ -118,6 +105,19 @@ <%= @stats[:total_female_participants] %>

+ +
+

+ +  <%= t("budgets.stats.total_male_participants").upcase %> + (<%= number_to_percentage(@stats[:male_percentage], + strip_insignificant_zeros: true, + precision: 2) %>) +

+

+ <%= @stats[:total_male_participants] %> +

+
From 9f6f7496c13420dd77ba5f9f2b69496812b3601e Mon Sep 17 00:00:00 2001 From: decabeza Date: Fri, 30 Jun 2017 23:31:53 +0200 Subject: [PATCH 20/42] changes text classes on gender stats --- app/views/budgets/stats/show.html.erb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/budgets/stats/show.html.erb b/app/views/budgets/stats/show.html.erb index 9b5d62b46..ef77d2030 100644 --- a/app/views/budgets/stats/show.html.erb +++ b/app/views/budgets/stats/show.html.erb @@ -93,7 +93,7 @@
-
+

 <%= t("budgets.stats.total_female_participants").upcase %> @@ -106,7 +106,7 @@

-
+

 <%= t("budgets.stats.total_male_participants").upcase %> From cdece488989cb28080841371700383138b52c005 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Fri, 30 Jun 2017 23:42:30 +0200 Subject: [PATCH 21/42] Order Budget headings by id when calculating heading stats --- app/models/budget/stats.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/budget/stats.rb b/app/models/budget/stats.rb index de07b7040..338b28fd1 100644 --- a/app/models/budget/stats.rb +++ b/app/models/budget/stats.rb @@ -129,7 +129,7 @@ class Budget def headings stats_cache("headings") do groups = Hash.new(0) - @budget.headings.each do |heading| + @budget.headings.order("id ASC").each do |heading| groups[heading.id] = Hash.new(0).merge(calculate_heading_totals(heading)) end From e5ec0bf6bbb841f3331495937d4aae79b4dba5c3 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Fri, 30 Jun 2017 23:48:18 +0200 Subject: [PATCH 22/42] counts votes instead of ballots --- app/models/budget/stats.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/budget/stats.rb b/app/models/budget/stats.rb index 338b28fd1..643c4fda0 100644 --- a/app/models/budget/stats.rb +++ b/app/models/budget/stats.rb @@ -31,7 +31,7 @@ class Budget end def total_votes - stats_cache("total_votes") { @budget.ballots.count } + stats_cache("total_votes") { @budget.ballots.map(&:lines).count } end def total_selected_investments From 50c0f5f2873c5fa9b31e4f39821b1ad1ea843bf2 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Sat, 1 Jul 2017 00:05:54 +0200 Subject: [PATCH 23/42] more efficient calculation of ballot lines --- app/models/budget/stats.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/budget/stats.rb b/app/models/budget/stats.rb index 643c4fda0..dda71554b 100644 --- a/app/models/budget/stats.rb +++ b/app/models/budget/stats.rb @@ -31,7 +31,7 @@ class Budget end def total_votes - stats_cache("total_votes") { @budget.ballots.map(&:lines).count } + stats_cache("total_votes") { @budget.ballots.pluck(:ballot_lines_count).inject(0) { |sum, x| sum + x } } end def total_selected_investments From be89289b090b0930f2a31a9a6a18fe4b475d0543 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Sat, 1 Jul 2017 10:32:59 +0200 Subject: [PATCH 24/42] Improve budget stats page with a new row showing each column totals --- app/models/budget/stats.rb | 2 ++ app/views/budgets/stats/show.html.erb | 29 ++++++++++++++++++++++++--- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/app/models/budget/stats.rb b/app/models/budget/stats.rb index dda71554b..a70c7d754 100644 --- a/app/models/budget/stats.rb +++ b/app/models/budget/stats.rb @@ -134,6 +134,7 @@ class Budget end groups[:total] = Hash.new(0) + groups[:total][:total_investments_count] = groups.collect {|_k, v| v[:total_investments_count]}.sum groups[:total][:total_participants_support_phase] = groups.collect {|_k, v| v[:total_participants_support_phase]}.sum groups[:total][:total_participants_vote_phase] = groups.collect {|_k, v| v[:total_participants_vote_phase]}.sum groups[:total][:total_participants_all_phase] = groups.collect {|_k, v| v[:total_participants_all_phase]}.sum @@ -152,6 +153,7 @@ class Budget def calculate_heading_totals(heading) { + total_investments_count: heading.investments.count, total_participants_support_phase: voters_by_heading(heading).uniq.count, total_participants_vote_phase: balloters_by_heading(heading.id).uniq.count, total_participants_all_phase: voters_and_balloters_by_heading(heading) diff --git a/app/views/budgets/stats/show.html.erb b/app/views/budgets/stats/show.html.erb index ef77d2030..b9b941307 100644 --- a/app/views/budgets/stats/show.html.erb +++ b/app/views/budgets/stats/show.html.erb @@ -167,7 +167,7 @@

<%= t("budgets.stats.by_heading") %>

- +
@@ -197,7 +197,7 @@ <% ["support", "vote", "all"].each do |phase| %> @@ -206,7 +206,7 @@ <%= @stats[:headings][heading.id]["total_participants_#{phase}_phase".to_sym] %> <% end %> + + + + + <% ["support", "vote", "all"].each do |phase| %> + + + + <% end %> +
<%= t("budgets.stats.heading") %> - <%= heading.investments.count %> + <%= @stats[:headings][heading.id][:total_investments_count] %> + class="border-left border-right text-center"> <%= number_to_percentage(@stats[:headings][heading.id]["percentage_participants_#{phase}_phase".to_sym], strip_insignificant_zeros: true, precision: 2) %> @@ -220,6 +220,29 @@ <% end %>
+ <%= t("budgets.stats.total").upcase %> + + <%= @stats[:headings][:total][:total_investments_count] %> + + <%= @stats[:headings][:total]["total_participants_#{phase}_phase".to_sym] %> + + <%= number_to_percentage(@stats[:headings][:total]["percentage_participants_#{phase}_phase".to_sym], + strip_insignificant_zeros: true, + precision: 2) %> + ">
From 4b2a2dd9956953627bcbb59f1d579e59cb180efa Mon Sep 17 00:00:00 2001 From: Bertocq Date: Sat, 1 Jul 2017 10:51:12 +0200 Subject: [PATCH 25/42] Improve percent round --- app/models/budget/stats.rb | 2 +- app/views/budgets/stats/show.html.erb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/budget/stats.rb b/app/models/budget/stats.rb index a70c7d754..17824643d 100644 --- a/app/models/budget/stats.rb +++ b/app/models/budget/stats.rb @@ -186,7 +186,7 @@ class Budget def calculate_percentage(fraction, total) percent = fraction / total.to_f - percent.nan? ? 0.0 : (percent * 100).round(2) + percent.nan? ? 0.0 : (percent * 100).round(3) end def supports(supportable) diff --git a/app/views/budgets/stats/show.html.erb b/app/views/budgets/stats/show.html.erb index b9b941307..4c9359595 100644 --- a/app/views/budgets/stats/show.html.erb +++ b/app/views/budgets/stats/show.html.erb @@ -221,7 +221,7 @@ <% end %> - + <%= t("budgets.stats.total").upcase %> Date: Sat, 1 Jul 2017 11:25:22 +0200 Subject: [PATCH 26/42] Order headings by id on budget stats view --- app/views/budgets/stats/show.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/budgets/stats/show.html.erb b/app/views/budgets/stats/show.html.erb index 4c9359595..050617da7 100644 --- a/app/views/budgets/stats/show.html.erb +++ b/app/views/budgets/stats/show.html.erb @@ -190,7 +190,7 @@ - <% @budget.headings.each do |heading| %> + <% @budget.headings.order("id ASC").each do |heading| %> <%= heading.name %> From e5a2440e91804cc6f8ceb6937c889b8ba5c8917d Mon Sep 17 00:00:00 2001 From: Bertocq Date: Sat, 1 Jul 2017 11:46:04 +0200 Subject: [PATCH 27/42] Remove the last totals row on Budget stats view --- app/views/budgets/stats/show.html.erb | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/app/views/budgets/stats/show.html.erb b/app/views/budgets/stats/show.html.erb index 050617da7..11c3c2461 100644 --- a/app/views/budgets/stats/show.html.erb +++ b/app/views/budgets/stats/show.html.erb @@ -220,29 +220,6 @@ <% end %> <% end %> - - - <%= t("budgets.stats.total").upcase %> - - - <%= @stats[:headings][:total][:total_investments_count] %> - - - <% ["support", "vote", "all"].each do |phase| %> - - <%= @stats[:headings][:total]["total_participants_#{phase}_phase".to_sym] %> - - - <%= number_to_percentage(@stats[:headings][:total]["percentage_participants_#{phase}_phase".to_sym], - strip_insignificant_zeros: true, - precision: 2) %> - - "> - <% end %> -
From 4691b486b0c0a957c14d1f4a1ac3e169bd0ff3c1 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Sat, 1 Jul 2017 17:33:49 +0200 Subject: [PATCH 28/42] Improve budget stats investments sent text to have a breakline on spanish --- app/views/budgets/stats/show.html.erb | 2 +- config/locales/en/budgets.yml | 2 +- config/locales/es/budgets.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/views/budgets/stats/show.html.erb b/app/views/budgets/stats/show.html.erb index 11c3c2461..6f117d4e0 100644 --- a/app/views/budgets/stats/show.html.erb +++ b/app/views/budgets/stats/show.html.erb @@ -171,7 +171,7 @@ <%= t("budgets.stats.heading") %> - <%= t("budgets.stats.investments_sent") %> + <%= t("budgets.stats.investments_sent_html") %> <%= t("budgets.stats.participants_support_phase") %> <%= t("budgets.stats.participants_voting_phase") %> <%= t("budgets.stats.participants_total") %> diff --git a/config/locales/en/budgets.yml b/config/locales/en/budgets.yml index 2b41cee5d..b40bd8145 100644 --- a/config/locales/en/budgets.yml +++ b/config/locales/en/budgets.yml @@ -214,7 +214,7 @@ en: years: years by_heading: "Participants by heading" heading: Heading - investments_sent: Investment proposals sent + investments_sent_html: "Investment proposals sent" participants_support_phase: Participants support phase participants_voting_phase: Participants voting phase participants_total: Total Participants diff --git a/config/locales/es/budgets.yml b/config/locales/es/budgets.yml index c72e8b85d..5f14ad8bd 100644 --- a/config/locales/es/budgets.yml +++ b/config/locales/es/budgets.yml @@ -214,7 +214,7 @@ es: years: años by_heading: "Participación por distritos" heading: Distrito - investments_sent: Propuestas enviadas + investments_sent_html: "Propuestas
enviadas" participants_support_phase: Participación fase apoyos participants_voting_phase: Participación fase votación participants_total: Participación total From c5a4a427c4a5ba26f063a423cebb9964f32a4089 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Wed, 12 Jul 2017 12:36:13 +0200 Subject: [PATCH 29/42] Add links between Budget stats and results routes --- app/views/budgets/executions/show.html.erb | 3 +++ app/views/budgets/results/show.html.erb | 3 +++ app/views/budgets/stats/show.html.erb | 8 ++++---- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/app/views/budgets/executions/show.html.erb b/app/views/budgets/executions/show.html.erb index c1abd1e5c..aa107e3b6 100644 --- a/app/views/budgets/executions/show.html.erb +++ b/app/views/budgets/executions/show.html.erb @@ -31,6 +31,9 @@
  • <%= link_to t("budgets.results.link"), budget_results_path(@budget) %>
  • +
  • + <%= link_to t("budgets.stats.link"), budget_stats_path(@budget) %> +
  • <%= link_to t("budgets.executions.link"), budget_executions_path(@budget), class: "is-active" %>
  • diff --git a/app/views/budgets/results/show.html.erb b/app/views/budgets/results/show.html.erb index b8b3e9de8..6e7f372f2 100644 --- a/app/views/budgets/results/show.html.erb +++ b/app/views/budgets/results/show.html.erb @@ -31,6 +31,9 @@ <%= t("shared.you_are_in") %> <%= link_to t("budgets.results.link"), budget_results_path(@budget), class: "is-active" %> +
  • + <%= link_to t("budgets.stats.link"), budget_stats_path(@budget) %> +
  • <%= link_to t("budgets.executions.link"), budget_executions_path(@budget) %>
  • diff --git a/app/views/budgets/stats/show.html.erb b/app/views/budgets/stats/show.html.erb index 6f117d4e0..ba5a1129f 100644 --- a/app/views/budgets/stats/show.html.erb +++ b/app/views/budgets/stats/show.html.erb @@ -22,13 +22,13 @@
      - + <% end %>
    • - <%= t("shared.you_are_in") %> <%= link_to t("budgets.stats.link"), budget_stats_path(@budget), class: "is-active" %>
    From 6a46719ff880b91e0ceb902ad60a90f5c0bc002f Mon Sep 17 00:00:00 2001 From: Bertocq Date: Wed, 12 Jul 2017 13:36:02 +0200 Subject: [PATCH 30/42] Link to results without heading unless its on the results menu --- app/views/budgets/show.html.erb | 2 +- app/views/budgets/stats/show.html.erb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/budgets/show.html.erb b/app/views/budgets/show.html.erb index 7e526a5e0..89e4e146c 100644 --- a/app/views/budgets/show.html.erb +++ b/app/views/budgets/show.html.erb @@ -38,7 +38,7 @@ <% if @budget.finished? %> <%= link_to t("budgets.show.see_results"), - budget_results_path(@budget, heading_id: @budget.headings.first), + budget_results_path(@budget), class: "button margin-top expanded" %> <% end %>
    diff --git a/app/views/budgets/stats/show.html.erb b/app/views/budgets/stats/show.html.erb index ba5a1129f..7d2db9f70 100644 --- a/app/views/budgets/stats/show.html.erb +++ b/app/views/budgets/stats/show.html.erb @@ -25,7 +25,7 @@ <% if @budget.finished? %>
  • <%= t("shared.you_are_in") %> - <%= link_to t("budgets.results.link"), budget_results_path(@budget, heading_id: @budget.headings.first.to_param) %> + <%= link_to t("budgets.results.link"), budget_results_path(@budget) %>
  • <% end %>
  • From 7b2f77dfbd0e48971ebcb905eb5a88d976c22736 Mon Sep 17 00:00:00 2001 From: decabeza Date: Wed, 9 Aug 2017 18:43:58 +0200 Subject: [PATCH 31/42] removes duplicated thead tag --- app/views/budgets/stats/show.html.erb | 1 - 1 file changed, 1 deletion(-) diff --git a/app/views/budgets/stats/show.html.erb b/app/views/budgets/stats/show.html.erb index 7d2db9f70..060599b67 100644 --- a/app/views/budgets/stats/show.html.erb +++ b/app/views/budgets/stats/show.html.erb @@ -187,7 +187,6 @@ <%= t("budgets.stats.percent_total_participants_html") %> <%= t("budgets.stats.percent_heading_census_html") %> - <% @budget.headings.order("id ASC").each do |heading| %> From 99d0ac52c0f66023fc8296be3ade1123aedc7500 Mon Sep 17 00:00:00 2001 From: decabeza Date: Thu, 8 Mar 2018 17:21:06 +0100 Subject: [PATCH 32/42] Fixes budgets stats ui for all phases --- app/views/budgets/stats/show.html.erb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/views/budgets/stats/show.html.erb b/app/views/budgets/stats/show.html.erb index 060599b67..0d41460ac 100644 --- a/app/views/budgets/stats/show.html.erb +++ b/app/views/budgets/stats/show.html.erb @@ -12,9 +12,12 @@
    -
    +
    <%= back_link_to budgets_path %> -

    <%= t("budgets.stats.title") %>
    <%= @budget.name %>

    +

    + <%= t("budgets.stats.title") %>
    + <%= @budget.name %> +

    From 3291b3274adfe1d778e0467961347b6c7067d12f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Wed, 4 Jul 2018 14:15:28 +0200 Subject: [PATCH 33/42] Added physical votes to stats --- app/models/budget/stats.rb | 10 +- spec/models/budget/stats_spec.rb | 195 +++++++++++++++++++++++++++++++ 2 files changed, 204 insertions(+), 1 deletion(-) create mode 100644 spec/models/budget/stats_spec.rb diff --git a/app/models/budget/stats.rb b/app/models/budget/stats.rb index 17824643d..d47139aae 100644 --- a/app/models/budget/stats.rb +++ b/app/models/budget/stats.rb @@ -95,7 +95,9 @@ class Budget end def participants - stats_cache("participants") { User.where(id: (authors + voters + balloters).uniq) } + stats_cache("participants") do + User.where(id: (authors + voters + balloters + poll_ballot_voters).uniq) + end end def authors @@ -110,6 +112,12 @@ class Budget stats_cache("balloters") { @budget.ballots.where("ballot_lines_count > ?", 0).pluck(:user_id) } end + def poll_ballot_voters + stats_cache("poll_ballot_voters") do + @budget&.poll ? @budget.poll.voters.pluck(:user_id) : [] + end + end + def total_participants_with_gender stats_cache("total_participants_with_gender") { participants.where.not(gender: nil).distinct.count } end diff --git a/spec/models/budget/stats_spec.rb b/spec/models/budget/stats_spec.rb new file mode 100644 index 000000000..9a12e7269 --- /dev/null +++ b/spec/models/budget/stats_spec.rb @@ -0,0 +1,195 @@ +require "rails_helper" + +describe Budget::Stats do + + before(:all) do + @budget = create(:budget) + @group = create(:budget_group, budget: @budget) + @heading = create(:budget_heading, group: @group, price: 1000) + + @investment1 = create(:budget_investment, :selected, author: create(:user, gender: "female"), + heading: @heading, price: 200, ballot_lines_count: 900, winner: true) + @investment2 = create(:budget_investment, :selected, author: create(:user, gender: "female"), + heading: @heading, price: 300, ballot_lines_count: 800, winner: true) + @investment3 = create(:budget_investment, :selected, author: create(:user, gender: "female", + date_of_birth: 40.years.ago), heading: @heading, price: 400, + ballot_lines_count: 880, winner: true) + @investment4 = create(:budget_investment, :selected, author: create(:user, gender: "male"), + heading: @heading, price: 100, ballot_lines_count: 915, winner: true) + @investment5 = create(:budget_investment, :unfeasible, author: create(:user, gender: "male", + date_of_birth: 25.years.ago), heading: @heading) + + @support1 = create(:vote, votable: @investment1, voter: create(:user, gender: "male")) + @support2 = create(:vote, votable: @investment2, voter: create(:user)) + + @budget_ballot1 = create(:budget_ballot, budget: @budget, user: create(:user, gender: "female", + date_of_birth: 54.years.ago)) + @budget_ballot2 = create(:budget_ballot, budget: @budget, user: create(:user, gender: "female")) + @budget_ballot3 = create(:budget_ballot, budget: @budget, user: create(:user, gender: "male")) + + @budget_ballot_line1 = create(:budget_ballot_line, ballot: @budget_ballot1, + investment: @investment1) + @budget_ballot_line2 = create(:budget_ballot_line, ballot: @budget_ballot2, + investment: @investment2) + @budget_ballot_line3 = create(:budget_ballot_line, ballot: @budget_ballot3, + investment: @investment3) + + @poll = create(:poll, budget: @budget) + @poll_voter = create(:poll_voter, :from_booth, poll: @poll) + + @budget_ballot4 = create(:budget_ballot, budget: @budget, physical: true, user: nil) + @budget_ballot_line4 = create(:budget_ballot_line, ballot: @budget_ballot4, + investment: @investment4) + + @stats = Budget::Stats.new(@budget).generate + end + + context "#total_participants" do + + it "returns the number of total participants" do + expect(@stats[:total_participants]).to be 11 + end + + end + + context "#total_participants_support_phase" do + + it "returns the number of total participants in the support phase" do + expect(@stats[:total_participants_support_phase]).to be 2 + end + + end + + context "#total_participants_vote_phase" do + + it "returns the number of total participants in the votes phase" do + expect(@stats[:total_participants_vote_phase]).to be 4 + end + + end + + context "#total_budget_investments" do + + it "returns the number of total budget investments" do + expect(@stats[:total_budget_investments]).to be 5 + end + + end + + context "#total_votes" do + + it "returns the number of total votes" do + expect(@stats[:total_votes]).to be 4 + end + + end + + context "#total_selected_investments" do + + it "returns the number of total selected investments" do + expect(@stats[:total_selected_investments]).to be 4 + end + + end + + context "#total_unfeasible_investments" do + + it "returns the number of total unfeasible investments" do + expect(@stats[:total_unfeasible_investments]).to be 1 + end + + end + + context "#total_male_participants" do + + it "returns the number of total male participants" do + expect(@stats[:total_male_participants]).to be 4 + end + + end + + context "#total_female_participants" do + + it "returns the number of total female participants" do + expect(@stats[:total_female_participants]).to be 6 + end + + end + + context "#total_supports" do + + it "returns the number of total supports" do + expect(@stats[:total_supports]).to be 2 + end + + end + + context "#total_unknown_gender_or_age" do + + it "returns the number of total unknown participants' gender or age" do + expect(@stats[:total_unknown_gender_or_age]).to be 1 + end + + end + + context "#age_groups" do + + it "returns the age groups hash" do + expect(@stats[:age_groups]["16 - 19"]).to be 0 + expect(@stats[:age_groups]["20 - 24"]).to be 7 + expect(@stats[:age_groups]["25 - 29"]).to be 1 + expect(@stats[:age_groups]["30 - 34"]).to be 0 + expect(@stats[:age_groups]["35 - 39"]).to be 1 + expect(@stats[:age_groups]["40 - 44"]).to be 1 + expect(@stats[:age_groups]["45 - 49"]).to be 0 + expect(@stats[:age_groups]["50 - 54"]).to be 1 + expect(@stats[:age_groups]["55 - 59"]).to be 0 + expect(@stats[:age_groups]["60 - 64"]).to be 0 + expect(@stats[:age_groups]["65 - 69"]).to be 0 + expect(@stats[:age_groups]["70 - 140"]).to be 0 + end + + end + + context "#male_percentage" do + + it "returns the percentage of male participants" do + expect(@stats[:male_percentage]).to be 40.0 + end + + end + + context "#female_percentage" do + + it "returns the percentage of female participants" do + expect(@stats[:female_percentage]).to be 60.0 + end + + end + + context "#headings" do + + it "returns headings data" do + expect(@stats[:headings][1][:total_investments_count]).to be 5 + expect(@stats[:headings][1][:total_participants_support_phase]).to be 2 + expect(@stats[:headings][1][:total_participants_vote_phase]).to be 4 + expect(@stats[:headings][1][:total_participants_all_phase]).to be 6 + expect(@stats[:headings][1][:percentage_participants_support_phase]).to be 100.0 + expect(@stats[:headings][1][:percentage_district_population_support_phase]).to be 0.162 + expect(@stats[:headings][1][:percentage_participants_vote_phase]).to be 100.0 + expect(@stats[:headings][1][:percentage_district_population_vote_phase]).to be 0.324 + expect(@stats[:headings][1][:percentage_participants_all_phase]).to be 100.0 + expect(@stats[:headings][1][:percentage_district_population_all_phase]).to be 0.486 + + expect(@stats[:headings][:total][:total_investments_count]).to be 5 + expect(@stats[:headings][:total][:total_participants_support_phase]).to be 2 + expect(@stats[:headings][:total][:total_participants_vote_phase]).to be 4 + expect(@stats[:headings][:total][:total_participants_all_phase]).to be 6 + expect(@stats[:headings][:total][:percentage_participants_support_phase]).to be 100.0 + expect(@stats[:headings][:total][:percentage_participants_vote_phase]).to be 100.0 + expect(@stats[:headings][:total][:percentage_participants_all_phase]).to be 100.0 + end + + end + +end From 0c5f801c19fc14c4cb6aa9e76ac902c6179913a2 Mon Sep 17 00:00:00 2001 From: Marko Lovic Date: Wed, 1 Aug 2018 17:53:33 +0200 Subject: [PATCH 34/42] Keep DB clean after running budget stats spec This spec was leaving the DB "dirty" because it was creating records in a before(:all) hook. These records are not cleaned up automatically when using the :transaction strategy for DatabaseCleaner. Using before(:each), however, causes another problem. Some of the code depends on the heading id being 1 (see app/models/budget/ballot/line.rb#L48). Because of SQL auto-increment, this is only the case the first time the hook is run, as different id's are assigned on subsequent runs. This is fixed by forcing the id to always be 1. --- spec/models/budget/stats_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/models/budget/stats_spec.rb b/spec/models/budget/stats_spec.rb index 9a12e7269..ba5e642bb 100644 --- a/spec/models/budget/stats_spec.rb +++ b/spec/models/budget/stats_spec.rb @@ -2,7 +2,7 @@ require "rails_helper" describe Budget::Stats do - before(:all) do + before(:each) do @budget = create(:budget) @group = create(:budget_group, budget: @budget) @heading = create(:budget_heading, group: @group, price: 1000) From 70e108d5933357ed3f3b9da461421148eca99c89 Mon Sep 17 00:00:00 2001 From: Marko Lovic Date: Wed, 22 Aug 2018 14:12:37 +0200 Subject: [PATCH 35/42] Simplify spec --- spec/models/budget/stats_spec.rb | 35 ++++++++++++++++---------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/spec/models/budget/stats_spec.rb b/spec/models/budget/stats_spec.rb index ba5e642bb..78aea057c 100644 --- a/spec/models/budget/stats_spec.rb +++ b/spec/models/budget/stats_spec.rb @@ -170,24 +170,25 @@ describe Budget::Stats do context "#headings" do it "returns headings data" do - expect(@stats[:headings][1][:total_investments_count]).to be 5 - expect(@stats[:headings][1][:total_participants_support_phase]).to be 2 - expect(@stats[:headings][1][:total_participants_vote_phase]).to be 4 - expect(@stats[:headings][1][:total_participants_all_phase]).to be 6 - expect(@stats[:headings][1][:percentage_participants_support_phase]).to be 100.0 - expect(@stats[:headings][1][:percentage_district_population_support_phase]).to be 0.162 - expect(@stats[:headings][1][:percentage_participants_vote_phase]).to be 100.0 - expect(@stats[:headings][1][:percentage_district_population_vote_phase]).to be 0.324 - expect(@stats[:headings][1][:percentage_participants_all_phase]).to be 100.0 - expect(@stats[:headings][1][:percentage_district_population_all_phase]).to be 0.486 + heading_stats = @stats[:headings][@heading.id] + expect(heading_stats[:total_investments_count]).to be 5 + expect(heading_stats[:total_participants_support_phase]).to be 2 + expect(heading_stats[:total_participants_vote_phase]).to be 4 + expect(heading_stats[:total_participants_all_phase]).to be 6 + expect(heading_stats[:percentage_participants_support_phase]).to be 100.0 + expect(heading_stats[:percentage_district_population_support_phase]).to be 0.162 + expect(heading_stats[:percentage_participants_vote_phase]).to be 100.0 + expect(heading_stats[:percentage_district_population_vote_phase]).to be 0.324 + expect(heading_stats[:percentage_participants_all_phase]).to be 100.0 + expect(heading_stats[:percentage_district_population_all_phase]).to be 0.486 - expect(@stats[:headings][:total][:total_investments_count]).to be 5 - expect(@stats[:headings][:total][:total_participants_support_phase]).to be 2 - expect(@stats[:headings][:total][:total_participants_vote_phase]).to be 4 - expect(@stats[:headings][:total][:total_participants_all_phase]).to be 6 - expect(@stats[:headings][:total][:percentage_participants_support_phase]).to be 100.0 - expect(@stats[:headings][:total][:percentage_participants_vote_phase]).to be 100.0 - expect(@stats[:headings][:total][:percentage_participants_all_phase]).to be 100.0 + expect(heading_stats[:total_investments_count]).to be 5 + expect(heading_stats[:total_participants_support_phase]).to be 2 + expect(heading_stats[:total_participants_vote_phase]).to be 4 + expect(heading_stats[:total_participants_all_phase]).to be 6 + expect(heading_stats[:percentage_participants_support_phase]).to be 100.0 + expect(heading_stats[:percentage_participants_vote_phase]).to be 100.0 + expect(heading_stats[:percentage_participants_all_phase]).to be 100.0 end end From c2457e36a585748caea63f541685d54d99ea26c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Thu, 5 Jul 2018 18:40:17 +0200 Subject: [PATCH 36/42] Add budget stats permissions for normal users and admins --- app/models/abilities/administrator.rb | 1 + app/models/abilities/everyone.rb | 2 +- spec/features/budgets/stats_spec.rb | 37 +++++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 spec/features/budgets/stats_spec.rb diff --git a/app/models/abilities/administrator.rb b/app/models/abilities/administrator.rb index a72997dbf..9f8c7e965 100644 --- a/app/models/abilities/administrator.rb +++ b/app/models/abilities/administrator.rb @@ -66,6 +66,7 @@ module Abilities can [:hide, :update, :toggle_selection], Budget::Investment can [:valuate, :comment_valuation], Budget::Investment can :create, Budget::ValuatorAssignment + can :read_stats, Budget, phase: "reviewing_ballots" can [:search, :edit, :update, :create, :index, :destroy], Banner diff --git a/app/models/abilities/everyone.rb b/app/models/abilities/everyone.rb index 90d4161c2..626be1c0a 100644 --- a/app/models/abilities/everyone.rb +++ b/app/models/abilities/everyone.rb @@ -21,7 +21,7 @@ module Abilities can [:read], Budget::Group can [:read, :print, :json_data], Budget::Investment can [:read_results, :read_executions], Budget, phase: "finished" - can :read_stats, Budget, phase: ["reviewing_ballots", "finished"] + can :read_stats, Budget, phase: "finished" can :new, DirectMessage can [:read, :debate, :draft_publication, :allegations, :result_publication, :proposals, :milestones], Legislation::Process, published: true diff --git a/spec/features/budgets/stats_spec.rb b/spec/features/budgets/stats_spec.rb new file mode 100644 index 000000000..ce1982cdf --- /dev/null +++ b/spec/features/budgets/stats_spec.rb @@ -0,0 +1,37 @@ +require "rails_helper" + +feature "Stats" do + + let(:budget) { create(:budget) } + let(:group) { create(:budget_group, budget: budget) } + let(:heading) { create(:budget_heading, group: group, price: 1000) } + + describe "Show" do + + it "is not accessible to normal users if phase is not 'finished'" do + budget.update(phase: "reviewing_ballots") + + visit budget_stats_path(budget.id) + expect(page).to have_content "You do not have permission to carry out the action "\ + "'read_stats' on budget." + end + + it "is accessible to normal users if phase is 'finished'" do + budget.update(phase: "finished") + + visit budget_stats_path(budget.id) + expect(page).to have_content "Stats" + end + + it "is accessible to administrators when budget has phase 'reviewing_ballots'" do + budget.update(phase: "reviewing_ballots") + + login_as(create(:administrator).user) + + visit budget_stats_path(budget.id) + expect(page).to have_content "Stats" + end + + end + +end From fac99cfb109b625a98acc66a52c3c8415814f05c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Thu, 5 Jul 2018 18:41:14 +0200 Subject: [PATCH 37/42] Add web and booth participants in budget stats --- app/models/budget/stats.rb | 20 ++++++++++++++++---- app/views/budgets/stats/show.html.erb | 17 ++++++++++++----- config/locales/en/budgets.yml | 2 ++ config/locales/es/budgets.yml | 2 ++ spec/models/budget/stats_spec.rb | 16 ++++++++++++++++ 5 files changed, 48 insertions(+), 9 deletions(-) diff --git a/app/models/budget/stats.rb b/app/models/budget/stats.rb index d47139aae..c7e162c81 100644 --- a/app/models/budget/stats.rb +++ b/app/models/budget/stats.rb @@ -6,9 +6,11 @@ class Budget end def generate - stats = %w[total_participants total_participants_support_phase total_participants_vote_phase total_budget_investments total_votes - total_selected_investments total_unfeasible_investments total_male_participants total_female_participants total_supports - total_unknown_gender_or_age age_groups male_percentage female_percentage headings] + stats = %w[total_participants total_participants_support_phase total_participants_vote_phase + total_budget_investments total_votes total_selected_investments + total_unfeasible_investments total_male_participants total_female_participants + total_supports total_unknown_gender_or_age age_groups male_percentage + female_percentage headings total_participants_web total_participants_booths] stats.map { |stat_name| [stat_name.to_sym, send(stat_name)] }.to_h end @@ -22,6 +24,16 @@ class Budget stats_cache("total_participants_support_phase") { voters.uniq.count } end + def total_participants_web + stats_cache("total_participants_web") do + (balloters - poll_ballot_voters).uniq.compact.count + end + end + + def total_participants_booths + stats_cache("total_participants_booths") { poll_ballot_voters.uniq.count } + end + def total_participants_vote_phase stats_cache("total_participants_vote_phase") { balloters.uniq.count } end @@ -96,7 +108,7 @@ class Budget def participants stats_cache("participants") do - User.where(id: (authors + voters + balloters + poll_ballot_voters).uniq) + User.where(id: (authors + voters + balloters + poll_ballot_voters).uniq.compact) end end diff --git a/app/views/budgets/stats/show.html.erb b/app/views/budgets/stats/show.html.erb index 0d41460ac..4c976343a 100644 --- a/app/views/budgets/stats/show.html.erb +++ b/app/views/budgets/stats/show.html.erb @@ -76,11 +76,18 @@ <%= @stats[:total_supports] %> <%= t("budgets.stats.supports") %>
    -   - <%= t("budgets.stats.total_participants_vote_phase") %>: - - <%= @stats[:total_participants_vote_phase] %> <%= t("budgets.stats.participants") %>, - <%= @stats[:total_votes] %> <%= t("budgets.stats.votes") %>
    +
    + +   + <%= t("budgets.stats.total_participants_web") %>: + + <%= @stats[:total_participants_web] %>
    +
    + +   + <%= t("budgets.stats.total_participants_booths") %>: + + <%= @stats[:total_participants_booths] %>

    diff --git a/config/locales/en/budgets.yml b/config/locales/en/budgets.yml index b40bd8145..29a1ee813 100644 --- a/config/locales/en/budgets.yml +++ b/config/locales/en/budgets.yml @@ -200,6 +200,8 @@ en: total_selected_investments: Proposals on final phase total_unfeasible_investments: Unfeasible proposals total_participants_support_phase: Support phase + total_participants_web: Vote phase web participants + total_participants_booths: Vote phase booth participants participants: Participants supports: Supports votes: Votes diff --git a/config/locales/es/budgets.yml b/config/locales/es/budgets.yml index 5f14ad8bd..226c560cb 100644 --- a/config/locales/es/budgets.yml +++ b/config/locales/es/budgets.yml @@ -200,6 +200,8 @@ es: total_selected_investments: Propuestas en la fase final total_unfeasible_investments: Propuestas inviables total_participants_support_phase: Fase de apoyos + total_participants_web: Participantes web en votación final + total_participants_booths: Participantes en urnas votación final participants: Participantes supports: Apoyos votes: Votos diff --git a/spec/models/budget/stats_spec.rb b/spec/models/budget/stats_spec.rb index 78aea057c..7beafb4e0 100644 --- a/spec/models/budget/stats_spec.rb +++ b/spec/models/budget/stats_spec.rb @@ -68,6 +68,22 @@ describe Budget::Stats do end + context "#total_participants_web" do + + it "returns the number of total participants in the votes phase via web" do + expect(@stats[:total_participants_web]).to be 3 + end + + end + + context "#total_participants_booths" do + + it "returns the number of total participants in the votes phase in booths" do + expect(@stats[:total_participants_booths]).to be 1 + end + + end + context "#total_budget_investments" do it "returns the number of total budget investments" do From c2b9042ad7ca965507e86cb47401f5c5ab7fb4e4 Mon Sep 17 00:00:00 2001 From: Angel Perez Date: Wed, 27 Jun 2018 09:28:47 -0400 Subject: [PATCH 38/42] Add 'Execution' tab to a finished Budget stats This tab will show all winner investments projects with milestones --- app/views/budgets/stats/show.html.erb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/views/budgets/stats/show.html.erb b/app/views/budgets/stats/show.html.erb index 4c976343a..180834fe5 100644 --- a/app/views/budgets/stats/show.html.erb +++ b/app/views/budgets/stats/show.html.erb @@ -34,6 +34,11 @@
  • <%= link_to t("budgets.stats.link"), budget_stats_path(@budget), class: "is-active" %>
  • + <% if @budget.finished? %> +
  • + <%= link_to t("budgets.executions.link"), budget_executions_path(@budget) %> +
  • + <% end %>
    From 3bbdffceaf13a603cc0c3f30021fc257f410824b Mon Sep 17 00:00:00 2001 From: Angel Perez Date: Mon, 2 Jul 2018 17:12:43 -0400 Subject: [PATCH 39/42] Remove conditional to render tabs on budgets/stats#show 'Results' and 'Execution' tabs are now shown to the user regardless of the budget's current status --- app/views/budgets/stats/show.html.erb | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/app/views/budgets/stats/show.html.erb b/app/views/budgets/stats/show.html.erb index 180834fe5..af91054cc 100644 --- a/app/views/budgets/stats/show.html.erb +++ b/app/views/budgets/stats/show.html.erb @@ -25,20 +25,16 @@
      - <% if @budget.finished? %> -
    • - <%= t("shared.you_are_in") %> - <%= link_to t("budgets.results.link"), budget_results_path(@budget) %> -
    • - <% end %> +
    • + <%= t("shared.you_are_in") %> + <%= link_to t("budgets.results.link"), budget_results_path(@budget) %> +
    • <%= link_to t("budgets.stats.link"), budget_stats_path(@budget), class: "is-active" %>
    • - <% if @budget.finished? %> -
    • - <%= link_to t("budgets.executions.link"), budget_executions_path(@budget) %> -
    • - <% end %> +
    • + <%= link_to t("budgets.executions.link"), budget_executions_path(@budget) %> +
    From a889f62f68ec2c8922c46221fcfe86f70a6cc918 Mon Sep 17 00:00:00 2001 From: Angel Perez Date: Mon, 9 Jul 2018 07:54:22 -0400 Subject: [PATCH 40/42] Remove unused budget I18n keys --- config/locales/en/budgets.yml | 2 -- config/locales/es/budgets.yml | 2 -- 2 files changed, 4 deletions(-) diff --git a/config/locales/en/budgets.yml b/config/locales/en/budgets.yml index 29a1ee813..8616539fc 100644 --- a/config/locales/en/budgets.yml +++ b/config/locales/en/budgets.yml @@ -204,8 +204,6 @@ en: total_participants_booths: Vote phase booth participants participants: Participants supports: Supports - votes: Votes - total_participants_vote_phase: Voting Phase by_gender: "Participants by gender" total_male_participants: Mens total_female_participants: Women diff --git a/config/locales/es/budgets.yml b/config/locales/es/budgets.yml index 226c560cb..cc849d1c6 100644 --- a/config/locales/es/budgets.yml +++ b/config/locales/es/budgets.yml @@ -204,8 +204,6 @@ es: total_participants_booths: Participantes en urnas votación final participants: Participantes supports: Apoyos - votes: Votos - total_participants_vote_phase: Fase de votación total: Total by_gender: "Participación por género" total_male_participants: Hombres From 7b2495845dcda15817f50b29d48c860f29472dd3 Mon Sep 17 00:00:00 2001 From: decabeza Date: Thu, 12 Jul 2018 16:47:52 +0200 Subject: [PATCH 41/42] Moves social tags outside cache on budget stats --- app/views/budgets/stats/show.html.erb | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/app/views/budgets/stats/show.html.erb b/app/views/budgets/stats/show.html.erb index af91054cc..ea0c2acb6 100644 --- a/app/views/budgets/stats/show.html.erb +++ b/app/views/budgets/stats/show.html.erb @@ -1,14 +1,14 @@ -<% cache [@stats] do %> - <% provide :title do %> - <%= t("budgets.stats.page_title", budget: @budget.name) %> - <% end %> - <% provide :social_media_meta_tags do %> - <%= render "shared/social_media_meta_tags", - social_url: budget_url(@budget), - social_title: @budget.name, - social_description: @budget.description_finished %> - <% end %> +<% provide :title do %> + <%= t("budgets.stats.page_title", budget: @budget.name) %> +<% end %> +<% provide :social_media_meta_tags do %> +<%= render "shared/social_media_meta_tags", + social_url: budget_url(@budget), + social_title: @budget.name, + social_description: @budget.description_finished %> +<% end %> +<% cache [@stats] do %>
    From abb6eb18b0b52d71e7cc7ed484e49ee5d4b88d67 Mon Sep 17 00:00:00 2001 From: voodoorai2000 Date: Thu, 7 Mar 2019 15:10:51 +0100 Subject: [PATCH 42/42] Order headings by name and group Note that we are relying on the existing `sort_by_name`[1] method in the `Budget::Heading` class. This method sorts by DESC group name first and then ASC heading name. [1] https://github.com/AyuntamientoMadrid/consul/pull/1875 --- app/controllers/budgets/results_controller.rb | 1 + app/controllers/budgets/stats_controller.rb | 1 + app/views/budgets/results/show.html.erb | 6 ++---- app/views/budgets/stats/show.html.erb | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/controllers/budgets/results_controller.rb b/app/controllers/budgets/results_controller.rb index 40586ed96..e8e80a234 100644 --- a/app/controllers/budgets/results_controller.rb +++ b/app/controllers/budgets/results_controller.rb @@ -8,6 +8,7 @@ module Budgets def show authorize! :read_results, @budget @investments = Budget::Result.new(@budget, @heading).investments + @headings = @budget.headings.sort_by_name end private diff --git a/app/controllers/budgets/stats_controller.rb b/app/controllers/budgets/stats_controller.rb index 558a00865..080bf0ef9 100644 --- a/app/controllers/budgets/stats_controller.rb +++ b/app/controllers/budgets/stats_controller.rb @@ -7,6 +7,7 @@ module Budgets def show authorize! :read_stats, @budget @stats = load_stats + @headings = @budget.headings.sort_by_name end private diff --git a/app/views/budgets/results/show.html.erb b/app/views/budgets/results/show.html.erb index 6e7f372f2..43e403090 100644 --- a/app/views/budgets/results/show.html.erb +++ b/app/views/budgets/results/show.html.erb @@ -46,10 +46,8 @@

    <%= t("budgets.results.heading_selection_title") %>

    -