12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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
57
58
59
|
# File 'lib/bb_analytics/models/stats_for_year.rb', line 12
def save
DataStore.instance.db.execute("select * from stats_for_years where player_external_id = ? and year = ? and team = ?",
[self.player_external_id, self.year, self.team]) do |row|
DataStore.instance.db.execute "update stats_for_years " +
"set year = ?, team = ?, games = ?, at_bats = ?, runs =?, " +
"hits = ?, doubles = ?, triples = ?, home_runs = ?, runs_batted_in = ?, " +
"stolen_bases = ?, caught_stealing = ?, batting_average = ?, slugging_percentage = ?, fantasy_points = ? " +
"where player_external_id = ?",
[(self.year.present? ? self.year : row[1]),
(self.team.present? ? self.team : row[2]),
(self.games.present? ? self.games : row[3]),
(self.at_bats.present? ? self.at_bats : row[4]),
(self.runs.present? ? self.runs : row[5]),
(self.hits.present? ? self.hits : row[6]),
(self.doubles.present? ? self.doubles : row[7]),
(self.triples.present? ? self.triples : row[8]),
(self.home_runs.present? ? self.home_runs : row[9]),
(self.runs_batted_in.present? ? self.runs_batted_in : row[10]),
(self.stolen_bases.present? ? self.stolen_bases : row[11]),
(self.caught_stealing.present? ? self.caught_stealing : row[12]),
(self.batting_average.present? ? self.batting_average : row[13]),
(self.slugging_percentage.present? ? self.slugging_percentage : row[14]),
(self.fantasy_points.present? ? self.fantasy_points : row[15]),
self.player_external_id]
return
end
DataStore.instance.db.execute "insert into stats_for_years values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)",
[self.player_external_id,
self.year,
self.team,
self.games,
self.at_bats,
self.runs,
self.hits,
self.doubles,
self.triples,
self.home_runs,
self.runs_batted_in,
self.stolen_bases,
self.caught_stealing,
self.batting_average,
self.slugging_percentage,
self.fantasy_points]
end
|