icu_tournament 1.0.6 → 1.0.7
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/lib/icu_tournament/tournament_sp.rb +30 -16
- data/lib/icu_tournament/version.rb +1 -1
- data/spec/tournament_sp_spec.rb +42 -15
- metadata +2 -2
|
@@ -12,35 +12,45 @@ module ICU
|
|
|
12
12
|
|
|
13
13
|
This is the format produced by the Windows program, SwissPerfect[http://www.swissperfect.com/]. It consists of three
|
|
14
14
|
files with the same name but different endings: <em>.ini</em> for meta data such as tournament name and tie-break
|
|
15
|
-
rules, <em>.trn</em> for the player details such as name and
|
|
15
|
+
rules, <em>.trn</em> for the player details such as name and rating, and <em>.sco</em> for the results. The first
|
|
16
16
|
file is text and the other two are in an old binary format known as <em>DBase 3</em>.
|
|
17
17
|
|
|
18
18
|
To parse such a set of files, use either the _parse_file!_ or _parse_file_ method supplying the name of any one
|
|
19
19
|
of the three files or just the stem name without any ending. In case of error, such as any of the files not being
|
|
20
20
|
found, _parse_file!_ will throw an exception while _parse_file_ will return _nil_ and record an error message.
|
|
21
|
-
As well as a file name or stem name, you
|
|
22
|
-
information.
|
|
21
|
+
As well as a file name or stem name, you should also supply a start date in the options as SwissPerfect does not
|
|
22
|
+
record this information.
|
|
23
23
|
|
|
24
24
|
parser = ICU::Tournament::SwissPerfect.new
|
|
25
|
-
tournament = parser.parse_file('champs',
|
|
25
|
+
tournament = parser.parse_file('champs', :start => '2010-07-03') # looks for "champs.ini", "champs.trn" and "champs.sco"
|
|
26
26
|
puts parser.error unless tournament
|
|
27
27
|
|
|
28
28
|
Alternatively, if all three files are in a ZIP archive, the parser will extract them if the name of the
|
|
29
|
-
archive file
|
|
29
|
+
archive file is supplied to the _parse_file_ method and it ends in ".zip" (case insensitive):
|
|
30
30
|
|
|
31
|
-
tournament = parser.parse_file('champs.zip',
|
|
31
|
+
tournament = parser.parse_file('champs.zip', :start => '2010-07-03')
|
|
32
|
+
|
|
33
|
+
Or, if the file is a ZIP archive but it's name doesn't end in ".zip", that can be signalled with an option:
|
|
34
|
+
|
|
35
|
+
tournament = parser.parse_file('/tmp/a84f21ge', :zip => true, :start => '2010-07-03')
|
|
32
36
|
|
|
33
37
|
Note there must be only three files in the archive, they must all have the same stem name and
|
|
34
38
|
their endings should be ".ini", ".trn" and ".sco" (case insensitive).
|
|
35
39
|
|
|
40
|
+
If no start date is supplied it will default to 2000-01-01, and can be reset later.
|
|
41
|
+
|
|
42
|
+
tournament = parser.parse_file('champs.zip')
|
|
43
|
+
tournament.start # => '2000-01-01'
|
|
44
|
+
tournament.start = '2010-07-03'
|
|
45
|
+
|
|
36
46
|
By default, the parser extracts local ratings and IDs from the SwissPerfect files. If international
|
|
37
47
|
ratings or IDs are required instead, use the options _id_ and _rating_. For example:
|
|
38
48
|
|
|
39
|
-
tournament = parser.parse_file('ncc',
|
|
49
|
+
tournament = parser.parse_file('ncc', :start => '2010-05-08')
|
|
40
50
|
tournament.player(2).id # => 12379 (ICU ID)
|
|
41
51
|
tournament.player(2).rating # => 2556 (ICU rating)
|
|
42
52
|
|
|
43
|
-
tournament = parser.parse_file('ncc',
|
|
53
|
+
tournament = parser.parse_file('ncc', :start => '2010-05-08', :id => :intl, :rating => :intl)
|
|
44
54
|
tournament.player(2).id # => 1205064 (FIDE ID)
|
|
45
55
|
tournament.player(2).rating # => 2530 (FIDE rating)
|
|
46
56
|
|
|
@@ -69,7 +79,8 @@ renumbering method) before serializing. For example:
|
|
|
69
79
|
|
|
70
80
|
There should be no need to explicitly rank the tournament first, as that information is already present in
|
|
71
81
|
SwissPerfect files (i.e. each player should already have a rank after the files have been parsed).
|
|
72
|
-
Additionally, the tie break rules used for the tournament will be available from
|
|
82
|
+
Additionally, the tie break rules used for the tournament will be available from the _tie_break_ method,
|
|
83
|
+
dir example:
|
|
73
84
|
|
|
74
85
|
tournament.tie_breaks # => [:buchholz, :harkness]
|
|
75
86
|
|
|
@@ -78,6 +89,8 @@ Should you wish to rank the tournament using a different set of tie-break rules,
|
|
|
78
89
|
tournament.tie_breaks = [:wins, :blacks]
|
|
79
90
|
swiss_perfect = tournament.rerank.renumber.serialize('SwissPerfect')
|
|
80
91
|
|
|
92
|
+
See ICU::Tournament for more about tie-breaks.
|
|
93
|
+
|
|
81
94
|
=end
|
|
82
95
|
|
|
83
96
|
class SwissPerfect
|
|
@@ -98,11 +111,12 @@ Should you wish to rank the tournament using a different set of tie-break rules,
|
|
|
98
111
|
SCO = %w{ROUND WHITE BLACK W_SCORE B_SCORE W_TYPE B_TYPE} # not used W_SUBSCO, B_SUBSCO
|
|
99
112
|
|
|
100
113
|
# Parse SP data returning a Tournament or raising an exception on error.
|
|
101
|
-
def parse_file!(file,
|
|
102
|
-
@t = Tournament.new('Dummy',
|
|
114
|
+
def parse_file!(file, arg={})
|
|
115
|
+
@t = Tournament.new('Dummy', '2000-01-01')
|
|
116
|
+
@t.start = arg[:start] if arg[:start]
|
|
103
117
|
@bonus = {}
|
|
104
118
|
@start_no = {}
|
|
105
|
-
ini, trn, sco = get_files(file)
|
|
119
|
+
ini, trn, sco = get_files(file, arg)
|
|
106
120
|
parse_ini(ini)
|
|
107
121
|
parse_trn(trn, arg)
|
|
108
122
|
parse_sco(sco)
|
|
@@ -113,9 +127,9 @@ Should you wish to rank the tournament using a different set of tie-break rules,
|
|
|
113
127
|
|
|
114
128
|
# Parse SP data returning an ICU::Tournament or a nil on failure. In the latter
|
|
115
129
|
# case, an error message will be available via the <em>error</em> method.
|
|
116
|
-
def parse_file(file,
|
|
130
|
+
def parse_file(file, arg={})
|
|
117
131
|
begin
|
|
118
|
-
parse_file!(file,
|
|
132
|
+
parse_file!(file, arg)
|
|
119
133
|
rescue => ex
|
|
120
134
|
@error = ex.message
|
|
121
135
|
nil
|
|
@@ -153,8 +167,8 @@ Should you wish to rank the tournament using a different set of tie-break rules,
|
|
|
153
167
|
|
|
154
168
|
private
|
|
155
169
|
|
|
156
|
-
def get_files(file)
|
|
157
|
-
file.match(/\.zip$/i) ? get_zip_files(file) : get_bare_files(file)
|
|
170
|
+
def get_files(file, arg)
|
|
171
|
+
file.match(/\.zip$/i) || arg[:zip] ? get_zip_files(file) : get_bare_files(file)
|
|
158
172
|
end
|
|
159
173
|
|
|
160
174
|
def get_bare_files(file)
|
data/spec/tournament_sp_spec.rb
CHANGED
|
@@ -28,7 +28,7 @@ module ICU
|
|
|
28
28
|
|
|
29
29
|
before(:all) do
|
|
30
30
|
@p = ICU::Tournament::SwissPerfect.new
|
|
31
|
-
@t = @p.parse_file(SAMPLES + 'gonzaga_challengers_2010.trn', "2010-01-29")
|
|
31
|
+
@t = @p.parse_file(SAMPLES + 'gonzaga_challengers_2010.trn', :start => "2010-01-29")
|
|
32
32
|
@s = open(SAMPLES + 'gonzaga_challengers_2010.txt') { |f| f.read }
|
|
33
33
|
end
|
|
34
34
|
|
|
@@ -40,8 +40,8 @@ module ICU
|
|
|
40
40
|
it "should have correct details for selected players" do
|
|
41
41
|
@t.player(2).signature.should == "Mullooly, Neil M.|6438|1083|6.0|1|123456|WWWWWW|WBWBWB|TTTTTT" # winner
|
|
42
42
|
@t.player(4).signature.should == "Gallagher, Mark|12138|1036|4.0|9|123456|WLWWWL|WBWBWB|FTTTTT" # had one bye
|
|
43
|
-
@t.player(45).signature.should == "Catre, Loredan||507|3.5|18|123456|WDLWLW|BWBWBW|FTTTFT"
|
|
44
|
-
@t.player(56).signature.should == "McDonnell, Cathal||498|0.0|54|1|L|-|F"
|
|
43
|
+
@t.player(45).signature.should == "Catre, Loredan||507|3.5|18|123456|WDLWLW|BWBWBW|FTTTFT" # had two byes
|
|
44
|
+
@t.player(56).signature.should == "McDonnell, Cathal||498|0.0|54|1|L|-|F" # last
|
|
45
45
|
end
|
|
46
46
|
|
|
47
47
|
it "should have consistent ranks" do
|
|
@@ -61,7 +61,7 @@ module ICU
|
|
|
61
61
|
|
|
62
62
|
before(:all) do
|
|
63
63
|
@p = ICU::Tournament::SwissPerfect.new
|
|
64
|
-
@t = @p.parse_file(SAMPLES + 'junior_championships_u19_2010.sco', "2010-04-11")
|
|
64
|
+
@t = @p.parse_file(SAMPLES + 'junior_championships_u19_2010.sco', :start => "2010-04-11")
|
|
65
65
|
@s = open(SAMPLES + 'junior_championships_u19_2010.txt') { |f| f.read }
|
|
66
66
|
end
|
|
67
67
|
|
|
@@ -94,7 +94,7 @@ module ICU
|
|
|
94
94
|
|
|
95
95
|
before(:all) do
|
|
96
96
|
@p = ICU::Tournament::SwissPerfect.new
|
|
97
|
-
@t = @p.parse_file(SAMPLES + 'LimerickClubChampionship09.ini', "2009-09-15")
|
|
97
|
+
@t = @p.parse_file(SAMPLES + 'LimerickClubChampionship09.ini', :start => "2009-09-15")
|
|
98
98
|
end
|
|
99
99
|
|
|
100
100
|
it "should parse and have the right basic details" do
|
|
@@ -124,7 +124,7 @@ module ICU
|
|
|
124
124
|
|
|
125
125
|
before(:all) do
|
|
126
126
|
@p = ICU::Tournament::SwissPerfect.new
|
|
127
|
-
@t = @p.parse_file(SAMPLES + 'junior_provincials_u16_2010', "2010-02-02")
|
|
127
|
+
@t = @p.parse_file(SAMPLES + 'junior_provincials_u16_2010', :start => "2010-02-02")
|
|
128
128
|
end
|
|
129
129
|
|
|
130
130
|
it "should parse and have the right basic details" do
|
|
@@ -152,7 +152,7 @@ module ICU
|
|
|
152
152
|
|
|
153
153
|
before(:all) do
|
|
154
154
|
@p = ICU::Tournament::SwissPerfect.new
|
|
155
|
-
@t = @p.parse_file(SAMPLES + 'mulcahy_2010', "2010-01-15")
|
|
155
|
+
@t = @p.parse_file(SAMPLES + 'mulcahy_2010', :start => "2010-01-15")
|
|
156
156
|
end
|
|
157
157
|
|
|
158
158
|
it "should parse and have the right basic details" do
|
|
@@ -177,7 +177,7 @@ module ICU
|
|
|
177
177
|
|
|
178
178
|
before(:all) do
|
|
179
179
|
@p = ICU::Tournament::SwissPerfect.new
|
|
180
|
-
@t = @p.parse_file(SAMPLES + 'ncc', "2010-05-08")
|
|
180
|
+
@t = @p.parse_file(SAMPLES + 'ncc', :start => "2010-05-08")
|
|
181
181
|
end
|
|
182
182
|
|
|
183
183
|
it "should parse and have the right basic details" do
|
|
@@ -193,7 +193,7 @@ module ICU
|
|
|
193
193
|
end
|
|
194
194
|
|
|
195
195
|
it "should have correct details for selection of players, including international IDs and ratings when so configured" do
|
|
196
|
-
@t = @p.parse_file(SAMPLES + 'ncc', "2010-05-08", :id => :intl, :rating => :intl)
|
|
196
|
+
@t = @p.parse_file(SAMPLES + 'ncc', :start => "2010-05-08", :id => :intl, :rating => :intl)
|
|
197
197
|
@t.player(2).signature.should == "Szabo, Gergely|1205064||4.0|4|1234|WWWW|WBWB|TTTT"
|
|
198
198
|
@t.player(5).signature.should == "Daly, Colm|2500434||3.5|7|1234|WWWD|WBWB|TTTT"
|
|
199
199
|
@t.player(8).signature.should == "Vega, Marcos Llaneza|2253585||3.0|16|1234|DDWW|BWBW|TTTT"
|
|
@@ -205,7 +205,7 @@ module ICU
|
|
|
205
205
|
|
|
206
206
|
before(:all) do
|
|
207
207
|
@p = ICU::Tournament::SwissPerfect.new
|
|
208
|
-
@t = @p.parse_file(SAMPLES + 'nosuchzipfile.zip', "2010-05-08")
|
|
208
|
+
@t = @p.parse_file(SAMPLES + 'nosuchzipfile.zip', :start => "2010-05-08")
|
|
209
209
|
end
|
|
210
210
|
|
|
211
211
|
it "should not parse and should have a relevant error" do
|
|
@@ -218,7 +218,7 @@ module ICU
|
|
|
218
218
|
|
|
219
219
|
before(:all) do
|
|
220
220
|
@p = ICU::Tournament::SwissPerfect.new
|
|
221
|
-
@t = @p.parse_file(SAMPLES + 'notazipfile.zip', "2010-05-08")
|
|
221
|
+
@t = @p.parse_file(SAMPLES + 'notazipfile.zip', :start => "2010-05-08")
|
|
222
222
|
end
|
|
223
223
|
|
|
224
224
|
it "should not parse and have a should have relevant error" do
|
|
@@ -231,7 +231,7 @@ module ICU
|
|
|
231
231
|
|
|
232
232
|
before(:all) do
|
|
233
233
|
@p = ICU::Tournament::SwissPerfect.new
|
|
234
|
-
@t = @p.parse_file(SAMPLES + 'notenoughfiles.zip', "2010-05-08")
|
|
234
|
+
@t = @p.parse_file(SAMPLES + 'notenoughfiles.zip', :start => "2010-05-08")
|
|
235
235
|
end
|
|
236
236
|
|
|
237
237
|
it "should not parse and should have a relevant error" do
|
|
@@ -244,7 +244,7 @@ module ICU
|
|
|
244
244
|
|
|
245
245
|
before(:all) do
|
|
246
246
|
@p = ICU::Tournament::SwissPerfect.new
|
|
247
|
-
@t = @p.parse_file(SAMPLES + 'mixedstems.zip', "2010-05-08")
|
|
247
|
+
@t = @p.parse_file(SAMPLES + 'mixedstems.zip', :start => "2010-05-08")
|
|
248
248
|
end
|
|
249
249
|
|
|
250
250
|
it "should not parse and should have a relevant error" do
|
|
@@ -253,11 +253,11 @@ module ICU
|
|
|
253
253
|
end
|
|
254
254
|
end
|
|
255
255
|
|
|
256
|
-
context "
|
|
256
|
+
context "ZIP file" do
|
|
257
257
|
|
|
258
258
|
before(:all) do
|
|
259
259
|
@p = ICU::Tournament::SwissPerfect.new
|
|
260
|
-
@t = @p.parse_file(SAMPLES + 'nccz.zip', "2010-05-08")
|
|
260
|
+
@t = @p.parse_file(SAMPLES + 'nccz.zip', :start => "2010-05-08")
|
|
261
261
|
end
|
|
262
262
|
|
|
263
263
|
it "should parse and have the right basic details" do
|
|
@@ -272,6 +272,33 @@ module ICU
|
|
|
272
272
|
@t.player(67).signature.should == "Lee, Shane|780|1633|1.0|52|134|DLD|WWW|TTT"
|
|
273
273
|
end
|
|
274
274
|
end
|
|
275
|
+
|
|
276
|
+
context "ZIP file without a ZIP ending" do
|
|
277
|
+
|
|
278
|
+
before(:all) do
|
|
279
|
+
@p = ICU::Tournament::SwissPerfect.new
|
|
280
|
+
end
|
|
281
|
+
|
|
282
|
+
it "should not parse unless ZIP format is signalled with an option" do
|
|
283
|
+
lambda { @p.parse_file!(SAMPLES + 'nccz.piz', :start => "2010-05-08") }.should raise_error(/cannot find/i)
|
|
284
|
+
end
|
|
285
|
+
|
|
286
|
+
it "should parse if ZIP format is signalled with an option" do
|
|
287
|
+
lambda { @p.parse_file!(SAMPLES + 'nccz.piz', :zip => true, :start => "2010-05-08") }.should_not raise_error
|
|
288
|
+
end
|
|
289
|
+
end
|
|
290
|
+
|
|
291
|
+
context "Defaulting the start date" do
|
|
292
|
+
|
|
293
|
+
before(:all) do
|
|
294
|
+
@p = ICU::Tournament::SwissPerfect.new
|
|
295
|
+
@t = @p.parse_file(SAMPLES + 'nccz.zip')
|
|
296
|
+
end
|
|
297
|
+
|
|
298
|
+
it "should default the start date if not supplied" do
|
|
299
|
+
@t.start.should == "2000-01-01"
|
|
300
|
+
end
|
|
301
|
+
end
|
|
275
302
|
end
|
|
276
303
|
end
|
|
277
304
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: icu_tournament
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.0.
|
|
4
|
+
version: 1.0.7
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Mark Orr
|
|
@@ -9,7 +9,7 @@ autorequire:
|
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
11
|
|
|
12
|
-
date: 2010-07-
|
|
12
|
+
date: 2010-07-25 00:00:00 +01:00
|
|
13
13
|
default_executable:
|
|
14
14
|
dependencies:
|
|
15
15
|
- !ruby/object:Gem::Dependency
|