rpi-calculator 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/crashing_the_dance/rpi_calculator.rb +30 -2
- data/lib/crashing_the_dance/rpi_calculator/opponent_game.rb +4 -0
- data/lib/crashing_the_dance/rpi_calculator/rpi.rb +163 -6
- data/lib/crashing_the_dance/rpi_calculator/version.rb +1 -1
- data/spec/fixtures/games-palm-conference.csv +23 -0
- data/spec/fixtures/games-palm-nonconference.csv +23 -0
- data/spec/fixtures/teams-palm-conference.csv +12 -0
- data/spec/fixtures/teams-palm-nonconference.csv +12 -0
- data/spec/lib/rpi_calculator_spec.rb +162 -0
- data/spec/spec_helper.rb +6 -2
- metadata +10 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1f53e5620fb6cc90d905cfbf6f55a29a27fb6f79
|
4
|
+
data.tar.gz: 42d390dc079ed74c5dcef40544c6a6ae047f8cd5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 345b0c263347bd011edd83ab3da855c5ec79eff9729132b6b35764f3a4bb956d8cca756723a32939390cffaff18b1222f49b95b73e953119da37a73068eef0ba
|
7
|
+
data.tar.gz: 1fa7c9b66c0328ea12646bff5658341fa3136afe3285a30c4dd20bca9ae37193844b184fd678a0d6706ef66036ade9848b43ba067338ad6301931504aec08e70
|
@@ -9,9 +9,13 @@ module CrashingTheDance
|
|
9
9
|
# also use fixtures to test them. simple, lightweight.
|
10
10
|
def self.calculate(teams, games)
|
11
11
|
by_team = games_by_team(teams, games)
|
12
|
-
teams =
|
12
|
+
teams = build_rpi teams, by_team
|
13
13
|
calculate_owp teams, by_team
|
14
14
|
calculate_oowp teams
|
15
|
+
calculate_conference_owp teams, by_team
|
16
|
+
calculate_conference_oowp teams
|
17
|
+
calculate_nonconference_owp teams, by_team
|
18
|
+
calculate_nonconference_oowp teams
|
15
19
|
teams
|
16
20
|
end
|
17
21
|
|
@@ -29,7 +33,31 @@ module CrashingTheDance
|
|
29
33
|
end
|
30
34
|
end
|
31
35
|
|
32
|
-
def self.
|
36
|
+
def self.calculate_conference_oowp(teams)
|
37
|
+
teams.each do |team|
|
38
|
+
team.calculate_conference_oowp teams
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.calculate_conference_owp(teams, games_by_team)
|
43
|
+
teams.each do |team|
|
44
|
+
team.calculate_conference_owp(games_by_team)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.calculate_nonconference_oowp(teams)
|
49
|
+
teams.each do |team|
|
50
|
+
team.calculate_nonconference_oowp teams
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.calculate_nonconference_owp(teams, games_by_team)
|
55
|
+
teams.each do |team|
|
56
|
+
team.calculate_nonconference_owp(games_by_team)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def self.build_rpi(teams, games_by_team)
|
33
61
|
teams.map { |team| RPI.new team, games_by_team[team] }
|
34
62
|
end
|
35
63
|
|
@@ -1,14 +1,19 @@
|
|
1
1
|
module CrashingTheDance
|
2
2
|
module RpiCalculator
|
3
3
|
class RPI
|
4
|
-
attr_reader :team,
|
4
|
+
attr_reader :team,
|
5
|
+
:games, :games_conference, :games_nonconference,
|
6
|
+
:wins, :losses,
|
7
|
+
:rpi_wins, :rpi_losses,
|
8
|
+
:wins_conference, :losses_conference,
|
9
|
+
:rpi_wins_conference, :rpi_losses_conference,
|
10
|
+
:wins_nonconference, :losses_nonconference,
|
11
|
+
:rpi_wins_nonconference, :rpi_losses_nonconference
|
5
12
|
|
6
13
|
def initialize(team, games)
|
7
14
|
@team = team
|
8
|
-
|
9
|
-
|
10
|
-
@oowp = 0.0
|
11
|
-
@rpi = nil
|
15
|
+
initialize_games(games)
|
16
|
+
initialize_rpi
|
12
17
|
calculate_record
|
13
18
|
end
|
14
19
|
|
@@ -28,6 +33,22 @@ module CrashingTheDance
|
|
28
33
|
end
|
29
34
|
end
|
30
35
|
|
36
|
+
def rpi_win_percentage_conference
|
37
|
+
if games_conference.count > 0
|
38
|
+
rpi_wins_conference / (rpi_wins_conference + rpi_losses_conference)
|
39
|
+
else
|
40
|
+
0.0
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def rpi_win_percentage_nonconference
|
45
|
+
if games_nonconference.count > 0
|
46
|
+
rpi_wins_nonconference / (rpi_wins_nonconference + rpi_losses_nonconference)
|
47
|
+
else
|
48
|
+
0.0
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
31
52
|
def owp
|
32
53
|
@owp
|
33
54
|
end
|
@@ -36,10 +57,34 @@ module CrashingTheDance
|
|
36
57
|
@oowp
|
37
58
|
end
|
38
59
|
|
60
|
+
def owp_conference
|
61
|
+
@owp_conference
|
62
|
+
end
|
63
|
+
|
64
|
+
def oowp_conference
|
65
|
+
@oowp_conference
|
66
|
+
end
|
67
|
+
|
68
|
+
def owp_nonconference
|
69
|
+
@owp_nonconference
|
70
|
+
end
|
71
|
+
|
72
|
+
def oowp_nonconference
|
73
|
+
@oowp_nonconference
|
74
|
+
end
|
75
|
+
|
39
76
|
def rpi
|
40
77
|
@rpi ||= calculate_rpi
|
41
78
|
end
|
42
79
|
|
80
|
+
def rpi_conference
|
81
|
+
@rpi_conference ||= calculate_rpi_conference
|
82
|
+
end
|
83
|
+
|
84
|
+
def rpi_nonconference
|
85
|
+
@rpi_nonconference ||= calculate_rpi_nonconference
|
86
|
+
end
|
87
|
+
|
43
88
|
# To calculate opponent's winning percentage (OWP), you remove games against
|
44
89
|
# the team in question.
|
45
90
|
# However, for the purpose of calculating OWP and OOWP, use standard WP.
|
@@ -66,12 +111,84 @@ module CrashingTheDance
|
|
66
111
|
end
|
67
112
|
end
|
68
113
|
|
114
|
+
# hate this repitition but not yet sure how to consolidate
|
115
|
+
# the logic is roughly the same, but they
|
116
|
+
# set separate instance variables
|
117
|
+
def calculate_conference_owp(games_by_team)
|
118
|
+
if games_conference.count > 0
|
119
|
+
sum_owp = games_conference.inject(0.0) do |sum, game|
|
120
|
+
sked = opponent_schedule game.opponent, games_by_team
|
121
|
+
ow = sked.inject(0) { |wins, og| wins + og.wins }
|
122
|
+
sum + (sked.empty? ? 0.0 : (ow.to_f / sked.count.to_f))
|
123
|
+
end
|
124
|
+
@owp_conference = sum_owp / games_conference.count.to_f
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
def calculate_conference_oowp(all_teams)
|
129
|
+
if games_conference.count > 0
|
130
|
+
sum_oowp = games_conference.inject(0.0) do |sum, game|
|
131
|
+
opponent = all_teams.find { |t| game.opponent.eql? t.team }
|
132
|
+
sum + opponent.owp
|
133
|
+
end
|
134
|
+
@oowp_conference = sum_oowp / games_conference.count.to_f
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
def calculate_nonconference_owp(games_by_team)
|
139
|
+
if games_nonconference.count > 0
|
140
|
+
sum_owp = games_nonconference.inject(0.0) do |sum, game|
|
141
|
+
sked = opponent_schedule game.opponent, games_by_team
|
142
|
+
ow = sked.inject(0) { |wins, og| wins + og.wins }
|
143
|
+
sum + (sked.empty? ? 0.0 : (ow.to_f / sked.count.to_f))
|
144
|
+
end
|
145
|
+
@owp_nonconference = sum_owp / games_nonconference.count.to_f
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
def calculate_nonconference_oowp(all_teams)
|
150
|
+
if games_nonconference.count > 0
|
151
|
+
sum_oowp = games_nonconference.inject(0.0) do |sum, game|
|
152
|
+
opponent = all_teams.find { |t| game.opponent.eql? t.team }
|
153
|
+
sum + opponent.owp
|
154
|
+
end
|
155
|
+
@oowp_nonconference = sum_oowp / games_nonconference.count.to_f
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
69
159
|
private
|
70
160
|
|
161
|
+
def initialize_games(games)
|
162
|
+
@games = games
|
163
|
+
@games_conference = games.select { |game| game.conference? }
|
164
|
+
@games_nonconference = games.reject { |game| game.conference? }
|
165
|
+
end
|
166
|
+
|
167
|
+
def initialize_rpi
|
168
|
+
@owp = 0.0
|
169
|
+
@oowp = 0.0
|
170
|
+
@owp_conference = 0.0
|
171
|
+
@oowp_conference = 0.0
|
172
|
+
@owp_nonconference = 0.0
|
173
|
+
@oowp_nonconference = 0.0
|
174
|
+
@rpi = nil
|
175
|
+
@rpi_conference = nil
|
176
|
+
@rpi_nonconference = nil
|
177
|
+
end
|
178
|
+
|
71
179
|
def calculate_rpi
|
72
180
|
0.25 * rpi_win_percentage + 0.5 * owp + 0.25 * oowp
|
73
181
|
end
|
74
182
|
|
183
|
+
# these are common, how can we consolidate?
|
184
|
+
def calculate_rpi_conference
|
185
|
+
0.25 * rpi_win_percentage_conference + 0.5 * owp_conference + 0.25 * oowp_conference
|
186
|
+
end
|
187
|
+
|
188
|
+
def calculate_rpi_nonconference
|
189
|
+
0.25 * rpi_win_percentage_nonconference + 0.5 * owp_nonconference + 0.25 * oowp_nonconference
|
190
|
+
end
|
191
|
+
|
75
192
|
# filters out games against this team
|
76
193
|
def opponent_schedule(opponent, games_by_team)
|
77
194
|
all = games_by_team[opponent] || []
|
@@ -80,13 +197,53 @@ module CrashingTheDance
|
|
80
197
|
|
81
198
|
# w/l is commonly used, so can we extract it to a module?
|
82
199
|
def calculate_record
|
200
|
+
initialize_wl
|
201
|
+
initialize_wl_conference
|
202
|
+
initialize_wl_nonconference
|
203
|
+
games.each do |game|
|
204
|
+
calculate_wl game
|
205
|
+
calculate_wl_conference game
|
206
|
+
calculate_wl_nonconference game
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
210
|
+
def initialize_wl
|
83
211
|
@wins = @rpi_wins = 0
|
84
212
|
@losses = @rpi_losses = 0
|
85
|
-
|
213
|
+
end
|
214
|
+
|
215
|
+
def initialize_wl_conference
|
216
|
+
@wins_conference = @rpi_wins_conference = 0
|
217
|
+
@losses_conference = @rpi_losses_conference = 0
|
218
|
+
end
|
219
|
+
|
220
|
+
def initialize_wl_nonconference
|
221
|
+
@wins_nonconference = @rpi_wins_nonconference = 0
|
222
|
+
@losses_nonconference = @rpi_losses_nonconference = 0
|
223
|
+
end
|
224
|
+
|
225
|
+
def calculate_wl(game)
|
86
226
|
@wins += 1 if game.win?
|
87
227
|
@losses += 1 if game.loss?
|
88
228
|
@rpi_wins += game.rpi_wins
|
89
229
|
@rpi_losses += game.rpi_losses
|
230
|
+
end
|
231
|
+
|
232
|
+
def calculate_wl_conference(game)
|
233
|
+
if game.conference?
|
234
|
+
@wins_conference += 1 if game.win?
|
235
|
+
@losses_conference += 1 if game.loss?
|
236
|
+
@rpi_wins_conference += game.rpi_wins
|
237
|
+
@rpi_losses_conference += game.rpi_losses
|
238
|
+
end
|
239
|
+
end
|
240
|
+
|
241
|
+
def calculate_wl_nonconference(game)
|
242
|
+
unless game.conference?
|
243
|
+
@wins_nonconference += 1 if game.win?
|
244
|
+
@losses_nonconference += 1 if game.loss?
|
245
|
+
@rpi_wins_nonconference += game.rpi_wins
|
246
|
+
@rpi_losses_nonconference += game.rpi_losses
|
90
247
|
end
|
91
248
|
end
|
92
249
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
vis_team,vis_score,home_team,home_score,neutral,conference
|
2
|
+
Notre Dame,0,Valparaiso,1,,C
|
3
|
+
Valparaiso,1,Indiana,0,,C
|
4
|
+
Valparaiso,0,Purdue,1,,C
|
5
|
+
Michigan State,0,Notre Dame,1,
|
6
|
+
Notre Dame,0,Purdue,1
|
7
|
+
Notre Dame,0,IUPUI,1
|
8
|
+
Indiana,0,Kentucky,1
|
9
|
+
Indiana,0,Ball State,1
|
10
|
+
Duke,0,Purdue,1,N
|
11
|
+
UCLA,0,Purdue,1
|
12
|
+
IUPUI,0,Duke,1,N
|
13
|
+
Duke,1,IUPUI,0,
|
14
|
+
IUPUI,0,Duke,1,
|
15
|
+
IUPUI,0,Duke,1
|
16
|
+
IUPUI,0,UCLA,1
|
17
|
+
Ball State,0,UCLA,1
|
18
|
+
UCLA,1,Ball State,0
|
19
|
+
Kentucky,0,Ball State,1
|
20
|
+
Schmoo,0,Michigan State,1
|
21
|
+
Schmoo,0,Michigan State,1
|
22
|
+
Schmoo,0,Kentucky,1
|
23
|
+
Schmoo,0,Kentucky,1,N
|
@@ -0,0 +1,23 @@
|
|
1
|
+
vis_team,vis_score,home_team,home_score,neutral,conference
|
2
|
+
Notre Dame,0,Valparaiso,1,,
|
3
|
+
Valparaiso,1,Indiana,0,,
|
4
|
+
Valparaiso,0,Purdue,1,,
|
5
|
+
Michigan State,0,Notre Dame,1,
|
6
|
+
Notre Dame,0,Purdue,1
|
7
|
+
Notre Dame,0,IUPUI,1
|
8
|
+
Indiana,0,Kentucky,1
|
9
|
+
Indiana,0,Ball State,1
|
10
|
+
Duke,0,Purdue,1,N
|
11
|
+
UCLA,0,Purdue,1
|
12
|
+
IUPUI,0,Duke,1,N
|
13
|
+
Duke,1,IUPUI,0,
|
14
|
+
IUPUI,0,Duke,1,
|
15
|
+
IUPUI,0,Duke,1
|
16
|
+
IUPUI,0,UCLA,1
|
17
|
+
Ball State,0,UCLA,1
|
18
|
+
UCLA,1,Ball State,0
|
19
|
+
Kentucky,0,Ball State,1
|
20
|
+
Schmoo,0,Michigan State,1
|
21
|
+
Schmoo,0,Michigan State,1
|
22
|
+
Schmoo,0,Kentucky,1
|
23
|
+
Schmoo,0,Kentucky,1,N
|
@@ -70,6 +70,18 @@ describe "RPI calculator" do
|
|
70
70
|
expect(valpo.win_percentage).to be_within(0.0001).of(0.0000)
|
71
71
|
end
|
72
72
|
|
73
|
+
it "calculates the right conference win/loss record" do
|
74
|
+
valpo = @rpi.find { |team| team.team.name.eql? "Valparaiso" }
|
75
|
+
expect(valpo.wins_conference).to eq(0)
|
76
|
+
expect(valpo.losses_conference).to eq(0)
|
77
|
+
end
|
78
|
+
|
79
|
+
it "calculates the right nonconference win/loss record" do
|
80
|
+
valpo = @rpi.find { |team| team.team.name.eql? "Valparaiso" }
|
81
|
+
expect(valpo.wins_nonconference).to eq(0)
|
82
|
+
expect(valpo.losses_nonconference).to eq(0)
|
83
|
+
end
|
84
|
+
|
73
85
|
it "calculates the RPI OWP" do
|
74
86
|
valpo = @rpi.find { |team| team.team.name.eql? "Valparaiso" }
|
75
87
|
expect(valpo.owp).to be_within(0.0001).of(0.0)
|
@@ -84,6 +96,16 @@ describe "RPI calculator" do
|
|
84
96
|
valpo = @rpi.find { |team| team.team.name.eql? "Valparaiso" }
|
85
97
|
expect(valpo.rpi).to be_within(0.0001).of(0.0)
|
86
98
|
end
|
99
|
+
|
100
|
+
it "calculates the conference RPI" do
|
101
|
+
valpo = @rpi.find { |team| team.team.name.eql? "Valparaiso" }
|
102
|
+
expect(valpo.rpi_conference).to be_within(0.0001).of(0.0)
|
103
|
+
end
|
104
|
+
|
105
|
+
it "calculates the nonconference RPI" do
|
106
|
+
valpo = @rpi.find { |team| team.team.name.eql? "Valparaiso" }
|
107
|
+
expect(valpo.rpi_nonconference).to be_within(0.0001).of(0.0)
|
108
|
+
end
|
87
109
|
end
|
88
110
|
|
89
111
|
# This comes from Jerry Palm's example RPI scenario at
|
@@ -102,6 +124,18 @@ describe "RPI calculator" do
|
|
102
124
|
expect(valpo.win_percentage).to be_within(0.0001).of(0.6667)
|
103
125
|
end
|
104
126
|
|
127
|
+
it "calculates the right conference win/loss record" do
|
128
|
+
valpo = @rpi.find { |team| team.team.name.eql? "Valparaiso" }
|
129
|
+
expect(valpo.wins_conference).to eq(0)
|
130
|
+
expect(valpo.losses_conference).to eq(0)
|
131
|
+
end
|
132
|
+
|
133
|
+
it "calculates the right non-conference win/loss record" do
|
134
|
+
valpo = @rpi.find { |team| team.team.name.eql? "Valparaiso" }
|
135
|
+
expect(valpo.wins_nonconference).to eq(2)
|
136
|
+
expect(valpo.losses_nonconference).to eq(1)
|
137
|
+
end
|
138
|
+
|
105
139
|
it "calculates the RPI win/loss record" do
|
106
140
|
valpo = @rpi.find { |team| team.team.name.eql? "Valparaiso" }
|
107
141
|
expect(valpo.rpi_wins).to be_within(0.0001).of(2.0)
|
@@ -125,6 +159,134 @@ describe "RPI calculator" do
|
|
125
159
|
end
|
126
160
|
end
|
127
161
|
|
162
|
+
# the same as the Palm scenario with all Valpo games as conference games
|
163
|
+
# using all games will make it easier to verify ground truth
|
164
|
+
context "the Palm scenario as conference" do
|
165
|
+
before(:each) do
|
166
|
+
@teams = teams_fixture 'palm-conference'
|
167
|
+
games = games_fixture 'palm-conference'
|
168
|
+
@rpi = CrashingTheDance::RpiCalculator.calculate @teams, games
|
169
|
+
end
|
170
|
+
|
171
|
+
it "calculates the right conference win/loss record" do
|
172
|
+
valpo = @rpi.find { |team| team.team.name.eql? "Valparaiso" }
|
173
|
+
expect(valpo.wins_conference).to eq(2)
|
174
|
+
expect(valpo.losses_conference).to eq(1)
|
175
|
+
end
|
176
|
+
|
177
|
+
it "calculates the conference RPI win/loss record" do
|
178
|
+
valpo = @rpi.find { |team| team.team.name.eql? "Valparaiso" }
|
179
|
+
expect(valpo.rpi_wins_conference).to be_within(0.0001).of(2.0)
|
180
|
+
expect(valpo.rpi_losses_conference).to be_within(0.0001).of(0.6)
|
181
|
+
end
|
182
|
+
|
183
|
+
it "calculates the conference RPI" do
|
184
|
+
valpo = @rpi.find { |team| team.team.name.eql? "Valparaiso" }
|
185
|
+
expect(valpo.rpi_conference).to be_within(0.0001).of(0.5777)
|
186
|
+
end
|
187
|
+
|
188
|
+
it "calculates the nonconference RPI" do
|
189
|
+
valpo = @rpi.find { |team| team.team.name.eql? "Valparaiso" }
|
190
|
+
expect(valpo.rpi_nonconference).to be_within(0.0001).of(0.0000)
|
191
|
+
end
|
192
|
+
|
193
|
+
it "calculates the right non-conference win/loss record" do
|
194
|
+
valpo = @rpi.find { |team| team.team.name.eql? "Valparaiso" }
|
195
|
+
expect(valpo.wins_nonconference).to eq(0)
|
196
|
+
expect(valpo.losses_nonconference).to eq(0)
|
197
|
+
end
|
198
|
+
|
199
|
+
it "calculates the non-conference RPI win/loss record" do
|
200
|
+
valpo = @rpi.find { |team| team.team.name.eql? "Valparaiso" }
|
201
|
+
expect(valpo.rpi_wins_nonconference).to be_within(0.0001).of(0.0)
|
202
|
+
expect(valpo.rpi_losses_nonconference).to be_within(0.0001).of(0.0)
|
203
|
+
end
|
204
|
+
|
205
|
+
it "calculates the conference RPI OWP" do
|
206
|
+
valpo = @rpi.find { |team| team.team.name.eql? "Valparaiso" }
|
207
|
+
expect(valpo.owp_conference).to be_within(0.0001).of(0.4444)
|
208
|
+
end
|
209
|
+
|
210
|
+
it "calculates the conference RPI OOWP" do
|
211
|
+
valpo = @rpi.find { |team| team.team.name.eql? "Valparaiso" }
|
212
|
+
expect(valpo.oowp_conference).to be_within(0.0001).of(0.6528)
|
213
|
+
end
|
214
|
+
|
215
|
+
it "calculates the non-conference RPI OWP" do
|
216
|
+
valpo = @rpi.find { |team| team.team.name.eql? "Valparaiso" }
|
217
|
+
expect(valpo.owp_nonconference).to be_within(0.0001).of(0.0000)
|
218
|
+
end
|
219
|
+
|
220
|
+
it "calculates the nonconference RPI OOWP" do
|
221
|
+
valpo = @rpi.find { |team| team.team.name.eql? "Valparaiso" }
|
222
|
+
expect(valpo.oowp_nonconference).to be_within(0.0001).of(0.0000)
|
223
|
+
end
|
224
|
+
end
|
225
|
+
|
226
|
+
# the same as the Palm scenario with all Valpo games as conference games
|
227
|
+
# using all games will make it easier to verify ground truth
|
228
|
+
context "the Palm scenario as nonconference" do
|
229
|
+
before(:each) do
|
230
|
+
@teams = teams_fixture 'palm-nonconference'
|
231
|
+
games = games_fixture 'palm-nonconference'
|
232
|
+
@rpi = CrashingTheDance::RpiCalculator.calculate @teams, games
|
233
|
+
end
|
234
|
+
|
235
|
+
it "calculates the right nonconference win/loss record" do
|
236
|
+
valpo = @rpi.find { |team| team.team.name.eql? "Valparaiso" }
|
237
|
+
expect(valpo.wins_nonconference).to eq(2)
|
238
|
+
expect(valpo.losses_nonconference).to eq(1)
|
239
|
+
end
|
240
|
+
|
241
|
+
it "calculates the nonconference RPI win/loss record" do
|
242
|
+
valpo = @rpi.find { |team| team.team.name.eql? "Valparaiso" }
|
243
|
+
expect(valpo.rpi_wins_nonconference).to be_within(0.0001).of(2.0)
|
244
|
+
expect(valpo.rpi_losses_nonconference).to be_within(0.0001).of(0.6)
|
245
|
+
end
|
246
|
+
|
247
|
+
it "calculates the nonconference RPI" do
|
248
|
+
valpo = @rpi.find { |team| team.team.name.eql? "Valparaiso" }
|
249
|
+
expect(valpo.rpi_nonconference).to be_within(0.0001).of(0.5777)
|
250
|
+
end
|
251
|
+
|
252
|
+
it "calculates the conference RPI" do
|
253
|
+
valpo = @rpi.find { |team| team.team.name.eql? "Valparaiso" }
|
254
|
+
expect(valpo.rpi_conference).to be_within(0.0001).of(0.0000)
|
255
|
+
end
|
256
|
+
|
257
|
+
it "calculates the right conference win/loss record" do
|
258
|
+
valpo = @rpi.find { |team| team.team.name.eql? "Valparaiso" }
|
259
|
+
expect(valpo.wins_conference).to eq(0)
|
260
|
+
expect(valpo.losses_conference).to eq(0)
|
261
|
+
end
|
262
|
+
|
263
|
+
it "calculates the conference RPI win/loss record" do
|
264
|
+
valpo = @rpi.find { |team| team.team.name.eql? "Valparaiso" }
|
265
|
+
expect(valpo.rpi_wins_conference).to be_within(0.0001).of(0.0)
|
266
|
+
expect(valpo.rpi_losses_conference).to be_within(0.0001).of(0.0)
|
267
|
+
end
|
268
|
+
|
269
|
+
it "calculates the nonconference RPI OWP" do
|
270
|
+
valpo = @rpi.find { |team| team.team.name.eql? "Valparaiso" }
|
271
|
+
expect(valpo.owp_nonconference).to be_within(0.0001).of(0.4444)
|
272
|
+
end
|
273
|
+
|
274
|
+
it "calculates the nonconference RPI OOWP" do
|
275
|
+
valpo = @rpi.find { |team| team.team.name.eql? "Valparaiso" }
|
276
|
+
expect(valpo.oowp_nonconference).to be_within(0.0001).of(0.6528)
|
277
|
+
end
|
278
|
+
|
279
|
+
it "calculates the conference RPI OWP" do
|
280
|
+
valpo = @rpi.find { |team| team.team.name.eql? "Valparaiso" }
|
281
|
+
expect(valpo.owp_conference).to be_within(0.0001).of(0.0000)
|
282
|
+
end
|
283
|
+
|
284
|
+
it "calculates the conference RPI OOWP" do
|
285
|
+
valpo = @rpi.find { |team| team.team.name.eql? "Valparaiso" }
|
286
|
+
expect(valpo.oowp_conference).to be_within(0.0001).of(0.0000)
|
287
|
+
end
|
288
|
+
end
|
289
|
+
|
128
290
|
context "full season" do
|
129
291
|
end
|
130
292
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -11,10 +11,14 @@ Team = Struct.new(:name, :id) do
|
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
-
Game = Struct.new(:vis_team, :home_team, :vis_score, :home_score, :neutral) do
|
14
|
+
Game = Struct.new(:vis_team, :home_team, :vis_score, :home_score, :neutral, :conference) do
|
15
15
|
def neutral?
|
16
16
|
!neutral.nil? && neutral == "N"
|
17
17
|
end
|
18
|
+
|
19
|
+
def conference?
|
20
|
+
!conference.nil? && conference == "C"
|
21
|
+
end
|
18
22
|
end
|
19
23
|
|
20
24
|
def games_fixture(which)
|
@@ -29,7 +33,7 @@ def games_fixture(which)
|
|
29
33
|
teams.find { |team| team.name.eql?(row["home_team"]) },
|
30
34
|
row["vis_score"].to_i,
|
31
35
|
row["home_score"].to_i,
|
32
|
-
row["neutral"])
|
36
|
+
row["neutral"], row["conference"])
|
33
37
|
end
|
34
38
|
games
|
35
39
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rpi-calculator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andy Cox
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-12-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -98,8 +98,12 @@ files:
|
|
98
98
|
- lib/crashing_the_dance/rpi_calculator/version.rb
|
99
99
|
- rpi-calculator.gemspec
|
100
100
|
- spec/fixtures/games-onegame.csv
|
101
|
+
- spec/fixtures/games-palm-conference.csv
|
102
|
+
- spec/fixtures/games-palm-nonconference.csv
|
101
103
|
- spec/fixtures/games-palm.csv
|
102
104
|
- spec/fixtures/teams-onegame.csv
|
105
|
+
- spec/fixtures/teams-palm-conference.csv
|
106
|
+
- spec/fixtures/teams-palm-nonconference.csv
|
103
107
|
- spec/fixtures/teams-palm.csv
|
104
108
|
- spec/fixtures/teams-single.csv
|
105
109
|
- spec/lib/opponent_game_spec.rb
|
@@ -131,8 +135,12 @@ specification_version: 4
|
|
131
135
|
summary: On your computer, calculatin' your RPI.
|
132
136
|
test_files:
|
133
137
|
- spec/fixtures/games-onegame.csv
|
138
|
+
- spec/fixtures/games-palm-conference.csv
|
139
|
+
- spec/fixtures/games-palm-nonconference.csv
|
134
140
|
- spec/fixtures/games-palm.csv
|
135
141
|
- spec/fixtures/teams-onegame.csv
|
142
|
+
- spec/fixtures/teams-palm-conference.csv
|
143
|
+
- spec/fixtures/teams-palm-nonconference.csv
|
136
144
|
- spec/fixtures/teams-palm.csv
|
137
145
|
- spec/fixtures/teams-single.csv
|
138
146
|
- spec/lib/opponent_game_spec.rb
|