icu_ratings 1.5.2 → 1.5.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -262,16 +262,19 @@ module ICU
262
262
  def calculate_bonus
263
263
  return if @kfactor <= 24 || @results.size <= 4 || @rating >= 2100
264
264
  change = rating_change
265
+ # Remember the key inputs to the calculation
265
266
  @pb_rating = (@rating + change).round
266
267
  @pb_performance = @performance.round
268
+ # Calculate the bonus.
267
269
  return if change <= 35 || @rating + change >= 2100
268
270
  threshold = 32 + 3 * (@results.size - 4)
269
271
  bonus = (change - threshold).round
270
272
  return if bonus <= 0
271
273
  bonus = (1.25 * bonus).round if kfactor >= 40
272
- [2100, @performance].each { |max| bonus = max - @rating if bonus + @rating > max }
274
+ # Determine if it should be capped or not.
275
+ [2100, @performance].each { |max| bonus = (max - @rating - change).round if @rating + change + bonus >= max }
273
276
  return if bonus <= 0
274
- bonus = bonus.round
277
+ # Store the value.
275
278
  @bonus_rating = @rating + change + bonus
276
279
  @bonus = bonus
277
280
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module ICU
4
4
  class Ratings
5
- VERSION = "1.5.2"
5
+ VERSION = "1.5.3"
6
6
  end
7
7
  end
@@ -744,7 +744,7 @@ module ICU
744
744
  end
745
745
  end
746
746
  end
747
-
747
+
748
748
  it "players eligible for a bonus should have pre-bonus data" do
749
749
  p = @t.player(1)
750
750
  p.pb_rating.should be_kind_of Fixnum
@@ -2256,5 +2256,194 @@ module ICU
2256
2256
  @t.iterations2.should be > 1
2257
2257
  end
2258
2258
  end
2259
+
2260
+ context "#rate - Kieran O'Riordan in the Mulcahy Cup 2012" do
2261
+ before(:each) do
2262
+ @t = ICU::RatedTournament.new(desc: "Mulcahy Cup 2012")
2263
+
2264
+ # Add the players of most interest (Kieran and his opponents).
2265
+ @p = @t.add_player(3976, desc: "Kieran O'Riordan", rating: 1883, kfactor: 40)
2266
+ @o1 = @t.add_player(3966, desc: "Jonathan Kiely", rating: 1113, kfactor: 24)
2267
+ @o2 = @t.add_player(3973, desc: "Donal O'Hallahan", rating: 1465, kfactor: 24)
2268
+ @o3 = @t.add_player(3952, desc: "Arnaud, Aoustin", rating: 1984, kfactor: 32)
2269
+ @o4 = @t.add_player(3968, desc: "Ronan Magee", rating: 1957, kfactor: 40)
2270
+ @o5 = @t.add_player(3961, desc: "Barry Foran", rating: 1417, kfactor: 24)
2271
+ @o6 = @t.add_player(3958, desc: "Henk De Jonge", rating: 1977, kfactor: 32)
2272
+
2273
+ # Add all the other players.
2274
+ @t.add_player(3953, desc: "Joe Browne", rating: 900, kfactor: 24)
2275
+ @t.add_player(3954, desc: "Daniel Cashin", rating: 1393, kfactor: 40)
2276
+ @t.add_player(3955, desc: "Anne B Coughlan", rating: 1224, kfactor: 24)
2277
+ @t.add_player(3956, desc: "Maurice J Coveney", rating: 1270, kfactor: 24)
2278
+ @t.add_player(3957, desc: "Tony Dalton", rating: 1068, kfactor: 24)
2279
+ @t.add_player(3959, desc: "Desmond Doran", rating: 737, kfactor: 40)
2280
+ @t.add_player(3960, desc: "Peter Doyle", rating: 1010, kfactor: 32)
2281
+ @t.add_player(3962, desc: "Jonathan Grimmer")
2282
+ @t.add_player(3963, desc: "Len Hackett", rating: 1569, kfactor: 24)
2283
+ @t.add_player(3964, desc: "Jim Harkin", rating: 1366, kfactor: 32)
2284
+ @t.add_player(3965, desc: "Tom Healy", rating: 1852, kfactor: 24)
2285
+ @t.add_player(3967, desc: "Paul C Kiely", rating: 1815, kfactor: 24)
2286
+ @t.add_player(3969, desc: "Adrian McAuliffe", rating: 1171, games: 19)
2287
+ @t.add_player(3970, desc: "D. Gerry McCarthy", rating: 1754, kfactor: 24)
2288
+ @t.add_player(3971, desc: "Tom McGrath", rating: 982, kfactor: 40)
2289
+ @t.add_player(3972, desc: "Niki Mullins", rating: 1443, kfactor: 24)
2290
+ @t.add_player(3974, desc: "Mark O'Hallahan", rating: 1115, kfactor: 40)
2291
+ @t.add_player(3975, desc: "David O'Kelly", rating: 1487, kfactor: 24)
2292
+ @t.add_player(3977, desc: "Pat O'Riordan", rating: 875, kfactor: 32)
2293
+ @t.add_player(3978, desc: "Marco Piazza", rating: 1511, games: 6)
2294
+ @t.add_player(3979, desc: "Krzysztof Przestrzelski", rating: 942, kfactor: 40)
2295
+ @t.add_player(3980, desc: "Oliver Roberts", rating: 743, kfactor: 40)
2296
+ @t.add_player(3981, desc: "Stephen Short", rating: 1891, kfactor: 24)
2297
+ @t.add_player(3982, desc: "Bernd Thee", rating: 1760, kfactor: 24)
2298
+ @t.add_player(3983, desc: "Pat Twomey", rating: 1728, kfactor: 24)
2299
+
2300
+ # Kieran's results.
2301
+ @t.add_result(1, 3976, 3966, "W")
2302
+ @t.add_result(2, 3976, 3973, "W")
2303
+ @t.add_result(3, 3976, 3952, "D")
2304
+ @t.add_result(4, 3976, 3968, "W")
2305
+ @t.add_result(5, 3976, 3961, "W")
2306
+ @t.add_result(6, 3976, 3958, "D")
2307
+
2308
+ # Other results.
2309
+ @t.add_result(1, 3979, 3970, "L")
2310
+ @t.add_result(1, 3972, 3952, "L")
2311
+ @t.add_result(1, 3980, 3975, "L")
2312
+ @t.add_result(1, 3983, 3971, "D")
2313
+ @t.add_result(1, 3968, 3964, "W")
2314
+ @t.add_result(1, 3973, 3959, "W")
2315
+ @t.add_result(1, 3961, 3958, "L")
2316
+ @t.add_result(1, 3962, 3956, "W")
2317
+ @t.add_result(1, 3969, 3967, "L")
2318
+ @t.add_result(1, 3981, 3955, "W")
2319
+ @t.add_result(1, 3963, 3953, "W")
2320
+ @t.add_result(1, 3974, 3965, "W")
2321
+ @t.add_result(1, 3978, 3977, "W")
2322
+ @t.add_result(1, 3982, 3957, "W")
2323
+ @t.add_result(2, 3979, 3954, "L")
2324
+ @t.add_result(2, 3957, 3956, "L")
2325
+ @t.add_result(2, 3967, 3960, "W")
2326
+ @t.add_result(2, 3972, 3966, "W")
2327
+ @t.add_result(2, 3980, 3955, "L")
2328
+ @t.add_result(2, 3983, 3974, "W")
2329
+ @t.add_result(2, 3968, 3963, "W")
2330
+ @t.add_result(2, 3969, 3961, "L")
2331
+ @t.add_result(2, 3981, 3975, "D")
2332
+ @t.add_result(2, 3964, 3953, "W")
2333
+ @t.add_result(2, 3970, 3952, "L")
2334
+ @t.add_result(2, 3978, 3962, "W")
2335
+ @t.add_result(2, 3971, 3965, "L")
2336
+ @t.add_result(2, 3982, 3958, "L")
2337
+ @t.add_result(3, 3971, 3956, "D")
2338
+ @t.add_result(3, 3982, 3964, "W")
2339
+ @t.add_result(3, 3979, 3966, "L")
2340
+ @t.add_result(3, 3972, 3959, "W")
2341
+ @t.add_result(3, 3980, 3957, "W")
2342
+ @t.add_result(3, 3983, 3975, "D")
2343
+ @t.add_result(3, 3968, 3967, "D")
2344
+ @t.add_result(3, 3973, 3955, "W")
2345
+ @t.add_result(3, 3977, 3963, "L")
2346
+ @t.add_result(3, 3969, 3953, "W")
2347
+ @t.add_result(3, 3981, 3962, "D")
2348
+ @t.add_result(3, 3974, 3961, "L")
2349
+ @t.add_result(3, 3970, 3960, "W")
2350
+ @t.add_result(3, 3965, 3954, "W")
2351
+ @t.add_result(3, 3978, 3958, "L")
2352
+ @t.add_result(4, 3956, 3954, "L")
2353
+ @t.add_result(4, 3966, 3962, "L")
2354
+ @t.add_result(4, 3971, 3969, "W")
2355
+ @t.add_result(4, 3982, 3975, "D")
2356
+ @t.add_result(4, 3957, 3953, "L")
2357
+ @t.add_result(4, 3958, 3952, "L")
2358
+ @t.add_result(4, 3980, 3979, "W")
2359
+ @t.add_result(4, 3983, 3972, "W")
2360
+ @t.add_result(4, 3973, 3970, "D")
2361
+ @t.add_result(4, 3977, 3955, "D")
2362
+ @t.add_result(4, 3963, 3961, "L")
2363
+ @t.add_result(4, 3981, 3967, "L")
2364
+ @t.add_result(4, 3964, 3960, "W")
2365
+ @t.add_result(4, 3974, 3959, "W")
2366
+ @t.add_result(4, 3978, 3965, "W")
2367
+ @t.add_result(5, 3975, 3970, "L")
2368
+ @t.add_result(5, 3956, 3955, "L")
2369
+ @t.add_result(5, 3966, 3953, "W")
2370
+ @t.add_result(5, 3982, 3978, "W")
2371
+ @t.add_result(5, 3967, 3952, "L")
2372
+ @t.add_result(5, 3960, 3959, "W")
2373
+ @t.add_result(5, 3983, 3958, "L")
2374
+ @t.add_result(5, 3973, 3962, "L")
2375
+ @t.add_result(5, 3977, 3969, "L")
2376
+ @t.add_result(5, 3981, 3954, "W")
2377
+ @t.add_result(5, 3974, 3963, "L")
2378
+ @t.add_result(5, 3965, 3964, "W")
2379
+ @t.add_result(6, 3975, 3955, "W")
2380
+ @t.add_result(6, 3966, 3960, "D")
2381
+ @t.add_result(6, 3971, 3963, "L")
2382
+ @t.add_result(6, 3979, 3953, "L")
2383
+ @t.add_result(6, 3982, 3967, "D")
2384
+ @t.add_result(6, 3959, 3957, "L")
2385
+ @t.add_result(6, 3962, 3952, "D")
2386
+ @t.add_result(6, 3983, 3961, "W")
2387
+ @t.add_result(6, 3973, 3972, "W")
2388
+ @t.add_result(6, 3969, 3964, "L")
2389
+ @t.add_result(6, 3977, 3956, "L")
2390
+ @t.add_result(6, 3981, 3978, "W")
2391
+ @t.add_result(6, 3970, 3965, "L")
2392
+ @t.add_result(6, 3974, 3954, "L")
2393
+ end
2394
+
2395
+ it "should be setup properly" do
2396
+ @p.desc.should == "Kieran O'Riordan"
2397
+ @o1.desc.should == "Jonathan Kiely"
2398
+ @o2.desc.should == "Donal O'Hallahan"
2399
+ @o3.desc.should == "Arnaud, Aoustin"
2400
+ @o4.desc.should == "Ronan Magee"
2401
+ @o5.desc.should == "Barry Foran"
2402
+ @o6.desc.should == "Henk De Jonge"
2403
+
2404
+ @p.type.should == :rated
2405
+ @o1.type.should == :rated
2406
+ @o2.type.should == :rated
2407
+ @o3.type.should == :rated
2408
+ @o4.type.should == :rated
2409
+ @o5.type.should == :rated
2410
+ @o6.type.should == :rated
2411
+
2412
+ @p.rating.should == 1883
2413
+ @o1.rating.should == 1113
2414
+ @o2.rating.should == 1465
2415
+ @o3.rating.should == 1984
2416
+ @o4.rating.should == 1957
2417
+ @o5.rating.should == 1417
2418
+ @o6.rating.should == 1977
2419
+
2420
+ @t.iterations1.should be_nil
2421
+ @t.iterations2.should be_nil
2422
+ end
2423
+
2424
+ it "player should not get a bonus because his pre-bonus performance is lower than his post-bonus rating" do
2425
+ @t.rate!(version: 2)
2426
+
2427
+ @p.new_rating.should be_within(0.5).of(1924)
2428
+
2429
+ @p.bonus.should == 0
2430
+ @o1.bonus.should == 0
2431
+ @o2.bonus.should == 0
2432
+ @o3.bonus.should == 0
2433
+ @o4.bonus.should == 0
2434
+ @o5.bonus.should == 0
2435
+ @o6.bonus.should == 0
2436
+
2437
+ threshold = @p.rating + 32 + 3 * (@p.results.size - 4)
2438
+
2439
+ # He would have got a bonus ...
2440
+ pre_cap_bonus = ((@p.pb_rating - threshold).round * 1.25).round
2441
+ pre_cap_bonus.should be > 0
2442
+
2443
+ # ... if it wasn't for his low performance.
2444
+ post_cap_bonus = @p.pb_performance - @p.pb_rating
2445
+ post_cap_bonus.should be < 0
2446
+ end
2447
+ end
2259
2448
  end
2260
2449
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: icu_ratings
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.2
4
+ version: 1.5.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-29 00:00:00.000000000 Z
12
+ date: 2012-12-31 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -111,7 +111,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
111
111
  version: '0'
112
112
  segments:
113
113
  - 0
114
- hash: 87268456819351268
114
+ hash: -2799968708998636265
115
115
  required_rubygems_version: !ruby/object:Gem::Requirement
116
116
  none: false
117
117
  requirements:
@@ -120,7 +120,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
120
120
  version: '0'
121
121
  segments:
122
122
  - 0
123
- hash: 87268456819351268
123
+ hash: -2799968708998636265
124
124
  requirements: []
125
125
  rubyforge_project: icu_ratings
126
126
  rubygems_version: 1.8.23