sportdb 1.6.10 → 1.6.11

Sign up to get free protection for your applications and to get access to all the features.
@@ -31,9 +31,11 @@ lib/sportdb/models/league.rb
31
31
  lib/sportdb/models/person.rb
32
32
  lib/sportdb/models/prop.rb
33
33
  lib/sportdb/models/race.rb
34
+ lib/sportdb/models/record.rb
34
35
  lib/sportdb/models/region.rb
35
36
  lib/sportdb/models/roster.rb
36
37
  lib/sportdb/models/round.rb
38
+ lib/sportdb/models/run.rb
37
39
  lib/sportdb/models/season.rb
38
40
  lib/sportdb/models/team.rb
39
41
  lib/sportdb/models/track.rb
File without changes
@@ -43,9 +43,11 @@ require 'sportdb/models/league'
43
43
  require 'sportdb/models/person'
44
44
  require 'sportdb/models/prop'
45
45
  require 'sportdb/models/race'
46
+ require 'sportdb/models/record'
46
47
  require 'sportdb/models/region'
47
48
  require 'sportdb/models/roster'
48
49
  require 'sportdb/models/round'
50
+ require 'sportdb/models/run'
49
51
  require 'sportdb/models/season'
50
52
  require 'sportdb/models/team'
51
53
  require 'sportdb/models/track'
@@ -14,14 +14,22 @@ require 'yaml'
14
14
 
15
15
  ## shortcuts for models
16
16
 
17
+ Badge = SportDb::Models::Badge
17
18
  Event = SportDb::Models::Event
18
- Team = SportDb::Models::Team
19
19
  Game = SportDb::Models::Game
20
+ Goal = SportDb::Models::Goal
20
21
  Group = SportDb::Models::Group
22
+ League = SportDb::Models::League
23
+ Person = SportDb::Models::Person
24
+ Race = SportDb::Models::Race
25
+ Record = SportDb::Models::Record
26
+ Roster = SportDb::Models::Roster
21
27
  Round = SportDb::Models::Round
28
+ Run = SportDb::Models::Run
22
29
  Season = SportDb::Models::Season
23
- League = SportDb::Models::League
24
- Badge = SportDb::Models::Badge
30
+ Team = SportDb::Models::Team
31
+ Track = SportDb::Models::Track
32
+
25
33
 
26
34
  Tag = WorldDb::Models::Tag
27
35
  Tagging = WorldDb::Models::Tagging
@@ -11,6 +11,7 @@ module SportDb
11
11
  # for now delete all tables
12
12
 
13
13
  Goal.delete_all
14
+ Record.delete_all
14
15
 
15
16
  Game.delete_all
16
17
  Event.delete_all
@@ -19,7 +20,8 @@ module SportDb
19
20
  GroupTeam.delete_all
20
21
  Round.delete_all
21
22
  Badge.delete_all
22
-
23
+
24
+ Run.delete_all
23
25
  Race.delete_all
24
26
  Roster.delete_all
25
27
 
@@ -32,14 +32,21 @@ class Event < ActiveRecord::Base
32
32
  def title
33
33
  league.title
34
34
  end
35
-
35
+
36
36
  def full_title # includes season (e.g. year)
37
37
  "#{league.title} #{season.title}"
38
38
  end
39
-
39
+
40
+
40
41
  #####################
41
42
  ## convenience helper for text parser/reader
42
43
 
44
+ ###
45
+ ## fix: use/add to_teams_table( rec ) for reuse
46
+ #
47
+ ## @known_teams = @event.known_teams_table
48
+
49
+
43
50
  def known_teams_table
44
51
 
45
52
  ## build known teams table w/ synonyms e.g.
@@ -61,7 +68,7 @@ class Event < ActiveRecord::Base
61
68
  titles = titles.sort { |left,right| right.length <=> left.length }
62
69
 
63
70
  ## escape for regex plus allow subs for special chars/accents
