Add a button to download the stats in CSV
This commit is contained in:
parent
746f9c8f78
commit
9292e243ef
3 changed files with 43 additions and 1 deletions
|
@ -1,6 +1,8 @@
|
|||
class StatsController < ApplicationController
|
||||
layout "new_application"
|
||||
|
||||
before_action :authenticate_administration!, only: [:download]
|
||||
|
||||
MEAN_NUMBER_OF_CHAMPS_IN_A_FORM = 24.0
|
||||
|
||||
def index
|
||||
|
@ -36,6 +38,41 @@ class StatsController < ApplicationController
|
|||
@cloned_from_library_procedures_ratio = cloned_from_library_procedures_ratio
|
||||
end
|
||||
|
||||
def download
|
||||
headers = [
|
||||
'ID du dossier',
|
||||
'ID de la procédure',
|
||||
'Nom de la procédure',
|
||||
'ID utilisateur',
|
||||
'Etat du fichier',
|
||||
'Durée en brouillon',
|
||||
'Durée en construction',
|
||||
'Durée en instruction'
|
||||
]
|
||||
|
||||
data = Dossier
|
||||
.includes(:procedure, :user)
|
||||
.in_batches
|
||||
.flat_map do |dossiers|
|
||||
|
||||
dossiers
|
||||
.pluck(
|
||||
"dossiers.id",
|
||||
"procedures.id",
|
||||
"procedures.libelle",
|
||||
"users.id",
|
||||
"dossiers.state",
|
||||
"dossiers.en_construction_at - dossiers.created_at",
|
||||
"dossiers.en_instruction_at - dossiers.en_construction_at",
|
||||
"dossiers.processed_at - dossiers.en_instruction_at"
|
||||
)
|
||||
end
|
||||
|
||||
respond_to do |format|
|
||||
format.csv { send_data(SpreadsheetArchitect.to_xlsx(headers: headers, data: data), filename: "statistiques.csv") }
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def cloned_from_library_procedures_ratio
|
||||
|
|
|
@ -112,3 +112,7 @@
|
|||
= column_chart @cloned_from_library_procedures_ratio, ytitle: 'procédures clonées / total procédure', xtitle: 'semaines'
|
||||
|
||||
.clearfix
|
||||
|
||||
%h2.new-h2 Téléchargement
|
||||
|
||||
= link_to "Télécharger les statistiques (CSV)", stats_download_path(format: :csv), class: 'button secondary'
|
||||
|
|
|
@ -99,7 +99,8 @@ Rails.application.routes.draw do
|
|||
get 'users' => 'users#index'
|
||||
get 'admin' => 'admin#index'
|
||||
|
||||
resources :stats, only: [:index]
|
||||
get '/stats' => 'stats#index'
|
||||
get '/stats/download' => 'stats#download'
|
||||
resources :accessibilite, only: [:index]
|
||||
resources :demandes, only: [:new, :create]
|
||||
|
||||
|
|
Loading…
Reference in a new issue