From cf71df3f0abec9760ec87b246c4be155ee2a8569 Mon Sep 17 00:00:00 2001 From: Eugene Burmakin Date: Sat, 25 May 2024 13:45:49 +0200 Subject: [PATCH] Scope stats to user --- app/helpers/application_helper.rb | 6 +++--- app/models/stat.rb | 4 ++-- app/views/stats/_year.html.erb | 2 +- app/views/stats/index.html.erb | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index a32fb095..b853d767 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -37,7 +37,7 @@ module ApplicationHelper %w[info success warning error accent secondary primary] end - def countries_and_cities_stat(year) + def countries_and_cities_stat(year, user) data = Stat.year_cities_and_countries(year, user) countries = data[:countries] cities = data[:cities] @@ -45,8 +45,8 @@ module ApplicationHelper "#{countries} countries, #{cities} cities" end - def year_distance_stat_in_km(year) - Stat.year_distance(year).sum { _1[1] } + def year_distance_stat_in_km(year, user) + Stat.year_distance(year, user).sum { _1[1] } end def past?(year, month) diff --git a/app/models/stat.rb b/app/models/stat.rb index da10fece..5209f8f3 100644 --- a/app/models/stat.rb +++ b/app/models/stat.rb @@ -27,8 +27,8 @@ class Stat < ApplicationRecord end end - def self.year_distance(year) - stats = where(year: year).order(:month) + def self.year_distance(year, user) + stats = where(year:, user:).order(:month) (1..12).to_a.map do |month| month_stat = stats.select { |stat| stat.month == month }.first diff --git a/app/views/stats/_year.html.erb b/app/views/stats/_year.html.erb index 8aa80d00..8971f3ce 100644 --- a/app/views/stats/_year.html.erb +++ b/app/views/stats/_year.html.erb @@ -4,7 +4,7 @@
<%= column_chart( - Stat.year_distance(year), + Stat.year_distance(year, current_user), height: '200px', suffix: ' km', xtitle: 'Days', diff --git a/app/views/stats/index.html.erb b/app/views/stats/index.html.erb index 33508af3..f815239a 100644 --- a/app/views/stats/index.html.erb +++ b/app/views/stats/index.html.erb @@ -77,7 +77,7 @@

<% cache [current_user, 'year_distance_stat_in_km', year], skip_digest: true do %> - <%= number_with_delimiter year_distance_stat_in_km(year) %>km + <%= number_with_delimiter year_distance_stat_in_km(year, current_user) %>km <% end %>

<% if REVERSE_GEOCODING_ENABLED %> @@ -88,7 +88,7 @@
<% end %> <%= column_chart( - Stat.year_distance(year), + Stat.year_distance(year, current_user), height: '200px', suffix: ' km', xtitle: 'Days',