diff --git a/app/models/concerns/statisticable.rb b/app/models/concerns/statisticable.rb
index 5e62e31a2..8eed2e0ca 100644
--- a/app/models/concerns/statisticable.rb
+++ b/app/models/concerns/statisticable.rb
@@ -41,8 +41,8 @@ module Statisticable
participants.female.count
end
- def total_unknown_gender_or_age
- participants.where("gender IS NULL OR date_of_birth is NULL").uniq.count
+ def total_no_demographic_data
+ participants.where("gender IS NULL OR date_of_birth IS NULL OR geozone_id IS NULL").count
end
def male_percentage
@@ -153,8 +153,7 @@ module Statisticable
end
def gender_methods
- %i[total_male_participants total_female_participants total_unknown_gender_or_age
- male_percentage female_percentage]
+ %i[total_male_participants total_female_participants male_percentage female_percentage]
end
def age_methods
@@ -162,7 +161,7 @@ module Statisticable
end
def geozone_methods
- [:participants_by_geozone]
+ %i[participants_by_geozone total_no_demographic_data]
end
def stats_cache(*method_names)
diff --git a/app/views/budgets/stats/show.html.erb b/app/views/budgets/stats/show.html.erb
index 5ce48bd88..0f19d2d41 100644
--- a/app/views/budgets/stats/show.html.erb
+++ b/app/views/budgets/stats/show.html.erb
@@ -145,9 +145,9 @@
-
+
- <%= t("stats.budgets.no_demographic_data", total: @stats.total_unknown_gender_or_age) %>
+ <%= t("stats.no_demographic_data", total: @stats.total_no_demographic_data) %>
<%= t("stats.budgets.participatory_disclaimer") %>
diff --git a/app/views/polls/stats.html.erb b/app/views/polls/stats.html.erb
index 7fb485e83..d6ebc71b4 100644
--- a/app/views/polls/stats.html.erb
+++ b/app/views/polls/stats.html.erb
@@ -114,6 +114,12 @@
+
+
+
+ <%= t("stats.no_demographic_data", total: @stats.total_no_demographic_data) %>
+
+
diff --git a/config/locales/en/stats.yml b/config/locales/en/stats.yml
index f02b4360c..99bcdf99e 100644
--- a/config/locales/en/stats.yml
+++ b/config/locales/en/stats.yml
@@ -13,6 +13,7 @@ en:
age_range: "%{start} - %{finish} years old"
total: "Total"
geozone: "District"
+ no_demographic_data: "* There is no demographic data for %{total} participants."
budgets:
link: "Stats"
page_title: "%{budget} - Participation stats"
@@ -29,7 +30,6 @@ en:
participants_total: "Total Participants"
percent_total_participants_html: "%
Total
Participants"
percent_heading_census_html: "%
Heading
Census"
- no_demographic_data: "* There is no demographic data for %{total} participants."
participatory_disclaimer: "** The numbers of total participants 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."
polls:
diff --git a/config/locales/es/stats.yml b/config/locales/es/stats.yml
index 323d026a3..dac0beee0 100644
--- a/config/locales/es/stats.yml
+++ b/config/locales/es/stats.yml
@@ -13,6 +13,7 @@ es:
age_range: "De %{start} a %{finish} años"
total: "Total"
geozone: "Distrito"
+ no_demographic_data: "* No se dispone de los datos demográficos de %{total} participantes."
budgets:
link: "Estadísticas"
page_title: "%{budget} - Estadísticas de participación"
@@ -29,7 +30,6 @@ es:
participants_total: Total de participantes
percent_total_participants_html: "%
Total
Participantes"
percent_heading_census_html: "%
Censo
Distrito"
- no_demographic_data: "* No se dispone de los datos demográficos de %{total} participantes."
participatory_disclaimer: "** Las cifras de total de participantes 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."
polls:
diff --git a/spec/models/budget/stats_spec.rb b/spec/models/budget/stats_spec.rb
index 2f7091b9b..71630e21e 100644
--- a/spec/models/budget/stats_spec.rb
+++ b/spec/models/budget/stats_spec.rb
@@ -153,12 +153,6 @@ describe Budget::Stats do
end
end
- describe "#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
-
describe "#male_percentage" do
it "returns the percentage of male participants" do
expect(stats.male_percentage).to be 60.0
diff --git a/spec/models/statisticable_spec.rb b/spec/models/statisticable_spec.rb
index 9794ef7bc..3757d3db8 100644
--- a/spec/models/statisticable_spec.rb
+++ b/spec/models/statisticable_spec.rb
@@ -102,6 +102,38 @@ describe Statisticable do
end
end
+ describe "#total_no_demographic_data" do
+ it "returns users with no defined gender" do
+ create(:user, gender: nil)
+
+ expect(stats.total_no_demographic_data).to be 1
+ end
+
+ it "returns users with no defined age" do
+ create(:user, gender: "female", date_of_birth: nil)
+
+ expect(stats.total_no_demographic_data).to be 1
+ end
+
+ it "returns users with no defined geozone" do
+ create(:user, gender: "female", geozone: nil)
+
+ expect(stats.total_no_demographic_data).to be 1
+ end
+
+ it "returns users with no defined gender, age nor geozone" do
+ create(:user, gender: nil, date_of_birth: nil, geozone: nil)
+
+ expect(stats.total_no_demographic_data).to be 1
+ end
+
+ it "doesn't return users with defined gender, age and geozone" do
+ create(:user, gender: "male", date_of_birth: 20.years.ago, geozone: create(:geozone))
+
+ expect(stats.total_no_demographic_data).to be 0
+ end
+ end
+
describe "#stats_methods" do
it "includes total participants" do
expect(stats.stats_methods).to include(:total_participants)