64
- titles = titles.map { |title| title_esc_regex( title ) }
71
+ titles = titles.map { |title| TextUtils.title_esc_regex( title ) }
65
72
 
66
73
  titles << team.code if team.code.present?
67
74
  titles << team.key
@@ -3,8 +3,8 @@ module SportDb::Models
3
3
 
4
4
  class Goal < ActiveRecord::Base
5
5
 
6
- belongs_to :game
7
- belongs_to :person
6
+ belongs_to :game
7
+ belongs_to :person
8
8
 
9
9
  end # class Goal
10
10
 
@@ -3,12 +3,12 @@ module SportDb::Models
3
3
 
4
4
  class Race < ActiveRecord::Base
5
5
 
6
- belongs_to :track
7
- belongs_to :event
8
-
9
- ### fix/todo: add runs/records (records - join table - run/race+person)
10
- ## has_many :runs # e.g. Test Drive, Quali 1, Quali 2, Quali 3, Race
11
- ## run - has_many records? - run_stats? - what name to use?
6
+ belongs_to :track
7
+ belongs_to :event
8
+
9
+ ### fix/todo: add runs/records (records - join table - run/race+person)
10
+ ## has_many :runs # e.g. Test Drive, Quali 1, Quali 2, Quali 3, Race
11
+ ## run - has_many records? - run_stats? - what name to use?
12
12
 
13
13
  end # class Race
14
14
 
@@ -0,0 +1,13 @@
1
+ module SportDb::Models
2
+
3
+
4
+ class Record < ActiveRecord::Base
5
+
6
+ belongs_to :race # or
7
+ belongs_to :run
8
+ belongs_to :person
9
+
10
+ end # class Record
11
+
12
+
13
+ end # module SportDb::Models
@@ -0,0 +1,11 @@
1
+ module SportDb::Models
2
+
3
+
4
+ class Run < ActiveRecord::Base
5
+
6
+ belongs_to :race
7
+
8
+ end # class Run
9
+
10
+
11
+ end # module SportDb::Models
@@ -6,6 +6,46 @@ class Track < ActiveRecord::Base
6
6
 
7
7
  belongs_to :country, :class_name => 'WorldDb::Models::Country', :foreign_key => 'country_id'
8
8
 
9
+ #####################
10
+ ## convenience helper for text parser/reader
11
+
12
+ ### fix: move to event!!! (e.g. scoped by event)
13
+
14
+ 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
46
+ end # method known_tracks_table
47
+
48
+
9
49
 
10
50
  def self.create_or_update_from_values( new_attributes, values )
11
51
 
@@ -89,6 +89,12 @@ class Reader
89
89
  load_persons( name )
90
90
  elsif name =~ /^teams/ # e.g. teams.txt in formula1.db
91
91
  load_teams( name )
92
+ elsif name =~ /\/races/ # e.g. 2013/races.txt in formula1.db
93
+ load_races( name )
94
+ elsif name =~ /\/squads/ || name =~ /\/rosters/ # e.g. 2013/squads.txt in formula1.db
95
+ load_rosters( name )
96
+ elsif name =~ /\/([0-9]{2})-/
97
+ load_records( name ) # e.g. 2013/04-gp-monaco.txt in formula1.db
92
98
  elsif name =~ /^seasons/
93
99
  load_seasons( name )
94
100
  elsif name =~ /^leagues/
@@ -372,6 +378,136 @@ class Reader
372
378
  end
373
379
 
374
380
 
