sportdb 1.8.1 → 1.8.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -19,10 +19,12 @@ lib/sportdb/deleter.rb
19
19
  lib/sportdb/lang.rb
20
20
  lib/sportdb/models/badge.rb
21
21
  lib/sportdb/models/event.rb
22
+ lib/sportdb/models/event_ground.rb
22
23
  lib/sportdb/models/event_team.rb
23
24
  lib/sportdb/models/forward.rb
24
25
  lib/sportdb/models/game.rb
25
26
  lib/sportdb/models/goal.rb
27
+ lib/sportdb/models/ground.rb
26
28
  lib/sportdb/models/group.rb
27
29
  lib/sportdb/models/group_team.rb
28
30
  lib/sportdb/models/league.rb
@@ -37,9 +37,11 @@ require 'sportdb/models/world/continent'
37
37
  require 'sportdb/models/world/region'
38
38
  require 'sportdb/models/badge'
39
39
  require 'sportdb/models/event'
40
+ require 'sportdb/models/event_ground'
40
41
  require 'sportdb/models/event_team'
41
42
  require 'sportdb/models/game'
42
43
  require 'sportdb/models/goal'
44
+ require 'sportdb/models/ground'
43
45
  require 'sportdb/models/group'
44
46
  require 'sportdb/models/group_team'
45
47
  require 'sportdb/models/league'
@@ -52,6 +54,7 @@ require 'sportdb/models/run'
52
54
  require 'sportdb/models/season'
53
55
  require 'sportdb/models/team'
54
56
  require 'sportdb/models/track'
57
+
55
58
  require 'sportdb/models/utils' # e.g. GameCursor
56
59
 
57
60
  ## add backwards compatible namespace (delete later!)
@@ -16,6 +16,7 @@ module SportDb
16
16
  Game.delete_all
17
17
  Event.delete_all
18
18
  EventTeam.delete_all
19
+ EventGround.delete_all
19
20
  Group.delete_all
20
21
  GroupTeam.delete_all
21
22
  Round.delete_all
@@ -31,6 +32,8 @@ module SportDb
31
32
 
32
33
  League.delete_all
33
34
  Season.delete_all
35
+
36
+ Ground.delete_all # stadiums
34
37
  end
35
38
 
36
39
  end # class Deleter
@@ -6,15 +6,19 @@ class Event < ActiveRecord::Base
6
6
 
7
7
  belongs_to :league
8
8
  belongs_to :season
9
-
9
+
10
10
  has_many :rounds, :order => 'pos' # all (fix and flex) rounds
11
11
  has_many :games, :through => :rounds
12
-
12
+
13
13
  has_many :groups, :order => 'pos'
14
-
15
- has_many :event_teams, :class_name => 'EventTeam'
14
+
15
+ has_many :event_teams, :class_name => 'EventTeam'
16
16
  has_many :teams, :through => :event_teams
17
17
 
18
+ has_many :event_grounds, :class_name => 'EventGround'
19
+ has_many :grounds, :through => :event_grounds
20
+
21
+
18
22
  before_save :on_before_save
19
23
 
20
24
  def add_teams_from_ary!( team_keys )
@@ -0,0 +1,12 @@
1
+ module SportDb::Model
2
+
3
+
4
+ class EventGround < ActiveRecord::Base
5
+ self.table_name = 'events_grounds'
6
+
7
+ belongs_to :event
8
+ belongs_to :ground
9
+ end # class EventGround
10
+
11
+
12
+ end # module SportDb::Model
@@ -17,6 +17,7 @@ module SportDb::Model
17
17
 
18
18
  class Team < ActiveRecord::Base ; end
19
19
  class League < ActiveRecord::Base ; end
20
+ class Ground < ActiveRecord::Base ; end
20
21
 
21
22
  end
22
23
 
@@ -28,5 +29,6 @@ module WorldDb::Model
28
29
  # - just include once in loader??
29
30
  Team = SportDb::Model::Team
30
31
  League = SportDb::Model::League
32
+ Ground = SportDb::Model::Ground
31
33
 
32
34
  end
@@ -3,14 +3,18 @@ module SportDb::Model
3
3
 
