From 8f0bccf5b36ed0d55b0ca0b5b62a90038551237b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Fri, 4 Jan 2019 17:27:21 +0100 Subject: [PATCH] Add mail votes stub to poll stats So far we don't know about implemenation details. --- app/models/poll/stats.rb | 26 ++++++++++--- app/views/polls/stats.html.erb | 70 +++++++++++++++++----------------- 2 files changed, 57 insertions(+), 39 deletions(-) diff --git a/app/models/poll/stats.rb b/app/models/poll/stats.rb index cc4e5318d..191139d5a 100644 --- a/app/models/poll/stats.rb +++ b/app/models/poll/stats.rb @@ -2,22 +2,26 @@ class Poll::Stats include Statisticable alias_method :poll, :resource + CHANNELS = %i[web booth mail] + def self.stats_methods super + %i[total_valid_votes total_white_votes total_null_votes total_participants_web total_web_valid total_web_white total_web_null total_participants_booth total_booth_valid total_booth_white total_booth_null + total_participants_mail total_mail_valid total_mail_white total_mail_null total_participants_web_percentage total_participants_booth_percentage - valid_percentage_web valid_percentage_booth total_valid_percentage - white_percentage_web white_percentage_booth total_white_percentage - null_percentage_web null_percentage_booth total_null_percentage] + total_participants_mail_percentage + valid_percentage_web valid_percentage_booth valid_percentage_mail total_valid_percentage + white_percentage_web white_percentage_booth white_percentage_mail total_white_percentage + null_percentage_web null_percentage_booth null_percentage_mail total_null_percentage] end def total_participants total_participants_web + total_participants_booth end - %i[web booth].each do |channel| + CHANNELS.each do |channel| define_method :"total_participants_#{channel}" do send(:"total_#{channel}_valid") + send(:"total_#{channel}_white") + @@ -53,8 +57,20 @@ class Poll::Stats recounts.sum(:null_amount) end + def total_mail_valid + 0 # TODO + end + + def total_mail_white + 0 # TODO + end + + def total_mail_null + 0 # TODO + end + %i[valid white null].each do |type| - %i[web booth].each do |channel| + CHANNELS.each do |channel| define_method :"#{type}_percentage_#{channel}" do calculate_percentage(send(:"total_#{channel}_#{type}"), send(:"total_#{type}_votes")) end diff --git a/app/views/polls/stats.html.erb b/app/views/polls/stats.html.erb index db9dfd83d..a97e5ec43 100644 --- a/app/views/polls/stats.html.erb +++ b/app/views/polls/stats.html.erb @@ -30,51 +30,53 @@ <%= t("polls.show.stats.votes") %> - <%= t("polls.show.stats.web") %> - <%= t("polls.show.stats.booth") %> + <% Poll::Stats::CHANNELS.each do |channel| %> + <%= t("polls.show.stats.#{channel}") %> + <% end %> <%= t("polls.show.stats.total") %> <%= t("polls.show.stats.valid") %> - - <%= @stats[:total_web_valid] %> - (<%= @stats[:valid_percentage_web].round(2) %>%) - - - <%= @stats[:total_booth_valid] %> - (<%= @stats[:valid_percentage_booth].round(2) %>%) - + + <% Poll::Stats::CHANNELS.each do |channel| %> + + <%= @stats[:"total_#{channel}_valid"] %> + (<%= @stats[:"valid_percentage_#{channel}"].round(2) %>%) + + <% end %> + <%= @stats[:total_valid_votes] %> (<%= @stats[:total_valid_percentage].round(2) %>%) + <%= t("polls.show.stats.white") %> - - <%= @stats[:total_web_white] %> - (<%= @stats[:white_percentage_web].round(2) %>%) - - - <%= @stats[:total_booth_white] %> - (<%= @stats[:white_percentage_booth].round(2) %>%) - + + <% Poll::Stats::CHANNELS.each do |channel| %> + + <%= @stats[:"total_#{channel}_white"] %> + (<%= @stats[:"white_percentage_#{channel}"].round(2) %>%) + + <% end %> + <%= @stats[:total_white_votes] %> (<%= @stats[:total_white_percentage].round(2) %>%) <%= t("polls.show.stats.null_votes") %> - - <%= @stats[:total_web_null] %> - (<%= @stats[:null_percentage_web].round(2) %>%) - - - <%= @stats[:total_booth_null] %> - (<%= @stats[:null_percentage_booth].round(2) %>%) - + + <% Poll::Stats::CHANNELS.each do |channel| %> + + <%= @stats[:"total_#{channel}_null"] %> + (<%= @stats[:"null_percentage_#{channel}"].round(2) %>%) + + <% end %> + <%= @stats[:total_null_votes] %> (<%= @stats[:total_null_percentage].round(2) %>%) @@ -82,14 +84,14 @@ <%= t("polls.show.stats.total") %> - - <%= @stats[:total_participants_web] %> - (<%= @stats[:total_participants_web_percentage].round(2) %>%) - - - <%= @stats[:total_participants_booth] %> - (<%= @stats[:total_participants_booth_percentage].round(2) %>%) - + + <% Poll::Stats::CHANNELS.each do |channel| %> + + <%= @stats[:"total_participants_#{channel}"] %> + (<%= @stats[:"total_participants_#{channel}_percentage"].round(2) %>%) + + <% end %> + <%= @stats[:total_participants] %>