Merge pull request #3987 from betagouv/fix-3986-ROI-Admin

Fix 3986 roi admin
This commit is contained in:
Nicolas Bouilleaud 2019-07-01 11:31:56 +02:00 committed by GitHub
commit a238be2f2c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 28 additions and 9 deletions

View file

@ -64,7 +64,7 @@ En local, un utilisateur de test est créé automatiquement, avec les identifian
AutoArchiveProcedureJob.set(cron: "* * * * *").perform_later AutoArchiveProcedureJob.set(cron: "* * * * *").perform_later
WeeklyOverviewJob.set(cron: "0 7 * * 1").perform_later WeeklyOverviewJob.set(cron: "0 7 * * 1").perform_later
AutoReceiveDossiersForProcedureJob.set(cron: "* * * * *").perform_later(procedure_declaratoire_id, Dossier.states.fetch(:en_instruction)) AutoReceiveDossiersForProcedureJob.set(cron: "* * * * *").perform_later(procedure_declaratoire_id, Dossier.states.fetch(:en_instruction))
SendinblueUpdateAdministrateursJob.set(cron: "0 10 * * *").perform_later UpdateAdministrateurUsageStatisticsJob.set(cron: "0 10 * * *").perform_later
FindDubiousProceduresJob.set(cron: "0 0 * * *").perform_later FindDubiousProceduresJob.set(cron: "0 0 * * *").perform_later
Administrateurs::ActivateBeforeExpirationJob.set(cron: "0 8 * * *").perform_later Administrateurs::ActivateBeforeExpirationJob.set(cron: "0 8 * * *").perform_later
WarnExpiringDossiersJob.set(cron: "0 0 1 * *").perform_later WarnExpiringDossiersJob.set(cron: "0 0 1 * *").perform_later

View file

@ -1,4 +1,6 @@
class UpdateAdministrateurUsageStatisticsJob < ApplicationJob class UpdateAdministrateurUsageStatisticsJob < ApplicationJob
queue_as :cron
def perform def perform
AdministrateurUsageStatisticsService.new.update_administrateurs AdministrateurUsageStatisticsService.new.update_administrateurs
end end

View file

@ -24,6 +24,7 @@ class AdministrateurUsageStatisticsService
def administrateur_stats(administrateur) def administrateur_stats(administrateur)
nb_dossiers_by_procedure_id = nb_dossiers_by_procedure_id(administrateur.id) nb_dossiers_by_procedure_id = nb_dossiers_by_procedure_id(administrateur.id)
nb_dossiers_by_synthetic_state = nb_dossiers_by_synthetic_state(administrateur.id) nb_dossiers_by_synthetic_state = nb_dossiers_by_synthetic_state(administrateur.id)
nb_dossiers_roi = nb_dossiers_by_procedure_id.reject { |procedure_id, _count| is_brouillon(procedure_id) }.map { |_procedure_id, count| count }.sum
result = { result = {
ds_sign_in_count: administrateur.sign_in_count, ds_sign_in_count: administrateur.sign_in_count,
@ -57,7 +58,9 @@ class AdministrateurUsageStatisticsService
.map { |_procedure_id, count| count } .map { |_procedure_id, count| count }
.max || 0, .max || 0,
nb_dossiers_traite: nb_dossiers_by_synthetic_state['termine'], nb_dossiers_traite: nb_dossiers_by_synthetic_state['termine'],
nb_dossiers_dossier_en_instruction: nb_dossiers_by_synthetic_state['en_instruction'] nb_dossiers_dossier_en_instruction: nb_dossiers_by_synthetic_state['en_instruction'],
admin_roi_low: nb_dossiers_roi * 7.04,
admin_roi_high: nb_dossiers_roi * 17.25
} }
if administrateur.current_sign_in_at.present? if administrateur.current_sign_in_at.present?

View file

@ -29,7 +29,9 @@ describe AdministrateurUsageStatisticsService do
nb_dossiers: 0, nb_dossiers: 0,
nb_dossiers_max: 0, nb_dossiers_max: 0,
nb_dossiers_traite: 0, nb_dossiers_traite: 0,
nb_dossiers_dossier_en_instruction: 0 nb_dossiers_dossier_en_instruction: 0,
admin_roi_low: 0,
admin_roi_high: 0
) )
end end
end end
@ -80,7 +82,9 @@ describe AdministrateurUsageStatisticsService do
nb_dossiers: 0, nb_dossiers: 0,
nb_dossiers_max: 0, nb_dossiers_max: 0,
nb_dossiers_traite: 0, nb_dossiers_traite: 0,
nb_dossiers_dossier_en_instruction: 0 nb_dossiers_dossier_en_instruction: 0,
admin_roi_low: 0,
admin_roi_high: 0
) )
end end
end end
@ -108,7 +112,9 @@ describe AdministrateurUsageStatisticsService do
nb_dossiers: 21, nb_dossiers: 21,
nb_dossiers_max: 21, nb_dossiers_max: 21,
nb_dossiers_traite: 7, nb_dossiers_traite: 7,
nb_dossiers_dossier_en_instruction: 7 nb_dossiers_dossier_en_instruction: 7,
admin_roi_low: 147.84,
admin_roi_high: 362.25
) )
end end
end end
@ -127,7 +133,9 @@ describe AdministrateurUsageStatisticsService do
nb_dossiers: 0, nb_dossiers: 0,
nb_dossiers_max: 0, nb_dossiers_max: 0,
nb_dossiers_traite: 0, nb_dossiers_traite: 0,
nb_dossiers_dossier_en_instruction: 0 nb_dossiers_dossier_en_instruction: 0,
admin_roi_low: 0,
admin_roi_high: 0
) )
end end
end end
@ -155,7 +163,9 @@ describe AdministrateurUsageStatisticsService do
nb_dossiers: 0, nb_dossiers: 0,
nb_dossiers_max: 0, nb_dossiers_max: 0,
nb_dossiers_traite: 0, nb_dossiers_traite: 0,
nb_dossiers_dossier_en_instruction: 0 nb_dossiers_dossier_en_instruction: 0,
admin_roi_low: 0,
admin_roi_high: 0
) )
end end
end end
@ -181,7 +191,9 @@ describe AdministrateurUsageStatisticsService do
nb_dossiers: 3, nb_dossiers: 3,
nb_dossiers_max: 3, nb_dossiers_max: 3,
nb_dossiers_traite: 1, nb_dossiers_traite: 1,
nb_dossiers_dossier_en_instruction: 1 nb_dossiers_dossier_en_instruction: 1,
admin_roi_low: 21.12,
admin_roi_high: 51.75
) )
end end
end end
@ -209,7 +221,9 @@ describe AdministrateurUsageStatisticsService do
nb_dossiers: 21, nb_dossiers: 21,
nb_dossiers_max: 21, nb_dossiers_max: 21,
nb_dossiers_traite: 7, nb_dossiers_traite: 7,
nb_dossiers_dossier_en_instruction: 7 nb_dossiers_dossier_en_instruction: 7,
admin_roi_low: 147.84,
admin_roi_high: 362.25
) )
end end
end end