Add poll stats by geozone and channel

This commit is contained in:
Javi Martín
2019-01-04 19:34:58 +01:00
parent 202fb44008
commit 8f69113233
6 changed files with 101 additions and 3 deletions

View File

@@ -19,7 +19,8 @@ class Poll::Stats
total_female_web total_female_booth total_female_mail
male_web_percentage male_booth_percentage male_mail_percentage
female_web_percentage female_booth_percentage female_mail_percentage
web_participants_by_age booth_participants_by_age mail_participants_by_age]
web_participants_by_age booth_participants_by_age mail_participants_by_age
web_participants_by_geozone booth_participants_by_geozone mail_participants_by_geozone]
end
@@ -47,6 +48,19 @@ class Poll::Stats
relative_to: :participants_between_ages)
end
define_method :"#{channel}_participants_by_geozone" do
geozones.map do |geozone|
count = send(:"#{channel}_participants").where(geozone: geozone).count
[
geozone.name,
{
count: count,
percentage: calculate_percentage(count, participants.where(geozone: geozone).count)
}
]
end.to_h
end
%i[male female].each do |gender|
define_method :"total_#{gender}_#{channel}" do
send(:"#{channel}_participants").public_send(gender).count