From 558070d53087a372b2617faa0a103bd69565e86d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Tue, 19 Mar 2019 12:38:27 +0100 Subject: [PATCH] Remove geozone participation percentage We currently don't store geozone population. --- app/models/concerns/statisticable.rb | 7 ++----- app/views/shared/stats/_geozone.html.erb | 4 +--- config/locales/en/stats.yml | 1 - config/locales/es/stats.yml | 1 - spec/models/poll/stats_spec.rb | 15 ++++----------- 5 files changed, 7 insertions(+), 21 deletions(-) diff --git a/app/models/concerns/statisticable.rb b/app/models/concerns/statisticable.rb index 5c6289ed1..a19d9d962 100644 --- a/app/models/concerns/statisticable.rb +++ b/app/models/concerns/statisticable.rb @@ -75,11 +75,8 @@ module Statisticable [ geozone.name, { - total: { - count: count, - percentage: calculate_percentage(count, total_participants) - }, - percentage: calculate_percentage(count, geozone.users.count) + count: count, + percentage: calculate_percentage(count, total_participants) } ] end.to_h diff --git a/app/views/shared/stats/_geozone.html.erb b/app/views/shared/stats/_geozone.html.erb index 683ae951e..62828dc73 100644 --- a/app/views/shared/stats/_geozone.html.erb +++ b/app/views/shared/stats/_geozone.html.erb @@ -6,7 +6,6 @@ <%= t("stats.geozone") %> <%= t("stats.total") %> - <%= t("stats.geozone_participation") %> @@ -14,8 +13,7 @@ <% stats.participants_by_geozone.each do |geozone, participants| %> <%= geozone %> - <%= "#{participants[:total][:count]} (#{number_to_stats_percentage(participants[:total][:percentage])})" %> - <%= number_to_stats_percentage(participants[:percentage]) %> + <%= "#{participants[:count]} (#{number_to_stats_percentage(participants[:percentage])})" %> <% end %> diff --git a/config/locales/en/stats.yml b/config/locales/en/stats.yml index df2bd9549..f02b4360c 100644 --- a/config/locales/en/stats.yml +++ b/config/locales/en/stats.yml @@ -13,7 +13,6 @@ en: age_range: "%{start} - %{finish} years old" total: "Total" geozone: "District" - geozone_participation: "% District population participants" budgets: link: "Stats" page_title: "%{budget} - Participation stats" diff --git a/config/locales/es/stats.yml b/config/locales/es/stats.yml index de363b7e2..323d026a3 100644 --- a/config/locales/es/stats.yml +++ b/config/locales/es/stats.yml @@ -13,7 +13,6 @@ es: age_range: "De %{start} a %{finish} años" total: "Total" geozone: "Distrito" - geozone_participation: "% Participantes población del distrito" budgets: link: "Estadísticas" page_title: "%{budget} - Estadísticas de participación" diff --git a/spec/models/poll/stats_spec.rb b/spec/models/poll/stats_spec.rb index 8199a593c..e55d51169 100644 --- a/spec/models/poll/stats_spec.rb +++ b/spec/models/poll/stats_spec.rb @@ -170,17 +170,10 @@ describe Poll::Stats do 3.times { create :poll_voter, poll: poll, user: create(:user, :level_two, geozone: hobbiton) } 2.times { create :poll_voter, poll: poll, user: create(:user, :level_two, geozone: rivendel) } - expect(stats.participants_by_geozone["Hobbiton"][:total]).to eq(count: 3, percentage: 60.0) - expect(stats.participants_by_geozone["Rivendel"][:total]).to eq(count: 2, percentage: 40.0) - end - - it "calculates percentage relative to the geozone population" do - midgar = create(:geozone, name: "Midgar") - - create(:poll_voter, poll: poll, user: create(:user, :level_two, geozone: midgar)) - 2.times { create :user, :level_two, geozone: midgar } - - expect(stats.participants_by_geozone["Midgar"][:percentage]).to eq(33.333) + expect(stats.participants_by_geozone["Hobbiton"][:count]).to eq 3 + expect(stats.participants_by_geozone["Hobbiton"][:percentage]).to eq 60.0 + expect(stats.participants_by_geozone["Rivendel"][:count]).to eq 2 + expect(stats.participants_by_geozone["Rivendel"][:percentage]).to eq 40.0 end end