Extract method to show stats percentage

This commit is contained in:
Javi Martín
2018-12-20 12:47:23 +01:00
parent 80486b8193
commit c0044f4e56
2 changed files with 10 additions and 18 deletions

View File

@@ -30,4 +30,8 @@ module StatsHelper
opt[:data][:graph] = admin_api_stats_path(budget_investments: true) opt[:data][:graph] = admin_api_stats_path(budget_investments: true)
content_tag :div, "", opt content_tag :div, "", opt
end end
def number_to_stats_percentage(number, options = {})
number_to_percentage(number, { strip_insignificant_zeros: true, precision: 2 }.merge(options))
end
end end

View File

@@ -108,9 +108,7 @@
<p id="female_percentage"> <p id="female_percentage">
<span class="label" style="background: #FF9E01"></span> <span class="label" style="background: #FF9E01"></span>
&nbsp;<%= t("budgets.stats.total_female_participants").upcase %> &nbsp;<%= t("budgets.stats.total_female_participants").upcase %>
(<%= number_to_percentage(@stats[:female_percentage], (<%= number_to_stats_percentage(@stats[:female_percentage]) %>)
strip_insignificant_zeros: true,
precision: 2) %>)
</p> </p>
<p id="total_female_participants" class="big-number-stat"> <p id="total_female_participants" class="big-number-stat">
<%= @stats[:total_female_participants] %> <%= @stats[:total_female_participants] %>
@@ -121,9 +119,7 @@
<p id="male_percentage"> <p id="male_percentage">
<span class="label" style="background: #FF6600"></span> <span class="label" style="background: #FF6600"></span>
&nbsp;<%= t("budgets.stats.total_male_participants").upcase %> &nbsp;<%= t("budgets.stats.total_male_participants").upcase %>
(<%= number_to_percentage(@stats[:male_percentage], (<%= number_to_stats_percentage(@stats[:male_percentage]) %>)
strip_insignificant_zeros: true,
precision: 2) %>)
</p> </p>
<p id="total_male_participants" class="big-number-stat"> <p id="total_male_participants" class="big-number-stat">
<%= @stats[:total_male_participants] %> <%= @stats[:total_male_participants] %>
@@ -154,17 +150,13 @@
<strong> <strong>
<% <%
percentage_age_count = all_ages_count == 0 ? 0 : (count / all_ages_count * 100) percentage_age_count = all_ages_count == 0 ? 0 : (count / all_ages_count * 100)
formatted_percentage_age_count = number_to_percentage(percentage_age_count, formatted_percentage_age_count = number_to_stats_percentage(percentage_age_count)
strip_insignificant_zeros: true,
precision: 2)
%> %>
<%= count %> <%= count %>
(<%= formatted_percentage_age_count %>) (<%= formatted_percentage_age_count %>)
</strong> </strong>
<div class="progress" role="progressbar" tabindex="0" aria-valuenow="20" aria-valuemin="0" aria-valuetext="<%= percentage_age_count %>" aria-valuemax="100"> <div class="progress" role="progressbar" tabindex="0" aria-valuenow="20" aria-valuemin="0" aria-valuetext="<%= percentage_age_count %>" aria-valuemax="100">
<span class="progress-meter" style="width: <%= number_to_percentage(percentage_age_count*5, <span class="progress-meter" style="width: <%= number_to_stats_percentage(percentage_age_count*5, locale: :en) %>;"></span>
strip_insignificant_zeros: true,
precision: 2, locale: :en) %>;"></span>
</div> </div>
</td> </td>
</tr> </tr>
@@ -217,15 +209,11 @@
</td> </td>
<td id="percentage_participants_<%= phase %>_phase_heading_<%= heading.id %>" <td id="percentage_participants_<%= phase %>_phase_heading_<%= heading.id %>"
class="border-left border-right text-center"> class="border-left border-right text-center">
<%= number_to_percentage(@stats[:headings][heading.id]["percentage_participants_#{phase}_phase".to_sym], <%= number_to_stats_percentage(@stats[:headings][heading.id]["percentage_participants_#{phase}_phase".to_sym]) %>
strip_insignificant_zeros: true,
precision: 2) %>
</td> </td>
<td id="percentage_district_population_<%= phase %>_phase_heading_<%= heading.id %>" <td id="percentage_district_population_<%= phase %>_phase_heading_<%= heading.id %>"
class="text-center border-right"> class="text-center border-right">
<%= number_to_percentage(@stats[:headings][heading.id]["percentage_district_population_#{phase}_phase".to_sym], <%= number_to_stats_percentage(@stats[:headings][heading.id]["percentage_district_population_#{phase}_phase".to_sym]) %>
strip_insignificant_zeros: true,
precision: 2) %>
</td> </td>
<% end %> <% end %>
</tr> </tr>