Include no geozone in no demographic data

This commit is contained in:
Javi Martín
2019-04-03 20:02:58 +02:00
parent 383909e16c
commit ae4cd06c24
7 changed files with 46 additions and 15 deletions

View File

@@ -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)

View File

@@ -145,9 +145,9 @@
<div class="row margin">
<div class="small-12 column">
<div id="total_unknown_gender_or_age">
<div id="total_no_demographic_data">
<p class="help-text">
<%= t("stats.budgets.no_demographic_data", total: @stats.total_unknown_gender_or_age) %>
<%= t("stats.no_demographic_data", total: @stats.total_no_demographic_data) %>
</p>
<p class="help-text">
<%= t("stats.budgets.participatory_disclaimer") %>

View File

@@ -114,6 +114,12 @@
</tbody>
</table>
</div>
<div id="total_no_demographic_data">
<p class="help-text">
<%= t("stats.no_demographic_data", total: @stats.total_no_demographic_data) %>
</p>
</div>
</div>
</div>
</div>

View File

@@ -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: "% <br>Total<br>Participants"
percent_heading_census_html: "% <br>Heading<br>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:

View File

@@ -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: "% <br>Total<br>Participantes"
percent_heading_census_html: "% <br>Censo<br>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:

View File

@@ -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

View File

@@ -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)