mirror of
https://github.com/Freika/dawarich.git
synced 2026-01-11 09:41:40 -05:00
Add a new page to show stats for a specific year
This commit is contained in:
parent
96a9900661
commit
2953ca6499
7 changed files with 41 additions and 17 deletions
|
|
@ -5,6 +5,11 @@ class StatsController < ApplicationController
|
||||||
@stats = current_user.stats.group_by(&:year).sort_by { _1 }.reverse
|
@stats = current_user.stats.group_by(&:year).sort_by { _1 }.reverse
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def show
|
||||||
|
@year = params[:year].to_i
|
||||||
|
@stats = current_user.stats.where(year: @year)
|
||||||
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
StatCreatingJob.perform_later(current_user.id)
|
StatCreatingJob.perform_later(current_user.id)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -30,4 +30,10 @@ class Stat < ApplicationRecord
|
||||||
[data[:day], data[:distance].round(2)]
|
[data[:day], data[:distance].round(2)]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.year_distance(year)
|
||||||
|
stats = where(year: year).order(:month)
|
||||||
|
|
||||||
|
stats.map { |stat| [Date::MONTHNAMES[stat.month], stat.distance] }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -10,13 +10,13 @@
|
||||||
<div class="card-actions justify-end">
|
<div class="card-actions justify-end">
|
||||||
<%= stat.toponyms.count %> countries, <%= stat.toponyms.sum { _1['cities'].count } %> cities
|
<%= stat.toponyms.count %> countries, <%= stat.toponyms.sum { _1['cities'].count } %> cities
|
||||||
</div>
|
</div>
|
||||||
<%= column_chart(
|
|
||||||
stat.daily_distance,
|
|
||||||
height: '100px',
|
|
||||||
suffix: ' km',
|
|
||||||
xtitle: 'Days',
|
|
||||||
ytitle: 'Distance'
|
|
||||||
) %>
|
|
||||||
<% end %>
|
<% end %>
|
||||||
|
<%= column_chart(
|
||||||
|
stat.daily_distance,
|
||||||
|
height: '100px',
|
||||||
|
suffix: ' km',
|
||||||
|
xtitle: 'Days',
|
||||||
|
ytitle: 'Distance'
|
||||||
|
) %>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
18
app/views/stats/_year.html.erb
Normal file
18
app/views/stats/_year.html.erb
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
<h2 class='text-3xl font-bold mt-10'>
|
||||||
|
<%= link_to year, "/stats/#{year}", class: 'underline hover:no-underline' %>
|
||||||
|
<%= link_to '[Map]', points_url(year_timespan(year)), class: 'underline hover:no-underline' %>
|
||||||
|
</h2>
|
||||||
|
<div class='my-10'>
|
||||||
|
<%= column_chart(
|
||||||
|
Stat.year_distance(year),
|
||||||
|
height: '200px',
|
||||||
|
suffix: ' km',
|
||||||
|
xtitle: 'Days',
|
||||||
|
ytitle: 'Distance'
|
||||||
|
) %>
|
||||||
|
</div>
|
||||||
|
<div class="mt-5 grid grid-cols-1 sm:grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6 p-4">
|
||||||
|
<% stats.each do |stat| %>
|
||||||
|
<%= render stat %>
|
||||||
|
<% end %>
|
||||||
|
</div>
|
||||||
|
|
@ -41,15 +41,6 @@
|
||||||
<%= link_to 'Update stats', stats_path, method: :post, class: 'btn btn-primary mt-5' %>
|
<%= link_to 'Update stats', stats_path, method: :post, class: 'btn btn-primary mt-5' %>
|
||||||
|
|
||||||
<% @stats.each do |year, stats| %>
|
<% @stats.each do |year, stats| %>
|
||||||
<h2 class='text-3xl font-bold mt-10'>
|
<%= render partial: 'stats/year', locals: { year: year, stats: stats } %>
|
||||||
<%= link_to points_url(year_timespan(year)), class: 'underline hover:no-underline' do %>
|
|
||||||
<%= year %>
|
|
||||||
<% end %>
|
|
||||||
</h2>
|
|
||||||
<div class="mt-5 grid grid-cols-1 sm:grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6 p-4">
|
|
||||||
<% stats.each do |stat| %>
|
|
||||||
<%= render stat %>
|
|
||||||
<% end %>
|
|
||||||
</div>
|
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
3
app/views/stats/show.html.erb
Normal file
3
app/views/stats/show.html.erb
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
<div class="w-full">
|
||||||
|
<%= render partial: 'stats/year', locals: { year: @year, stats: @stats } %>
|
||||||
|
</div>
|
||||||
|
|
@ -6,6 +6,7 @@ Rails.application.routes.draw do
|
||||||
post :update
|
post :update
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
get 'stats/:year', to: 'stats#show', constraints: { year: /\d{4}/ }
|
||||||
|
|
||||||
root to: 'home#index'
|
root to: 'home#index'
|
||||||
devise_for :users
|
devise_for :users
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue