<% content_for :title, 'Statistics' %>

Statistics

<% if Date.today >= Date.new(2025, 12, 31) %> <%= link_to users_digests_path, class: 'btn btn-outline btn-sm' do %> <%= icon 'earth' %> Year-End Digests <% end %> <% end %>
<%= number_with_delimiter(current_user.total_distance.round) %> <%= current_user.safe_settings.distance_unit %>
Total distance
<%= number_with_delimiter @points_total %>
Geopoints tracked
<% if DawarichSettings.reverse_geocoding_enabled? %> <%= render 'stats/reverse_geocoding_stats' %> <% else %>
<% end %>
All stats data above except for total distance and number of geopoints tracked is being updated daily
<% if current_user.active? %> <%= link_to 'Update stats', update_all_stats_path, data: { turbo_method: :put }, class: 'btn btn-primary mt-5' %> <% end %>
<% @stats.each do |year, stats| %>

<%= link_to year, "/stats/#{year}", class: 'underline hover:no-underline' %> <%= link_to '[Map]', map_url(year_timespan(year)), class: 'underline hover:no-underline' %>
Last update: <%= human_date(stats.first.updated_at) %> <%= link_to icon('refresh-ccw'), update_year_month_stats_path(year, :all), data: { turbo_method: :put }, class: 'text-sm text-gray-500 hover:text-primary' %>

<%= number_with_delimiter year_distance_stat(@year_distances[year], current_user).round %> <%= current_user.safe_settings.distance_unit %>

<% if DawarichSettings.reverse_geocoding_enabled? %>
<% location_data = countries_and_cities_stat_for_year(year, stats) %> <%= link_to "#{location_data[:countries_count]} countries, #{location_data[:cities_count]} cities", "##{location_data[:modal_id]}", class: "link link-primary", onclick: "document.getElementById('#{location_data[:modal_id]}').checked = true" %>
<% end %> <%= column_chart( @year_distances[year].map { |month_name, distance_meters| [month_name, Stat.convert_distance(distance_meters, current_user.safe_settings.distance_unit).round] }, height: '200px', suffix: " #{current_user.safe_settings.distance_unit}", xtitle: 'Days', ytitle: 'Distance', colors: [ '#397bb5', '#5A4E9D', '#3B945E', '#7BC96F', '#FFD54F', '#FFA94D', '#FF6B6B', '#FF8C42', '#C97E4F', '#8B4513', '#5A2E2E', '#265d7d' ] ) %>
<% end %>