381
+
382
+ def load_records( name )
383
+ path = "#{include_path}/#{name}.txt"
384
+
385
+ logger.info "parsing data '#{name}' (#{path})..."
386
+
387
+ ### SportDB.lang.lang = LangChecker.new.analyze( name, include_path )
388
+
389
+ reader = LineReader.new( path )
390
+
391
+ ## for now: use all tracks (later filter/scope by event)
392
+ # @known_tracks = Track.known_tracks_table
393
+
394
+ ## fix: add @known_teams - for now; use teams (not scoped by event)
395
+
396
+ load_records_worker( reader )
397
+
398
+ Prop.create_from_fixture!( name, path )
399
+ end
400
+
401
+ def load_records_worker( reader )
402
+
403
+ reader.each_line do |line|
404
+ logger.debug " line: >#{line}<"
405
+
406
+ ### fix: use new find_leading_pos!
407
+ # pos = find_game_pos!( line ) # alias -> rename to find_pos! or better use find_leading_pos!( line )
408
+
409
+ # match_person!( line )
410
+
411
+ # match_teams!( line )
412
+
413
+ record_attribs = {
414
+ # pos: pos,
415
+ # team_key: team_key # fix: use team_id
416
+ }
417
+
418
+ pp record_attribs
419
+ end # lines.each
420
+
421
+ end # method load_record_worker
422
+
423
+
424
+
425
+ def load_rosters( name )
426
+ path = "#{include_path}/#{name}.txt"
427
+
428
+ logger.info "parsing data '#{name}' (#{path})..."
429
+
430
+ ### SportDB.lang.lang = LangChecker.new.analyze( name, include_path )
431
+
432
+ reader = LineReader.new( path )
433
+
434
+ ## for now: use all tracks (later filter/scope by event)
435
+ # @known_tracks = Track.known_tracks_table
436
+
437
+ ## fix: add @known_teams - for now; use teams (not scoped by event)
438
+
439
+ load_rosters_worker( reader )
440
+
441
+ Prop.create_from_fixture!( name, path )
442
+
443
+ end
444
+
445
+ def load_rosters_worker( reader )
446
+
447
+ reader.each_line do |line|
448
+ logger.debug " line: >#{line}<"
449
+
450
+ ### fix: use new find_leading_pos!
451
+ pos = find_game_pos!( line ) # alias -> rename to find_pos! or better use find_leading_pos!( line )
452
+
453
+ # match_person!( line )
454
+
455
+ # match_teams!( line )
456
+
457
+ roster_attribs = {
458
+ pos: pos,
459
+ # team_key: team_key # fix: use team_id
460
+ }
461
+
462
+ pp roster_attribs
463
+ end # lines.each
464
+
465
+ end # method load_rosters_worker
466
+
467
+
468
+
469
+ def load_races( name )
470
+ path = "#{include_path}/#{name}.txt"
471
+
472
+ logger.info "parsing data '#{name}' (#{path})..."
473
+
474
+ ### SportDB.lang.lang = LangChecker.new.analyze( name, include_path )
475
+
476
+ reader = LineReader.new( path )
477
+
478
+ ## for now: use all tracks (later filter/scope by event)
479
+ @known_tracks = Track.known_tracks_table
480
+
481
+ load_races_worker( reader )
482
+
483
+ Prop.create_from_fixture!( name, path )
484
+
485
+ end
486
+
487
+ def load_races_worker( reader )
488
+
489
+ reader.each_line do |line|
490
+ logger.debug " line: >#{line}<"
491
+
492
+ ### fix: use new find_leading_pos!
493
+ pos = find_game_pos!( line ) # alias -> rename to find_pos! or better use find_leading_pos!( line )
494
+
495
+ match_track!( line )
496
+ track_key = find_track!( line )
497
+ date = find_date!( line )
498
+
499
+ race_attribs = {
500
+ pos: pos,
501
+ track_key: track_key, # fix: use track_id
502
+ start_at: date
503
+ }
504
+
505
+ pp race_attribs
506
+ end # lines.each
507
+
508
+ end # method load_races_worker
509
+
510
+
375
511
  def load_teams( name, more_values={} )
376
512
  path = "#{include_path}/#{name}.txt"
377
513
 
@@ -6,9 +6,9 @@ class CreateDb < ActiveRecord::Migration
6
6
  def up
7
7
 
8
8
  create_table :teams do |t|
9
+ t.string :key, :null => false # import/export key
9
10
  t.string :title, :null => false
