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
|
def stats_dossiers_funnel
|
||||||
Rails.cache.fetch("#{cache_key_with_version}/stats_dossiers_funnel", expires_in: 12.hours) do
|
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émarrés', dossiers.visible_by_user_or_administration.count + nb_dossiers_termines_supprimes],
|
||||||
['Déposés', dossiers.visible_by_administration.count],
|
['Déposés', dossiers.visible_by_administration.count + nb_dossiers_termines_supprimes],
|
||||||
['Instruction débutée', dossiers.visible_by_administration.state_instruction_commencee.count],
|
['Instruction débutée', dossiers.visible_by_administration.state_instruction_commencee.count + nb_dossiers_termines_supprimes],
|
||||||
['Traités', nb_dossiers_termines]
|
['Traités', nb_dossiers_termines]
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
@ -96,7 +96,11 @@ module ProcedureStatsConcern
|
||||||
private
|
private
|
||||||
|
|
||||||
def nb_dossiers_termines
|
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
|
end
|
||||||
|
|
||||||
def first_processed_at
|
def first_processed_at
|
||||||
|
|
|
@ -20,6 +20,7 @@ class DeletedDossier < ApplicationRecord
|
||||||
|
|
||||||
scope :order_by_updated_at, -> (order = :desc) { order(created_at: order) }
|
scope :order_by_updated_at, -> (order = :desc) { order(created_at: order) }
|
||||||
scope :deleted_since, -> (since) { where('deleted_dossiers.deleted_at >= ?', since) }
|
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: {
|
enum reason: {
|
||||||
user_request: 'user_request',
|
user_request: 'user_request',
|
||||||
|
@ -30,6 +31,14 @@ class DeletedDossier < ApplicationRecord
|
||||||
instructeur_request: 'instructeur_request'
|
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)
|
def self.create_from_dossier(dossier, reason)
|
||||||
return if !dossier.log_operations?
|
return if !dossier.log_operations?
|
||||||
|
|
||||||
|
|
|
@ -63,16 +63,15 @@ class Stat < ApplicationRecord
|
||||||
def deleted_dossiers_states
|
def deleted_dossiers_states
|
||||||
sanitize_and_exec(DeletedDossier, <<-EOF
|
sanitize_and_exec(DeletedDossier, <<-EOF
|
||||||
SELECT
|
SELECT
|
||||||
COUNT(*) FILTER ( WHERE state != 'brouillon' ) AS "not_brouillon",
|
COUNT(*) 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 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 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(*) FILTER ( WHERE state = 'en_construction' ) AS "en_construction",
|
COUNT(*) FILTER ( WHERE state = 'en_construction' ) AS "en_construction",
|
||||||
COUNT(*) FILTER ( WHERE state = 'en_instruction' ) AS "en_instruction",
|
COUNT(*) FILTER ( WHERE state = 'en_instruction' ) AS "en_instruction",
|
||||||
COUNT(*) FILTER ( WHERE state in ('accepte', 'refuse', 'sans_suite') ) AS "termines"
|
COUNT(*) FILTER ( WHERE state in ('accepte', 'refuse', 'sans_suite') ) AS "termines"
|
||||||
FROM deleted_dossiers
|
FROM deleted_dossiers
|
||||||
EOF
|
EOF
|
||||||
)
|
).merge('brouillon' => 0)
|
||||||
end
|
end
|
||||||
|
|
||||||
def last_four_months_serie(associations_with_date_attribute)
|
def last_four_months_serie(associations_with_date_attribute)
|
||||||
|
|
|
@ -4,10 +4,9 @@ describe Stat do
|
||||||
describe '.deleted_dossiers_states' do
|
describe '.deleted_dossiers_states' do
|
||||||
subject { Stat.send(:deleted_dossiers_states) }
|
subject { Stat.send(:deleted_dossiers_states) }
|
||||||
it 'find counts for columns' do
|
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: 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: :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_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: :en_instruction, deleted_at: 3.months.ago)
|
||||||
create(:deleted_dossier, dossier_id: create(:dossier).id, state: :accepte, 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["not_brouillon"]).to eq(8)
|
||||||
expect(subject["dossiers_depose_avant_30_jours"]).to eq(1)
|
expect(subject["dossiers_depose_avant_30_jours"]).to eq(1)
|
||||||
expect(subject["dossiers_deposes_entre_60_et_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_construction"]).to eq(3)
|
||||||
expect(subject["en_instruction"]).to eq(1)
|
expect(subject["en_instruction"]).to eq(1)
|
||||||
expect(subject["termines"]).to eq(3)
|
expect(subject["termines"]).to eq(4)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue