update stats with traitement model
This commit is contained in:
parent
0be4b50ade
commit
cea170e4a6
2 changed files with 17 additions and 19 deletions
|
@ -249,9 +249,11 @@ class StatsController < ApplicationController
|
|||
min_date = 11.months.ago
|
||||
max_date = Time.zone.now.to_date
|
||||
|
||||
processed_dossiers = dossiers
|
||||
processed_dossiers = Traitement.includes(:dossier)
|
||||
.where(dossier_id: dossiers)
|
||||
.where('dossiers.state' => Dossier::TERMINE)
|
||||
.where(:processed_at => min_date..max_date)
|
||||
.pluck(:groupe_instructeur_id, :en_construction_at, :processed_at)
|
||||
.pluck('dossiers.groupe_instructeur_id', 'dossiers.en_construction_at', :processed_at)
|
||||
|
||||
# Group dossiers by month
|
||||
processed_dossiers_by_month = processed_dossiers
|
||||
|
@ -290,11 +292,13 @@ class StatsController < ApplicationController
|
|||
min_date = 11.months.ago
|
||||
max_date = Time.zone.now.to_date
|
||||
|
||||
processed_dossiers = dossiers
|
||||
processed_dossiers = Traitement.includes(:dossier)
|
||||
.where(dossier: dossiers)
|
||||
.where('dossiers.state' => Dossier::TERMINE)
|
||||
.where(:processed_at => min_date..max_date)
|
||||
.pluck(
|
||||
:groupe_instructeur_id,
|
||||
Arel.sql('EXTRACT(EPOCH FROM (en_construction_at - created_at)) / 60 AS processing_time'),
|
||||
'dossiers.groupe_instructeur_id',
|
||||
Arel.sql('EXTRACT(EPOCH FROM (dossiers.en_construction_at - dossiers.created_at)) / 60 AS processing_time'),
|
||||
:processed_at
|
||||
)
|
||||
|
||||
|
|
|
@ -106,26 +106,23 @@ describe StatsController, type: :controller do
|
|||
before do
|
||||
procedure_1 = FactoryBot.create(:procedure)
|
||||
procedure_2 = FactoryBot.create(:procedure)
|
||||
dossier_p1_a = FactoryBot.create(:dossier,
|
||||
dossier_p1_a = FactoryBot.create(:dossier, :accepte,
|
||||
:procedure => procedure_1,
|
||||
:en_construction_at => 2.months.ago.beginning_of_month,
|
||||
:processed_at => 2.months.ago.beginning_of_month + 3.days)
|
||||
dossier_p1_b = FactoryBot.create(:dossier,
|
||||
dossier_p1_b = FactoryBot.create(:dossier, :accepte,
|
||||
:procedure => procedure_1,
|
||||
:en_construction_at => 2.months.ago.beginning_of_month,
|
||||
:processed_at => 2.months.ago.beginning_of_month + 1.day)
|
||||
dossier_p1_c = FactoryBot.create(:dossier,
|
||||
dossier_p1_c = FactoryBot.create(:dossier, :accepte,
|
||||
:procedure => procedure_1,
|
||||
:en_construction_at => 1.month.ago.beginning_of_month,
|
||||
:processed_at => 1.month.ago.beginning_of_month + 5.days)
|
||||
dossier_p2_a = FactoryBot.create(:dossier,
|
||||
dossier_p2_a = FactoryBot.create(:dossier, :accepte,
|
||||
:procedure => procedure_2,
|
||||
:en_construction_at => 2.months.ago.beginning_of_month,
|
||||
:processed_at => 2.months.ago.beginning_of_month + 4.days)
|
||||
|
||||
# Write directly in the DB to avoid the before_validation hook
|
||||
Dossier.update_all(state: Dossier.states.fetch(:accepte))
|
||||
|
||||
@expected_hash = {
|
||||
(2.months.ago.beginning_of_month).to_s => 3.0,
|
||||
(1.month.ago.beginning_of_month).to_s => 5.0
|
||||
|
@ -154,30 +151,27 @@ describe StatsController, type: :controller do
|
|||
before do
|
||||
procedure_1 = FactoryBot.create(:procedure, :with_type_de_champ, :types_de_champ_count => 24)
|
||||
procedure_2 = FactoryBot.create(:procedure, :with_type_de_champ, :types_de_champ_count => 48)
|
||||
dossier_p1_a = FactoryBot.create(:dossier,
|
||||
dossier_p1_a = FactoryBot.create(:dossier, :accepte,
|
||||
:procedure => procedure_1,
|
||||
:created_at => 2.months.ago.beginning_of_month,
|
||||
:en_construction_at => 2.months.ago.beginning_of_month + 30.minutes,
|
||||
:processed_at => 2.months.ago.beginning_of_month + 1.day)
|
||||
dossier_p1_b = FactoryBot.create(:dossier,
|
||||
dossier_p1_b = FactoryBot.create(:dossier, :accepte,
|
||||
:procedure => procedure_1,
|
||||
:created_at => 2.months.ago.beginning_of_month,
|
||||
:en_construction_at => 2.months.ago.beginning_of_month + 10.minutes,
|
||||
:processed_at => 2.months.ago.beginning_of_month + 1.day)
|
||||
dossier_p1_c = FactoryBot.create(:dossier,
|
||||
dossier_p1_c = FactoryBot.create(:dossier, :accepte,
|
||||
:procedure => procedure_1,
|
||||
:created_at => 1.month.ago.beginning_of_month,
|
||||
:en_construction_at => 1.month.ago.beginning_of_month + 50.minutes,
|
||||
:processed_at => 1.month.ago.beginning_of_month + 1.day)
|
||||
dossier_p2_a = FactoryBot.create(:dossier,
|
||||
dossier_p2_a = FactoryBot.create(:dossier, :accepte,
|
||||
:procedure => procedure_2,
|
||||
:created_at => 2.months.ago.beginning_of_month,
|
||||
:en_construction_at => 2.months.ago.beginning_of_month + 80.minutes,
|
||||
:processed_at => 2.months.ago.beginning_of_month + 1.day)
|
||||
|
||||
# Write directly in the DB to avoid the before_validation hook
|
||||
Dossier.update_all(state: Dossier.states.fetch(:accepte))
|
||||
|
||||
@expected_hash = {
|
||||
(2.months.ago.beginning_of_month).to_s => 30.0,
|
||||
(1.month.ago.beginning_of_month).to_s => 50.0
|
||||
|
|
Loading…
Add table
Reference in a new issue