baseball 0.4.0 → 1.0.0

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
  SHA256:
3
- metadata.gz: 3282ac577b06b9350a668b2f4c8731e79b798514b4d226a2c9c8cc2365383135
4
- data.tar.gz: b97971236e840d43777772ac7dbc26e64a194a12aa2605c2ac1c4b2fe9f8c7d6
3
+ metadata.gz: 89ba7861f9a4ff6ab8eb9e593ce96fd98d6ad93ff6fecf95d18ef755bfeeac51
4
+ data.tar.gz: e397f50bca09a4954b1eca3b7111dd5d0445712d37608633a92240e80f3b7cc3
5
5
  SHA512:
6
- metadata.gz: 56aa6a66e48a6e7f5eb431ec5616421ef9ce8262c2023c8c133c59e0966679ee3202911ffd75b3e1b6a5a606d332b685fbbd348ab6e065096435751011c03c26
7
- data.tar.gz: 445fd6f352b879b7e664e88aa95414c88e87732b96d85df96fe9c8bb169adf181754c6132a044fb25e6a19f5028435716a294501b2fae7466b22d670182b1005
6
+ metadata.gz: ebaaad7c2bf243d2fb2a0fed2cceb220ce6f89ca778b0c2d49b481f979c8ffbc2d429005cbfba187eb16fd4fcb14a923ad6d205667af62c6d1d1a5e49a546f85
7
+ data.tar.gz: aafd95eee82921c51f340a03191b74b19e7441c0d8c71d3564ffe5365fc5020b0cf8e96fd48e3a7f891ecdf33d59d31ae7ea543afd3514736f75015cc2769aa8
data/README.md CHANGED
@@ -73,6 +73,9 @@ Baseball.ops(your_player_hash)
73
73
 
74
74
  All values are returned as a string
75
75
 
76
+ Libary includes pitching, fielding, running, and batting stats. See tests for full hash key-values needed.
77
+ (More detailed documentation will be added shortly)
78
+
76
79
  ## Development
77
80
 
78
81
  After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -11,6 +11,7 @@ module Baseball
11
11
  #batter stats
12
12
  #pitcher stats
13
13
  # fielder stats
14
+ # runner stats
14
15
 
15
16
  def self.version_number
16
17
  Baseball::VERSION
@@ -43,6 +44,7 @@ module Baseball
43
44
  end
44
45
 
45
46
  #pitcher stats
47
+
46
48
  def self.era(pitcher_hash)
47
49
  include Pitching
48
50
  pitcher = Pitcher.new(pitcher_hash)
@@ -55,17 +57,32 @@ module Baseball
55
57
  pitcher.whip
56
58
  end
57
59
 
60
+ def self.k_per_nine(pitcher_hash)
61
+ include Pitching
62
+ pitcher = Pitcher.new(pitcher_hash)
63
+ pitcher.k_per_nine
64
+ end
65
+
58
66
  #fielder stats
67
+
59
68
  def self.fielding_percentage(fielder_hash)
60
69
  include Fielding
61
70
  fielder = Fielder.new(fielder_hash)
62
71
  fielder.fielding_percentage
63
72
  end
64
73
 
74
+ # runner stats
75
+
65
76
  def self.stolen_base_percentage(runner_hash)
66
77
  include Running
67
78
  runner = Runner.new(runner_hash)
68
79
  runner.stolen_base_percentage
69
80
  end
70
81
 
82
+ def self.stolen_base_runs(runner_hash)
83
+ include Running
84
+ runner = Runner.new(runner_hash)
85
+ runner.stolen_base_runs
86
+ end
87
+
71
88
  end
@@ -21,10 +21,7 @@ module Batting
21
21
  end
22
22
 
23
23
  def slugging_percentage
24
- player_doubles = @player[:doubles] * 2
25
- player_triples = @player[:triples] * 3
26
- player_hr = @player[:hr] * 4
27
- total_bases = @player[:singles] + player_doubles + player_triples + player_hr
24
+ total_bases = @player[:singles] + (@player[:doubles] * 2) + (@player[:triples] * 3) + @player[:hr] * 4
28
25
  slg = total_bases.to_f / @player[:at_bats].to_f
29
26
  slg = slg.round(3)
30
27
  slg_string = slg.to_s.sub!("0", "")
@@ -34,7 +31,22 @@ module Batting
34
31
  def ops
35
32
  player_ops = self.obp.to_f + self.slugging_percentage.to_f
36
33
  player_ops_string = player_ops.round(3)
37
- player_ops_string.to_s
34
+ player_ops_string = player_ops_string.to_s
35
+ if player_ops_string[0] === "0"
36
+ player_ops_string.to_s.sub!("0", "")
37
+ else
38
+ return player_ops_string
39
+ end
40
+ end
41
+
42
+ def base_runs
43
+ # a = hits + walks - hr
44
+ # b = (1.4 * totalbases - .6 * hits - 3 * HR + .1 * BB) * 1.02
45
+ # c = AB - Hits
46
+ # D = HR
47
+
48
+ # x = (A * B) / (B + C)
49
+ # x + D
38
50
  end
39
51
 
40
52
  end
@@ -9,7 +9,6 @@ module Fielding
9
9
  plays_plus_errors = plays + @player[:errors]
10
10
  player_avg = plays.to_f / plays_plus_errors.to_f
11
11
  avg = player_avg.round(3)
12
- # code smell - make this a several function called somewhere since this is used over multiple stats
13
12
  fielding_percentage = avg.to_s.sub!("0", "")
14
13
  figure_trailing_zeroes(fielding_percentage)
15
14
  end
@@ -8,14 +8,24 @@ module Pitching
8
8
  earned_runs = @player[:er] * 9
9
9
  avg = earned_runs / @player[:ip].to_f
10
10
  earned_run_average = avg.round(2)
11
+ earned_run_average.to_s
11
12
  end
12
13
 
13
14
  def whip
15
+ corrected_innings = third_inning_handler(@player[:ip]).to_f
14
16
  walks_plus_hits = @player[:walks] + @player[:hits]
15
- whip = walks_plus_hits / @player[:ip].to_f
16
- whip = whip.round(3)
17
+ figured_whip = walks_plus_hits / corrected_innings
18
+ figured_whip = figured_whip.round(3)
19
+ figured_whip.to_s
20
+ end
21
+
22
+ def k_per_nine
23
+ full_games = @player[:ip] / 9
24
+ so9 = @player[:so] / full_games.to_f
25
+ so9_final = so9.round(1)
26
+ so9_final.to_s
17
27
  end
18
- end
19
28
 
29
+ end
20
30
 
21
31
  end
@@ -8,6 +8,7 @@ module Player
8
8
 
9
9
  def figure_trailing_zeroes(arg)
10
10
  revised_number = arg
11
+
11
12
  if revised_number.length === 3
12
13
  revised_number = "#{revised_number}0"
13
14
  elsif revised_number.length === 2
@@ -17,6 +18,24 @@ module Player
17
18
  end
18
19
  end
19
20
 
21
+ def third_inning_handler(innings)
22
+ innings_string = innings.to_s
23
+ final_fig = innings_string[0..(innings_string.length - 2)]
24
+ final_num = innings_string[(innings_string.length - 2)..innings_string.length].to_f
25
+
26
+ if final_num == 0.1
27
+ returnable_innings = final_fig.to_f
28
+ returnable_innings += 0.33
29
+ returnable_innings.to_s
30
+ elsif final_num == 0.2
31
+ returnable_innings = final_fig.to_f
32
+ returnable_innings += 0.66
33
+ returnable_innings.to_s
34
+ else
35
+ return innings
36
+ end
37
+ end
38
+
20
39
  end
21
40
 
22
41
  end
@@ -12,6 +12,11 @@ module Running
12
12
  end
13
13
 
14
14
  def stolen_base_runs
15
+ stolen_base_adjustment = @player[:stolen_bases].to_f * 0.3
16
+ caught_stealing_adjustment = @player[:caught_stealing].to_f * 0.6
17
+ adjusted_stolen_base_runs = stolen_base_adjustment - caught_stealing_adjustment
18
+ base_runs = adjusted_stolen_base_runs.round(3)
19
+ return base_runs.to_s
15
20
  #Created by Total baseball
16
21
  # (.3 x stolen bases) - (.6 x caught stealing)
17
22
  end
@@ -1,3 +1,3 @@
1
1
  module Baseball
2
- VERSION = "0.4.0"
2
+ VERSION = "1.0.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: baseball
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brent Busby
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-03-16 00:00:00.000000000 Z
11
+ date: 2018-03-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -57,7 +57,6 @@ files:
57
57
  - lib/baseball.rb
58
58
  - lib/baseball/batting.rb
59
59
  - lib/baseball/fielding.rb
60
- - lib/baseball/helper.rb
61
60
  - lib/baseball/pitching.rb
62
61
  - lib/baseball/player.rb
63
62
  - lib/baseball/running.rb
@@ -1,14 +0,0 @@
1
- module Helper
2
-
3
- def figure_trailing_zeroes(arg)
4
- revised_number = arg
5
- if revised_number.length === 3
6
- revised_number = "#{revised_number}0"
7
- elsif revised_number.length === 2
8
- revised_number = "#{revised_number}00"
9
- else
10
- return revised_number
11
- end
12
- end
13
-
14
- end