[Fix #264] Add the last 4 months evolution graphs to Stats
This commit is contained in:
parent
0cc5d85f13
commit
ed7ba60cf0
3 changed files with 70 additions and 0 deletions
|
@ -5,6 +5,9 @@ class StatsController < ApplicationController
|
|||
procedures = Procedure.where(:published => true)
|
||||
dossiers = Dossier.where.not(:state => :draft)
|
||||
|
||||
@procedures_in_the_last_4_months = last_four_months_hash(procedures)
|
||||
@dossiers_in_the_last_4_months = last_four_months_hash(dossiers, :initiated_at)
|
||||
|
||||
@procedures_30_days_flow = thirty_days_flow_hash(procedures)
|
||||
@dossiers_30_days_flow = thirty_days_flow_hash(dossiers, :initiated_at)
|
||||
|
||||
|
@ -17,6 +20,19 @@ class StatsController < ApplicationController
|
|||
|
||||
private
|
||||
|
||||
def last_four_months_hash(association, date_attribute = :created_at)
|
||||
min_date = 3.months.ago.beginning_of_month.to_date
|
||||
max_date = Time.now.to_date
|
||||
|
||||
association
|
||||
.where(date_attribute => min_date..max_date)
|
||||
.group("DATE_TRUNC('month', #{date_attribute.to_s})")
|
||||
.count
|
||||
.to_a
|
||||
.sort{ |x, y| x[0] <=> y[0] }
|
||||
.map { |e| [I18n.l(e.first, format: "%B %Y"), e.last] }
|
||||
end
|
||||
|
||||
def thirty_days_flow_hash(association, date_attribute = :created_at)
|
||||
min_date = 30.days.ago.to_date
|
||||
max_date = Time.now.to_date
|
||||
|
|
|
@ -4,6 +4,22 @@
|
|||
|
||||
.stat-cards
|
||||
|
||||
.stat-card.stat-card-half.pull-left
|
||||
%span.stat-card-title Procédures dématérialisées / mois
|
||||
|
||||
.chart-container
|
||||
.chart
|
||||
= column_chart @procedures_in_the_last_4_months,
|
||||
:colors => ["rgba(61, 149, 236, 1)"]
|
||||
|
||||
.stat-card.stat-card-half.pull-left
|
||||
%span.stat-card-title Dossiers déposés / mois
|
||||
|
||||
.chart-container
|
||||
.chart
|
||||
= column_chart @dossiers_in_the_last_4_months,
|
||||
:colors => ["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 => "TPS.toggleChart(event, '.cumulative-procedures-chart');" }
|
||||
|
|
|
@ -1,6 +1,44 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe StatsController, type: :controller do
|
||||
describe "#last_four_months_hash" do
|
||||
context "without a date attribute" do
|
||||
before do
|
||||
FactoryGirl.create(:procedure, :created_at => 6.months.ago)
|
||||
FactoryGirl.create(:procedure, :created_at => 45.days.ago)
|
||||
FactoryGirl.create(:procedure, :created_at => 1.days.ago)
|
||||
FactoryGirl.create(:procedure, :created_at => 1.days.ago)
|
||||
end
|
||||
|
||||
let (:association) { Procedure.all }
|
||||
|
||||
subject { StatsController.new.send(:last_four_months_hash, association) }
|
||||
|
||||
it { expect(subject).to eq([
|
||||
[I18n.l(45.days.ago.beginning_of_month, format: "%B %Y"), 1],
|
||||
[I18n.l(1.days.ago.beginning_of_month, format: "%B %Y"), 2]
|
||||
] ) }
|
||||
end
|
||||
|
||||
context "with a date attribute" do
|
||||
before do
|
||||
FactoryGirl.create(:procedure, :created_at => 6.months.ago, :updated_at => 6.months.ago)
|
||||
FactoryGirl.create(:procedure, :created_at => 2.months.ago, :updated_at => 45.days.ago)
|
||||
FactoryGirl.create(:procedure, :created_at => 2.months.ago, :updated_at => 45.days.ago)
|
||||
FactoryGirl.create(:procedure, :created_at => 2.months.ago, :updated_at => 1.days.ago)
|
||||
end
|
||||
|
||||
let (:association) { Procedure.all }
|
||||
|
||||
subject { StatsController.new.send(:last_four_months_hash, association, :updated_at) }
|
||||
|
||||
it { expect(subject).to eq([
|
||||
[I18n.l(45.days.ago.beginning_of_month, format: "%B %Y"), 2],
|
||||
[I18n.l(1.days.ago.beginning_of_month, format: "%B %Y"), 1]
|
||||
] ) }
|
||||
end
|
||||
end
|
||||
|
||||
describe '#thirty_days_flow_hash' do
|
||||
context "without a date_attribut" do
|
||||
before do
|
||||
|
|
Loading…
Add table
Reference in a new issue