dawarich/app/controllers/stats_controller.rb

28 lines
811 B
Ruby
Raw Normal View History

# frozen_string_literal: true
2024-03-23 15:29:55 -04:00
class StatsController < ApplicationController
before_action :authenticate_user!
def index
@stats = current_user.stats.group_by(&:year).sort.reverse
@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
def show
@year = params[:year].to_i
@stats = current_user.stats.where(year: @year).order(:month)
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