From cc57370d6819593f374fedc8ed2b0dcabd7e5cca Mon Sep 17 00:00:00 2001 From: Scott Hillson Date: Wed, 16 Oct 2024 21:01:52 -0700 Subject: [PATCH 1/4] Update stats.rb --- app/services/stats.rb | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/app/services/stats.rb b/app/services/stats.rb index 5a526d388..b43a19625 100644 --- a/app/services/stats.rb +++ b/app/services/stats.rb @@ -4,11 +4,11 @@ module Stats def self.cache_and_query(method, years) cache_key = "#{method} #{years}" if Rails.cache.read(cache_key).present? - return Rails.cache.read(cache_key) + # return Rails.cache.read(cache_key) end chart_data = send(method, years) - Rails.cache.write(cache_key, chart_data, expires_in: 12.hours) + Rails.cache.write(cache_key, chart_data, expires_in: 24.hours) chart_data end @@ -158,7 +158,7 @@ def self.racer_days_gender_ratio(years) res = Result.joins(:event, :person).where(events: { year: year, type: "SingleDayEvent" }) .where(competition_result: false, team_competition_result: false) .where.not(person_id: nil).group("people.gender").count - counts = [res[nil] || 0, res["F"] || 0, res["M"] || 0, res["NB"] || 0] + counts = [Random.rand(1..100), Random.rand(1..100), Random.rand(1..100), Random.rand(1..100)] total = counts.sum.to_f chart_data[0][:data].push((counts[0] / total).round(4)) chart_data[1][:data].push((counts[1] / total).round(4)) @@ -171,10 +171,9 @@ def self.racer_days_gender_ratio(years) def self.total_juniors(years) chart_data = [{ name: "Juniors", data: [] }] years.each do |year| - beginning = Date.new(year.to_i, 1, 1).beginning_of_year res = Result.joins(:event, :person).where(events: { year: year, type: "SingleDayEvent" }) - .where(people: { date_of_birth: beginning - 18.years..beginning }) .where(competition_result: false, team_competition_result: false) + .where(category_id: Category.where("ages_begin > ? AND ages_begin < ?", 0, 19).select(:id)) .where.not(person_id: nil).distinct .count(:person_id) chart_data[0][:data].push(res) @@ -185,8 +184,8 @@ def self.total_juniors(years) def self.junior_racer_days(years) chart_data = [{ name: "Juniors", data: [] }] years.each do |year| - beginning = Date.new(year.to_i, 1, 1).beginning_of_year res = Result.joins(:event, :person).where(events: { year: year, type: "SingleDayEvent" }) + .where(category_id: Category.where("ages_begin > ? AND ages_begin < ?", 0, 19).select(:id)) .where(people: { date_of_birth: beginning - 18.years..beginning }) .where(competition_result: false, team_competition_result: false) .where.not(person_id: nil) From 629e97fb988faeb7aabc2e88b0fc567c9f03f345 Mon Sep 17 00:00:00 2001 From: Scott Hillson Date: Wed, 16 Oct 2024 21:03:38 -0700 Subject: [PATCH 2/4] Update stats.rb --- app/services/stats.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/services/stats.rb b/app/services/stats.rb index b43a19625..d4e2d604f 100644 --- a/app/services/stats.rb +++ b/app/services/stats.rb @@ -158,7 +158,7 @@ def self.racer_days_gender_ratio(years) res = Result.joins(:event, :person).where(events: { year: year, type: "SingleDayEvent" }) .where(competition_result: false, team_competition_result: false) .where.not(person_id: nil).group("people.gender").count - counts = [Random.rand(1..100), Random.rand(1..100), Random.rand(1..100), Random.rand(1..100)] + counts = [res[nil] || 0, res["F"] || 0, res["M"] || 0, res["NB"] || 0] total = counts.sum.to_f chart_data[0][:data].push((counts[0] / total).round(4)) chart_data[1][:data].push((counts[1] / total).round(4)) @@ -186,7 +186,6 @@ def self.junior_racer_days(years) years.each do |year| res = Result.joins(:event, :person).where(events: { year: year, type: "SingleDayEvent" }) .where(category_id: Category.where("ages_begin > ? AND ages_begin < ?", 0, 19).select(:id)) - .where(people: { date_of_birth: beginning - 18.years..beginning }) .where(competition_result: false, team_competition_result: false) .where.not(person_id: nil) chart_data[0][:data].push(res) From 9ecb5b988764160e0d5e9e54f5bae4f3d849e141 Mon Sep 17 00:00:00 2001 From: Scott Hillson Date: Wed, 16 Oct 2024 21:04:14 -0700 Subject: [PATCH 3/4] Update stats.rb --- app/services/stats.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/services/stats.rb b/app/services/stats.rb index d4e2d604f..10118cf8c 100644 --- a/app/services/stats.rb +++ b/app/services/stats.rb @@ -4,7 +4,7 @@ module Stats def self.cache_and_query(method, years) cache_key = "#{method} #{years}" if Rails.cache.read(cache_key).present? - # return Rails.cache.read(cache_key) + return Rails.cache.read(cache_key) end chart_data = send(method, years) From 0c6f7f34bc9a04a7daf52f0b5482e9fb402d8bec Mon Sep 17 00:00:00 2001 From: Scott Hillson Date: Wed, 16 Oct 2024 21:05:39 -0700 Subject: [PATCH 4/4] Update stats.rb --- app/services/stats.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/services/stats.rb b/app/services/stats.rb index 10118cf8c..1197104e6 100644 --- a/app/services/stats.rb +++ b/app/services/stats.rb @@ -2,7 +2,7 @@ module Stats def self.cache_and_query(method, years) - cache_key = "#{method} #{years}" + cache_key = "#{method} #{years} 10162421" if Rails.cache.read(cache_key).present? return Rails.cache.read(cache_key) end