Skip to content

Commit

Permalink
Add rake tasks for clearing user stats
Browse files Browse the repository at this point in the history
  • Loading branch information
BGMP committed Feb 29, 2024
1 parent f79b460 commit 19c210d
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions lib/tasks/users.rake
Expand Up @@ -6,4 +6,50 @@ namespace :users do
u.update!
end
end

desc "Set all stats to zero for all users"
task clear_stats: :environment do
User.each do |u|
u.stats.race_wins = 0
u.stats.race_win_rate = 0.0
u.stats.race_podiums = 0
u.stats.race_count = 0
u.stats.positions_sum = 0
u.stats.session_wins = 0
u.stats.session_win_rate = 0.0
u.stats.session_podiums = 0
u.stats.session_count = 0
u.stats.average_position = 0.0
u.stats.participation_rate = 0.0
u.stats.official_score = 0.0
u.stats.obtained_points = 0

u.update!
end
end

desc "Set all stats to zero for a determined user"
task :clear_user_stats, [:username] => :environment do |t, args|
return if args[:username].nil?

u = User.find { |u| u.username.downcase.eql?(args[:username].downcase) }

return if u.nil?

u.stats.race_wins = 0
u.stats.race_win_rate = 0.0
u.stats.race_podiums = 0
u.stats.race_count = 0
u.stats.positions_sum = 0
u.stats.session_wins = 0
u.stats.session_win_rate = 0.0
u.stats.session_podiums = 0
u.stats.session_count = 0
u.stats.average_position = 0.0
u.stats.participation_rate = 0.0
u.stats.official_score = 0.0
u.stats.obtained_points = 0

u.update!
end
end

0 comments on commit 19c210d

Please sign in to comment.