From 031c40aa55db71a181dd10b8939dae08c504e123 Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Tue, 2 Apr 2019 14:29:00 +0200 Subject: [PATCH 1/2] stats: display 12 weeks of feedbacks --- app/controllers/stats_controller.rb | 2 +- spec/controllers/stats_controller_spec.rb | 21 +++++++++------------ 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/app/controllers/stats_controller.rb b/app/controllers/stats_controller.rb index a2c1f0214..a6febb8e3 100644 --- a/app/controllers/stats_controller.rb +++ b/app/controllers/stats_controller.rb @@ -132,7 +132,7 @@ class StatsController < ApplicationController Feedback.ratings.fetch(:happy) => "Satisfaits" } - number_of_weeks = 6 + number_of_weeks = 12 totals = Feedback .group_by_week(:created_at, last: number_of_weeks, current: false) .count diff --git a/spec/controllers/stats_controller_spec.rb b/spec/controllers/stats_controller_spec.rb index 0744ba38c..b70d75fab 100644 --- a/spec/controllers/stats_controller_spec.rb +++ b/spec/controllers/stats_controller_spec.rb @@ -228,20 +228,17 @@ describe StatsController, type: :controller do it 'returns weekly ratios between a given feedback and all feedback' do happy_data = stats.find { |g| g[:name] == 'Satisfaits' }[:data] - expect(happy_data.values[0]).to eq 0 - expect(happy_data.values[1]).to eq 0 - expect(happy_data.values[2]).to eq 0 - expect(happy_data.values[3]).to eq 25.0 - expect(happy_data.values[4]).to eq 50.0 - expect(happy_data.values[5]).to eq 75.0 + + expect(happy_data.values[-4]).to eq 0 + expect(happy_data.values[-3]).to eq 25.0 + expect(happy_data.values[-2]).to eq 50.0 + expect(happy_data.values[-1]).to eq 75.0 unhappy_data = stats.find { |g| g[:name] == 'Mécontents' }[:data] - expect(unhappy_data.values[0]).to eq 0 - expect(unhappy_data.values[1]).to eq 0 - expect(unhappy_data.values[2]).to eq 0 - expect(unhappy_data.values[3]).to eq 75.0 - expect(unhappy_data.values[4]).to eq 50.0 - expect(unhappy_data.values[5]).to eq 25.0 + expect(unhappy_data.values[-4]).to eq 0 + expect(unhappy_data.values[-3]).to eq 75.0 + expect(unhappy_data.values[-2]).to eq 50.0 + expect(unhappy_data.values[-1]).to eq 25.0 end it 'excludes values still in the current week' do From a8050ce13646f705e9c5c91cd4454a21d294b0af Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Tue, 2 Apr 2019 14:29:17 +0200 Subject: [PATCH 2/2] stats: display only the last year of contact rate --- app/controllers/stats_controller.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/controllers/stats_controller.rb b/app/controllers/stats_controller.rb index a6febb8e3..571e6d79f 100644 --- a/app/controllers/stats_controller.rb +++ b/app/controllers/stats_controller.rb @@ -162,7 +162,9 @@ class StatsController < ApplicationController end def contact_percentage - from = Date.new(2018, 1) + number_of_months = 13 + + from = Date.today.prev_month(number_of_months) to = Date.today.prev_month adapter = Helpscout::UserConversationsAdapter.new(from, to)