Skip to content

Commit

Permalink
Update stats.rb
Browse files Browse the repository at this point in the history
  • Loading branch information
scotthillson committed Oct 16, 2024
1 parent eace8d0 commit 2c45a56
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions app/services/stats.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

module Stats
def self.racer_days_by_discipline(years)
if Rails.cache.read("racer_days_by_discipline").present?
return Rails.cache.read("racer_days_by_discipline")
if Rails.cache.read("racer_days_by_discipline #{years}").present?
return Rails.cache.read("racer_days_by_discipline #{years}")
end

chart_data = racer_days_by_discipline_query(years)
Rails.cache.write("racer_days_by_discipline", chart_data, expires_in: 12.hours)
Rails.cache.write("racer_days_by_discipline #{years}", chart_data, expires_in: 12.hours)
chart_data
end

Expand All @@ -34,12 +34,12 @@ def self.racer_days_by_discipline_query(years)
end

def self.racers_by_discipline(years)
if Rails.cache.read("racers_by_discipline").present?
return Rails.cache.read("racers_by_discipline")
if Rails.cache.read("racers_by_discipline #{years}").present?
return Rails.cache.read("racers_by_discipline #{years}")
end

chart_data = racers_by_discipline_query(years)
Rails.cache.write("racers_by_discipline", chart_data, expires_in: 12.hours)
Rails.cache.write("racers_by_discipline #{years}", chart_data, expires_in: 12.hours)
chart_data
end

Expand All @@ -66,19 +66,19 @@ def self.racers_by_discipline_query(years)
end

def self.memberships(years)
return Rails.cache.read("memberships") if Rails.cache.read("memberships").present?
return Rails.cache.read("memberships #{years}") if Rails.cache.read("membership #{years}").present?

chart_data = [{ name: "Memberships", data: [] }]
years.each do |year|
res = LineItem.where(year: year, type: "LineItems::Membership").count
chart_data[0][:data].push(res)
end
Rails.cache.write("memberships", chart_data, expires_in: 12.hours)
Rails.cache.write("memberships #{years}", chart_data, expires_in: 12.hours)
chart_data
end

def self.total_racer_days(years)
return Rails.cache.read("total_racer_days") if Rails.cache.read("total_racer_days").present?
return Rails.cache.read("total_racer_days #{years}") if Rails.cache.read("total_racer_days #{years}").present?

chart_data = [{ name: "Total Racer Days", data: [] }]
years.each do |year|
Expand All @@ -87,12 +87,12 @@ def self.total_racer_days(years)
.where.not(person_id: nil).count
chart_data[0][:data].push(res)
end
Rails.cache.write("total_racer_days", chart_data, expires_in: 12.hours)
Rails.cache.write("total_racer_days #{years}", chart_data, expires_in: 12.hours)
chart_data
end

def self.total_racers(years)
return Rails.cache.read("total_racers") if Rails.cache.read("total_racers").present?
return Rails.cache.read("total_racers #{years}") if Rails.cache.read("total_racers #{years}").present?

chart_data = [{ name: "Racers", data: [] }]
years.each do |year|
Expand All @@ -102,12 +102,12 @@ def self.total_racers(years)
.count(:person_id)
chart_data[0][:data].push(res)
end
Rails.cache.write("total_racers", chart_data, expires_in: 12.hours)
Rails.cache.write("total_racers #{years}", chart_data, expires_in: 12.hours)
chart_data
end

def self.racer_days_by_gender(years)
return Rails.cache.read("racer_days_by_gender") if Rails.cache.read("racer_days_by_gender").present?
return Rails.cache.read("racer_days_by_gender #{years}") if Rails.cache.read("racer_days_by_gender #{years}").present?

chart_data = [
{ name: "Not Specified", data: [] },
Expand All @@ -124,12 +124,12 @@ def self.racer_days_by_gender(years)
chart_data[2][:data].push(res["M"] || 0)
chart_data[3][:data].push(res["NB"] || 0)
end
Rails.cache.write("racer_days_by_gender", chart_data, expires_in: 12.hours)
Rails.cache.write("racer_days_by_gender #{years}", chart_data, expires_in: 12.hours)
chart_data
end

def self.racers_by_gender(years)
return Rails.cache.read("racers_by_gender") if Rails.cache.read("racers_by_gender").present?
return Rails.cache.read("racers_by_gender #{years}") if Rails.cache.read("racers_by_gender #{years}").present?

chart_data = [
{ name: "Not Specified", data: [] },
Expand All @@ -146,12 +146,12 @@ def self.racers_by_gender(years)
chart_data[2][:data].push(res["M"] || 0)
chart_data[3][:data].push(res["NB"] || 0)
end
Rails.cache.write("racers_by_gender", chart_data, expires_in: 12.hours)
Rails.cache.write("racers_by_gender #{years}", chart_data, expires_in: 12.hours)
chart_data
end

def self.gender_ratio(years)
return Rails.cache.read("gender_ratio") if Rails.cache.read("gender_ratio").present?
return Rails.cache.read("gender_ratio #{years}") if Rails.cache.read("gender_ratio #{years}").present?

chart_data = [
{ name: "Not Specified", data: [] },
Expand All @@ -170,12 +170,12 @@ def self.gender_ratio(years)
chart_data[2][:data].push((counts[2] / total).round(2))
chart_data[3][:data].push((counts[3] / total).round(2))
end
Rails.cache.write("gender_ratio", chart_data, expires_in: 12.hours)
Rails.cache.write("gender_ratio #{years}", chart_data, expires_in: 12.hours)
chart_data
end

def self.racer_days_gender_ratio(years)
return Rails.cache.read("racer_days_gender_ratio") if Rails.cache.read("racer_days_gender_ratio").present?
return Rails.cache.read("racer_days_gender_ratio #{years}") if Rails.cache.read("racer_days_gender_ratio #{years}").present?

chart_data = [
{ name: "Not Specified", data: [] },
Expand All @@ -194,12 +194,12 @@ def self.racer_days_gender_ratio(years)
chart_data[2][:data].push((counts[2] / total).round(2))
chart_data[3][:data].push((counts[3] / total).round(2))
end
Rails.cache.write("racer_days_gender_ratio", chart_data, expires_in: 12.hours)
Rails.cache.write("racer_days_gender_ratio #{years}", chart_data, expires_in: 12.hours)
chart_data
end

def self.total_juniors(years)
return Rails.cache.read("total_juniors") if Rails.cache.read("total_juniors").present?
return Rails.cache.read("total_juniors #{years}") if Rails.cache.read("total_juniors #{years}").present?

chart_data = [{ name: "Juniors", data: [] }]
years.each do |year|
Expand All @@ -209,7 +209,7 @@ def self.total_juniors(years)
.count(:person_id)
chart_data[0][:data].push(res)
end
Rails.cache.write("total_juniors", chart_data, expires_in: 12.hours)
Rails.cache.write("total_juniors #{years}", chart_data, expires_in: 12.hours)
chart_data
end
end

0 comments on commit 2c45a56

Please sign in to comment.