sportdb 1.6.6 → 1.6.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -28,12 +28,15 @@ lib/sportdb/models/goal.rb
28
28
  lib/sportdb/models/group.rb
29
29
  lib/sportdb/models/group_team.rb
30
30
  lib/sportdb/models/league.rb
31
- lib/sportdb/models/player.rb
31
+ lib/sportdb/models/person.rb
32
32
  lib/sportdb/models/prop.rb
33
+ lib/sportdb/models/race.rb
33
34
  lib/sportdb/models/region.rb
35
+ lib/sportdb/models/roster.rb
34
36
  lib/sportdb/models/round.rb
35
37
  lib/sportdb/models/season.rb
36
38
  lib/sportdb/models/team.rb
39
+ lib/sportdb/models/track.rb
37
40
  lib/sportdb/reader.rb
38
41
  lib/sportdb/schema.rb
39
42
  lib/sportdb/stats.rb
data/Rakefile CHANGED
@@ -23,7 +23,7 @@ Hoe.spec 'sportdb' do
23
23
  # self.history_file = 'History.md'
24
24
 
25
25
  self.extra_deps = [
26
- ['worlddb', '~> 1.6'], # NB: worlddb already includes
26
+ ['worlddb', '~> 1.7'], # NB: worlddb already includes
27
27
  # - commander
28
28
  # - logutils
29
29
  # - textutils
@@ -40,12 +40,15 @@ require 'sportdb/models/goal'
40
40
  require 'sportdb/models/group'
41
41
  require 'sportdb/models/group_team'
42
42
  require 'sportdb/models/league'
43
- require 'sportdb/models/player'
43
+ require 'sportdb/models/person'
44
44
  require 'sportdb/models/prop'
45
+ require 'sportdb/models/race'
45
46
  require 'sportdb/models/region'
47
+ require 'sportdb/models/roster'
46
48
  require 'sportdb/models/round'
47
49
  require 'sportdb/models/season'
48
50
  require 'sportdb/models/team'
51
+ require 'sportdb/models/track'
49
52
  require 'sportdb/schema' # NB: requires sportdb/models (include SportDB::Models)
50
53
  require 'sportdb/utils'
51
54
  require 'sportdb/reader'
@@ -10,7 +10,8 @@ module SportDb
10
10
  def run
11
11
  # for now delete all tables
12
12
 
13
- Team.delete_all
13
+ Goal.delete_all
14
+
14
15
  Game.delete_all
15
16
  Event.delete_all
16
17
  EventTeam.delete_all
@@ -18,6 +19,14 @@ module SportDb
18
19
  GroupTeam.delete_all
19
20
  Round.delete_all
20
21
  Badge.delete_all
22
+
23
+ Race.delete_all
24
+ Roster.delete_all
25
+
26
+ Track.delete_all
27
+ Person.delete_all
28
+ Team.delete_all
29
+
21
30
  League.delete_all
22
31
  Season.delete_all
23
32
  end
@@ -4,7 +4,7 @@ module SportDb::Models
4
4
  class Goal < ActiveRecord::Base
5
5
 
6
6
  belongs_to :game
7
- belongs_to :player
7
+ belongs_to :person
8
8
 
9
9
  end # class Goal
10
10
 
@@ -13,6 +13,42 @@ class League < ActiveRecord::Base
13
13
  belongs_to :country, :class_name => 'WorldDb::Models::Country', :foreign_key => 'country_id'
14
14
 
15
15
 
16
+ def self.create_or_update_from_values( new_attributes, values )
17
+
18
+ ## fix: add/configure logger for ActiveRecord!!!
19
+ logger = LogKernel::Logger.root
20
+
21
+ ## check optional values
22
+ values.each_with_index do |value, index|
23
+ if value =~ /^club$/ # club flag
24
+ new_attributes[ :club ] = true
25
+ elsif value =~ /^[a-z]{2}$/ ## assume two-letter country key e.g. at,de,mx,etc.
26
+ value_country = Country.find_by_key!( value )
27
+ new_attributes[ :country_id ] = value_country.id
28
+ else
29
+ ## todo: assume title2 ??
30
+ ## assume title2 if title2 is empty (not already in use)
31
+ ## and if it title2 contains at least two letter e.g. [a-zA-Z].*[a-zA-Z]
32
+ # issue warning: unknown type for value
33
+ logger.warn "unknown type for value >#{value}< - key #{new_attributes[:key]}"
34
+ end
35
+ end
36
+
37
+ rec = League.find_by_key( new_attributes[ :key ] )
38
+ if rec.present?
39
+ logger.debug "update League #{rec.id}-#{rec.key}:"
40
+ else
41
+ logger.debug "create League:"
42
+ rec = League.new
43
+ end
44
+
45
+ logger.debug new_attributes.to_json
46
+
47
+ rec.update_attributes!( new_attributes )
48
+ end # create_or_update_from_values
49
+
50
+
51
+
16
52
  def self.create_from_ary!( leagues, more_values={} )
17
53
  leagues.each do |values|
18
54
 
@@ -1,11 +1,11 @@
1
1
  module SportDb::Models
2
2
 
3
3
 
4
- class Player < ActiveRecord::Base
4
+ class Person < ActiveRecord::Base
5
5
 
6
6
  has_many :goals
7
7
 
8
- end # class Player
8
+ end # class Person
9
9
 
10
10
 
11
11
  end # module SportDb::Models
@@ -0,0 +1,16 @@
1
+ module SportDb::Models
2
+
3
+
4
+ class Race < ActiveRecord::Base
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?
12
+
13
+ end # class Race
14
+
15
+
16
+ end # module SportDb::Models
@@ -0,0 +1,12 @@
1
+ module SportDb::Models
2
+
3
+ class Roster < ActiveRecord::Base
4
+
5
+ belongs_to :event
6
+ belongs_to :team
7
+ belongs_to :person
8
+
9
+ end # class Roster
10
+
11
+
12
+ end # module SportDb::Models
@@ -27,6 +27,50 @@ class Team < ActiveRecord::Base
27
27
  belongs_to :city, :class_name => 'WorldDb::Models::City', :foreign_key => 'city_id'
28
28
 
29
29
 
30
+
31
+ def self.create_or_update_from_values( new_attributes, values )
32
+
33
+ ## fix: add/configure logger for ActiveRecord!!!
34
+ logger = LogKernel::Logger.root
35
+
36
+ ## check optional values
37
+ values.each_with_index do |value, index|
38
+ if value =~ /^city:/ ## city:
39
+ value_city_key = value[5..-1] ## cut off city: prefix
40
+ value_city = City.find_by_key( value_city_key )
41
+ if value_city.present?
42
+ new_attributes[ :city_id ] = value_city.id
43
+ else
44
+ ## todo/fix: add strict mode flag - fail w/ exit 1 in strict mode
45
+ logger.warn "city with key #{value_city_key} missing"
46
+ ## todo: log errors to db log???
47
+ end
48
+ elsif value =~ /^[A-Z][A-Z0-9][A-Z0-9_]?$/ ## assume two or three-letter code e.g. FCB, RBS, etc.
49
+ new_attributes[ :code ] = value
50
+ elsif value =~ /^[a-z]{2}$/ ## assume two-letter country key e.g. at,de,mx,etc.
51
+ value_country = Country.find_by_key!( value )
52
+ new_attributes[ :country_id ] = value_country.id
53
+ else
54
+ ## todo: assume title2 ??
55
+ # issue warning: unknown type for value
56
+ logger.warn "unknown type for value >#{value}< - key #{new_attributes[:key]}"
57
+ end
58
+ end
59
+
60
+ rec = Team.find_by_key( new_attributes[ :key ] )
61
+ if rec.present?
62
+ logger.debug "update Team #{rec.id}-#{rec.key}:"
63
+ else
64
+ logger.debug "create Team:"
65
+ rec = Team.new
66
+ end
67
+
68
+ logger.debug new_attributes.to_json
69
+
70
+ rec.update_attributes!( new_attributes )
71
+ end # create_or_update_from_values
72
+
73
+
30
74
  def self.create_from_ary!( teams, more_values={} )
31
75
  teams.each do |values|
32
76
 
@@ -0,0 +1,46 @@
1
+ module SportDb::Models
2
+
3
+ class Track < ActiveRecord::Base
4
+
5
+ has_many :races
6
+
7
+ belongs_to :country, :class_name => 'WorldDb::Models::Country', :foreign_key => 'country_id'
8
+
9
+
10
+ def self.create_or_update_from_values( new_attributes, values )
11
+
12
+ ## fix: add/configure logger for ActiveRecord!!!
13
+ logger = LogKernel::Logger.root
14
+
15
+ ## check optional values
16
+ values.each_with_index do |value, index|
17
+ if value =~ /^[a-z]{2}$/ ## assume two-letter country key e.g. at,de,mx,etc.
18
+ value_country = Country.find_by_key!( value )
19
+ new_attributes[ :country_id ] = value_country.id
20
+ else
21
+ ## todo: assume title2 ??
22
+ ## assume title2 if title2 is empty (not already in use)
23
+ ## and if it title2 contains at least two letter e.g. [a-zA-Z].*[a-zA-Z]
24
+ # issue warning: unknown type for value
25
+ logger.warn "unknown type for value >#{value}< - key #{new_attributes[:key]}"
26
+ end
27
+ end
28
+
29
+ rec = Track.find_by_key( new_attributes[ :key ] )
30
+ if rec.present?
31
+ logger.debug "update Track #{rec.id}-#{rec.key}:"
32
+ else
33
+ logger.debug "create Track:"
34
+ rec = Track.new
35
+ end
36
+
37
+ logger.debug new_attributes.to_json
38
+
39
+ rec.update_attributes!( new_attributes )
40
+ end # create_or_update_from_values
41
+
42
+
43
+ end # class Track
44
+
45
+
46
+ end # module SportDb::Models
@@ -83,7 +83,9 @@ class Reader
83
83
  ## assume single fixture name
84
84
  name = rec
85
85
 
86
- if name =~ /^seasons/
86
+ if name =~ /^circuits/
87
+ load_tracks( name )
88
+ elsif name =~ /^seasons/
87
89
  load_seasons( name )
88
90
  elsif name =~ /^leagues/
89
91
  if name =~ /club/
@@ -146,13 +148,32 @@ class Reader
146
148
 
147
149
  reader = ValuesReader.new( path, more_values )
148
150
 
149
- load_leagues_worker( reader )
151
+ reader.each_line do |new_attributes, values|
152
+ League.create_or_update_from_values( new_attributes, values )
153
+ end # each lines
150
154
 
151
155
  Prop.create_from_fixture!( name, path )
152
156
 
153
157
  end # load_leagues
154
158
 
155
159
 
160
+ def load_tracks( name, more_values={} )
161
+
162
+ path = "#{include_path}/#{name}.txt"
163
+
164
+ logger.info "parsing data '#{name}' (#{path})..."
165
+
166
+ reader = ValuesReader.new( path, more_values )
167
+
168
+ reader.each_line do |new_attributes, values|
169
+ Track.create_or_update_from_values( new_attributes, values )
170
+ end # each lines
171
+
172
+ Prop.create_from_fixture!( name, path )
173
+
174
+ end # load_tracks
175
+
176
+
156
177
  def load_seasons( name )
157
178
  path = "#{include_path}/#{name}.yml"
158
179
 
@@ -160,6 +181,12 @@ class Reader
160
181
 
161
182
  reader = HashReader.new( path )
162
183
 
184
+ ####
185
+ ## fix!!!!!
186
+ ## use Season.create_or_update_from_hash or similar
187
+ ## use Season.create_or_update_from_hash_reader?? or similar
188
+ # move parsing code to model
189
+
163
190
  reader.each_typed do |key, value|
164
191
 
165
192
  ## puts "processing event attrib >>#{key}<< >>#{value}<<..."
@@ -207,6 +234,12 @@ class Reader
207
234
 
208
235
  logger.info "parsing data '#{name}' (#{path})..."
209
236
 
237
+ ####
238
+ ## fix!!!!!
239
+ ## use Event.create_or_update_from_hash or similar
240
+ ## use Event.create_or_update_from_hash_reader?? or similar
241
+ # move parsing code to model
242
+
210
243
  reader = HashReader.new( path )
211
244
 
212
245
  event_attribs = {}
@@ -323,7 +356,9 @@ class Reader
323
356
 
324
357
  reader = ValuesReader.new( path, more_values )
325
358
 
326
- load_teams_worker( reader )
359
+ reader.each_line do |new_attributes, values|
360
+ Team.create_or_update_from_values( new_attributes, valus )
361
+ end # each lines
327
362
 
328
363
  Prop.create_from_fixture!( name, path )
329
364
  end # load_teams
@@ -332,86 +367,6 @@ private
332
367
 
333
368
  include SportDB::FixtureHelpers
334
369
 
335
- def load_leagues_worker( reader )
336
-
337
- reader.each_line do |attribs, values|
338
-
339
- ## check optional values
340
- values.each_with_index do |value, index|
341
- if value =~ /^club$/ # club flag
342
- attribs[ :club ] = true
343
- elsif value =~ /^[a-z]{2}$/ ## assume two-letter country key e.g. at,de,mx,etc.
344
- value_country = Country.find_by_key!( value )
345
- attribs[ :country_id ] = value_country.id
346
- else
347
- ## todo: assume title2 ??
348
- ## assume title2 if title2 is empty (not already in use)
349
- ## and if it title2 contains at least two letter e.g. [a-zA-Z].*[a-zA-Z]
350
- # issue warning: unknown type for value
351
- logger.warn "unknown type for value >#{value}<"
352
- end
353
- end
354
-
355
- rec = League.find_by_key( attribs[ :key ] )
356
- if rec.present?
357
- logger.debug "update League #{rec.id}-#{rec.key}:"
358
- else
359
- logger.debug "create League:"
360
- rec = League.new
361
- end
362
-
363
- logger.debug attribs.to_json
364
-
365
- rec.update_attributes!( attribs )
366
-
367
- end # each lines
368
-
369
- end # load_leagues_worker
370
-
371
-
372
- def load_teams_worker( reader )
373
-
374
- reader.each_line do |attribs, values|
375
-
376
- ## check optional values
377
- values.each_with_index do |value, index|
378
- if value =~ /^city:/ ## city:
379
- value_city_key = value[5..-1] ## cut off city: prefix
380
- value_city = City.find_by_key( value_city_key )
381
- if value_city.present?
382
- attribs[ :city_id ] = value_city.id
383
- else
384
- ## todo/fix: add strict mode flag - fail w/ exit 1 in strict mode
385
- logger.warn "city with key #{value_city_key} missing"
386
- ## todo: log errors to db log???
387
- end
388
- elsif value =~ /^[A-Z][A-Z0-9][A-Z0-9_]?$/ ## assume two or three-letter code e.g. FCB, RBS, etc.
389
- attribs[ :code ] = value
390
- elsif value =~ /^[a-z]{2}$/ ## assume two-letter country key e.g. at,de,mx,etc.
391
- value_country = Country.find_by_key!( value )
392
- attribs[ :country_id ] = value_country.id
393
- else
394
- ## todo: assume title2 ??
395
- # issue warning: unknown type for value
396
- logger.warn "unknown type for value >#{value}<"
397
- end
398
- end
399
-
400
- rec = Team.find_by_key( attribs[ :key ] )
401
- if rec.present?
402
- logger.debug "update Team #{rec.id}-#{rec.key}:"
403
- else
404
- logger.debug "create Team:"
405
- rec = Team.new
406
- end
407
-
408
- logger.debug attribs.to_json
409
-
410
- rec.update_attributes!( attribs )
411
-
412
- end # each lines
413
- end # method load_teams_worker
414
-
415
370
  def load_fixtures_worker( event_key, reader )
416
371
 
417
372
  ## assume active activerecord connection
@@ -23,18 +23,26 @@ end
23
23
  add_index :teams, :key, :unique => true
24
24
 
25
25
 
26
- create_table :players do |t|
26
+ create_table :persons do |t| # use people ? instead of persons (person/persons makes it easier?)
27
27
  t.string :key, :null => false # import/export key
28
28
  t.string :name, :null => false
29
29
  t.string :synonyms # comma separated list of synonyms
30
30
 
31
+ ## todo: add gender flag (male/female -man/lady how?)
31
32
  t.date :born_at # optional date of birth (birthday)
32
- t.references :country, :null => false
33
+ ## todo: add country of birth might not be the same as nationality
34
+
35
+ t.references :city
36
+ t.references :region
37
+ t.references :country, :null => false # use for nationality? or rename to nationality?
38
+
39
+
33
40
  t.timestamps
34
41
  end
35
42
 
43
+ # join table: person+game(team1+team2+event(season+league))
36
44
  create_table :goals do |t|
37
- t.references :player, :null => false
45
+ t.references :person, :null => false
38
46
  t.references :game, :null => false
39
47
  t.integer :minute
40
48
  t.integer :offset # e.g. 45' +3 or 90' +2
@@ -49,6 +57,38 @@ create_table :goals do |t|
49
57
  end
50
58
 
51
59
 
60
+ create_table :tracks do |t| # e.g. Formula 1 circuits or Apline Ski resorts/slops/pistes
61
+ t.string :key, :null => false # import/export key
62
+ t.string :name, :null => false
63
+ t.string :synonyms # comma separated list of synonyms
64
+
65
+ t.references :city
66
+ t.references :region
67
+ t.references :country, :null => false
68
+ t.timestamps
69
+ end
70
+
71
+
72
+ # join table -> event(season+league)+track
73
+ create_table :races do |t| # e.g. Formula 1 race (Grand Prix Monaco) or Alpine Ski race (Downhill Lake Louise)
74
+ t.references :track
75
+ t.references :event
76
+ t.integer :pos, :null => false # Race #1,#2,#3,#4 etc.
77
+
78
+ t.datetime :start_at
79
+ t.timestamps
80
+ end
81
+
82
+ # join table -> person+team+event(season+league)
83
+ create_table :rosters do |t| # use squads as an alternative name? why? why not??
84
+ t.references :person
85
+ t.references :team
86
+ t.references :event
87
+ t.integer :pos, :null => false
88
+ t.timestamps
89
+ end
90
+
91
+
52
92
  create_table :events do |t|
53
93
  t.string :key, :null => false # import/export key
54
94
  t.references :league, :null => false
@@ -6,12 +6,17 @@ module SportDb
6
6
 
7
7
  def tables
8
8
  puts "Stats:"
9
- puts " #{Event.count} events / #{Round.count} rounds / #{Group.count} groups"
10
9
  puts " #{League.count} leagues / #{Season.count} seasons"
11
- puts " #{Country.count} countries / #{Region.count} regions / #{City.count} cities"
10
+ puts " #{Event.count} events (league+season recs) / #{Round.count} rounds / #{Group.count} groups"
12
11
  puts " #{Team.count} teams"
13
12
  puts " #{Game.count} games"
14
13
  puts " #{Badge.count} badges"
14
+
15
+ puts " #{Track.count} tracks / #{Race.count} races (track+event recs)"
16
+ puts " #{Person.count} persons / #{Roster.count} rosters (person+team+event recs)"
17
+ puts " #{Goal.count} goals (person+game recs)"
18
+
19
+ puts " #{Country.count} countries / #{Region.count} regions / #{City.count} cities"
15
20
 
16
21
  ## todo: add tags / taggings from worlddb
17
22
  end
@@ -1,6 +1,6 @@
1
1
 
2
2
  module SportDb
3
- VERSION = '1.6.6'
3
+ VERSION = '1.6.7'
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.6
4
+ version: 1.6.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,22 +9,22 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-24 00:00:00.000000000 Z
12
+ date: 2013-06-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: worlddb
16
- requirement: &72206260 !ruby/object:Gem::Requirement
16
+ requirement: &73513280 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
20
20
  - !ruby/object:Gem::Version
21
- version: '1.6'
21
+ version: '1.7'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *72206260
24
+ version_requirements: *73513280
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: commander
27
- requirement: &72206040 !ruby/object:Gem::Requirement
27
+ requirement: &73513060 !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: *72206040
35
+ version_requirements: *73513060
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rdoc
38
- requirement: &73407120 !ruby/object:Gem::Requirement
38
+ requirement: &73512840 !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: *73407120
46
+ version_requirements: *73512840
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: hoe
49
- requirement: &73406900 !ruby/object:Gem::Requirement
49
+ requirement: &73512620 !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: *73406900
57
+ version_requirements: *73512620
58
58
  description: sportdb - sport.db command line tool
59
59
  email: opensport@googlegroups.com
60
60
  executables:
@@ -93,12 +93,15 @@ files:
93
93
  - lib/sportdb/models/group.rb
94
94
  - lib/sportdb/models/group_team.rb
95
95
  - lib/sportdb/models/league.rb
96
- - lib/sportdb/models/player.rb
96
+ - lib/sportdb/models/person.rb
97
97
  - lib/sportdb/models/prop.rb
98
+ - lib/sportdb/models/race.rb
98
99
  - lib/sportdb/models/region.rb
100
+ - lib/sportdb/models/roster.rb
99
101
  - lib/sportdb/models/round.rb
100
102
  - lib/sportdb/models/season.rb
101
103
  - lib/sportdb/models/team.rb
104
+ - lib/sportdb/models/track.rb
102
105
  - lib/sportdb/reader.rb
103
106
  - lib/sportdb/schema.rb
104
107
  - lib/sportdb/stats.rb