Make the stats code more robust to empty databases
This commit is contained in:
parent
4a9cca1756
commit
d05209d28f
1 changed files with 10 additions and 2 deletions
|
@ -82,7 +82,11 @@ class StatsController < ApplicationController
|
|||
total = procedures.count
|
||||
last_30_days_count = procedures.where(published_at: 1.month.ago..Time.now).count
|
||||
previous_count = procedures.where(published_at: 2.months.ago..1.month.ago).count
|
||||
evolution = (((last_30_days_count.to_f / previous_count) - 1) * 100).round(0)
|
||||
if previous_count != 0
|
||||
evolution = (((last_30_days_count.to_f / previous_count) - 1) * 100).round(0)
|
||||
else
|
||||
evolution = 0
|
||||
end
|
||||
formatted_evolution = sprintf("%+d", evolution)
|
||||
|
||||
{
|
||||
|
@ -96,7 +100,11 @@ class StatsController < ApplicationController
|
|||
total = dossiers.count
|
||||
last_30_days_count = dossiers.where(en_construction_at: 1.month.ago..Time.now).count
|
||||
previous_count = dossiers.where(en_construction_at: 2.months.ago..1.month.ago).count
|
||||
evolution = (((last_30_days_count.to_f / previous_count) - 1) * 100).round(0)
|
||||
if previous_count != 0
|
||||
evolution = (((last_30_days_count.to_f / previous_count) - 1) * 100).round(0)
|
||||
else
|
||||
evolution = 0
|
||||
end
|
||||
formatted_evolution = sprintf("%+d", evolution)
|
||||
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue