rrschedule 0.1.5 → 0.1.6
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/README.rdoc +32 -16
- data/VERSION +1 -1
- data/lib/rrschedule.rb +22 -15
- data/test/test_rrschedule.rb +7 -0
- metadata +5 -5
data/README.rdoc
CHANGED
@@ -60,12 +60,12 @@ and will start a new round right after.
|
|
60
60
|
=== human readable schedule
|
61
61
|
puts schedule.to_s
|
62
62
|
|
63
|
-
===
|
64
|
-
|
65
|
-
|
66
|
-
puts "
|
67
|
-
|
68
|
-
puts g.team_a.to_s + " Vs " + g.team_b.to_s
|
63
|
+
=== Iterate through schedule
|
64
|
+
schedule.gamedays.each do |gd|
|
65
|
+
puts gd.date
|
66
|
+
puts "===================="
|
67
|
+
gd.games.each do |g|
|
68
|
+
puts g.team_a.to_s + " Vs " + g.team_b.to_s + " on playing surface ##{g.playing_surface} at #{g.game_time}"
|
69
69
|
end
|
70
70
|
puts "\n"
|
71
71
|
end
|
@@ -85,22 +85,38 @@ and will start a new round right after.
|
|
85
85
|
puts g.game_date.to_s + " on playing surface " + g.playing_surface.to_s + " at " + g.game_time.to_s
|
86
86
|
end
|
87
87
|
|
88
|
-
===
|
89
|
-
|
90
|
-
|
91
|
-
puts "
|
92
|
-
|
93
|
-
puts g.team_a.to_s + " Vs " + g.team_b.to_s
|
88
|
+
=== Each round of the roun-robin without any date/time or playing location info
|
89
|
+
#If you have an ODD number of teams you will see a "dummy" opponent in each round
|
90
|
+
schedule.rounds.each do |round|
|
91
|
+
puts "Round ##{round.round}"
|
92
|
+
round.games.each do |g|
|
93
|
+
puts g.team_a.to_s + " Vs " + g.team_b.to_s
|
94
94
|
end
|
95
95
|
puts "\n"
|
96
96
|
end
|
97
97
|
|
98
98
|
== Issues / Other
|
99
99
|
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
100
|
+
Starting from version 0.1.5, calling Schedule#gamedays will returns an array of Gameday instances.
|
101
|
+
If you upgrade to this version you will need to change your code accordingly.
|
102
|
+
|
103
|
+
#this won't work anymore
|
104
|
+
schedule.gamedays.each do |gd,games|
|
105
|
+
puts gd
|
106
|
+
|
107
|
+
games.each do |g|
|
108
|
+
end
|
109
|
+
#...
|
110
|
+
end
|
111
|
+
|
112
|
+
#do this instead
|
113
|
+
schedule.gamedays.each do |gd|
|
114
|
+
puts gd.date
|
115
|
+
gd.games.each do |g|
|
116
|
+
end
|
117
|
+
#...
|
118
|
+
end
|
119
|
+
|
104
120
|
|
105
121
|
Hope this gem will be useful to some people!
|
106
122
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.6
|
data/lib/rrschedule.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
# rrschedule (Round Robin Schedule generator)
|
2
2
|
# Auhtor: François Lamontagne
|
3
3
|
############################################################################################################################
|
4
|
-
require 'active_support'
|
4
|
+
require 'active_support/all'
|
5
5
|
module RRSchedule
|
6
6
|
class Schedule
|
7
7
|
attr_accessor :playing_surfaces, :game_times, :cycles, :wdays, :start_date, :exclude_dates, :shuffle_initial_order
|
8
8
|
attr_reader :teams, :rounds, :gamedays
|
9
|
-
|
9
|
+
|
10
10
|
def initialize(params={})
|
11
11
|
@gamedays = []
|
12
12
|
self.teams = params[:teams] || [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]
|
@@ -31,18 +31,17 @@ module RRSchedule
|
|
31
31
|
self
|
32
32
|
end
|
33
33
|
|
34
|
-
|
34
|
+
#TODO: consider refactoring with a recursive algorithm
|
35
35
|
def generate(params={})
|
36
36
|
@teams = @teams.sort_by{rand} if self.shuffle_initial_order
|
37
37
|
initial_order = @teams.clone
|
38
|
-
current_cycle = 0
|
39
|
-
current_round = 0
|
38
|
+
current_cycle = current_round = 0
|
40
39
|
all_games = []
|
41
|
-
|
40
|
+
|
42
41
|
#Loop start here
|
43
42
|
begin
|
44
43
|
games = []
|
45
|
-
t = @teams.clone
|
44
|
+
t = @teams.clone
|
46
45
|
while !t.empty? do
|
47
46
|
team_a = t.shift
|
48
47
|
team_b = t.reverse!.shift
|
@@ -50,8 +49,9 @@ module RRSchedule
|
|
50
49
|
games << {:team_a => team_a, :team_b => team_b}
|
51
50
|
all_games << {:team_a => team_a, :team_b => team_b}
|
52
51
|
end
|
53
|
-
|
54
|
-
current_round += 1
|
52
|
+
|
53
|
+
current_round += 1 #round completed
|
54
|
+
|
55
55
|
@rounds ||= []
|
56
56
|
@rounds << Round.new(
|
57
57
|
:round => current_round,
|
@@ -76,12 +76,12 @@ module RRSchedule
|
|
76
76
|
end
|
77
77
|
end
|
78
78
|
end until @teams == initial_order && current_cycle==self.cycles
|
79
|
-
|
79
|
+
|
80
80
|
slice(all_games)
|
81
81
|
self
|
82
82
|
end
|
83
83
|
|
84
|
-
|
84
|
+
#returns an array of Game instances where team_a and team_b are facing each other
|
85
85
|
def face_to_face(team_a,team_b)
|
86
86
|
res=[]
|
87
87
|
self.gamedays.each do |gd|
|
@@ -90,6 +90,7 @@ module RRSchedule
|
|
90
90
|
res.flatten
|
91
91
|
end
|
92
92
|
|
93
|
+
#human readable schedule
|
93
94
|
def to_s
|
94
95
|
res = ""
|
95
96
|
res << "#{self.gamedays.size.to_s} gamedays\n"
|
@@ -97,14 +98,14 @@ module RRSchedule
|
|
97
98
|
res << gd.date.strftime("%Y-%m-%d") + "\n"
|
98
99
|
res << "==========\n"
|
99
100
|
gd.games.each do |g|
|
100
|
-
res << "#{g.
|
101
|
+
res << "#{g.ta.to_s} VS #{g.tb.to_s} on playing surface #{g.ps} at #{g.gt.strftime("%I:%M %p")}\n"
|
101
102
|
end
|
102
103
|
res << "\n"
|
103
104
|
end
|
104
105
|
res
|
105
106
|
end
|
106
|
-
|
107
|
-
#
|
107
|
+
|
108
|
+
#return an array of Game instances where 'team' is playing
|
108
109
|
def by_team(team)
|
109
110
|
gms=[]
|
110
111
|
self.gamedays.each do |gd|
|
@@ -130,7 +131,8 @@ module RRSchedule
|
|
130
131
|
def teams=(arr)
|
131
132
|
@teams = arr.clone
|
132
133
|
raise ":dummy is a reserved team name. Please use something else" if @teams.member?(:dummy)
|
133
|
-
raise "at least 2 teams are required" if @teams.size == 1
|
134
|
+
raise "at least 2 teams are required" if @teams.size == 1
|
135
|
+
raise "teams have to be unique" if @teams.uniq.size < @teams.size
|
134
136
|
@teams << :dummy if @teams.size.odd?
|
135
137
|
end
|
136
138
|
|
@@ -193,6 +195,11 @@ module RRSchedule
|
|
193
195
|
|
194
196
|
class Game
|
195
197
|
attr_accessor :team_a, :team_b, :playing_surface, :game_time, :game_date
|
198
|
+
alias :ta :team_a
|
199
|
+
alias :tb :team_b
|
200
|
+
alias :ps :playing_surface
|
201
|
+
alias :gt :game_time
|
202
|
+
alias :gd :game_date
|
196
203
|
|
197
204
|
def initialize(params={})
|
198
205
|
self.team_a = params[:team_a]
|
data/test/test_rrschedule.rb
CHANGED
@@ -79,6 +79,13 @@ class TestRrschedule < Test::Unit::TestCase
|
|
79
79
|
schedule = RRSchedule::Schedule.new
|
80
80
|
assert schedule.teams.size > 1
|
81
81
|
end
|
82
|
+
|
83
|
+
should "not have a team that is specified twice" do
|
84
|
+
assert_raise RuntimeError do
|
85
|
+
schedule = RRSchedule::Schedule.new(:teams => %w(a a b c d e f g h i))
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
82
89
|
end
|
83
90
|
|
84
91
|
context "Any valid schedule" do
|
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:
|
4
|
+
hash: 23
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 6
|
10
|
+
version: 0.1.6
|
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: 2010-11-
|
18
|
+
date: 2010-11-11 00:00:00 -05:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -100,5 +100,5 @@ signing_key:
|
|
100
100
|
specification_version: 3
|
101
101
|
summary: Round-Robin schedule generator
|
102
102
|
test_files:
|
103
|
-
- test/test_rrschedule.rb
|
104
103
|
- test/helper.rb
|
104
|
+
- test/test_rrschedule.rb
|