10
11
  t.string :title2
11
- t.string :key, :null => false # import/export key
12
12
  t.string :code # make it not null? - three letter code (short title)
13
13
  t.string :synonyms # comma separated list of synonyms
14
14
  t.references :country, :null => false
@@ -72,20 +72,48 @@ end
72
72
 
73
73
  # join table -> event(season+league)+track
74
74
  create_table :races do |t| # e.g. Formula 1 race (Grand Prix Monaco) or Alpine Ski race (Downhill Lake Louise)
75
- t.references :track
76
- t.references :event
75
+ t.references :track, :null => false
76
+ t.references :event, :null => false
77
77
  t.integer :pos, :null => false # Race #1,#2,#3,#4 etc.
78
-
78
+
79
+ ## todo: add auto-created key (for import/export) e.g.
80
+
81
+ t.datetime :start_at
82
+ t.timestamps
83
+ end
84
+
85
+ create_table :runs do |t|
86
+ t.references :race, :null => false
87
+ t.integer :pos, :null => false
88
+
79
89
  t.datetime :start_at
80
90
  t.timestamps
81
91
  end
82
92
 
93
+ # join table -> race+person or run+person
94
+ create_table :records do |t| # use TimeRecord? instead of simple record
95
+ t.references :race # optional either race or run references
96
+ t.references :run
97
+ t.references :person, :null => false
98
+ t.integer :pos # 1,2,3, etc or 0
99
+ t.boolean :completed, :null => false, :default => true # completed race - find better name?
100
+ t.string :state # find a better name? e.g. retired, e.g.
101
+ t.string :comment # find a better name ? e.g. collision damage (if ret) for formula 1
102
+ t.time :time
103
+ t.string :timeline # e.g. + 0:45.343 or +1 lap
104
+ t.integer :laps # laps counter for formula1
105
+
106
+ t.timestamps
107
+ end
108
+
109
+
83
110
  # join table -> person+team+event(season+league)
84
111
  create_table :rosters do |t| # use squads as an alternative name? why? why not??
85
- t.references :person
86
- t.references :team
87
- t.references :event
112
+ t.references :person, :null => false
113
+ t.references :team, :null => false
114
+ t.references :event # make required?
88
115
  t.integer :pos, :null => false
116
+
89
117
  t.timestamps
90
118
  end
91
119
 
@@ -97,6 +125,7 @@ create_table :events do |t|
97
125
  t.date :start_at, :null => false # NB: only use date (w/o time)
98
126
  t.date :end_at # make it required??? # NB: only use date (w/o time)
99
127
  t.boolean :team3, :null => false, :default => true ## e.g. Champions League has no 3rd place (only 1st and 2nd/final)
128
+
100
129
  t.timestamps
101
130
  end
102
131
 
@@ -113,6 +142,7 @@ create_table :rounds do |t|
113
142
  t.boolean :knockout, :null => false, :default => false
114
143
  t.date :start_at, :null => false # NB: only use date (w/o time)
115
144
  t.date :end_at # todo: make it required e.g. :null => false # NB: only use date (w/o time)
145
+
116
146
  t.timestamps
117
147
  end
118
148
 
@@ -130,6 +160,7 @@ add_index :groups, :event_id # fk event_id index
130
160
 
131
161
 
132
162
  create_table :games do |t|
163
+ t.string :key # import/export key
133
164
  t.references :round, :null => false
134
165
  t.integer :pos, :null => false
135
166
  t.references :group # note: group is optional
@@ -161,7 +192,6 @@ create_table :games do |t|
161
192
  ### todo> find a better name (toto is not international/english?)
162
193
  ## rename to score12x or pt12x or result12x
163
194
  t.string :toto12x # 1,2,X,nil calculate on save
164
- t.string :key # import/export key
165
195
 
166
196
  t.timestamps
167
197
  end
@@ -12,7 +12,8 @@ module SportDb
12
12
  puts " #{Game.count} games"
