Delete the 30 days flows graphs

This commit is contained in:
gregoirenovel 2017-05-29 17:46:31 +02:00
parent 58aa94359c
commit 3215411547
3 changed files with 2 additions and 97 deletions

View file

@ -13,9 +13,6 @@ class StatsController < ApplicationController
@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)
@procedures_cumulative = cumulative_hash(procedures)
@dossiers_cumulative = cumulative_hash(dossiers, :initiated_at)
@ -38,32 +35,6 @@ class StatsController < ApplicationController
.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
thirty_days_flow_hash = association
.where(date_attribute => min_date..max_date)
.group("date_trunc('day', #{date_attribute.to_s})")
.count
clean_hash(thirty_days_flow_hash, min_date, max_date)
end
def clean_hash(h, min_date, max_date)
# Convert keys to date
h = Hash[h.map { |(k, v)| [k.to_date, v] }]
# Add missing vales where count is 0
(min_date..max_date).each do |date|
if h[date].nil?
h[date] = 0
end
end
h
end
def cumulative_hash(association, date_attribute = :created_at)
sum = 0
association

View file

@ -30,38 +30,20 @@
: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');" }
Cumul
%li.segmented-control-item{ :onclick => "TPS.toggleChart(event, '.flux-procedures-chart');" }
Flux (30 jours)
%span.stat-card-title.pull-left Procédures dématérialisées
.clearfix
%span.stat-card-title Procédures dématérialisées
.chart-container
.chart.cumulative-procedures-chart
= area_chart @procedures_cumulative,
:colors => ["rgba(61, 149, 236, 1)"]
.chart.flux-procedures-chart.hidden
= line_chart @procedures_30_days_flow,
: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-dossiers-chart');" }
Cumul
%li.segmented-control-item{ :onclick => "TPS.toggleChart(event, '.flux-dossiers-chart');" }
Flux (30 jours)
%span.stat-card-title.pull-left Dossiers déposés
.clearfix
%span.stat-card-title Dossiers déposés
.chart-container
.chart.cumulative-dossiers-chart
= area_chart @dossiers_cumulative,
:colors => ["rgba(61, 149, 236, 1)"]
.chart.flux-dossiers-chart.hidden
= line_chart @dossiers_30_days_flow,
:colors => ["rgba(61, 149, 236, 1)"]
- if administration_signed_in?
- cache "computation-heavy-stats", :expires_in => 1.day do

View file

@ -39,54 +39,6 @@ describe StatsController, type: :controller do
end
end
describe '#thirty_days_flow_hash' do
context "without a date_attribut" do
before do
FactoryGirl.create(:procedure, :created_at => 45.days.ago)
FactoryGirl.create(:procedure, :created_at => 15.days.ago)
FactoryGirl.create(:procedure, :created_at => 1.day.ago)
@expected_hash = {}
(30.days.ago.to_date..Time.now.to_date).each do |day|
if [15.days.ago.to_date, 1.day.ago.to_date].include?(day)
@expected_hash[day] = 1
else
@expected_hash[day] = 0
end
end
end
let (:association) { Procedure.all }
subject { StatsController.new.send(:thirty_days_flow_hash, association) }
it { expect(subject).to eq(@expected_hash) }
end
context "with a date_attribut" do
before do
FactoryGirl.create(:procedure, :created_at => 45.days.ago, :updated_at => 50.days.ago)
FactoryGirl.create(:procedure, :created_at => 15.days.ago, :updated_at => 10.days.ago)
FactoryGirl.create(:procedure, :created_at => 1.day.ago, :updated_at => 3.days.ago)
@expected_hash = {}
(30.days.ago.to_date..Time.now.to_date).each do |day|
if [10.days.ago.to_date, 3.day.ago.to_date].include?(day)
@expected_hash[day] = 1
else
@expected_hash[day] = 0
end
end
end
let (:association) { Procedure.all }
subject { StatsController.new.send(:thirty_days_flow_hash, association, :updated_at) }
it { expect(subject).to eq(@expected_hash) }
end
end
describe '#cumulative_hash' do
context "without a date attribute" do
before do