4
4
  class Game < ActiveRecord::Base
5
5
 
6
- belongs_to :team1, :class_name => 'Team', :foreign_key => 'team1_id'
7
- belongs_to :team2, :class_name => 'Team', :foreign_key => 'team2_id'
6
+ belongs_to :team1, class_name: 'Team', foreign_key: 'team1_id'
7
+ belongs_to :team2, class_name: 'Team', foreign_key: 'team2_id'
8
8
 
9
9
  belongs_to :round
10
10
  belongs_to :group # group is optional
11
11
 
12
+ belongs_to :ground # ground is optional
13
+ belongs_to :city, class_name: 'WorldDb::Model::City', foreign_key: 'city_id' # city is optioanl (remove?? redundant?? use ground ??)
14
+
12
15
  has_many :goals
13
16
 
17
+
14
18
  before_save :calc_winner
15
19
 
16
20
 
@@ -0,0 +1,91 @@
1
+ module SportDb::Model
2
+
3
+ class Ground < ActiveRecord::Base
4
+
5
+ belongs_to :country, class_name: 'WorldDb::Model::Country', foreign_key: 'country_id'
6
+ belongs_to :city, class_name: 'WorldDb::Model::City', foreign_key: 'city_id'
7
+
8
+ has_many :games
9
+
10
+
11
+ def self.create_or_update_from_values( new_attributes, values )
12
+
13
+ ## fix: add/configure logger for ActiveRecord!!!
14
+ logger = LogKernel::Logger.root
15
+
16
+ ## check optional values
17
+ logger.debug " [Ground] values >#{values.join('<>')}<"
18
+
19
+ city_title = ''
20
+
21
+ values.each_with_index do |value, index|
22
+ if value =~ /^[12][0-9]{3}$/ ## assume founding year
23
+ # skip founding/opening year fow now
24
+ logger.info " found year #{value}; skipping for now"
25
+ elsif value =~ /^[1-9][0-9_]+[0-9]$/ # number; assume capacity e.g. 12_541 or similar
26
+ # todo/fix: check how to differentiate between founding year and capacity if capcity islike year
27
+ # - by position ?? year is first entry, capacity is second ??? -add/fix
28
+
29
+ # skip capacity
30
+ logger.info " found capacity #{value}; skipping for now"
31
+ elsif value =~ /^[A-Z]{1,3}$/ # assume; state/region code e-g B | TX etc.
32
+ # skip region/state code
33
+ logger.info " found region/state code #{value}; skipping for now"
34
+ elsif value =~ /\/{2}/ # assume it's an address line e.g. xx // xx
35
+ logger.info " found address line #{value}; skipping for now"
36
+ elsif value =~ /^clubs:/ # assume it's clubs line e.g. clubs: Santos
37
+ logger.info " found clubs line #{value}; skipping for now"
38
+ elsif value =~ /^(?:[a-z]{2}\.)?wikipedia:/ # assume it's wikipedia e.g. [es.]wikipedia:
39
+ logger.info " found wikipedia line #{value}; skipping for now"
40
+ else
41
+ logger.info " found city >#{value}< for ground >#{new_attributes[ :key ]}<"
42
+
43
+ city_title = value.dup # remember for auto-add city
44
+
45
+ ## todo: assume title2 ??
46
+ ## assume title2 if title2 is empty (not already in use)
47
+ ## and if it title2 contains at least two letter e.g. [a-zA-Z].*[a-zA-Z]
48
+ # issue warning: unknown type for value
49
+ # logger.warn "unknown type for value >#{value}< - key #{new_attributes[:key]}"
50
+ end
51
+ end
52
+
53
+ logger.debug " find ground key: #{new_attributes[ :key ]}"
54
+
55
+ rec = Ground.find_by_key( new_attributes[ :key ] )
56
+ if rec.present?
57
+ logger.debug "update Ground #{rec.id}-#{rec.key}:"
58
+ else
59
+ logger.debug "create Ground:"
60
+ rec = Ground.new
61
+ end
62
+
63
+ logger.debug new_attributes.to_json
64
+
65
+ rec.update_attributes!( new_attributes )
66
+
67
+ #### try to auto-add city
68
+
69
+ if city_title.present?
70
+ city_values = [city_title]
71
+ city_attributes = {
72
+ country_id: rec.country_id,
73
+ # region_id: rec.region_id ### todo/fix: add region if present
74
+ }
75
+
76
+ # todo: add convenience helper create_or_update_from_title
77
+ city = City.create_or_update_from_values( city_values, city_attributes )
78
+
79
+ ### fix/todo: set new autoadd flag too?
80
+ ## e.g. check if updated? e.g. timestamp created <> updated otherwise assume created?
81
+
82
+ ## now at last add city_id to brewery!
83
+ rec.city_id = city.id
84
+ rec.save!
85
+ end
86
+ end # create_or_update_from_values
87
+
88
+
89
+ end # class Ground
90
+
91
+ end # module SportDb::Model
@@ -5,7 +5,9 @@
5
5
  module WorldDb::Model
6
6
 
7
7
  class City
8
- has_many :teams, class_name: 'SportDb::Model::Team', foreign_key: 'city_id'
8
+ has_many :teams, class_name: 'SportDb::Model::Team', foreign_key: 'city_id'
9
+ has_many :grounds, class_name: 'SportDb::Model::Ground', foreign_key: 'city_id'
10
+ has_many :games, :through => :grounds
9
11
  end
10
12
 
11
13
  end # module WorldDb::Model
@@ -5,6 +5,7 @@ module WorldDb::Model
5
5
  class Continent
6
6
  has_many :teams, :through => :countries
7
7
  has_many :leagues, :through => :countries
8
+ has_many :grounds, :through => :countries
8
9
  end # class Continent
9
10
 
10
11
  end # module WorldDb::Model
@@ -7,6 +7,7 @@ module WorldDb::Model
7
7
  class Country
8
8
  has_many :teams, class_name: 'SportDb::Model::Team', foreign_key: 'country_id'
9
9
  has_many :leagues, class_name: 'SportDb::Model::League', foreign_key: 'country_id'
10
+ has_many :grounds, class_name: 'SportDb::Model::Ground', foreign_key: 'country_id'
10
11
  end # class Country
11
12
 
12
13
  end # module WorldDb::Model
@@ -5,7 +5,8 @@
5
5
  module WorldDb::Model
6
6
 
7
7
  class Region
8
- has_many :teams, class_name: 'SportDb::Model::Team', :through => :cities
8
+ has_many :teams, class_name: 'SportDb::Model::Team', :through => :cities
9
+ has_many :grounds, class_name: 'SportDb::Model::Ground', :through => :cities
9
10
  end # class Region
10
11
 
11
12
  end # module WorldDb::Model
@@ -22,6 +22,10 @@ module Matcher
22
22
  match_xxx_for_country( name, 'skiers', &blk )
23
23
  end
24
24
 
25
+ def match_stadiums_for_country( name, &blk )
26
+ match_xxx_for_country( name, 'stadiums', &blk )
27
+ end
28
+
25
29
  end # module Matcher
26
30
 
27
31
 
@@ -92,6 +96,10 @@ class Reader
92
96
  load_records( name, race_id: race.id ) # e.g. 2013/04-gp-monaco.txt in formula1.db
93
97
  elsif name =~ /(?:^|\/)seasons/ # NB: ^seasons or also possible at-austria!/seasons
94
98
  load_seasons( name )
99
+ elsif match_stadiums_for_country( name ) do |country_key|
100
+ country = Country.find_by_key!( country_key )
101
+ load_stadiums( name, country_id: country.id )
102
+ end
95
103
  elsif match_leagues_for_country( name ) do |country_key| # name =~ /^([a-z]{2})\/leagues/
96
104
  # auto-add country code (from folder structure) for country-specific leagues
97
105
  # e.g. at/leagues
@@ -137,6 +145,15 @@ class Reader
137
145
  end
138
146
  end # method load
139
147
 
148
+
149
+ def load_stadiums( name, more_attribs={} )
150
+ reader = ValuesReaderV2.new( name, include_path, more_attribs )
151
+
152
+ reader.each_line do |new_attributes, values|
153
+ Ground.create_or_update_from_values( new_attributes, values )
154
+ end # each lines
155
+ end
156
+
140
157
 
141
158
  def load_leagues( name, more_attribs={} )
142
159
 
@@ -351,8 +368,18 @@ class Reader
351
368
 
352
369
  event_attribs['end_at'] = end_at
353
370
 
354
- elsif key == 'teams'
371
+ elsif key == 'grounds' || key == 'stadiums' || key == 'venues'
372
+ ## assume grounds value is an array
355
373
 
374
+ ground_ids = []
375
+ value.each do |item|
376
+ ground_key = item.to_s.strip
377
+ ground = Ground.find_by_key!( ground_key )
378
+ ground_ids << ground.id
379
+ end
380
+
381
+ event_attribs['ground_ids'] = ground_ids
382
+ elsif key == 'teams'
356
383
  ## assume teams value is an array
357
384
 
358
385
  team_ids = []
@@ -684,9 +711,13 @@ private
684
711
  @event = Event.find_by_key!( event_key )
685
712
 
686
713
  logger.debug "Event #{@event.key} >#{@event.title}<"
687
-
688
- @known_teams = @event.known_teams_table
689
-
714
+
715
+ ### fix: use build_title_table_for ??? why? why not??
716
+ @known_teams = @event.known_teams_table
717
+
718
+ @known_grounds = TextUtils.build_title_table_for( @event.grounds )
719
+
720
+
690
721
  parse_fixtures( reader )
691
722
 
692
723
  end # method load_fixtures
@@ -812,6 +843,12 @@ private
812
843
 
813
844
  scores = find_scores!( line )
814
845
 
846
+
847
+ map_ground!( line )
848
+ ground_key = find_ground!( line )
849
+ ground = ground_key.nil? ? nil : Ground.find_by_key!( ground_key )
850
+
851
+
815
852
  logger.debug " line: >#{line}<"
816
853
 
817
854
 
@@ -820,6 +857,7 @@ private
820
857
  team1 = Team.find_by_key!( team1_key )
821
858
  team2 = Team.find_by_key!( team2_key )
822
859
 
860
+
823
861
  ### check if games exists
824
862
  ## with this teams in this round if yes only update
825
863
  game = Game.find_by_round_id_and_team1_id_and_team2_id(
@@ -837,6 +875,7 @@ private
837
875
  play_at_v2: date_v2,
838
876
  postponed: postponed,
839
877
  knockout: @knockout_flag,
878
+ ground_id: ground.present? ? ground.id : nil,
840
879
  group_id: @group.present? ? @group.id : nil
841
880
  }
842
881
 
@@ -6,26 +6,46 @@ 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
10
- t.string :title, :null => false
9
+ t.string :key, null: false # import/export key
10
+ t.string :title, null: false
11
11
  t.string :title2
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
- t.references :country, :null => false
14
+ t.references :country, null: false
15
15
  t.references :city # NB: city is optional (should be required for clubs e.g. non-national teams)
16
- t.boolean :club, :null => false, :default => false # is it a club (not a national team)?
17
-
16
+ t.boolean :club, null: false, default: false # is it a club (not a national team)?
17
+
18
18
  ### fix: remove and add virtual attribute in model instead
19
- t.boolean :national, :null => false, :default => false # is it a national selection team (not a club)?
19
+ t.boolean :national, null: false, default: false # is it a national selection team (not a club)?
20
+ t.timestamps
21
+ end
22
+
23
+ add_index :teams, :key, unique: true
24
+
25
+
26
+ create_table :grounds do |t|
27
+ t.string :key, null: false # import/export key
28
+ t.string :title, null: false
29
+ t.string :synonyms # comma separated list of synonyms
30
+
31
+ t.references :country, null: false
32
+ t.references :city # todo: make city required ???
33
+
34
+ ### fix/todo: add since/founded/opened/build attrib eg. 2011 or 1987
35
+ ## - add capacity e.g. 40_000
36
+ ## fix: add address !!!! etc
37
+
38
+ ## add region ??? or just use region from city ??
39
+
20
40
  t.timestamps
21
41
  end
22
42
 