13
13
  puts " #{Badge.count} badges"
14
14
 
15
- puts " #{Track.count} tracks / #{Race.count} races (track+event recs)"
15
+ puts " #{Track.count} tracks / #{Race.count} races (track+event recs) / #{Run.count} runs"
16
+ puts " #{Record.count} records (race|run+person recs)"
16
17
  puts " #{Person.count} persons / #{Roster.count} rosters (person+team+event recs)"
17
18
  puts " #{Goal.count} goals (person+game recs)"
18
19
 
@@ -350,7 +350,52 @@ module SportDb::FixtureHelpers
350
350
  values = rec[1]
351
351
  match_team_worker!( line, key, values )
352
352
  end # each known_teams
353
- end # method translate_teams!
354
-
353
+ end # method match_teams!
354
+
355
+
356
+
357
+
358
+
359
+ 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
389
+ end
390
+
391
+ ## todo/fix: pass in known_tracks as a parameter? why? why not?
392
+ def match_track!( line )
393
+ @known_tracks.each do |rec|
394
+ key = rec[0]
395
+ values = rec[1]
396
+ match_track_worker!( line, key, values )
397
+ end # each known_tracks
398
+ end # method match_tracks!
399
+
355
400
 
356
401
  end # module SportDb::FixtureHelpers
@@ -1,6 +1,6 @@
1
1
 
2
2
  module SportDb
3
- VERSION = '1.6.10'
3
+ VERSION = '1.6.11'
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.10
4
+ version: 1.6.11
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-04 00:00:00.000000000Z
12
+ date: 2013-06-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: worlddb
16
- requirement: &15460344 !ruby/object:Gem::Requirement
16
+ requirement: &73622090 !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: *15460344
24
+ version_requirements: *73622090
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: commander
27
- requirement: &15459576 !ruby/object:Gem::Requirement
27
+ requirement: &73621870 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,38 +32,36 @@ dependencies:
32
32
  version: 4.1.3
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *15459576
35
+ version_requirements: *73621870
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rdoc
38
- requirement: &15459108 !ruby/object:Gem::Requirement
38
+ requirement: &73621650 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
42
42
  - !ruby/object:Gem::Version
43
- version: '4.0'
43
+ version: '3.10'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *15459108
46
+ version_requirements: *73621650
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: hoe
49
- requirement: &15458508 !ruby/object:Gem::Requirement
49
+ requirement: &73621430 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
53
53
  - !ruby/object:Gem::Version
54
- version: '3.6'
54
+ version: '3.3'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *15458508
57
+ version_requirements: *73621430
58
58
  description: sportdb - sport.db command line tool
59
59
  email: opensport@googlegroups.com
60
60
  executables:
61
61
  - sportdb
62
62
  extensions: []
63
63
  extra_rdoc_files:
64
- - History.md
65
64
  - Manifest.txt
66
- - README.md
67
65
  files:
68
66
  - History.md
69
67
  - Manifest.txt
@@ -98,9 +96,11 @@ files:
98
96
  - lib/sportdb/models/person.rb
99
97
  - lib/sportdb/models/prop.rb
100
98
  - lib/sportdb/models/race.rb
99
+ - lib/sportdb/models/record.rb
101
100
  - lib/sportdb/models/region.rb
102
101
  - lib/sportdb/models/roster.rb
103
102
  - lib/sportdb/models/round.rb
103
+ - lib/sportdb/models/run.rb
104
104
  - lib/sportdb/models/season.rb
105
105
  - lib/sportdb/models/team.rb
106
106
  - lib/sportdb/models/track.rb
@@ -148,7 +148,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
148
148
  version: '0'
149
149
  requirements: []
150
150
  rubyforge_project: sportdb
151
- rubygems_version: 1.7.2
151
+ rubygems_version: 1.8.17
152
152
  signing_key:
153
153
  specification_version: 3
154
154
  summary: sportdb - sport.db command line tool