Skip to content

Commit

Permalink
Merge pull request #32 from scottwillson/total-juniors
Browse files Browse the repository at this point in the history
Total juniors
  • Loading branch information
scotthillson authored Oct 17, 2024
2 parents 1e40404 + 0c6f7f3 commit c403cad
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions app/services/stats.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

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

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

Expand Down Expand Up @@ -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)
Expand All @@ -185,9 +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(people: { date_of_birth: beginning - 18.years..beginning })
.where(category_id: Category.where("ages_begin > ? AND ages_begin < ?", 0, 19).select(:id))
.where(competition_result: false, team_competition_result: false)
.where.not(person_id: nil)
chart_data[0][:data].push(res)
Expand Down

0 comments on commit c403cad

Please sign in to comment.