From 19696da736eb77d42eb3af11305cb2190a679c6b Mon Sep 17 00:00:00 2001 From: gregoirenovel Date: Mon, 19 Jun 2017 17:29:20 +0200 Subject: [PATCH] Add StatsController#percentage --- app/controllers/stats_controller.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/controllers/stats_controller.rb b/app/controllers/stats_controller.rb index 5cacd22d1..8f9139ec9 100644 --- a/app/controllers/stats_controller.rb +++ b/app/controllers/stats_controller.rb @@ -70,6 +70,10 @@ class StatsController < ApplicationController (collection.sum.to_f / collection.size).round(2) end + def percentage(numerator, denominator) + ((numerator.to_f / denominator) * 100).round(2) + end + def dossier_instruction_mean_time(dossiers) # In the 12 last months, we compute for each month # the average time it took to instruct a dossier @@ -166,7 +170,7 @@ class StatsController < ApplicationController result = 0 else weekly_dossier_with_avis_count = weekly_dossiers.select { |dossier| dossier.avis.present? }.count - result = ((weekly_dossier_with_avis_count.to_f / weekly_dossiers_count) * 100).round(2) + result = percentage(weekly_dossier_with_avis_count, weekly_dossiers_count) end [min_date.to_i, result] @@ -199,7 +203,7 @@ class StatsController < ApplicationController [min_date.to_i, 0] else answered_weekly_avis_count = weekly_avis.with_answer.count - result = ((answered_weekly_avis_count.to_f / weekly_avis_count) * 100).round(2) + result = percentage(answered_weekly_avis_count, weekly_avis_count) [min_date.to_i, result] end