Merge pull request #374 from sgmap/stats_pie_chart_group_admin
Stats pie chart group admin
This commit is contained in:
commit
a2693c2d77
3 changed files with 56 additions and 0 deletions
|
@ -16,6 +16,8 @@ class StatsController < ApplicationController
|
|||
@dossiers_cumulative = cumulative_hash(dossiers, :initiated_at)
|
||||
@dossiers_in_the_last_4_months = last_four_months_hash(dossiers, :initiated_at)
|
||||
|
||||
@procedures_count_per_administrateur = procedures_count_per_administrateur(procedures)
|
||||
|
||||
@dossier_instruction_mean_time = dossier_instruction_mean_time(dossiers)
|
||||
@dossier_filling_mean_time = dossier_filling_mean_time(dossiers)
|
||||
end
|
||||
|
@ -46,6 +48,15 @@ class StatsController < ApplicationController
|
|||
.reduce({}, :merge)
|
||||
end
|
||||
|
||||
def procedures_count_per_administrateur(procedures)
|
||||
count_per_administrateur = procedures.group(:administrateur_id).count.values
|
||||
{
|
||||
'Une procédure' => count_per_administrateur.select { |count| count == 1 }.count,
|
||||
'Entre deux et cinq procédures' => count_per_administrateur.select { |count| 2 <= count && count <= 5 }.count,
|
||||
'Plus de cinq procédures' => count_per_administrateur.select { |count| 5 < count }.count
|
||||
}
|
||||
end
|
||||
|
||||
def mean(collection)
|
||||
(collection.sum.to_f / collection.size).round(2)
|
||||
end
|
||||
|
|
|
@ -47,6 +47,15 @@
|
|||
= area_chart @dossiers_cumulative,
|
||||
:colors => ["rgba(61, 149, 236, 1)"]
|
||||
|
||||
.stat-card.stat-card-half.pull-left
|
||||
%span.stat-card-title
|
||||
Nombre d'administrations ayant dématérialisé N procédures
|
||||
|
||||
.chart-container
|
||||
.chart
|
||||
= pie_chart @procedures_count_per_administrateur,
|
||||
:colors => ["rgba(191, 220, 249, 1)", "rgba(113, 176, 239, 1)", "rgba(61, 149, 236, 1)"]
|
||||
|
||||
- if administration_signed_in?
|
||||
- cache "computation-heavy-stats", :expires_in => 1.day do
|
||||
.stat-card.stat-card-half.pull-left
|
||||
|
|
|
@ -75,6 +75,42 @@ describe StatsController, type: :controller do
|
|||
end
|
||||
end
|
||||
|
||||
describe "#procedures_count_per_administrateur" do
|
||||
let!(:administrateur_1) { create(:administrateur) }
|
||||
let!(:administrateur_2) { create(:administrateur) }
|
||||
let!(:administrateur_3) { create(:administrateur) }
|
||||
let!(:administrateur_4) { create(:administrateur) }
|
||||
let!(:administrateur_5) { create(:administrateur) }
|
||||
|
||||
before do
|
||||
3.times do
|
||||
create(:procedure, published: true, administrateur: administrateur_1)
|
||||
end
|
||||
|
||||
2.times do
|
||||
create(:procedure, published: true, administrateur: administrateur_2)
|
||||
end
|
||||
|
||||
8.times do
|
||||
create(:procedure, published: true, administrateur: administrateur_3)
|
||||
end
|
||||
|
||||
create(:procedure, published: true, administrateur: administrateur_4)
|
||||
end
|
||||
|
||||
let(:association){ Procedure.all }
|
||||
|
||||
subject { StatsController.new.send(:procedures_count_per_administrateur, association) }
|
||||
|
||||
it do
|
||||
is_expected.to eq({
|
||||
'Une procédure' => 1,
|
||||
'Entre deux et cinq procédures' => 2,
|
||||
'Plus de cinq procédures' => 1
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
describe "#dossier_instruction_mean_time" do
|
||||
# Month-2: mean 3 days
|
||||
# procedure_1: mean 2 days
|
||||
|
|
Loading…
Reference in a new issue