Add the weekly avis usage to Stats
This commit is contained in:
parent
082898af45
commit
b5f1b898c7
4 changed files with 57 additions and 2 deletions
|
@ -6,15 +6,25 @@ $blue-hover: rgba(61, 149, 236, 0.8);
|
||||||
$default-space: 15px;
|
$default-space: 15px;
|
||||||
|
|
||||||
$new-h1-margin-bottom: 4 * $default-space;
|
$new-h1-margin-bottom: 4 * $default-space;
|
||||||
|
$new-h2-margin-bottom: 3 * $default-space;
|
||||||
|
|
||||||
.new-h1 {
|
.new-h1,
|
||||||
|
.new-h2 {
|
||||||
color: $dark-grey;
|
color: $dark-grey;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
margin-bottom: $new-h1-margin-bottom;
|
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
|
||||||
|
.new-h1 {
|
||||||
|
margin-bottom: $new-h1-margin-bottom;
|
||||||
font-size: 41px;
|
font-size: 41px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.new-h2 {
|
||||||
|
margin-bottom: $new-h2-margin-bottom;
|
||||||
|
font-size: 36px;
|
||||||
|
}
|
||||||
|
|
||||||
$statistiques-padding-top: $default-space * 2;
|
$statistiques-padding-top: $default-space * 2;
|
||||||
|
|
||||||
.statistiques {
|
.statistiques {
|
||||||
|
|
|
@ -20,6 +20,8 @@ class StatsController < ApplicationController
|
||||||
|
|
||||||
@dossier_instruction_mean_time = dossier_instruction_mean_time(dossiers)
|
@dossier_instruction_mean_time = dossier_instruction_mean_time(dossiers)
|
||||||
@dossier_filling_mean_time = dossier_filling_mean_time(dossiers)
|
@dossier_filling_mean_time = dossier_filling_mean_time(dossiers)
|
||||||
|
|
||||||
|
@avis_usage = avis_usage
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
@ -144,4 +146,23 @@ class StatsController < ApplicationController
|
||||||
[month, month_average]
|
[month, month_average]
|
||||||
end.to_h
|
end.to_h
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def avis_usage
|
||||||
|
[3.week.ago, 2.week.ago, 1.week.ago].map do |min_date|
|
||||||
|
max_date = min_date + 1.week
|
||||||
|
|
||||||
|
weekly_dossiers = Dossier.includes(:avis).where(created_at: min_date..max_date).to_a
|
||||||
|
|
||||||
|
weekly_dossiers_count = weekly_dossiers.count
|
||||||
|
|
||||||
|
if weekly_dossiers_count == 0
|
||||||
|
result = 0
|
||||||
|
else
|
||||||
|
weekly_dossier_with_avis_count = weekly_dossiers.select { |dossier| dossier.avis.present? }.count
|
||||||
|
result = ((weekly_dossier_with_avis_count.to_f / weekly_dossiers_count) * 100).round(2)
|
||||||
|
end
|
||||||
|
|
||||||
|
[min_date.to_i, result]
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -77,3 +77,13 @@
|
||||||
:colors => ["rgba(61, 149, 236, 1)"]
|
:colors => ["rgba(61, 149, 236, 1)"]
|
||||||
|
|
||||||
.clearfix
|
.clearfix
|
||||||
|
|
||||||
|
- if administration_signed_in?
|
||||||
|
%h2.new-h2 Avis
|
||||||
|
|
||||||
|
.stat-cards
|
||||||
|
.stat-card.stat-card-half.pull-left
|
||||||
|
%span.stat-card-title Taux d'utilisation des avis
|
||||||
|
= line_chart @avis_usage, ytitle: 'dossiers avec avis / total dossiers', xtitle: 'semaines'
|
||||||
|
|
||||||
|
.clearfix
|
||||||
|
|
|
@ -210,4 +210,18 @@ describe StatsController, type: :controller do
|
||||||
|
|
||||||
it { expect(subject).to eq(@expected_hash) }
|
it { expect(subject).to eq(@expected_hash) }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe '#avis_usage' do
|
||||||
|
let!(:dossier) { create(:dossier) }
|
||||||
|
let!(:avis_with_dossier) { create(:avis) }
|
||||||
|
let!(:dossier2) { create(:dossier) }
|
||||||
|
|
||||||
|
before do
|
||||||
|
Timecop.freeze(Time.now)
|
||||||
|
end
|
||||||
|
|
||||||
|
subject { StatsController.new.send(:avis_usage) }
|
||||||
|
|
||||||
|
it { expect(subject).to match([[3.week.ago.to_i, 0], [2.week.ago.to_i, 0], [1.week.ago.to_i, 33.33]]) }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue