codenamev-baseball-stats 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +0 -1
- data/lib/baseball_stats.rb +2 -2
- data/lib/baseball_stats/database.rb +1 -1
- data/lib/baseball_stats/import.rb +8 -2
- data/lib/baseball_stats/version.rb +1 -1
- data/spec/baseball_stats_spec.rb +3 -3
- data/spec/lib/import_spec.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 45ebe0e703bd7bf9dee0b2ab32303330025a34ff
|
4
|
+
data.tar.gz: 1b7a93155365db0f0bc41510bacb6913710a8e05
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f87502b0a692b26c2ee7512bac41d05a357a9919d23ae49058eede0bdf933c1c401682e89645db055534de12dfa42eb105b976aa9b5b04c1844061b8b3e7da93
|
7
|
+
data.tar.gz: 1785c72149a5cbc4e925a047de3a5f14888389d79879fe59a96852e693329dc5fed107333fad50002b730ef6b164abb32a23d65516658dfc852dc395fe20386d
|
data/.gitignore
CHANGED
data/lib/baseball_stats.rb
CHANGED
@@ -35,9 +35,9 @@ module BaseballStats
|
|
35
35
|
end
|
36
36
|
|
37
37
|
def slugging_percentage_for_team_and_year(team_id, year)
|
38
|
-
battings_for_team = Batting.includes(:player).with_slugging_percentage.where(team_id: team_id, year_id: year)
|
38
|
+
battings_for_team = Batting.includes(:player).with_slugging_percentage.where(team_id: team_id, year_id: year).order('slugging_percentage DESC')
|
39
39
|
battings_for_team.collect {|batting|
|
40
|
-
{ player: batting.player_name, slugging_percentage: "#{
|
40
|
+
{ player: batting.player_name, slugging_percentage: "#{batting.slugging_percentage.to_f.round(3)}" }
|
41
41
|
}
|
42
42
|
end
|
43
43
|
|
@@ -15,7 +15,7 @@ module BaseballStats
|
|
15
15
|
@connection = nil
|
16
16
|
@root_path = File.expand_path('../../..', __FILE__).freeze
|
17
17
|
@db_dir = File.join(@root_path, 'db').freeze
|
18
|
-
@configuration = YAML::load(IO.read(
|
18
|
+
@configuration = YAML::load(IO.read(File.join(@db_dir, 'config.yml'))).freeze
|
19
19
|
@migrations_paths = [File.join(@root_path, 'db/migrate')].freeze
|
20
20
|
|
21
21
|
attr_accessor :configuration, :db_dir, :migrations_paths
|
@@ -14,14 +14,20 @@ module BaseballStats::Import
|
|
14
14
|
SEED_PLAYERS_CSV = File.expand_path('../../../sample_data/players.csv', __FILE__)
|
15
15
|
|
16
16
|
def seed_data
|
17
|
-
import_battings_from_csv(SEED_BATTINGS_CSV)
|
18
17
|
import_players_from_csv(SEED_PLAYERS_CSV)
|
18
|
+
import_battings_from_csv(SEED_BATTINGS_CSV)
|
19
19
|
end
|
20
20
|
|
21
21
|
def import_battings_from_csv(csv_file)
|
22
22
|
CreateBattings.up unless ActiveRecord::Base.connection.table_exists?('battings')
|
23
23
|
CSV.foreach(csv_file, headers: true, header_converters: :symbol) do |batting|
|
24
|
-
new_batting = BaseballStats::Batting.find_or_create_by(
|
24
|
+
new_batting = BaseballStats::Batting.find_or_create_by(
|
25
|
+
player_id: batting[:player_id],
|
26
|
+
year_id: batting[:year_id],
|
27
|
+
league: batting[:league],
|
28
|
+
team_id: batting[:team_id]
|
29
|
+
)
|
30
|
+
|
25
31
|
new_batting.league = batting[:league]
|
26
32
|
new_batting.team_id = batting[:team_id]
|
27
33
|
new_batting.appearances = batting[:appearances]
|
data/spec/baseball_stats_spec.rb
CHANGED
@@ -51,9 +51,9 @@ describe BaseballStats do
|
|
51
51
|
|
52
52
|
it 'returns an array of hashes for every player for the team for that year and their associated slugging percentage' do
|
53
53
|
expect(subject).to eq([
|
54
|
-
{ player:
|
55
|
-
{ player: player2.name, slugging_percentage: "44
|
56
|
-
{ player:
|
54
|
+
{ player: player3.name, slugging_percentage: "0.68" },
|
55
|
+
{ player: player2.name, slugging_percentage: "0.44" },
|
56
|
+
{ player: player1.name, slugging_percentage: "0.22" }
|
57
57
|
])
|
58
58
|
end
|
59
59
|
end
|
data/spec/lib/import_spec.rb
CHANGED
@@ -16,7 +16,7 @@ describe BaseballStats::Import do
|
|
16
16
|
subject { BaseballStats::Import.import_battings_from_csv(csv_file) }
|
17
17
|
|
18
18
|
it 'imports all battings into the database' do
|
19
|
-
expect{ subject }.to change{ BaseballStats::Batting.count }.to
|
19
|
+
expect{ subject }.to change{ BaseballStats::Batting.count }.to 17
|
20
20
|
end
|
21
21
|
|
22
22
|
it "only imports battings that don't yet exist" do
|