[fix #1832] Procedure Stat: display procedure cloned ratio
This commit is contained in:
parent
f46bf5a67e
commit
28ce027025
4 changed files with 50 additions and 0 deletions
|
@ -32,10 +32,28 @@ class StatsController < ApplicationController
|
|||
|
||||
@motivation_usage_dossier = motivation_usage_dossier
|
||||
@motivation_usage_procedure = motivation_usage_procedure
|
||||
|
||||
@cloned_from_library_procedures_ratio = cloned_from_library_procedures_ratio
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def cloned_from_library_procedures_ratio
|
||||
[3.weeks.ago, 2.weeks.ago, 1.week.ago].map do |date|
|
||||
min_date = date.beginning_of_week
|
||||
max_date = min_date.end_of_week
|
||||
|
||||
all_procedures = Procedure.created_during(min_date..max_date)
|
||||
cloned_from_library_procedures = all_procedures.cloned_from_library
|
||||
|
||||
denominator = [1, all_procedures.count].max
|
||||
|
||||
ratio = percentage(cloned_from_library_procedures.count, denominator)
|
||||
|
||||
[l(max_date, format: '%d/%m/%Y'), ratio]
|
||||
end
|
||||
end
|
||||
|
||||
def max_date
|
||||
if administration_signed_in?
|
||||
Time.now.to_date
|
||||
|
|
|
@ -39,6 +39,8 @@ class Procedure < ApplicationRecord
|
|||
scope :archivees, -> { where.not(archived_at: nil) }
|
||||
scope :publiees_ou_archivees, -> { where.not(published_at: nil) }
|
||||
scope :by_libelle, -> { order(libelle: :asc) }
|
||||
scope :created_during, -> (range) { where(created_at: range) }
|
||||
scope :cloned_from_library, -> { where(cloned_from_library: true) }
|
||||
|
||||
validates :libelle, presence: true, allow_blank: false, allow_nil: false
|
||||
validates :description, presence: true, allow_blank: false, allow_nil: false
|
||||
|
|
|
@ -103,3 +103,12 @@
|
|||
= column_chart @motivation_usage_procedure, ytitle: 'procedures avec motivation / total procedures', xtitle: 'semaines'
|
||||
|
||||
.clearfix
|
||||
|
||||
%h2.new-h2 Utilisation de la bibliothèque
|
||||
|
||||
.stat-cards
|
||||
.stat-card.stat-card-half.pull-left
|
||||
%span.stat-card-title Taux d'utilisation de la bibliothèque
|
||||
= column_chart @cloned_from_library_procedures_ratio, ytitle: 'procédures clonées / total procédure', xtitle: 'semaines'
|
||||
|
||||
.clearfix
|
||||
|
|
|
@ -310,4 +310,25 @@ describe StatsController, type: :controller do
|
|||
|
||||
it { expect(subject).to match([[I18n.l(3.weeks.ago.end_of_week, format: '%d/%m/%Y'), 0], [I18n.l(2.weeks.ago.end_of_week, format: '%d/%m/%Y'), 0], [I18n.l(1.week.ago.end_of_week, format: '%d/%m/%Y'), 33.33]]) }
|
||||
end
|
||||
|
||||
describe "#cloned_from_library_procedures_ratio" do
|
||||
let!(:procedure1) { create(:procedure, created_at: 3.weeks.ago) }
|
||||
let!(:procedure2) { create(:procedure, created_at: 2.weeks.ago) }
|
||||
let!(:procedure3) { create(:procedure, created_at: 2.weeks.ago, cloned_from_library: true) }
|
||||
|
||||
before { Timecop.freeze(Time.now) }
|
||||
after { Timecop.return }
|
||||
|
||||
subject { StatsController.new.send(:cloned_from_library_procedures_ratio) }
|
||||
|
||||
let(:result) do
|
||||
[
|
||||
[I18n.l(3.weeks.ago.end_of_week, format: '%d/%m/%Y'), 0],
|
||||
[I18n.l(2.weeks.ago.end_of_week, format: '%d/%m/%Y'), 50.0],
|
||||
[I18n.l(1.week.ago.end_of_week, format: '%d/%m/%Y'), 0]
|
||||
]
|
||||
end
|
||||
|
||||
it { expect(subject).to match(result) }
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue