Merge pull request #9291 from colinux/stats

Stats: ignore aperçus, brouillons en construction & dossiers des démarches en brouillon
This commit is contained in:
Colin Darie 2023-07-11 08:36:12 +00:00 committed by GitHub
commit 07432503a7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 37 additions and 2 deletions

View file

@ -50,12 +50,13 @@ class Stat < ApplicationRecord
COUNT(*) FILTER ( WHERE state != 'brouillon' ) AS "not_brouillon",
COUNT(*) FILTER ( WHERE state != 'brouillon' and depose_at BETWEEN :one_month_ago AND :now ) AS "dossiers_depose_avant_30_jours",
COUNT(*) FILTER ( WHERE state != 'brouillon' and depose_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 = 'brouillon' AND editing_fork_origin_id IS NULL AND (for_procedure_preview IS NULL OR for_procedure_preview = false)) AS "brouillon",
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 dossiers
WHERE hidden_at IS NULL
WHERE hidden_at IS NULL
AND revision_id NOT IN (SELECT r.id FROM procedure_revisions r LEFT JOIN procedures p ON r.procedure_id=p.id WHERE p.aasm_state = 'brouillon')
EOF
)
end

View file

@ -21,6 +21,40 @@ describe Stat, type: :model do
end
end
describe '.dossiers_states' do
let(:procedure) { create(:procedure, :published) }
before do
create_list(:dossier, 2, :en_construction, depose_at: 10.days.ago, procedure:)
create_list(:dossier, 3, :en_construction, depose_at: 40.days.ago, procedure:)
create_list(:dossier, 3, :brouillon, procedure:, for_procedure_preview: nil)
create_list(:dossier, 1, :brouillon, procedure:, for_procedure_preview: false)
create_list(:dossier, 6, :en_instruction, procedure:)
create_list(:dossier, 5, :accepte, procedure:)
create_list(:dossier, 1, :refuse, procedure:)
create_list(:dossier, 1, :sans_suite, procedure:)
# ignored dossiers
create(:dossier, :brouillon, editing_fork_origin: Dossier.en_construction.first)
create(:dossier, :brouillon, procedure: create(:procedure, :draft))
create(:dossier, :brouillon, for_procedure_preview: true)
end
subject(:stats) { Stat.send(:dossiers_states) }
it 'works' do
expect(stats["not_brouillon"]).to eq(18)
expect(stats["dossiers_depose_avant_30_jours"]).to eq(2)
expect(stats["dossiers_deposes_entre_60_et_30_jours"]).to eq(3)
expect(stats["brouillon"]).to eq(4)
expect(stats["en_construction"]).to eq(5)
expect(stats["en_instruction"]).to eq(6)
expect(stats["termines"]).to eq(7)
end
end
describe '.update_stats' do
it 'merges dossiers_states and deleted_dossiers_states' do
stats = {