From bc07a875eb3108b623ad61481735fcc951eb96f3 Mon Sep 17 00:00:00 2001 From: Christophe Robillard Date: Tue, 6 Jul 2021 15:00:33 +0200 Subject: [PATCH] integrate a mininum weight for the average dossier weight before this commit, the average dossier weight took account only pieces justificatives. With this commit, we add a minimum weight for other files included in an archive like pdf_export, log operations, attachments added to traitements. This minimum weight is set arbitrary, from the observation of some random procedures in production --- app/models/procedure.rb | 3 ++- spec/models/procedure_spec.rb | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/models/procedure.rb b/app/models/procedure.rb index e02100f4b..823badc02 100644 --- a/app/models/procedure.rb +++ b/app/models/procedure.rb @@ -55,6 +55,7 @@ class Procedure < ApplicationRecord MAX_DUREE_CONSERVATION = 36 MAX_DUREE_CONSERVATION_EXPORT = 3.hours + MIN_WEIGHT = 350000 has_many :revisions, -> { order(:id) }, class_name: 'ProcedureRevision', inverse_of: :procedure belongs_to :draft_revision, class_name: 'ProcedureRevision', optional: false belongs_to :published_revision, class_name: 'ProcedureRevision', optional: true @@ -684,7 +685,7 @@ class Procedure < ApplicationRecord .where(type: Champs::PieceJustificativeChamp.to_s, dossier: dossiers_sample) .sum('active_storage_blobs.byte_size') - total_size / dossiers_sample.length + MIN_WEIGHT + total_size / dossiers_sample.length else nil end diff --git a/spec/models/procedure_spec.rb b/spec/models/procedure_spec.rb index b6b8f7cf6..a24ad648a 100644 --- a/spec/models/procedure_spec.rb +++ b/spec/models/procedure_spec.rb @@ -1026,7 +1026,7 @@ describe Procedure do end it 'estimates average dossier weight' do - expect(procedure.reload.average_dossier_weight).to eq 5 + expect(procedure.reload.average_dossier_weight).to eq(5 + Procedure::MIN_WEIGHT) end end