sportdb 1.6.11 → 1.6.12

Sign up to get free protection for your applications and to get access to all the features.
@@ -48,40 +48,7 @@ class Event < ActiveRecord::Base
48
48
 
49
49
 
50
50
  def known_teams_table
51
-
52
- ## build known teams table w/ synonyms e.g.
53
- #
54
- # [[ 'wolfsbrug', [ 'VfL Wolfsburg' ]],
55
- # [ 'augsburg', [ 'FC Augsburg', 'Augi2', 'Augi3' ]],
56
- # [ 'stuttgart', [ 'VfB Stuttgart' ]] ]
57
-
58
- known_teams = []
59
-
60
- teams.each_with_index do |team,index|
61
-
62
- titles = []
63
- titles << team.title
64
- titles += team.synonyms.split('|') if team.synonyms.present?
65
-
66
- ## NB: sort here by length (largest goes first - best match)
67
- # exclude code and key (key should always go last)
68
- titles = titles.sort { |left,right| right.length <=> left.length }
69
-
70
- ## escape for regex plus allow subs for special chars/accents
71
- titles = titles.map { |title| TextUtils.title_esc_regex( title ) }
72
-
73
- titles << team.code if team.code.present?
74
- titles << team.key
75
-
76
- known_teams << [ team.key, titles ]
77
-
78
- ### fix:
79
- ## plain logger
80
-
81
- LogUtils::Logger.root.debug " Team[#{index+1}] #{team.key} >#{titles.join('|')}<"
82
- end
83
-
84
- known_teams
51
+ @known_teams_table ||= build_match_table_for( teams )
85
52
  end # method known_teams_table
86
53
 
87
54
  end # class Event
@@ -9,44 +9,14 @@ class Track < ActiveRecord::Base
9
9
  #####################
10
10
  ## convenience helper for text parser/reader
11
11
 
12
- ### fix: move to event!!! (e.g. scoped by event)
12
+
13
+ ### fix: move known_tracks_table to event!!! (e.g. scoped by event)
13
14
 
14
15
  def self.known_tracks_table
15
-
16
- ## build known tracks table w/ synonyms e.g.
17
- #
18
- # [[ 'wolfsbrug', [ 'VfL Wolfsburg' ]],
19
- # [ 'augsburg', [ 'FC Augsburg', 'Augi2', 'Augi3' ]],
20
- # [ 'stuttgart', [ 'VfB Stuttgart' ]] ]
21
-
22
- known_tracks = []
23
-
24
- Track.all.each_with_index do |track,index|
25
-
26
- titles = []
27
- titles << track.title
28
- titles += track.synonyms.split('|') if track.synonyms.present?
29
-
30
- ## NB: sort here by length (largest goes first - best match)
31
- # exclude code and key (key should always go last)
32
- titles = titles.sort { |left,right| right.length <=> left.length }
33
-
34
- ## escape for regex plus allow subs for special chars/accents
35
- titles = titles.map { |title| TextUtils.title_esc_regex( title ) }
36
-
37
- known_tracks << [ track.key, titles ]
38
-
39
- ### fix:
40
- ## plain logger
41
-
42
- LogUtils::Logger.root.debug " Track[#{index+1}] #{track.key} >#{titles.join('|')}<"
43
- end
44
-
45
- known_tracks
16
+ @@known_tracks_table ||= build_match_table_for( Track.all )
46
17
  end # method known_tracks_table
47
18
 
48
19
 
49
-
50
20
  def self.create_or_update_from_values( new_attributes, values )
51
21
 
52
22
  ## fix: add/configure logger for ActiveRecord!!!
@@ -150,65 +150,44 @@ class Reader
150
150
  end # method load
151
151
 
152
152
 
153
- def load_leagues( name, more_values={} )
154
-
155
- path = "#{include_path}/#{name}.txt"
153
+ def load_leagues( name, more_attribs={} )
156
154
 
157
- logger.info "parsing data '#{name}' (#{path})..."
158
-
159
- reader = ValuesReader.new( path, more_values )
155
+ reader = ValuesReaderV2.new( name, include_path, more_attribs )
160
156
 
161
157
  reader.each_line do |new_attributes, values|
162
158
  League.create_or_update_from_values( new_attributes, values )
163
159
  end # each lines
164
-
165
- Prop.create_from_fixture!( name, path )
166
-
167
- end # load_leagues
168
160
 
161
+ end # load_leagues
169
162
 
