2024-06-07 15:22:57 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
2024-03-23 15:29:55 -04:00
|
|
|
class StatsController < ApplicationController
|
|
|
|
|
before_action :authenticate_user!
|
|
|
|
|
|
|
|
|
|
def index
|
2024-06-07 15:22:57 -04:00
|
|
|
@stats = current_user.stats.group_by(&:year).sort.reverse
|
2024-12-02 08:44:22 -05:00
|
|
|
@points_total = current_user.tracked_points.count
|
|
|
|
|
@points_reverse_geocoded = current_user.total_reverse_geocoded_points
|
|
|
|
|
@points_reverse_geocoded_without_data = current_user.total_reverse_geocoded_points_without_data
|
2024-03-23 15:29:55 -04:00
|
|
|
end
|
2024-03-24 14:25:33 -04:00
|
|
|
|
2024-03-24 14:46:55 -04:00
|
|
|
def show
|
|
|
|
|
@year = params[:year].to_i
|
2024-03-28 10:11:59 -04:00
|
|
|
@stats = current_user.stats.where(year: @year).order(:month)
|
2024-03-24 14:46:55 -04:00
|
|
|
end
|
|
|
|
|
|
2024-03-24 14:25:33 -04:00
|
|
|
def update
|
2024-12-06 10:52:36 -05:00
|
|
|
current_user.years_tracked.each do |year|
|
|
|
|
|
(1..12).each do |month|
|
|
|
|
|
Stats::CalculatingJob.perform_later(current_user.id, year, month)
|
|
|
|
|
end
|
|
|
|
|
end
|
2024-03-24 14:25:33 -04:00
|
|
|
|
|
|
|
|
redirect_to stats_path, notice: 'Stats are being updated', status: :see_other
|
|
|
|
|
end
|
2024-03-23 15:29:55 -04:00
|
|
|
end
|