Skip to content

Instantly share code, notes, and snippets.

@bernsno
Created August 6, 2009 00:54
Show Gist options
  • Save bernsno/163069 to your computer and use it in GitHub Desktop.
Save bernsno/163069 to your computer and use it in GitHub Desktop.
positions = Position.all(:conditions => ["name in (?)", ["wr","rb","te"]])
players = Player.all(:conditions => ["position_id in (?)", positions.map(&:id)])
rec_td_stat_name = StatName.find_by_title("Reception Touchdowns")
rush_td_stat_name = StatName.find_by_title("Rush Touchdowns")
rrtd_stat_name = StatName.find_by_title("Rushing and Receiving Touchdowns")
players.each do |player|
seasons = player.career_seasons
seasons.each do |season|
stats = []
[rec_td_stat_name, rush_td_stat_name].each do |stat_name|
stats << player.career_stats.find_by_season_id_and_stat_name_id(season.id, stat_name).value
end
rrtds = player.career_stats.find_by_season_id_and_stat_name_id(season.id, rrtd_stat_name)
rrts.update_attribute :value, stats.sum
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment