commit
f5ccb60d86
5 changed files with 109 additions and 1 deletions
2
Gemfile
2
Gemfile
|
@ -84,6 +84,8 @@ gem "premailer-rails"
|
|||
|
||||
gem 'smart_listing'
|
||||
|
||||
gem 'groupdate'
|
||||
|
||||
gem 'bootstrap-wysihtml5-rails', '~> 0.3.3.8'
|
||||
|
||||
gem 'spreadsheet_architect', '~> 1.4.8' # https://github.com/westonganger/spreadsheet_architect/issues/14
|
||||
|
|
|
@ -369,6 +369,8 @@ GEM
|
|||
formatador (0.2.5)
|
||||
globalid (0.4.1)
|
||||
activesupport (>= 4.2.0)
|
||||
groupdate (4.0.1)
|
||||
activesupport (>= 4.2)
|
||||
guard (2.14.2)
|
||||
formatador (>= 0.2.4)
|
||||
listen (>= 2.7, < 4.0)
|
||||
|
@ -834,6 +836,7 @@ DEPENDENCIES
|
|||
fog
|
||||
fog-openstack
|
||||
font-awesome-rails
|
||||
groupdate
|
||||
guard
|
||||
guard-livereload
|
||||
guard-rspec
|
||||
|
|
|
@ -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
|
||||
|
@ -10,6 +12,9 @@ class StatsController < ApplicationController
|
|||
@procedures_count = procedures.count
|
||||
@dossiers_count = dossiers.count
|
||||
|
||||
@satisfaction_usagers = satisfaction_usagers
|
||||
@dossiers_states = dossiers_states
|
||||
|
||||
@procedures_cumulative = cumulative_hash(procedures, :published_at)
|
||||
@procedures_in_the_last_4_months = last_four_months_hash(procedures, :published_at)
|
||||
|
||||
|
@ -36,8 +41,83 @@ 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 dossiers_states
|
||||
{
|
||||
'Brouilllon' => Dossier.state_brouillon.count,
|
||||
'En construction' => Dossier.state_en_construction.count,
|
||||
'En instruction' => Dossier.state_en_instruction.count,
|
||||
'Terminé' => Dossier.state_termine.count
|
||||
}
|
||||
end
|
||||
|
||||
def satisfaction_usagers
|
||||
legend = {
|
||||
"0" => "Mécontents",
|
||||
"1" => "Neutres",
|
||||
"2" => "Satisfaits"
|
||||
}
|
||||
|
||||
totals = Feedback.where(created_at: 5.weeks.ago..Time.now).group_by_week(:created_at).count
|
||||
|
||||
(0..2).map do |mark|
|
||||
data = Feedback
|
||||
.where(created_at: 5.weeks.ago..Time.now, mark: mark)
|
||||
.group_by_week(:created_at)
|
||||
.count
|
||||
.map do |week, count|
|
||||
total = totals[week]
|
||||
|
||||
if total > 0
|
||||
[week, (count.to_f / total).round(2)]
|
||||
else
|
||||
0
|
||||
end
|
||||
end.to_h
|
||||
|
||||
{
|
||||
name: legend[mark.to_s],
|
||||
data: data
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def cloned_from_library_procedures_ratio
|
||||
[3.weeks.ago, 2.weeks.ago, 1.week.ago].map do |date|
|
||||
min_date = date.beginning_of_week
|
||||
|
|
|
@ -15,6 +15,24 @@
|
|||
%span.big-number-card-number
|
||||
= number_with_delimiter(@dossiers_count)
|
||||
|
||||
.stat-card.stat-card-half.pull-left
|
||||
%span.stat-card-title
|
||||
Satisfaction usager
|
||||
|
||||
.chart-container
|
||||
.chart
|
||||
= line_chart @satisfaction_usagers,
|
||||
colors: ["#F28900", "rgba(161, 0, 5, 0.9)", "#15AD70"]
|
||||
|
||||
.stat-card.stat-card-half.pull-left
|
||||
%span.stat-card-title
|
||||
Répartition des dossiers
|
||||
|
||||
.chart-container
|
||||
.chart
|
||||
= pie_chart @dossiers_states,
|
||||
colors: ["rgba(222, 238, 265, 1)", "rgba(191, 220, 249, 1)", "rgba(113, 176, 239, 1)", "rgba(61, 149, 236, 1)"]
|
||||
|
||||
.stat-card.stat-card-half.pull-left
|
||||
%ul.segmented-control.pull-right
|
||||
%li.segmented-control-item.segmented-control-item-active{ :onclick => "DS.toggleChart(event, '.monthly-procedures-chart');" }
|
||||
|
@ -112,3 +130,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…
Add table
Reference in a new issue