rrschedule 0.3.0 → 0.3.1

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.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.10
1
+ 0.3.1
@@ -60,3 +60,11 @@ At the moment the playing locations are distributed randomly for every matchup.
60
60
  might play a lot more often on a playing field than on another.
61
61
 
62
62
  The work in this branch will try to fix this issue.
63
+
64
+ ## Optional balancing for Game Times (branch crated on 2011/10/02)
65
+
66
+ I created this branch to solve a very specific case. When you generate a schedule with multiple divisions, you generally want that all
67
+ teams of a given division plays at the same game times. (e.g. Division A plays at 7:00, B plays at 9:00 and so on). However with the new
68
+ balancing feature (see 2011/09/23 branch), it is no longer possible to achieve this.
69
+
70
+ I will add options balanced_gt and balanced_ps, both true by default.
data/lib/rrschedule.rb CHANGED
@@ -4,13 +4,15 @@
4
4
  module RRSchedule
5
5
  class Schedule
6
6
  attr_reader :flights, :rounds, :gamedays
7
- attr_accessor :teams, :rules, :cycles, :start_date, :exclude_dates,:shuffle
7
+ attr_accessor :teams, :rules, :cycles, :start_date, :exclude_dates,:shuffle, :balanced_gt, :balanced_ps
8
8
 
9
9
  def initialize(params={})
10
10
  @gamedays = []
11
11
  self.teams = params[:teams] || []
12
12
  self.cycles = params[:cycles] || 1
13
13
  self.shuffle = params[:shuffle].nil? ? true : params[:shuffle]
14
+ self.balanced_gt = params[:balanced_gt].nil? ? true : params[:balanced_gt]
15
+ self.balanced_ps = params[:balanced_ps].nil? ? true : params[:balanced_ps]
14
16
  self.exclude_dates = params[:exclude_dates] || []
15
17
  self.start_date = params[:start_date] || Date.today
16
18
  self.rules = params[:rules] || []
@@ -232,24 +234,34 @@ module RRSchedule
232
234
  def get_best_gt(game)
233
235
  x = {}
234
236
  gt_left = @gt_ps_avail.reject{|k,v| v.empty?}
235
- gt_left.each_key do |gt|
236
- x[gt] = [
237
- @stats[game.team_a][:gt][gt] + @stats[game.team_b][:gt][gt],
238
- rand(1000)
239
- ]
237
+
238
+ if self.balanced_gt
239
+ gt_left.each_key do |gt|
240
+ x[gt] = [
241
+ @stats[game.team_a][:gt][gt] + @stats[game.team_b][:gt][gt],
242
+ rand(1000)
243
+ ]
244
+ end
245
+ x.sort_by{|k,v| [v[0],v[1]]}.first[0]
246
+ else
247
+ gt_left.sort.first[0]
240
248
  end
241
- x.sort_by{|k,v| [v[0],v[1]]}.first[0]
242
249
  end
243
250
 
244
251
  def get_best_ps(game,gt)
245
252
  x = {}
246
- @gt_ps_avail[gt].each do |ps|
247
- x[ps] = [
248
- @stats[game.team_a][:ps][ps] + @stats[game.team_b][:ps][ps],
249
- rand(1000)
250
- ]
253
+
254
+ if self.balanced_ps
255
+ @gt_ps_avail[gt].each do |ps|
256
+ x[ps] = [
257
+ @stats[game.team_a][:ps][ps] + @stats[game.team_b][:ps][ps],
258
+ rand(1000)
259
+ ]
260
+ end
261
+ x.sort_by{|k,v| [v[0],v[1]]}.first[0]
262
+ else
263
+ @gt_ps_avail[gt].first[0]
251
264
  end
252
- x.sort_by{|k,v| [v[0],v[1]]}.first[0]
253
265
  end
254
266
 
255
267
  def reset_resource_availability
data/test_schedule.rb CHANGED
@@ -33,3 +33,35 @@ schedule=RRSchedule::Schedule.new(
33
33
  :shuffle => true,
34
34
  :start_date => Date.parse("2010/10/13")
35
35
  ).generate
36
+
37
+ require 'rubygems'
38
+ require 'active_support/all'
39
+ require './lib/rrschedule.rb'
40
+ include RRSchedule
41
+ schedule=RRSchedule::Schedule.new(
42
+ :teams => [
43
+ %w(A1 A2 A3 A4 A5 A6 A7 A8),
44
+ %w(B1 B2 B3 B4 B5 B6 B7 B8),
45
+ %w(C1 C2 C3 C4 C5 C6 C7 C8),
46
+ %w(D1 D2 D3 D4 D5 D6 D7 D8),
47
+ %w(E1 E2 E3 E4 E5 E6 E7 E8),
48
+ ],
49
+
50
+ :rules => [
51
+ RRSchedule::Rule.new(
52
+ :wday => 1,
53
+ :gt => ["7:00 PM"],
54
+ :ps => ["1","2","3","4"],
55
+ ),
56
+ RRSchedule::Rule.new(
57
+ :wday => 3,
58
+ :gt => ["7:00 PM","9:00 PM"],
59
+ :ps => ["1","2","3","4","5","6","7","8"],
60
+ )
61
+
62
+ ],
63
+ :cycles => 1,
64
+ :start_date => Date.parse("2010/10/13"),
65
+ :balanced_gt => false,
66
+ :balanced_ps => true
67
+ ).generate
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: rrschedule
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.3.0
5
+ version: 0.3.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - flamontagne