procedure: ignore bad data when computing usual_instruction_time
Fix #3655
This commit is contained in:
parent
2c26dba741
commit
b1a7018d30
2 changed files with 10 additions and 0 deletions
|
@ -467,6 +467,7 @@ class Procedure < ApplicationRecord
|
||||||
|
|
||||||
def percentile_time(start_attribute, end_attribute, p)
|
def percentile_time(start_attribute, end_attribute, p)
|
||||||
times = dossiers
|
times = dossiers
|
||||||
|
.where.not(start_attribute => nil, end_attribute => nil)
|
||||||
.where(end_attribute => 1.month.ago..Time.zone.now)
|
.where(end_attribute => 1.month.ago..Time.zone.now)
|
||||||
.pluck(start_attribute, end_attribute)
|
.pluck(start_attribute, end_attribute)
|
||||||
.map { |(start_date, end_date)| end_date - start_date }
|
.map { |(start_date, end_date)| end_date - start_date }
|
||||||
|
|
|
@ -780,6 +780,15 @@ describe Procedure do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'when there is a dossier with bad data' do
|
||||||
|
let(:delays) { [2.days, 2.days] }
|
||||||
|
let!(:bad_dossier) { create_dossier(instruction_date: nil, processed_date: 10.days.ago) }
|
||||||
|
|
||||||
|
it 'ignores bad dossiers' do
|
||||||
|
expect(procedure.usual_instruction_time).to be_within(10.seconds).of(2.days)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context 'when there is only one processed dossier' do
|
context 'when there is only one processed dossier' do
|
||||||
let(:delays) { [1.day] }
|
let(:delays) { [1.day] }
|
||||||
it { expect(procedure.usual_instruction_time).to be_within(10.seconds).of(1.day) }
|
it { expect(procedure.usual_instruction_time).to be_within(10.seconds).of(1.day) }
|
||||||
|
|
Loading…
Reference in a new issue