rrschedule 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.2.1
data/lib/rrschedule.rb CHANGED
@@ -133,6 +133,7 @@ module RRSchedule
133
133
  #a game date, a game time and a playing surface. We then process our rounds one by one
134
134
  #and we put each matchup in the next available slot of the flat schedule
135
135
  def dispatch_games(rounds)
136
+ teams_day = {}
136
137
  flat_schedule = generate_flat_schedule
137
138
 
138
139
  rounds_copy = Marshal.load(Marshal.dump(rounds)) #deep clone
@@ -145,9 +146,20 @@ module RRSchedule
145
146
  if cur_round
146
147
  cur_round.games.each do |game|
147
148
  unless [game.team_a,game.team_b].include?(:dummy)
149
+ if teams_day[flat_schedule[i][:gamedate]] && (teams_day[flat_schedule[i][:gamedate]].include?(game.team_a) || teams_day[flat_schedule[i][:gamedate]].include?(game.team_b))
150
+ #team is already playing this day. This can happen if we have flights with different number of teams in it.
151
+ gamedate = flat_schedule[i][:gamedate]
152
+ while flat_schedule[i] && flat_schedule[i][:gamedate] == gamedate do
153
+ i += 1
154
+ end
155
+ end
156
+
148
157
  flat_schedule[i][:team_a] = game.team_a
149
158
  flat_schedule[i][:team_b] = game.team_b
150
- i+=1
159
+ teams_day[flat_schedule[i][:gamedate]] ||= []
160
+ teams_day[flat_schedule[i][:gamedate]] << game.team_a
161
+ teams_day[flat_schedule[i][:gamedate]] << game.team_b
162
+ i += 1
151
163
  end
152
164
  end
153
165
  end
@@ -189,11 +201,14 @@ module RRSchedule
189
201
 
190
202
  @flights.each do |flight|
191
203
  games_left += @cycles * (flight.include?(:dummy) ? ((flight.size-1)/2.0)*(flight.size-2) : (flight.size/2)*(flight.size-1))
192
- max_games_per_day += (flight.include?(:dummy) ? (flight.size-2)/2.0 : (flight.size-1)/2.0).ceil
204
+ max_games_per_day += (flight.include?(:dummy) ? ((flight.size-2)/2.0) : (flight.size-1)/2.0).ceil
193
205
  end
194
206
 
195
- #process all games
207
+
208
+ #while there are games to process...
196
209
  while games_left > 0 do
210
+
211
+ #add all possible games based on the current rule
197
212
  cur_rule.gt.each do |gt|
198
213
  cur_rule.ps.each do |ps|
199
214
 
@@ -140,7 +140,7 @@ class TestRrschedule < Test::Unit::TestCase
140
140
  context "multiple rules on the same weekday" do
141
141
  setup do
142
142
  @s = Schedule.new
143
- @s.teams = [%w(a1 a2 a3 a4 a5), %w(b1 b2 b3 b4 b5 b6 b7 b8)]
143
+ @s.teams = [%w(a1 a2 a3 a4 a5 a6 a7 a8), %w(b1 b2 b3 b4 b5 b6 b7 b8)]
144
144
  @s.rules = [
145
145
  Rule.new(:wday => 4, :gt => ["7:00PM"], :ps => %w(field#1 field#2)),
146
146
  Rule.new(:wday => 4, :gt => ["9:00PM"], :ps => %w(field#1 field#2 field#3))
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rrschedule
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 21
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 0
10
- version: 0.2.0
9
+ - 1
10
+ version: 0.2.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - flamontagne
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-01-25 00:00:00 -05:00
18
+ date: 2011-02-15 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency