From 93ba0cc03844a8ecb227ab6279f354bd32804e00 Mon Sep 17 00:00:00 2001 From: Christophe Robillard Date: Tue, 10 Aug 2021 17:37:42 +0200 Subject: [PATCH 1/2] stats: rend plus explicite le graphe taux d'acceptation --- app/models/concerns/procedure_stats_concern.rb | 11 ++++++++--- app/views/shared/procedures/_stats.html.haml | 9 ++++++++- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/app/models/concerns/procedure_stats_concern.rb b/app/models/concerns/procedure_stats_concern.rb index 146925ea1..16a86e9f6 100644 --- a/app/models/concerns/procedure_stats_concern.rb +++ b/app/models/concerns/procedure_stats_concern.rb @@ -31,11 +31,12 @@ module ProcedureStatsConcern end def stats_termines_states + nb_dossiers_termines = dossiers.state_termine.count Rails.cache.fetch("#{cache_key_with_version}/stats_termines_states", expires_in: 12.hours) do [ - ['Acceptés', dossiers.where(state: :accepte).count], - ['Refusés', dossiers.where(state: :refuse).count], - ['Classés sans suite', dossiers.where(state: :sans_suite).count] + ['Acceptés', percentage(dossiers.where(state: :accepte).count, nb_dossiers_termines)], + ['Refusés', percentage(dossiers.where(state: :refuse).count, nb_dossiers_termines)], + ['Classés sans suite', percentage(dossiers.where(state: :sans_suite).count, nb_dossiers_termines)] ] end end @@ -106,6 +107,10 @@ module ProcedureStatsConcern (seconds / 60.0 / 60.0 / 24.0).ceil end + def percentage(value, total) + (100 * value / total.to_f).round(1) + end + def pretty_month(month) I18n.l(month, format: "%B %Y") end diff --git a/app/views/shared/procedures/_stats.html.haml b/app/views/shared/procedures/_stats.html.haml index e5dd83236..c797f3d51 100644 --- a/app/views/shared/procedures/_stats.html.haml +++ b/app/views/shared/procedures/_stats.html.haml @@ -30,10 +30,17 @@ .stat-cards .stat-card.stat-card-half.pull-left %span.stat-card-title TAUX D’ACCEPTATION + .stat-card-details depuis le lancement de la procédure .chart-container .chart - colors = %w(#C3D9FF #0069CC #1C7EC9) # from _colors.scss - = pie_chart @termines_states, colors: colors + = pie_chart @termines_states, + code: true, + colors: colors, + label: 'Taux', + suffix: '%', + library: { plotOptions: { pie: { dataLabels: { enabled: true, format: '{point.name} : {point.percentage: .1f}%' } } } } + .stat-card.stat-card-half.pull-left %span.stat-card-title RÉPARTITION PAR SEMAINE From 1c564bb744a1c818f56a36e26a4346bbe54ff993 Mon Sep 17 00:00:00 2001 From: Christophe Robillard Date: Wed, 11 Aug 2021 11:30:47 +0200 Subject: [PATCH 2/2] =?UTF-8?q?homogeneise=20les=20couleurs=20utilis=C3=A9?= =?UTF-8?q?es=20pour=20les=20stats?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/shared/procedures/_stats.html.haml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/views/shared/procedures/_stats.html.haml b/app/views/shared/procedures/_stats.html.haml index c797f3d51..6b81229b7 100644 --- a/app/views/shared/procedures/_stats.html.haml +++ b/app/views/shared/procedures/_stats.html.haml @@ -33,10 +33,9 @@ .stat-card-details depuis le lancement de la procédure .chart-container .chart - - colors = %w(#C3D9FF #0069CC #1C7EC9) # from _colors.scss = pie_chart @termines_states, code: true, - colors: colors, + colors: %w(#387EC3 #AE2C2B #FAD859), label: 'Taux', suffix: '%', library: { plotOptions: { pie: { dataLabels: { enabled: true, format: '{point.name} : {point.percentage: .1f}%' } } } }