Add StatsController#percentage
This commit is contained in:
parent
458d671c14
commit
19696da736
1 changed files with 6 additions and 2 deletions
|
@ -70,6 +70,10 @@ class StatsController < ApplicationController
|
||||||
(collection.sum.to_f / collection.size).round(2)
|
(collection.sum.to_f / collection.size).round(2)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def percentage(numerator, denominator)
|
||||||
|
((numerator.to_f / denominator) * 100).round(2)
|
||||||
|
end
|
||||||
|
|
||||||
def dossier_instruction_mean_time(dossiers)
|
def dossier_instruction_mean_time(dossiers)
|
||||||
# In the 12 last months, we compute for each month
|
# In the 12 last months, we compute for each month
|
||||||
# the average time it took to instruct a dossier
|
# the average time it took to instruct a dossier
|
||||||
|
@ -166,7 +170,7 @@ class StatsController < ApplicationController
|
||||||
result = 0
|
result = 0
|
||||||
else
|
else
|
||||||
weekly_dossier_with_avis_count = weekly_dossiers.select { |dossier| dossier.avis.present? }.count
|
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
|
end
|
||||||
|
|
||||||
[min_date.to_i, result]
|
[min_date.to_i, result]
|
||||||
|
@ -199,7 +203,7 @@ class StatsController < ApplicationController
|
||||||
[min_date.to_i, 0]
|
[min_date.to_i, 0]
|
||||||
else
|
else
|
||||||
answered_weekly_avis_count = weekly_avis.with_answer.count
|
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]
|
[min_date.to_i, result]
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue