Add poll stats by geozone and channel
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user