Improved results and stats percentages

This commit is contained in:
María Checa
2017-10-20 17:18:54 +02:00
parent dfa8f4590a
commit e85c98f4b4
3 changed files with 15 additions and 37 deletions

View File

@@ -41,7 +41,7 @@ class Poll::Question::Answer < ActiveRecord::Base
end end
def total_votes_percentage def total_votes_percentage
((total_votes*100) / question.answers_total_votes).round(2) rescue 0 question.answers_total_votes == 0 ? 0 : (total_votes * 100) / question.answers_total_votes
end end
def set_most_voted def set_most_voted

View File

@@ -1,6 +1,6 @@
<% provide :title do %><%= @poll.name %><% end %> <% provide :title do %><%= @poll.name %><% end %>
<div class="polls-show"> <div class="polls-results-stats">
<%= render "poll_header" %> <%= render "poll_header" %>
<%= render "poll_subnav" %> <%= render "poll_subnav" %>
@@ -18,7 +18,7 @@
<div class="small-12 medium-9 column"> <div class="small-12 medium-9 column">
<%- @poll.questions.each do |question| %> <%- @poll.questions.each do |question| %>
<table id="question_<%= question.id %>_results_table"> <table id="question_<%= question.id %>_results_table">
<h3 anchor="<%= question.title.parameterize %>"><%= question.title %></h3> <h3 id="<%= question.title.parameterize %>"><%= question.title %></h3>
<thead> <thead>
<tr> <tr>
<%- question.question_answers.each do |answer| %> <%- question.question_answers.each do |answer| %>
@@ -31,7 +31,7 @@
<%- question.question_answers.each do |answer| %> <%- question.question_answers.each do |answer| %>
<td id="answer_<%= answer.id %>_result" <%= answer.most_voted? ? "class=win" : "" %>> <td id="answer_<%= answer.id %>_result" <%= answer.most_voted? ? "class=win" : "" %>>
<%= answer.total_votes %> <%= answer.total_votes %>
(<%= answer.total_votes_percentage %>%) (<%= answer.total_votes_percentage.round(2) %>%)
</td> </td>
<% end %> <% end %>
</tr> </tr>

View File

@@ -36,77 +36,55 @@
<th scope="row"><%= t("polls.show.stats.valid") %></th> <th scope="row"><%= t("polls.show.stats.valid") %></th>
<td> <td>
<%= @stats[:total_web_valid] %> <%= @stats[:total_web_valid] %>
<small><em>(<%= number_to_percentage(@stats[:valid_percentage_web], <small><em>(<%= @stats[:valid_percentage_web].round(2) %>%)</em></small>
strip_insignificant_zeros: true,
precision: 2) %>)</em></small>
</td> </td>
<td> <td>
<%= @stats[:total_booth_valid] %> <%= @stats[:total_booth_valid] %>
<small><em>(<%= number_to_percentage(@stats[:valid_percentage_booth], <small><em>(<%= @stats[:valid_percentage_booth].round(2) %>%)</em></small>
strip_insignificant_zeros: true,
precision: 2) %>)</em></small>
</td> </td>
<td> <td>
<%= @stats[:total_valid_votes] %> <%= @stats[:total_valid_votes] %>
<small><em>(<%= number_to_percentage(@stats[:total_valid_percentage], <small><em>(<%= @stats[:total_valid_percentage].round(2) %>%)</em></small>
strip_insignificant_zeros: true,
precision: 2) %>)</em></small>
</td> </td>
</tr> </tr>
<tr> <tr>
<th scope="row"><%= t("polls.show.stats.white") %></th> <th scope="row"><%= t("polls.show.stats.white") %></th>
<td> <td>
<%= @stats[:total_web_white] %> <%= @stats[:total_web_white] %>
<small><em>(<%= number_to_percentage(@stats[:white_percentage_web], <small><em>(<%= @stats[:white_percentage_web].round(2) %>%)</em></small>
strip_insignificant_zeros: true,
precision: 2) %>)</em></small>
</td> </td>
<td> <td>
<%= @stats[:total_booth_white] %> <%= @stats[:total_booth_white] %>
<small><em>(<%= number_to_percentage(@stats[:white_percentage_booth], <small><em>(<%= @stats[:white_percentage_booth].round(2) %>%)</em></small>
strip_insignificant_zeros: true,
precision: 2) %>)</em></small>
</td> </td>
<td><%= @stats[:total_white_votes] %> <td><%= @stats[:total_white_votes] %>
<small><em>(<%= number_to_percentage(@stats[:total_white_percentage], <small><em>(<%= @stats[:total_white_percentage].round(2) %>%)</em></small>
strip_insignificant_zeros: true,
precision: 2) %>)</em></small>
</td> </td>
</tr> </tr>
<tr> <tr>
<th scope="row"><%= t("polls.show.stats.null_votes") %></th> <th scope="row"><%= t("polls.show.stats.null_votes") %></th>
<td> <td>
<%= @stats[:total_web_null] %> <%= @stats[:total_web_null] %>
<small><em>(<%= number_to_percentage(@stats[:null_percentage_web], <small><em>(<%= @stats[:null_percentage_web].round(2) %>%)</em></small>
strip_insignificant_zeros: true,
precision: 2) %>)</em></small>
</td> </td>
<td> <td>
<%= @stats[:total_booth_null] %> <%= @stats[:total_booth_null] %>
<small><em>(<%= number_to_percentage(@stats[:null_percentage_booth], <small><em>(<%= @stats[:null_percentage_booth].round(2) %>%)</em></small>
strip_insignificant_zeros: true,
precision: 2) %>)</em></small>
</td> </td>
<td> <td>
<%= @stats[:total_null_votes] %> <%= @stats[:total_null_votes] %>
<small><em>(<%= number_to_percentage(@stats[:total_null_percentage], <small><em>(<%= @stats[:total_null_percentage].round(2) %>%)</em></small>
strip_insignificant_zeros: true,
precision: 2) %>)</em></small>
</td> </td>
</tr> </tr>
<tr> <tr>
<th scope="row"><%= t("polls.show.stats.total") %></th> <th scope="row"><%= t("polls.show.stats.total") %></th>
<td> <td>
<%= @stats[:total_participants_web] %> <%= @stats[:total_participants_web] %>
<small><em>(<%= number_to_percentage(@stats[:total_participants_web_percentage], <small><em>(<%= @stats[:total_participants_web_percentage].round(2) %>%)</em></small>
strip_insignificant_zeros: true,
precision: 2) %>)</em></small>
</td> </td>
<td> <td>
<%= @stats[:total_participants_booth] %> <%= @stats[:total_participants_booth] %>
<small><em>(<%= number_to_percentage(@stats[:total_participants_booth_percentage], <small><em>(<%= @stats[:total_participants_booth_percentage].round(2) %>%)</em></small>
strip_insignificant_zeros: true,
precision: 2) %>)</em></small>
</td> </td>
<td><%= @stats[:total_participants_web] + @stats[:total_participants_booth] %></td> <td><%= @stats[:total_participants_web] + @stats[:total_participants_booth] %></td>
</tr> </tr>