23
- add_index :teams, :key, :unique => true
43
+ add_index :grounds, :key, unique: true
24
44
 
25
45
 
26
46
  create_table :persons do |t| # use people ? instead of persons (person/persons makes it easier?)
27
- t.string :key, :null => false # import/export key
28
- t.string :name, :null => false
47
+ t.string :key, null: false # import/export key
48
+ t.string :name, null: false
29
49
  t.string :synonyms # comma separated list of synonyms
30
50
  t.string :code # three letter code (short title)
31
51
 
@@ -35,48 +55,48 @@ create_table :persons do |t| # use people ? instead of persons (person/person
35
55
 
36
56
  t.references :city
37
57
  t.references :region
38
- t.references :country, :null => false
58
+ t.references :country, null: false
39
59
 
40
- t.references :nationality, :null => false # by default assume same as country of birth (see above)
60
+ t.references :nationality, null: false # by default assume same as country of birth (see above)
41
61
 
42
62
  t.timestamps
43
63
  end
44
64
 
45
65
  # join table: person+game(team1+team2+event(season+league))
46
66
  create_table :goals do |t|
47
- t.references :person, :null => false
48
- t.references :game, :null => false
67
+ t.references :person, null: false
68
+ t.references :game, null: false
49
69
  t.integer :minute
50
70
  t.integer :offset # e.g. 45' +3 or 90' +2
51
71
  t.integer :score1
52
72
  t.integer :score2
53
73
 
54
74
  ## type of goal (penalty, owngoal)
55
- t.boolean :penalty, :null => false, :default => false
56
- t.boolean :owngoal, :null => false, :default => false # de: Eigentor -> # todo: find better name?
75
+ t.boolean :penalty, null: false, default: false
76
+ t.boolean :owngoal, null: false, default: false # de: Eigentor -> # todo: find better name?
57
77
 
58
78
  t.timestamps
59
79
  end
60
80
 
61
81
 
62
82
  create_table :tracks do |t| # e.g. Formula 1 circuits or Apline Ski resorts/slops/pistes
63
- t.string :key, :null => false # import/export key
64
- t.string :title, :null => false
83
+ t.string :key, null: false # import/export key
84
+ t.string :title, null: false
65
85
  t.string :synonyms # comma separated list of synonyms
66
86
  t.string :code # three letter code (short title)
67
87
 
68
88
  t.references :city
69
89
  t.references :region
70
- t.references :country, :null => false
90
+ t.references :country, null: false
71
91
  t.timestamps
72
92
  end
73
93
 
74
94
 
75
95
  # join table -> event(season+league)+track
76
96
  create_table :races do |t| # e.g. Formula 1 race (Grand Prix Monaco) or Alpine Ski race (Downhill Lake Louise)
77
- t.references :track, :null => false
78
- t.references :event, :null => false
79
- t.integer :pos, :null => false # Race #1,#2,#3,#4 etc.
97
+ t.references :track, null: false
98
+ t.references :event, null: false
99
+ t.integer :pos, null: false # Race #1,#2,#3,#4 etc.
80
100
 
81
101
  ## todo: add auto-created key (for import/export) e.g.
82
102
 
@@ -85,8 +105,8 @@ create_table :races do |t| # e.g. Formula 1 race (Grand Prix Monaco) or Alpi
85
105
  end
86
106
 
87
107
  create_table :runs do |t|
88
- t.references :race, :null => false
89
- t.integer :pos, :null => false
108
+ t.references :race, null: false
109
+ t.integer :pos, null: false
90
110
 
91
111
  t.datetime :start_at
92
112
  t.timestamps
@@ -96,9 +116,9 @@ end
96
116
  create_table :records do |t| # use TimeRecord? instead of simple record
97
117
  t.references :race # optional either race or run references
98
118
  t.references :run
99
- t.references :person, :null => false
119
+ t.references :person, null: false
100
120
  t.integer :pos # 1,2,3, etc or 0
101
- t.boolean :completed, :null => false, :default => true # completed race - find better name?
121
+ t.boolean :completed, null: false, default: true # completed race - find better name?
102
122
  t.string :state # find a better name? e.g. retired, e.g.
103
123
  t.string :comment # find a better name ? e.g. collision damage (if ret) for formula 1
104
124
  t.time :time
@@ -111,22 +131,22 @@ end
111
131
 
112
132
  # join table -> person+team+event(season+league)
113
133
  create_table :rosters do |t| # use squads as an alternative name? why? why not??
114
- t.references :person, :null => false
115
- t.references :team, :null => false
134
+ t.references :person, null: false
135
+ t.references :team, null: false
116
136
  t.references :event # make required?
117
- t.integer :pos, :null => false
137
+ t.integer :pos, null: false
118
138
 
119
139
  t.timestamps
120
140
  end
121
141
 
122
142
 
123
143
  create_table :events do |t|
124
- t.string :key, :null => false # import/export key
125
- t.references :league, :null => false
126
- t.references :season, :null => false
127
- t.date :start_at, :null => false # NB: only use date (w/o time)
144
+ t.string :key, null: false # import/export key
145
+ t.references :league, null: false
146
+ t.references :season, null: false
147
+ t.date :start_at, null: false # NB: only use date (w/o time)
128
148
  t.date :end_at # make it required??? # NB: only use date (w/o time)
129
- t.boolean :team3, :null => false, :default => true ## e.g. Champions League has no 3rd place (only 1st and 2nd/final)
149
+ t.boolean :team3, null: false, default: true ## e.g. Champions League has no 3rd place (only 1st and 2nd/final)
130
150
 
131
151
  #### track 1-n sources (from repos) - # todo move to its own table later
132
152
  ## NB: relative to event.yml - use mapper to "resolve" to full path w/ repo; use league+season keys
@@ -137,18 +157,18 @@ create_table :events do |t|
137
157
  t.timestamps
138
158
  end
139
159
 
140
- add_index :events, :key, :unique => true
160
+ add_index :events, :key, unique: true
141
161
 
142
162
 
143
163
  create_table :rounds do |t|
144
- t.references :event, :null => false
145
- t.string :title, :null => false
164
+ t.references :event, null: false
165
+ t.string :title, null: false
146
166
  t.string :title2
147
- t.integer :pos, :null => false
167
+ t.integer :pos, null: false
148
168
  ## add new table stage/stages for grouping rounds in group rounds and playoff rounds, for example???
149
169
  ## # "regular" season (group) games or post-season (playoff) knockouts (k.o's)
150
- t.boolean :knockout, :null => false, :default => false
151
- t.date :start_at, :null => false # NB: only use date (w/o time)
170
+ t.boolean :knockout, null: false, default: false
171
+ t.date :start_at, null: false # NB: only use date (w/o time)
152
172
  t.date :end_at # todo: make it required e.g. :null => false # NB: only use date (w/o time)
153
173
 
154
174
  t.timestamps
@@ -158,9 +178,9 @@ add_index :rounds, :event_id # fk event_id index
158
178
 
159
179
 
160
180
  create_table :groups do |t| # Teamgruppe (zB Gruppe A, Gruppe B, etc.)
161
- t.references :event, :null => false
162
- t.string :title, :null => false
163
- t.integer :pos, :null => false
181
+ t.references :event, null: false
182
+ t.string :title, null: false
183
+ t.integer :pos, null: false
164
184
  t.timestamps
165
185
  end
166
186
 
@@ -169,19 +189,23 @@ add_index :groups, :event_id # fk event_id index
169
189
 
170
190
  create_table :games do |t|
171
191
  t.string :key # import/export key
172
- t.references :round, :null => false
173
- t.integer :pos, :null => false
192
+ t.references :round, null: false
193
+ t.integer :pos, null: false
174
194
  t.references :group # note: group is optional
175
- t.references :team1, :null => false
176
- t.references :team2, :null => false
195
+ t.references :team1, null: false
196
+ t.references :team2, null: false
177
197
 
178
- t.datetime :play_at, :null => false
179
- t.boolean :postponed, :null => false, :default => false
198
+ t.datetime :play_at, null: false
199
+ t.boolean :postponed, null: false, default: false
180
200
  t.datetime :play_at_v2 # optional old date (when postponed)
