Merge pull request #3723 from betagouv/improve-stats

Améliorations de la page /stats
This commit is contained in:
Pierre de La Morinerie 2019-04-02 17:28:34 +02:00 committed by GitHub
commit b8c309acdb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 14 deletions

View file

@ -132,7 +132,7 @@ class StatsController < ApplicationController
Feedback.ratings.fetch(:happy) => "Satisfaits" Feedback.ratings.fetch(:happy) => "Satisfaits"
} }
number_of_weeks = 6 number_of_weeks = 12
totals = Feedback totals = Feedback
.group_by_week(:created_at, last: number_of_weeks, current: false) .group_by_week(:created_at, last: number_of_weeks, current: false)
.count .count
@ -162,7 +162,9 @@ class StatsController < ApplicationController
end end
def contact_percentage 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 to = Date.today.prev_month
adapter = Helpscout::UserConversationsAdapter.new(from, to) adapter = Helpscout::UserConversationsAdapter.new(from, to)

View file

@ -228,20 +228,17 @@ describe StatsController, type: :controller do
it 'returns weekly ratios between a given feedback and all feedback' do it 'returns weekly ratios between a given feedback and all feedback' do
happy_data = stats.find { |g| g[:name] == 'Satisfaits' }[:data] 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[-4]).to eq 0
expect(happy_data.values[2]).to eq 0 expect(happy_data.values[-3]).to eq 25.0
expect(happy_data.values[3]).to eq 25.0 expect(happy_data.values[-2]).to eq 50.0
expect(happy_data.values[4]).to eq 50.0 expect(happy_data.values[-1]).to eq 75.0
expect(happy_data.values[5]).to eq 75.0
unhappy_data = stats.find { |g| g[:name] == 'Mécontents' }[:data] unhappy_data = stats.find { |g| g[:name] == 'Mécontents' }[:data]
expect(unhappy_data.values[0]).to eq 0 expect(unhappy_data.values[-4]).to eq 0
expect(unhappy_data.values[1]).to eq 0 expect(unhappy_data.values[-3]).to eq 75.0
expect(unhappy_data.values[2]).to eq 0 expect(unhappy_data.values[-2]).to eq 50.0
expect(unhappy_data.values[3]).to eq 75.0 expect(unhappy_data.values[-1]).to eq 25.0
expect(unhappy_data.values[4]).to eq 50.0
expect(unhappy_data.values[5]).to eq 25.0
end end
it 'excludes values still in the current week' do it 'excludes values still in the current week' do