Merge pull request #2481 from betagouv/port-stats-api-to-stats-page
Port stats api to stats page
This commit is contained in:
commit
6081f2ebc7
6 changed files with 44 additions and 37 deletions
|
@ -126,6 +126,7 @@ $big-number-card-padding: 2 * $segmented-control-item-border-radius;
|
|||
display: block;
|
||||
text-align: center;
|
||||
margin: 0 auto;
|
||||
margin-bottom: 20px;
|
||||
color: $light-grey;
|
||||
}
|
||||
|
||||
|
@ -137,3 +138,10 @@ $big-number-card-padding: 2 * $segmented-control-item-border-radius;
|
|||
font-weight: bold;
|
||||
color: $blue;
|
||||
}
|
||||
|
||||
.big-number-card-detail {
|
||||
display: block;
|
||||
text-align: center;
|
||||
color: $blue;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,18 +0,0 @@
|
|||
class API::StatistiquesController < ApplicationController
|
||||
def dossiers_stats
|
||||
render json: {
|
||||
total: total_dossiers,
|
||||
mois: dossiers_mois
|
||||
}
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def total_dossiers
|
||||
Dossier.state_not_brouillon.size
|
||||
end
|
||||
|
||||
def dossiers_mois
|
||||
Dossier.state_not_brouillon.where(created_at: (1.month.ago)..Time.now).size
|
||||
end
|
||||
end
|
|
@ -9,8 +9,8 @@ class StatsController < ApplicationController
|
|||
procedures = Procedure.publiees_ou_archivees
|
||||
dossiers = Dossier.where.not(:state => :brouillon)
|
||||
|
||||
@procedures_count = procedures.count
|
||||
@dossiers_count = dossiers.count
|
||||
@procedures_numbers = procedures_numbers(procedures)
|
||||
@dossiers_numbers = dossiers_numbers(dossiers)
|
||||
|
||||
@satisfaction_usagers = satisfaction_usagers
|
||||
@dossiers_states = dossiers_states
|
||||
|
@ -78,6 +78,34 @@ class StatsController < ApplicationController
|
|||
|
||||
private
|
||||
|
||||
def procedures_numbers(procedures)
|
||||
total = procedures.count
|
||||
last_30_days_count = procedures.where(published_at: 1.month.ago..Time.now).count
|
||||
previous_count = procedures.where(published_at: 2.months.ago..1.month.ago).count
|
||||
evolution = (((last_30_days_count.to_f / previous_count) - 1) * 100).round(0)
|
||||
formatted_evolution = sprintf("%+d", evolution)
|
||||
|
||||
{
|
||||
total: total.to_s,
|
||||
last_30_days_count: last_30_days_count.to_s,
|
||||
evolution: formatted_evolution
|
||||
}
|
||||
end
|
||||
|
||||
def dossiers_numbers(dossiers)
|
||||
total = dossiers.count
|
||||
last_30_days_count = dossiers.where(en_construction_at: 1.month.ago..Time.now).count
|
||||
previous_count = dossiers.where(en_construction_at: 2.months.ago..1.month.ago).count
|
||||
evolution = (((last_30_days_count.to_f / previous_count) - 1) * 100).round(0)
|
||||
formatted_evolution = sprintf("%+d", evolution)
|
||||
|
||||
{
|
||||
total: total.to_s,
|
||||
last_30_days_count: last_30_days_count.to_s,
|
||||
evolution: formatted_evolution
|
||||
}
|
||||
end
|
||||
|
||||
def dossiers_states
|
||||
{
|
||||
'Brouilllon' => Dossier.state_brouillon.count,
|
||||
|
|
|
@ -8,12 +8,16 @@
|
|||
.stat-card.stat-card-half.big-number-card.pull-left
|
||||
%span.big-number-card-title TOTAL PROCÉDURES DÉMATÉRIALISÉES
|
||||
%span.big-number-card-number
|
||||
= number_with_delimiter(@procedures_count)
|
||||
= number_with_delimiter(@procedures_numbers[:total])
|
||||
%span.big-number-card-detail
|
||||
#{number_with_delimiter(@procedures_numbers[:last_30_days_count])} (#{@procedures_numbers[:evolution]} %) sur les 30 derniers jours
|
||||
|
||||
.stat-card.stat-card-half.big-number-card.pull-left
|
||||
%span.big-number-card-title TOTAL DOSSIERS DÉPOSÉS
|
||||
%span.big-number-card-number
|
||||
= number_with_delimiter(@dossiers_count)
|
||||
= number_with_delimiter(@dossiers_numbers[:total])
|
||||
%span.big-number-card-detail
|
||||
#{number_with_delimiter(@dossiers_numbers[:last_30_days_count])} (#{@dossiers_numbers[:evolution]} %) sur les 30 derniers jours
|
||||
|
||||
.stat-card.stat-card-half.pull-left
|
||||
%span.stat-card-title
|
||||
|
|
|
@ -261,10 +261,6 @@ Rails.application.routes.draw do
|
|||
resources :dossiers, only: [:index, :show]
|
||||
end
|
||||
end
|
||||
|
||||
namespace :statistiques do
|
||||
get 'dossiers' => '/api/statistiques#dossiers_stats'
|
||||
end
|
||||
end
|
||||
|
||||
#
|
||||
|
|
|
@ -1,11 +0,0 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe API::StatistiquesController, type: :controller do
|
||||
describe '#GET dossiers_stats' do
|
||||
before do
|
||||
get :dossiers_stats
|
||||
end
|
||||
|
||||
it { expect(response.status).to eq 200 }
|
||||
end
|
||||
end
|
Loading…
Add table
Reference in a new issue