return nil when no traitement time

This commit is contained in:
Christophe Robillard 2021-06-17 10:30:27 +02:00
parent 887c5cb4a9
commit 896190b91e
2 changed files with 10 additions and 5 deletions

View file

@ -67,16 +67,21 @@ module ProcedureStatsConcern
.group_by { |t| t[:processed_at].beginning_of_month }
.transform_values { |month| month.map { |h| h[:processed_at] - h[:en_construction_at] } }
.transform_values { |traitement_times_for_month| traitement_times_for_month.percentile(PERCENTILE).ceil }
.transform_values { |seconds| seconds == 0 ? nil : seconds }
.transform_values { |seconds| convert_seconds_in_days(seconds) }
.transform_keys { |month| pretty_month(month) }
end
def usual_traitement_time_for_recent_dossiers(nb_days)
now = Time.zone.now
traitement_times((now - nb_days.days)..now)
.map { |times| times[:processed_at] - times[:en_construction_at] }
.percentile(PERCENTILE)
.ceil
traitement_time =
traitement_times((now - nb_days.days)..now)
.map { |times| times[:processed_at] - times[:en_construction_at] }
.percentile(PERCENTILE)
.ceil
traitement_time = nil if traitement_time == 0
traitement_time
end
private

View file

@ -45,7 +45,7 @@ describe ProcedureStatsConcern do
context 'where there is no processed dossier' do
let(:delays) { [] }
it { expect(procedure.usual_traitement_time_for_recent_dossiers(30)).to eq 0 }
it { expect(procedure.usual_traitement_time_for_recent_dossiers(30)).to eq nil }
end
end