mirror of
https://github.com/Freika/dawarich.git
synced 2026-01-11 17:51:39 -05:00
Scope stats to user
This commit is contained in:
parent
5f18a3051d
commit
cf71df3f0a
4 changed files with 8 additions and 8 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
</h2>
|
||||
<div class='my-10'>
|
||||
<%= column_chart(
|
||||
Stat.year_distance(year),
|
||||
Stat.year_distance(year, current_user),
|
||||
height: '200px',
|
||||
suffix: ' km',
|
||||
xtitle: 'Days',
|
||||
|
|
|
|||
|
|
@ -77,7 +77,7 @@
|
|||
</h2>
|
||||
<p>
|
||||
<% 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 %>
|
||||
</p>
|
||||
<% if REVERSE_GEOCODING_ENABLED %>
|
||||
|
|
@ -88,7 +88,7 @@
|
|||
</div>
|
||||
<% end %>
|
||||
<%= column_chart(
|
||||
Stat.year_distance(year),
|
||||
Stat.year_distance(year, current_user),
|
||||
height: '200px',
|
||||
suffix: ' km',
|
||||
xtitle: 'Days',
|
||||
|
|
|
|||
Loading…
Reference in a new issue