From fe50a83780bb1b53521f94609191cd7701e30cbc Mon Sep 17 00:00:00 2001 From: Scott Hillson Date: Mon, 7 Oct 2024 11:01:36 -0700 Subject: [PATCH] Update stats.rb --- app/services/stats.rb | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) 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