181
201
  t.datetime :play_at_v3 # optional odl date (when postponed twice)
182
202
 
183
- t.boolean :knockout, :null => false, :default => false
184
- t.boolean :home, :null => false, :default => true # is team1 play at home (that is, at its home stadium)
203
+ t.references :ground # optional - stadium (lets you get city,region,country,etc)
204
+ t.references :city # optional - convenience for ground.city_id ???
205
+
206
+
207
+ t.boolean :knockout, null: false, default: false
208
+ t.boolean :home, null: false, default: true # is team1 play at home (that is, at its home stadium)
185
209
  t.integer :score1
186
210
  t.integer :score2
187
211
  t.integer :score1et # extratime - team 1 (opt)
@@ -201,7 +225,7 @@ create_table :games do |t|
201
225
  t.timestamps
202
226
  end
203
227
 
204
- add_index :games, :key, :unique => true
228
+ add_index :games, :key, unique: true
205
229
  add_index :games, :round_id # fk round_id index
206
230
  add_index :games, :group_id # fk group_id index
207
231
  add_index :games, :next_game_id # fk next_game_id index
@@ -211,40 +235,52 @@ add_index :games, :prev_game_id # fk next_game_id index
211
235
 
212
236
  # todo: remove id from join table (without extra fields)? why?? why not??
213
237
  create_table :events_teams do |t|
214
- t.references :event, :null => false
215
- t.references :team, :null => false
238
+ t.references :event, null: false
239
+ t.references :team, null: false
216
240
  t.timestamps
217
241
  end
218
242
 
219
- add_index :events_teams, [:event_id,:team_id], :unique => true
243
+ add_index :events_teams, [:event_id,:team_id], unique: true
220
244
  add_index :events_teams, :event_id
221
245
 
222
246
 
247
+ # todo: remove id from join table (without extra fields)? why?? why not??
248
+ create_table :events_grounds do |t|
249
+ t.references :event, null: false
250
+ t.references :ground, null: false
251
+ t.timestamps
252
+ end
253
+
254
+ add_index :events_grounds, [:event_id,:ground_id], unique: true
255
+ add_index :events_grounds, :event_id
256
+
257
+
258
+
223
259
  create_table :groups_teams do |t|
224
- t.references :group, :null => false
225
- t.references :team, :null => false
260
+ t.references :group, null: false
261
+ t.references :team, null: false
226
262
  t.timestamps
227
263
  end
228
264
 
229
- add_index :groups_teams, [:group_id,:team_id], :unique => true
265
+ add_index :groups_teams, [:group_id,:team_id], unique: true
230
266
  add_index :groups_teams, :group_id
231
-
232
-
267
+
268
+
233
269
  ### todo: add models and some seed data
234
270
 
235
271
  create_table :seasons do |t| ## also used for years
236
- t.string :key, :null => false
237
- t.string :title, :null => false # e.g. 2011/12, 2012/13 ### what to do w/ 2012? for world cup etc?
272
+ t.string :key, null: false
273
+ t.string :title, null: false # e.g. 2011/12, 2012/13 ### what to do w/ 2012? for world cup etc?
238
274
  t.timestamps
239
275
  end
240
276
 
241
277
  create_table :leagues do |t| ## also for cups/conferences/tournaments/world series/etc.
242
- t.string :key, :null => false
243
- t.string :title, :null => false # e.g. Premier League, Deutsche Bundesliga, World Cup, Champions League, etc.
278
+ t.string :key, null: false
279
+ t.string :title, null: false # e.g. Premier League, Deutsche Bundesliga, World Cup, Champions League, etc.
244
280
  t.references :country ## optional for now , :null => false ### todo: create "virtual" country for international leagues e.g. use int? or world (ww?)/europe (eu)/etc. similar? already taken??
245
281
 
246
282
  ## fix: rename to :clubs from :club
247
- t.boolean :club, :null => false, :default => false # club teams or national teams?
283
+ t.boolean :club, null: false, default: false # club teams or national teams?
248
284
  ## todo: add t.boolean :national flag? for national teams?
249
285
  ## t.boolean :international, :null => false, :default => false # national league or international?
250
286
  ## t.boolean :cup ## or regular season league??