170
- def load_tracks( name, more_values={} )
171
-
172
- path = "#{include_path}/#{name}.txt"
173
163
 
174
- logger.info "parsing data '#{name}' (#{path})..."
164
+ def load_tracks( name, more_attribs={} )
175
165
 
176
- reader = ValuesReader.new( path, more_values )
166
+ reader = ValuesReaderV2.new( name, include_path, more_attribs )
177
167
 
178
168
  reader.each_line do |new_attributes, values|
179
169
  Track.create_or_update_from_values( new_attributes, values )
180
170
  end # each lines
181
-
182
- Prop.create_from_fixture!( name, path )
183
171
 
184
172
  end # load_tracks
185
173
 
186
174
 
187
175
 
188
- def load_persons( name, more_values={} )
189
-
190
- path = "#{include_path}/#{name}.txt"
191
-
192
- logger.info "parsing data '#{name}' (#{path})..."
176
+ def load_persons( name, more_attribs={} )
193
177
 
194
- reader = ValuesReader.new( path, more_values )
178
+ reader = ValuesReaderV2.new( name, include_path, more_attribs )
195
179
 
196
180
  reader.each_line do |new_attributes, values|
197
181
  Person.create_or_update_from_values( new_attributes, values )
198
182
  end # each lines
199
-
200
- Prop.create_from_fixture!( name, path )
201
183
 
202
184
  end # load_persons
203
185
 
204
186
 
205
187
 
206
188
  def load_seasons( name )
207
- path = "#{include_path}/#{name}.yml"
208
-
209
- logger.info "parsing data '#{name}' (#{path})..."
210
189
 
211
- reader = HashReader.new( path )
190
+ reader = HashReaderV2.new( name, include_path )
212
191
 
213
192
  ####
214
193
  ## fix!!!!!
@@ -251,17 +230,12 @@ class Reader
251
230
  end
252
231
 
253
232
  end # each key,value
254
-
255
- Prop.create_from_fixture!( name, path )
256
-
233
+
257
234
  end # load_seasons
258
235
 
259
236
 
260
237
 
261
238
  def load_event( name )
262
- path = "#{include_path}/#{name}.yml"
263
-
264
- logger.info "parsing data '#{name}' (#{path})..."
265
239
 
266
240
  ####
267
241
  ## fix!!!!!
@@ -269,7 +243,7 @@ class Reader
269
243
  ## use Event.create_or_update_from_hash_reader?? or similar
270
244
  # move parsing code to model
271
245
 
272
- reader = HashReader.new( path )
246
+ reader = HashReaderV2.new( name, include_path )
273
247
 
274
248
  event_attribs = {}
275
249
 
@@ -345,9 +319,7 @@ class Reader
345
319
  logger.debug event_attribs.to_json
346
320
 
347
321
  event.update_attributes!( event_attribs )
348
-
349
- Prop.create_from_fixture!( name, path )
350
-
322
+
351
323
  end # load_event
352
324
 
353
325
 
@@ -508,18 +480,12 @@ class Reader
508
480
  end # method load_races_worker
509
481
 
510
482
 
511
- def load_teams( name, more_values={} )
512
- path = "#{include_path}/#{name}.txt"
513
-
514
- logger.info "parsing data '#{name}' (#{path})..."
515
-
516
- reader = ValuesReader.new( path, more_values )
483
+ def load_teams( name, more_attribs={} )
484
+ reader = ValuesReaderV2.new( name, include_path, more_attribs )
517
485
 
518
486
  reader.each_line do |new_attributes, values|
519
487
  Team.create_or_update_from_values( new_attributes, values )
520
488
  end # each lines
521
-
522
- Prop.create_from_fixture!( name, path )
523
489
  end # load_teams
524
490
 
525
491
  private
data/lib/sportdb/utils.rb CHANGED
@@ -3,6 +3,48 @@
3
3
  ### some utils moved to worldbdb/utils for reuse
4
4
 
5
5
 
6
+ ### fix: move to textutils??
7
+
8
+
9
+ def build_match_table_for( recs )
10
+ ## build known tracks table w/ synonyms e.g.
11
+ #
12
+ # [[ 'wolfsbrug', [ 'VfL Wolfsburg' ]],
13
+ # [ 'augsburg', [ 'FC Augsburg', 'Augi2', 'Augi3' ]],
14
+ # [ 'stuttgart', [ 'VfB Stuttgart' ]] ]
15
+
16
+ known_titles = []
17
+
18
+ recs.each_with_index do |rec,index|
19
+
20
+ titles = []
21
+ titles << rec.title
22
+ titles += rec.synonyms.split('|') if rec.synonyms.present?
23
+
24
+ ## NB: sort here by length (largest goes first - best match)
25
+ # exclude code and key (key should always go last)
26
+ titles = titles.sort { |left,right| right.length <=> left.length }
27
+
28
+ ## escape for regex plus allow subs for special chars/accents
29
+ titles = titles.map { |title| TextUtils.title_esc_regex( title ) }
30
+
31
+ ## NB: only include code field - if defined
32
+ titles << rec.code if rec.respond_to?(:code) && rec.code.present?
33
+
34
+ known_titles << [ rec.key, titles ]
35
+
36
+ ### fix:
37
+ ## plain logger
38
+
39
+ LogUtils::Logger.root.debug " #{rec.class.name}[#{index+1}] #{rec.key} >#{titles.join('|')}<"
40
+ end
41
+
42
+ known_titles
43
+ end
44
+
45
+
46
+
47
+
6
48
  module SportDb::FixtureHelpers
7
49
 
8
50
  def is_postponed?( line )
@@ -286,47 +328,37 @@ module SportDb::FixtureHelpers
286
328
  end
287
329
  scores
288
330
  end # methdod find_scores!
289
-
290
331
 
291
- def find_team_worker!( line, index )
332
+
333
+ ## todo/fix:
334
+ # find a better name find_xxx_by_title ?? find_xxx_w_match_table? or similiar
335
+ # move to its own file/module for easier maintance
336
+ # include build_match_table_for
337
+ # - lets us change internals e.g. lets improve matcher using a reverse index, for example
338
+
339
+ def find_xxx_worker!( name, line )
292
340
  regex = /@@oo([^@]+?)oo@@/ # e.g. everything in @@ .... @@ (use non-greedy +? plus all chars but not @, that is [^@])
293
-
341
+
342
+ upcase_name = name.upcase
343
+ downcase_name = name.downcase
344
+
294
345
  if line =~ regex
295
346
  value = "#{$1}"
296
- logger.debug " team#{index}: >#{value}<"
347
+ logger.debug " #{downcase_name}: >#{value}<"
297
348
 
298
- line.sub!( regex, "[TEAM#{index}]" )
349
+ line.sub!( regex, "[#{upcase_name}]" )
299
350
 
300
351
  return $1
301
352
  else
302
353
  return nil
303
354
  end
304
355
  end
305
-
306
- def find_teams!( line )
307
- counter = 1
308
- teams = []
309
-
310
- team = find_team_worker!( line, counter )
311
- while team.present?
312
- teams << team
313
- counter += 1
314
- team = find_team_worker!( line, counter )
315
- end
316
-
317
- teams
318
- end
319
356
 
320
- def find_team1!( line )
321
- find_team_worker!( line, 1 )
322
- end
323
-
324
- def find_team2!( line )
325
- find_team_worker!( line, 2 )
326
- end
327
357
 
358
+ def match_xxx_worker!( name, line, key, values )
359
+
360
+ downcase_name = name.downcase
328
361
 
329
- def match_team_worker!( line, key, values )
330
362
  values.each do |value|
331
363
  ## nb: \b does NOT include space or newline for word boundry (only alphanums e.g. a-z0-9)
332
364
  ## (thus add it, allows match for Benfica Lis. for example - note . at the end)
@@ -334,7 +366,7 @@ module SportDb::FixtureHelpers
334
366
  ## check add $ e.g. (\b| |\t|$) does this work? - check w/ Benfica Lis.$
335
367
  regex = /\b#{value}(\b| |\t|$)/ # wrap with world boundry (e.g. match only whole words e.g. not wac in wacker)
336
368
  if line =~ regex
337
- logger.debug " match for team >#{key}< >#{value}<"
369
+ logger.debug " match for #{downcase_name} >#{key}< >#{value}<"
338
370
  # make sure @@oo{key}oo@@ doesn't match itself with other key e.g. wacker, wac, etc.
339
371
  line.sub!( regex, "@@oo#{key}oo@@ " ) # NB: add one space char at end
340
372
  return true # break out after first match (do NOT continue)
@@ -342,50 +374,46 @@ module SportDb::FixtureHelpers
342
374
  end
343
375
  return false
344
376
  end
