Merge pull request #6388 from betagouv/main

2021-08-12-01
This commit is contained in:
krichtof 2021-08-12 12:01:27 +02:00 committed by GitHub
commit b18574974f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 35 additions and 11 deletions

View file

@ -65,7 +65,6 @@ $stat-card-half-horizontal-spacing: 4 * $default-space;
.stat-card-details {
font-size: 13px;
text-align: center;
font-style: italic;
}

View file

@ -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
@ -52,7 +53,12 @@ module ProcedureStatsConcern
# 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 }
{
name: state,
data: chart_data .where(state: state) .group_by_week do |dossier|
dossier.traitements.first.processed_at
end.map { |k, v| [k, v.count] }.to_h.transform_keys { |week| pretty_week(week) }
}
# rubocop:enable Style/HashTransformValues
end
end
@ -101,7 +107,15 @@ 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
def pretty_week(week)
I18n.l(week, format: '%d %b')
end
end

View file

@ -27,7 +27,7 @@ class ProcedureArchiveService
Zip::OutputStream.open(tmp_file) do |zipfile|
bug_reports = ''
files.each do |attachment, pj_filename|
zipfile.put_next_entry("procedure-#{@procedure.id}/#{pj_filename}")
zipfile.put_next_entry("#{zip_root_folder(@procedure)}/#{pj_filename}")
begin
zipfile.puts(attachment.download)
rescue
@ -35,7 +35,7 @@ class ProcedureArchiveService
end
end
if !bug_reports.empty?
zipfile.put_next_entry("LISEZMOI.txt")
zipfile.put_next_entry("#{zip_root_folder(@procedure)}/LISEZMOI.txt")
zipfile.puts(bug_reports)
end
end
@ -58,6 +58,10 @@ class ProcedureArchiveService
private
def zip_root_folder(procedure)
"procedure-#{@procedure.id}"
end
def create_list_of_attachments(dossiers)
dossiers.flat_map do |dossier|
ActiveStorage::DownloadableFile.create_list_from_dossier(dossier)

View file

@ -30,13 +30,20 @@
.stat-cards
.stat-card.stat-card-half.pull-left
%span.stat-card-title TAUX DACCEPTATION
.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: %w(#387EC3 #AE2C2B #FAD859),
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
.stat-card-details au cours des 6 derniers mois
.chart-container
.chart
= line_chart @termines_by_week, colors: ["#387EC3", "#AE2C2B", "#FAD859"]
= line_chart @termines_by_week, colors: ["#387EC3", "#AE2C2B", "#FAD859"], ytitle: 'Nb dossiers'

View file

@ -90,7 +90,7 @@ describe ProcedureArchiveService do
archive.file.open do |f|
files = ZipTricks::FileReader.read_zip_structure(io: f)
expect(files.size).to be 4
expect(files.last.filename).to include("LISEZMOI")
expect(files.last.filename).to eq("procedure-#{procedure.id}/LISEZMOI.txt")
expect(extract(f, files.last)).to match(/Impossible de .*cni.*png/)
end
end