affiche evolution temps de traitement

This commit is contained in:
Christophe Robillard 2021-06-04 16:19:19 +02:00
parent 701b72494d
commit 45ffae9eb3
5 changed files with 47 additions and 0 deletions

View file

@ -210,6 +210,7 @@ module Instructeurs
@dossiers_funnel = @procedure.stats_dossiers_funnel
@termines_states = @procedure.stats_termines_states
@termines_by_week = @procedure.stats_termines_by_week
@usual_traitement_time_by_month = @procedure.usual_traitement_time_by_month_in_days
end
private

View file

@ -5,6 +5,7 @@ module Users
return procedure_not_found if @procedure.blank? || @procedure.brouillon?
@usual_traitement_time = @procedure.stats_usual_traitement_time
@usual_traitement_time_by_month = @procedure.stats_usual_traitement_time_by_month_in_days
@dossiers_funnel = @procedure.stats_dossiers_funnel
@termines_states = @procedure.stats_termines_states
@termines_by_week = @procedure.stats_termines_by_week

View file

@ -7,6 +7,12 @@ module ProcedureStatsConcern
end
end
def stats_usual_traitement_time_by_month_in_days
Rails.cache.fetch("#{cache_key_with_version}/stats_usual_traitement_time_by_month_in_days", expires_in: 12.hours) do
usual_traitement_time_by_month_in_days
end
end
def stats_dossiers_funnel
Rails.cache.fetch("#{cache_key_with_version}/stats_dossiers_funnel", expires_in: 12.hours) do
[

View file

@ -582,6 +582,37 @@ class Procedure < ApplicationRecord
end
end
def usual_traitement_time_by_month
first_processed_at = Traitement.includes(:dossier)
.where(dossier: self.dossiers)
.where.not('dossiers.en_construction_at' => nil, :processed_at => nil)
.order(:processed_at)
.pick(:processed_at)
return [] if first_processed_at.nil?
month_index = first_processed_at.at_end_of_month
month_range = []
while month_index <= Time.zone.now.at_end_of_month
month_range << month_index
month_index += 1.month
end
month_range.map do |month|
[I18n.l(month, format: "%B %Y"), compute_usual_traitement_time_for_month(month)]
end
end
def usual_traitement_time_by_month_in_days
usual_traitement_time_by_month.map do |month, time_in_seconds|
if time_in_seconds.present?
time_in_days = (time_in_seconds / 60.0 / 60.0 / 24.0).ceil
else
time_in_days = nil
end
[month, time_in_days]
end
end
def populate_champ_stable_ids
TypeDeChamp
.joins(:revisions)

View file

@ -13,6 +13,14 @@
%span.big-number-card-detail
90% des demandes du mois dernier ont été traitées en moins de #{distance_of_time_in_words(@usual_traitement_time)}.
.stat-cards
.stat-card.stat-card-half.pull-left
%span.stat-card-title TEMPS DE TRAITEMENT
.chart-container
.chart
- colors = %w(#C3D9FF #0069CC #1C7EC9) # from _colors.scss
= column_chart @usual_traitement_time_by_month, ytitle: "Nb Jours"
.stat-cards
.stat-card.stat-card-half.pull-left
%span.stat-card-title AVANCÉE DES DOSSIERS