@@ -252,12 +288,12 @@ create_table :leagues do |t| ## also for cups/conferences/tournaments/world ser
252
288
  end
253
289
 
254
290
  create_table :badges do |t|
255
- t.references :team, :null => false
291
+ t.references :team, null: false
256
292
  ## todo/fix: use event insead of league+season ??
257
293
  ## t.references :event, :null => false # event => league+season
258
- t.references :league, :null => false
259
- t.references :season, :null => false
260
- t.string :title, :null => false # Meister, Weltmeister, Europameister, Cupsieger, Vize-Meister, Aufsteiger, Absteiger, etc.
294
+ t.references :league, null: false
295
+ t.references :season, null: false
296
+ t.string :title, null: false # Meister, Weltmeister, Europameister, Cupsieger, Vize-Meister, Aufsteiger, Absteiger, etc.
261
297
  t.timestamps
262
298
  end
263
299
 
@@ -17,6 +17,8 @@ module SportDb
17
17
  puts " #{Person.count} persons / #{Roster.count} rosters (person+team+event recs)"
18
18
  puts " #{Goal.count} goals (person+game recs)"
19
19
 
20
+ puts " #{Ground.count} grounds|stadiums"
21
+
20
22
  puts " #{Country.count} countries / #{Region.count} regions / #{City.count} cities"
21
23
 
22
24
  ## todo: add tags / taggings from worlddb
@@ -528,6 +528,17 @@ module SportDb::FixtureHelpers
528
528
  map_teams!( line )
529
529
  end
530
530
 
531
+
532
+ def find_ground!( line )
533
+ TextUtils.find_key_for!( 'ground', line )
534
+ end
535
+
536
+ ## todo/fix: pass in known_grounds as a parameter? why? why not?
537
+ def map_ground!( line )
538
+ TextUtils.map_titles_for!( 'ground', line, @known_grounds )
539
+ end
540
+
541
+
531
542
  def find_track!( line )
532
543
  TextUtils.find_key_for!( 'track', line )
533
544
  end
@@ -1,6 +1,6 @@
1
1
 
2
2
  module SportDb
3
- VERSION = '1.8.1'
3
+ VERSION = '1.8.2'
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.8.1
4
+ version: 1.8.2
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: 2014-02-09 00:00:00.000000000 Z
12
+ date: 2014-02-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: worlddb
16
- requirement: &20011296 !ruby/object:Gem::Requirement
16
+ requirement: &5976588 !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: *20011296
24
+ version_requirements: *5976588
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: fetcher
27
- requirement: &20009076 !ruby/object:Gem::Requirement
27
+ requirement: &5974812 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0.3'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *20009076
35
+ version_requirements: *5974812
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: gli
38
- requirement: &20104680 !ruby/object:Gem::Requirement
38
+ requirement: &5973264 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 2.5.6
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *20104680
46
+ version_requirements: *5973264
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rdoc
49
- requirement: &20102280 !ruby/object:Gem::Requirement
49
+ requirement: &5987700 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '4.0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *20102280
57
+ version_requirements: *5987700
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: hoe
60
- requirement: &20099184 !ruby/object:Gem::Requirement
60
+ requirement: &5981688 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,7 +65,7 @@ dependencies:
65
65
  version: '3.7'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *20099184
68
+ version_requirements: *5981688
69
69
  description: sportdb - sport.db command line tool
70
70
  email: opensport@googlegroups.com
71
71
  executables:
@@ -97,10 +97,12 @@ files:
97
97
  - lib/sportdb/lang.rb
98
98
  - lib/sportdb/models/badge.rb
99
99
  - lib/sportdb/models/event.rb
100
+ - lib/sportdb/models/event_ground.rb
100
101
  - lib/sportdb/models/event_team.rb
101
102
  - lib/sportdb/models/forward.rb
102
103
  - lib/sportdb/models/game.rb
103
104
  - lib/sportdb/models/goal.rb
105
+ - lib/sportdb/models/ground.rb
104
106
  - lib/sportdb/models/group.rb
105
107
  - lib/sportdb/models/group_team.rb
106
108
  - lib/sportdb/models/league.rb