diff --git a/app/services/stats.rb b/app/services/stats.rb index c20597e91..1a05e0481 100644 --- a/app/services/stats.rb +++ b/app/services/stats.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true module Stats - def years + def self.years %w[2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024] end @@ -36,26 +36,12 @@ def self.racer_days_by_discipline def self.total_racer_days return Rails.cache.read("total_racer_days") if Rails.cache.read("total_racer_days").present? - chart_data = [] - Discipline.pluck(:name).each do |discipline| - chart_data.push({ name: discipline, data: [] }) - end + chart_data = [{ name: "Total Racer Days", data: [] }] years.each do |year| res = Result.joins(:event).where(events: { year: year, type: "SingleDayEvent" }) .where(competition_result: false, team_competition_result: false) .where.not(person_id: nil).count - chart_data.each do |data| - if res[data[:name]].nil? - data[:data].push(0) - else - data[:data].push(res[data[:name]]) - end - end - end - chart_data.each do |data| - if data[:data].sum.zero? - chart_data.delete(data) - end + chart_data[0][:data].push(res) end Rails.cache.write("total_racer_days", chart_data, expires_in: 12.hours) chart_data