feat(procedure): include deleted dossiers in stats
This commit is contained in:
parent
eb3039aeca
commit
21f47dcb01
4 changed files with 24 additions and 13 deletions
|
@ -22,9 +22,9 @@ module ProcedureStatsConcern
|
|||
def stats_dossiers_funnel
|
||||
Rails.cache.fetch("#{cache_key_with_version}/stats_dossiers_funnel", expires_in: 12.hours) do
|
||||
[
|
||||
['Démarrés', dossiers.visible_by_user_or_administration.count],
|
||||
['Déposés', dossiers.visible_by_administration.count],
|
||||
['Instruction débutée', dossiers.visible_by_administration.state_instruction_commencee.count],
|
||||
['Démarrés', dossiers.visible_by_user_or_administration.count + nb_dossiers_termines_supprimes],
|
||||
['Déposés', dossiers.visible_by_administration.count + nb_dossiers_termines_supprimes],
|
||||
['Instruction débutée', dossiers.visible_by_administration.state_instruction_commencee.count + nb_dossiers_termines_supprimes],
|
||||
['Traités', nb_dossiers_termines]
|
||||
]
|
||||
end
|
||||
|
@ -96,7 +96,11 @@ module ProcedureStatsConcern
|
|||
private
|
||||
|
||||
def nb_dossiers_termines
|
||||
@nb_dossiers_termines ||= dossiers.visible_by_administration.state_termine.count
|
||||
@nb_dossiers_termines ||= dossiers.visible_by_administration.state_termine.count + nb_dossiers_termines_supprimes
|
||||
end
|
||||
|
||||
def nb_dossiers_termines_supprimes
|
||||
@nb_dossiers_termines_supprimes ||= deleted_dossiers.state_termine.count
|
||||
end
|
||||
|
||||
def first_processed_at
|
||||
|
|
|
@ -20,6 +20,7 @@ class DeletedDossier < ApplicationRecord
|
|||
|
||||
scope :order_by_updated_at, -> (order = :desc) { order(created_at: order) }
|
||||
scope :deleted_since, -> (since) { where('deleted_dossiers.deleted_at >= ?', since) }
|
||||
scope :state_termine, -> { where(state: [states.fetch(:accepte), states.fetch(:refuse), states.fetch(:sans_suite)]) }
|
||||
|
||||
enum reason: {
|
||||
user_request: 'user_request',
|
||||
|
@ -30,6 +31,14 @@ class DeletedDossier < ApplicationRecord
|
|||
instructeur_request: 'instructeur_request'
|
||||
}
|
||||
|
||||
enum state: {
|
||||
en_construction: 'en_construction',
|
||||
en_instruction: 'en_instruction',
|
||||
accepte: 'accepte',
|
||||
refuse: 'refuse',
|
||||
sans_suite: 'sans_suite'
|
||||
}
|
||||
|
||||
def self.create_from_dossier(dossier, reason)
|
||||
return if !dossier.log_operations?
|
||||
|
||||
|
|
|
@ -63,16 +63,15 @@ class Stat < ApplicationRecord
|
|||
def deleted_dossiers_states
|
||||
sanitize_and_exec(DeletedDossier, <<-EOF
|
||||
SELECT
|
||||
COUNT(*) FILTER ( WHERE state != 'brouillon' ) AS "not_brouillon",
|
||||
COUNT(*) FILTER ( WHERE state != 'brouillon' and deleted_at BETWEEN :one_month_ago AND :now ) AS "dossiers_depose_avant_30_jours",
|
||||
COUNT(*) FILTER ( WHERE state != 'brouillon' and deleted_at BETWEEN :two_months_ago AND :one_month_ago ) AS "dossiers_deposes_entre_60_et_30_jours",
|
||||
COUNT(*) FILTER ( WHERE state = 'brouillon' ) AS "brouillon",
|
||||
COUNT(*) AS "not_brouillon",
|
||||
COUNT(*) FILTER ( WHERE deleted_at BETWEEN :one_month_ago AND :now ) AS "dossiers_depose_avant_30_jours",
|
||||
COUNT(*) FILTER ( WHERE deleted_at BETWEEN :two_months_ago AND :one_month_ago ) AS "dossiers_deposes_entre_60_et_30_jours",
|
||||
COUNT(*) FILTER ( WHERE state = 'en_construction' ) AS "en_construction",
|
||||
COUNT(*) FILTER ( WHERE state = 'en_instruction' ) AS "en_instruction",
|
||||
COUNT(*) FILTER ( WHERE state in ('accepte', 'refuse', 'sans_suite') ) AS "termines"
|
||||
FROM deleted_dossiers
|
||||
EOF
|
||||
)
|
||||
).merge('brouillon' => 0)
|
||||
end
|
||||
|
||||
def last_four_months_serie(associations_with_date_attribute)
|
||||
|
|
|
@ -4,10 +4,9 @@ describe Stat do
|
|||
describe '.deleted_dossiers_states' do
|
||||
subject { Stat.send(:deleted_dossiers_states) }
|
||||
it 'find counts for columns' do
|
||||
create(:deleted_dossier, dossier_id: create(:dossier).id, state: :termine)
|
||||
create(:deleted_dossier, dossier_id: create(:dossier).id, state: :accepte)
|
||||
create(:deleted_dossier, dossier_id: create(:dossier).id, state: :en_construction, deleted_at: 1.month.ago)
|
||||
create(:deleted_dossier, dossier_id: create(:dossier).id, state: :en_construction, deleted_at: 2.months.ago)
|
||||
create(:deleted_dossier, dossier_id: create(:dossier).id, state: :brouillon, deleted_at: 3.months.ago)
|
||||
create(:deleted_dossier, dossier_id: create(:dossier).id, state: :en_construction, deleted_at: 3.months.ago)
|
||||
create(:deleted_dossier, dossier_id: create(:dossier).id, state: :en_instruction, deleted_at: 3.months.ago)
|
||||
create(:deleted_dossier, dossier_id: create(:dossier).id, state: :accepte, deleted_at: 3.months.ago)
|
||||
|
@ -17,10 +16,10 @@ describe Stat do
|
|||
expect(subject["not_brouillon"]).to eq(8)
|
||||
expect(subject["dossiers_depose_avant_30_jours"]).to eq(1)
|
||||
expect(subject["dossiers_deposes_entre_60_et_30_jours"]).to eq(1)
|
||||
expect(subject["brouillon"]).to eq(1)
|
||||
expect(subject["brouillon"]).to eq(0)
|
||||
expect(subject["en_construction"]).to eq(3)
|
||||
expect(subject["en_instruction"]).to eq(1)
|
||||
expect(subject["termines"]).to eq(3)
|
||||
expect(subject["termines"]).to eq(4)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue