30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/bb_analytics/models/importer.rb', line 30
def save_stats_for_year
@csv.keys.each do |key|
csv[key].each do |year|
stats = StatsForYear.new
stats.player_external_id = key
stats.year = year[:yearid]
stats.team = year[:teamid]
stats.games = year[:g]
stats.at_bats = year[:ab]
stats.runs = year[:r]
stats.hits = year[:h]
stats.doubles = year[:'2b']
stats.triples = year[:'3b']
stats.home_runs = year[:hr]
stats.runs_batted_in = year[:rbi]
stats.stolen_bases = year[:sb]
stats.caught_stealing = year[:cs]
stats.calculate_batting_average!
stats.calculate_slugging_percentage!
stats.calculate_fantasy_points!
stats.save if stats.year.present?
stats
end
end
end
|