codenamev-baseball-stats 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c417a1b413d90176dc6f70512e1ade4e5960fae3
4
- data.tar.gz: 6720d67cd34ab5e2809ae2774557136c97b31f5a
3
+ metadata.gz: 45ebe0e703bd7bf9dee0b2ab32303330025a34ff
4
+ data.tar.gz: 1b7a93155365db0f0bc41510bacb6913710a8e05
5
5
  SHA512:
6
- metadata.gz: 65e7b299497cf8aafa69c17e010a490cd5cb97ad89ffb39d4b05437d7dede1c775afa49d527c8552850e1e5c3300e124425ecde0d4e3e6992a196311d23c3670
7
- data.tar.gz: 5feca95cba15116f0184d3b9aac2f5ba221795f78f3962f96db25f0c7b0a57aafc098ebd04c95193c50f7e84553f2d59100467a1721dc05661f129ffcb7d4c5c
6
+ metadata.gz: f87502b0a692b26c2ee7512bac41d05a357a9919d23ae49058eede0bdf933c1c401682e89645db055534de12dfa42eb105b976aa9b5b04c1844061b8b3e7da93
7
+ data.tar.gz: 1785c72149a5cbc4e925a047de3a5f14888389d79879fe59a96852e693329dc5fed107333fad50002b730ef6b164abb32a23d65516658dfc852dc395fe20386d
data/.gitignore CHANGED
@@ -3,7 +3,6 @@
3
3
  *.gem
4
4
  *.rbc
5
5
  .bundle
6
- .config
7
6
  .yardoc
8
7
  Gemfile.lock
9
8
  InstalledFiles
@@ -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: "#{(batting.slugging_percentage.to_f * 100).round(2)}%" }
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("#{@db_dir}/config.yml")).freeze
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(player_id: batting[:player_id], year_id: batting[:year_id])
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]
@@ -1,3 +1,3 @@
1
1
  module BaseballStats
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -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: player1.name, slugging_percentage: "22.0%" },
55
- { player: player2.name, slugging_percentage: "44.0%" },
56
- { player: player3.name, slugging_percentage: "68.0%" }
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
@@ -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 16
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: codenamev-baseball-stats
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Valentino Stoll