From 6ed339e7aa82c95f6f2b8c4fbb28d2cdbcc78002 Mon Sep 17 00:00:00 2001 From: kara Diaby Date: Wed, 2 Jun 2021 12:45:47 +0200 Subject: [PATCH 1/4] modify controllers --- .../instructeurs/procedures_controller.rb | 1 + .../users/statistiques_controller.rb | 21 +++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 app/controllers/users/statistiques_controller.rb diff --git a/app/controllers/instructeurs/procedures_controller.rb b/app/controllers/instructeurs/procedures_controller.rb index a76c690a5..b96c83dc5 100644 --- a/app/controllers/instructeurs/procedures_controller.rb +++ b/app/controllers/instructeurs/procedures_controller.rb @@ -209,6 +209,7 @@ module Instructeurs @usual_traitement_time = @procedure.stats_usual_traitement_time @dossiers_funnel = @procedure.stats_dossiers_funnel @termines_states = @procedure.stats_termines_states + @termines_by_week = @procedure.stats_termines_by_week end private diff --git a/app/controllers/users/statistiques_controller.rb b/app/controllers/users/statistiques_controller.rb new file mode 100644 index 000000000..456a93572 --- /dev/null +++ b/app/controllers/users/statistiques_controller.rb @@ -0,0 +1,21 @@ +module Users + class StatistiquesController < ApplicationController + def statistiques + @procedure = procedure + return procedure_not_found if @procedure.blank? || @procedure.brouillon? + + @usual_traitement_time = @procedure.stats_usual_traitement_time + @dossiers_funnel = @procedure.stats_dossiers_funnel + @termines_states = @procedure.stats_termines_states + @termines_by_week = @procedure.stats_termines_by_week + + render :show + end + + private + + def procedure + Procedure.publiees.or(Procedure.brouillons).find_by(path: params[:path]) + end + end +end From 3555c9696ac3a6b493f8af1e69f913394e8ab8dd Mon Sep 17 00:00:00 2001 From: kara Diaby Date: Wed, 2 Jun 2021 12:47:07 +0200 Subject: [PATCH 2/4] modify concern --- app/models/concerns/procedure_stats_concern.rb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/app/models/concerns/procedure_stats_concern.rb b/app/models/concerns/procedure_stats_concern.rb index 7e487c6a4..a98fe4e23 100644 --- a/app/models/concerns/procedure_stats_concern.rb +++ b/app/models/concerns/procedure_stats_concern.rb @@ -27,4 +27,22 @@ module ProcedureStatsConcern ] end end + + def stats_termines_by_week + Rails.cache.fetch("#{cache_key_with_version}/stats_termines_by_week", expires_in: 12.hours) do + now = Time.zone.now + chart_data = dossiers.joins(:traitements) + .state_termine + .where(traitements: { processed_at: (now.beginning_of_week - 6.months)..now.end_of_week }) + + dossier_state_values = chart_data.pluck(:state).sort.uniq + + # rubocop:disable Style/HashTransformValues + dossier_state_values + .map do |state| + { name: state, data: chart_data.where(state: state).group_by_week { |dossier| dossier.traitements.first.processed_at }.map { |k, v| [k, v.count] }.to_h } + # rubocop:enable Style/HashTransformValues + end + end + end end From 66f0fa35f283eec59a4608ffbdb15fc9aba68c01 Mon Sep 17 00:00:00 2001 From: kara Diaby Date: Wed, 2 Jun 2021 12:47:53 +0200 Subject: [PATCH 3/4] layout --- .../instructeurs/procedures/stats.html.haml | 29 +-------------- app/views/shared/procedures/_stats.html.haml | 35 +++++++++++++++++++ app/views/statistiques/show.html.haml | 4 +++ app/views/users/_procedure_footer.html.haml | 4 +++ 4 files changed, 44 insertions(+), 28 deletions(-) create mode 100644 app/views/shared/procedures/_stats.html.haml create mode 100644 app/views/statistiques/show.html.haml diff --git a/app/views/instructeurs/procedures/stats.html.haml b/app/views/instructeurs/procedures/stats.html.haml index 28ea42acd..4d83e6d16 100644 --- a/app/views/instructeurs/procedures/stats.html.haml +++ b/app/views/instructeurs/procedures/stats.html.haml @@ -5,31 +5,4 @@ locals: { steps: [link_to(@procedure.libelle, instructeur_procedure_path(@procedure)), 'Statistiques'] } -.statistiques - -# Load Chartkick lazily, by using our React lazy-loader. - -# (Chartkick itself doesn't use React though) - = react_component('Chartkick') - - %h1.new-h1= title - .stat-cards - - if @usual_traitement_time.present? - .stat-card.big-number-card - %span.big-number-card-title TEMPS DE TRAITEMENT USUEL - %span.big-number-card-number - = distance_of_time_in_words(@usual_traitement_time) - %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 AVANCÉE DES DOSSIERS - .chart-container - .chart - = area_chart @dossiers_funnel - - .stat-card.stat-card-half.pull-left - %span.stat-card-title TAUX D’ACCEPTATION - .chart-container - .chart - - colors = %w(#C3D9FF #0069CC #1C7EC9) # from _colors.scss - = pie_chart @termines_states, colors: colors += render partial: 'shared/procedures/stats', locals: { title: title } diff --git a/app/views/shared/procedures/_stats.html.haml b/app/views/shared/procedures/_stats.html.haml new file mode 100644 index 000000000..fb6925914 --- /dev/null +++ b/app/views/shared/procedures/_stats.html.haml @@ -0,0 +1,35 @@ +.statistiques + -# Load Chartkick lazily, by using our React lazy-loader. + -# (Chartkick itself doesn't use React though) + = react_component('Chartkick') + + %h1.new-h1= title + .stat-cards + - if @usual_traitement_time.present? + .stat-card.big-number-card + %span.big-number-card-title TEMPS DE TRAITEMENT USUEL + %span.big-number-card-number + = distance_of_time_in_words(@usual_traitement_time) + %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 AVANCÉE DES DOSSIERS + .chart-container + .chart + = area_chart @dossiers_funnel + + .stat-card.stat-card-half.pull-left + %span.stat-card-title TAUX D’ACCEPTATION + .chart-container + .chart + - colors = %w(#C3D9FF #0069CC #1C7EC9) # from _colors.scss + = pie_chart @termines_states, colors: colors + + .stat-cards + .stat-card.stat-card-half.pull-left + %span.stat-card-title RÉPARTITION PAR SEMAINE + .chart-container + .chart + = line_chart @termines_by_week, colors: ["#387EC3", "#AE2C2B", "#FAD859"] diff --git a/app/views/statistiques/show.html.haml b/app/views/statistiques/show.html.haml new file mode 100644 index 000000000..0de25c09c --- /dev/null +++ b/app/views/statistiques/show.html.haml @@ -0,0 +1,4 @@ +- title = "Statistiques · #{@procedure.libelle}" +- content_for(:title, title) + += render partial: 'shared/procedures/stats', locals: { title: title } diff --git a/app/views/users/_procedure_footer.html.haml b/app/views/users/_procedure_footer.html.haml index b225927c6..65c5f2f30 100644 --- a/app/views/users/_procedure_footer.html.haml +++ b/app/views/users/_procedure_footer.html.haml @@ -33,6 +33,10 @@ - horaires = "Horaires : #{formatted_horaires(service.horaires)}" = simple_format(horaires, {}, wrapper_tag: 'span') + %li + Statistiques : + = link_to "voir les statistiques de la démarche", statistiques_path(procedure.path) + - politiques = politiques_conservation_de_donnees(procedure) - if politiques.present? From da1d83b967e2554cbc4783e9919c4a3b55808dfa Mon Sep 17 00:00:00 2001 From: kara Diaby Date: Wed, 2 Jun 2021 12:48:24 +0200 Subject: [PATCH 4/4] add route --- config/routes.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/config/routes.rb b/config/routes.rb index a876587b1..214001c4f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -248,6 +248,10 @@ Rails.application.routes.draw do # scope module: 'users' do + namespace :statistiques do + get '/:path', action: 'statistiques' + end + namespace :commencer do get '/test/:path/dossier_vide', action: 'dossier_vide_pdf_test', as: :dossier_vide_test get '/test/:path', action: 'commencer_test', as: :test