377
+
378
+
379
+
380
+ def find_teams!( line )
381
+ counter = 1
382
+ teams = []
383
+
384
+ team = find_xxx_worker!( "team#{counter}", line )
385
+ while team.present?
386
+ teams << team
387
+ counter += 1
388
+ team = find_xxx_worker!( "team#{counter}", line )
389
+ end
390
+
391
+ teams
392
+ end
393
+
394
+ ## todo: check if find_team1 gets used? if not remove it!! use find_teams!
395
+ def find_team1!( line )
396
+ find_xxx_worker!( 'team1', line )
397
+ end
398
+
399
+ def find_team2!( line )
400
+ find_xxx_worker!( 'team2', line )
401
+ end
402
+
345
403
 
346
404
  ## todo/fix: pass in known_teams as a parameter? why? why not?
347
405
  def match_teams!( line )
348
406
  @known_teams.each do |rec|
349
407
  key = rec[0]
350
408
  values = rec[1]
351
- match_team_worker!( line, key, values )
352
- end # each known_teams
409
+ match_xxx_worker!( 'team', line, key, values )
410
+ end # each known_teams
353
411
  end # method match_teams!
354
412
 
355
413
 
356
414
 
357
-
358
-
359
415
  def find_track!( line )
360
- regex = /@@oo([^@]+?)oo@@/ # e.g. everything in @@ .... @@ (use non-greedy +? plus all chars but not @, that is [^@])
361
-
362
- if line =~ regex
363
- value = "#{$1}"
364
- logger.debug " track#{index}: >#{value}<"
365
-
366
- line.sub!( regex, "[TRACK]" )
367
-
368
- return $1
369
- else
370
- return nil
371
- end
372
- end
373
-
374
- def match_track_worker!( line, key, values )
375
- values.each do |value|
376
- ## nb: \b does NOT include space or newline for word boundry (only alphanums e.g. a-z0-9)
377
- ## (thus add it, allows match for Benfica Lis. for example - note . at the end)
378
-
379
- ## check add $ e.g. (\b| |\t|$) does this work? - check w/ Benfica Lis.$
380
- regex = /\b#{value}(\b| |\t|$)/ # wrap with world boundry (e.g. match only whole words e.g. not wac in wacker)
381
- if line =~ regex
382
- logger.debug " match for track >#{key}< >#{value}<"
383
- # make sure @@oo{key}oo@@ doesn't match itself with other key e.g. wacker, wac, etc.
384
- line.sub!( regex, "@@oo#{key}oo@@ " ) # NB: add one space char at end
385
- return true # break out after first match (do NOT continue)
386
- end
387
- end
388
- return false
416
+ find_xxx_worker!( 'track', line )
389
417
  end
390
418
 
391
419
  ## todo/fix: pass in known_tracks as a parameter? why? why not?
@@ -393,7 +421,7 @@ module SportDb::FixtureHelpers
393
421
  @known_tracks.each do |rec|
394
422
  key = rec[0]
395
423
  values = rec[1]
396
- match_track_worker!( line, key, values )
424
+ match_xxx_worker!( 'track', line, key, values )
397
425
  end # each known_tracks
398
426
  end # method match_tracks!
399
427
 
@@ -1,6 +1,6 @@
1
1
 
2
2
  module SportDb
3
- VERSION = '1.6.11'
3
+ VERSION = '1.6.12'
4
4
  end
5
5
 
6
6
  ###########################################
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sportdb
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.11
4
+ version: 1.6.12
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-06-05 00:00:00.000000000 Z
12
+ date: 2013-06-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: worlddb
16
- requirement: &73622090 !ruby/object:Gem::Requirement
16
+ requirement: &77877370 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '1.7'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *73622090
24
+ version_requirements: *77877370
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: commander
27
- requirement: &73621870 !ruby/object:Gem::Requirement
27
+ requirement: &77877150 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 4.1.3
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *73621870
35
+ version_requirements: *77877150
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rdoc
38
- requirement: &73621650 !ruby/object:Gem::Requirement
38
+ requirement: &77876930 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '3.10'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *73621650
46
+ version_requirements: *77876930
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: hoe
49
- requirement: &73621430 !ruby/object:Gem::Requirement
49
+ requirement: &77876710 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: '3.3'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *73621430
57
+ version_requirements: *77876710
58
58
  description: sportdb - sport.db command line tool
59
59
  email: opensport@googlegroups.com
60
60
  executables: