Add nice statistics

This commit is contained in:
Eugene Burmakin
2024-03-23 21:16:11 +01:00
parent f7b4b6d51f
commit 2e6d05aa40
5 changed files with 40 additions and 36 deletions

View File

@@ -7,4 +7,17 @@ class User < ApplicationRecord
has_many :imports, dependent: :destroy
has_many :points, through: :imports
has_many :stats
def total_km
Stat.where(user: self).sum(:distance)
end
def total_countries
Stat.where(user: self).pluck(:toponyms).flatten.uniq.size
end
def total_cities
Stat.where(user: self).pluck(:toponyms).flatten.size
end
end

View File

@@ -19,10 +19,7 @@
<%= render 'shared/navbar' %>
<%= render 'shared/flash' %>
<div class="flex flex-row gap-5">
<!--div class='w-1/4 mt-10'>
<%#= render 'shared/left_sidebar' %>
</div-->
<div class='w-3/4'>
<div class='w-3/4 mt-10'>
<%= yield %>
</div>
<div class='w-1/4 mt-10'>

View File

@@ -10,7 +10,7 @@
<li><%= link_to 'Stats', stats_url %></li>
</ul>
</div>
<%= link_to 'Dawarich', root_path, class: 'btn btn-ghost normal-case text-xl'%>
<%= link_to 'DaWarIch', root_path, class: 'btn btn-ghost normal-case text-xl mr-10'%>
<label class="flex cursor-pointer gap-2">
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="5"/><path d="M12 1v2M12 21v2M4.2 4.2l1.4 1.4M18.4 18.4l1.4 1.4M1 12h2M21 12h2M4.2 19.8l1.4-1.4M18.4 5.6l1.4-1.4"/></svg>
<input type="checkbox" value="light" class="toggle theme-controller"/>

View File

@@ -1,4 +1,28 @@
<div class="w-full">
<div class="stats shadow w-full bg-base-200">
<div class="stat text-center">
<div class="stat-value text-primary">
<%= number_with_delimiter(current_user.total_km) %> km
</div>
<div class="stat-title">Total distance</div>
</div>
<div class="stat text-center">
<div class="stat-value text-secondary">
<%= current_user.total_countries %>
</div>
<div class="stat-title">Countries visited</div>
</div>
<div class="stat text-center">
<div class="stat-value">
<%= current_user.total_cities %>
</div>
<div class="stat-title">Cities visited</div>
</div>
</div>
<% @stats.each do |year, stats| %>
<h2 class='text-3xl font-bold mt-10'>
<%= link_to points_url(year_timespan(year)), class: 'underline hover:no-underline' do %>

View File

@@ -1,33 +1,3 @@
# Files in the config/locales directory are used for internationalization
# and are automatically loaded by Rails. If you want to use locales other
# than English, add the necessary files in this directory.
#
# To use the locales, use `I18n.t`:
#
# I18n.t "hello"
#
# In views, this is aliased to just `t`:
#
# <%= t("hello") %>
#
# To use a different locale, set it with `I18n.locale`:
#
# I18n.locale = :es
#
# This would use the information in config/locales/es.yml.
#
# The following keys must be escaped otherwise they will not be retrieved by
# the default I18n backend:
#
# true, false, on, off, yes, no
#
# Instead, surround them with single quotes.
#
# en:
# "true": "foo"
#
# To learn more, please read the Rails Internationalization guide
# available at https://guides.rubyonrails.org/i18n.html.
en:
hello: "Hello world"