Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

start adding grounds

  • Loading branch information...
commit 10badc7462715803d5f34a0374019760c94077ad 1 parent 75efa8a
@geraldb geraldb authored
View
1  Manifest.txt
@@ -23,6 +23,7 @@ lib/sportdb/models/event_team.rb
lib/sportdb/models/forward.rb
lib/sportdb/models/game.rb
lib/sportdb/models/goal.rb
+lib/sportdb/models/ground.rb
lib/sportdb/models/group.rb
lib/sportdb/models/group_team.rb
lib/sportdb/models/league.rb
View
2  lib/sportdb.rb
@@ -40,6 +40,7 @@
require 'sportdb/models/event_team'
require 'sportdb/models/game'
require 'sportdb/models/goal'
+require 'sportdb/models/ground'
require 'sportdb/models/group'
require 'sportdb/models/group_team'
require 'sportdb/models/league'
@@ -52,6 +53,7 @@
require 'sportdb/models/season'
require 'sportdb/models/team'
require 'sportdb/models/track'
+
require 'sportdb/models/utils' # e.g. GameCursor
## add backwards compatible namespace (delete later!)
View
2  lib/sportdb/deleter.rb
@@ -31,6 +31,8 @@ def run
League.delete_all
Season.delete_all
+
+ Ground.delete_all # stadiums
end
end # class Deleter
View
2  lib/sportdb/models/forward.rb
@@ -17,6 +17,7 @@ module SportDb::Model
class Team < ActiveRecord::Base ; end
class League < ActiveRecord::Base ; end
+ class Ground < ActiveRecord::Base ; end
end
@@ -28,5 +29,6 @@ module WorldDb::Model
# - just include once in loader??
Team = SportDb::Model::Team
League = SportDb::Model::League
+ Ground = SportDb::Model::Ground
end
View
59 lib/sportdb/models/ground.rb
@@ -0,0 +1,59 @@
+module SportDb::Model
+
+class Ground < ActiveRecord::Base
+
+ belongs_to :country, class_name: 'WorldDb::Model::Country', foreign_key: 'country_id'
+ belongs_to :city, class_name: 'WorldDb::Model::City', foreign_key: 'city_id'
+
+
+ def self.create_or_update_from_values( new_attributes, values )
+
+ ## fix: add/configure logger for ActiveRecord!!!
+ logger = LogKernel::Logger.root
+
+ ## check optional values
+ logger.debug " [Ground] values >#{values.join('<>')}<"
+
+ values.each_with_index do |value, index|
+ if value =~ /^[12][0-9]{3}$/ ## assume founding year
+ # skip founding/opening year fow now
+ logger.info " found year #{value}; skipping for now"
+ elsif value =~ /^[1-9][0-9_]+[0-9]$/ # number; assume capacity e.g. 12_541 or similar
+ # todo/fix: check how to differentiate between founding year and capacity if capcity islike year
+ # - by position ?? year is first entry, capacity is second ??? -add/fix
+
+ # skip capacity
+ logger.info " found capacity #{value}; skipping for now"
+ elsif value =~ /^[A-Z]{1,3}$/ # assume; state/region code e-g B | TX etc.
+ # skip region/state code
+ logger.info " found region/state code #{value}; skipping for now"
+ else
+ logger.info " found city >#{value}< for ground >#{new_attributes[ :key ]}<"
+
+ ## todo: assume title2 ??
+ ## assume title2 if title2 is empty (not already in use)
+ ## and if it title2 contains at least two letter e.g. [a-zA-Z].*[a-zA-Z]
+ # issue warning: unknown type for value
+ # logger.warn "unknown type for value >#{value}< - key #{new_attributes[:key]}"
+ end
+ end
+
+ logger.debug " find ground key: #{new_attributes[ :key ]}"
+
+ rec = Ground.find_by_key( new_attributes[ :key ] )
+ if rec.present?
+ logger.debug "update Ground #{rec.id}-#{rec.key}:"
+ else
+ logger.debug "create Ground:"
+ rec = Ground.new
+ end
+
+ logger.debug new_attributes.to_json
+
+ rec.update_attributes!( new_attributes )
+ end # create_or_update_from_values
+
+
+end # class Ground
+
+end # module SportDb::Model
View
3  lib/sportdb/models/world/city.rb
@@ -5,7 +5,8 @@
module WorldDb::Model
class City
- has_many :teams, class_name: 'SportDb::Model::Team', foreign_key: 'city_id'
+ has_many :teams, class_name: 'SportDb::Model::Team', foreign_key: 'city_id'
+ has_many :grounds, class_name: 'SportDb::Model::Ground', foreign_key: 'city_id'
end
end # module WorldDb::Model
View
1  lib/sportdb/models/world/continent.rb
@@ -5,6 +5,7 @@ module WorldDb::Model
class Continent
has_many :teams, :through => :countries
has_many :leagues, :through => :countries
+ has_many :grounds, :through => :countries
end # class Continent
end # module WorldDb::Model
View
1  lib/sportdb/models/world/country.rb
@@ -7,6 +7,7 @@ module WorldDb::Model
class Country
has_many :teams, class_name: 'SportDb::Model::Team', foreign_key: 'country_id'
has_many :leagues, class_name: 'SportDb::Model::League', foreign_key: 'country_id'
+ has_many :grounds, class_name: 'SportDb::Model::Ground', foreign_key: 'country_id'
end # class Country
end # module WorldDb::Model
View
3  lib/sportdb/models/world/region.rb
@@ -5,7 +5,8 @@
module WorldDb::Model
class Region
- has_many :teams, class_name: 'SportDb::Model::Team', :through => :cities
+ has_many :teams, class_name: 'SportDb::Model::Team', :through => :cities
+ has_many :grounds, class_name: 'SportDb::Model::Ground', :through => :cities
end # class Region
end # module WorldDb::Model
View
17 lib/sportdb/reader.rb
@@ -22,6 +22,10 @@ def match_skiers_for_country( name, &blk )
match_xxx_for_country( name, 'skiers', &blk )
end
+ def match_stadiums_for_country( name, &blk )
+ match_xxx_for_country( name, 'stadiums', &blk )
+ end
+
end # module Matcher
@@ -92,6 +96,10 @@ def load( name ) # convenience helper for all-in-one reader
load_records( name, race_id: race.id ) # e.g. 2013/04-gp-monaco.txt in formula1.db
elsif name =~ /(?:^|\/)seasons/ # NB: ^seasons or also possible at-austria!/seasons
load_seasons( name )
+ elsif match_stadiums_for_country( name ) do |country_key|
+ country = Country.find_by_key!( country_key )
+ load_stadiums( name, country_id: country.id )
+ end
elsif match_leagues_for_country( name ) do |country_key| # name =~ /^([a-z]{2})\/leagues/
# auto-add country code (from folder structure) for country-specific leagues
# e.g. at/leagues
@@ -137,6 +145,15 @@ def load( name ) # convenience helper for all-in-one reader
end
end # method load
+
+ def load_stadiums( name, more_attribs={} )
+ reader = ValuesReaderV2.new( name, include_path, more_attribs )
+
+ reader.each_line do |new_attributes, values|
+ Ground.create_or_update_from_values( new_attributes, values )
+ end # each lines
+ end
+
def load_leagues( name, more_attribs={} )
View
20 lib/sportdb/schema.rb
@@ -23,6 +23,26 @@ def up
add_index :teams, :key, :unique => true
+create_table :grounds do |t|
+ t.string :key, :null => false # import/export key
+ t.string :title, :null => false
+ t.string :synonyms # comma separated list of synonyms
+
+ t.references :country, :null => false
+ t.references :city # todo: make city required ???
+
+ ### fix/todo: add since/founded/opened/build attrib eg. 2011 or 1987
+ ## - add capacity e.g. 40_000
+ ## fix: add address !!!! etc
+
+ ## add region ??? or just use region from city ??
+
+ t.timestamps
+end
+
+add_index :grounds, :key, :unique => true
+
+
create_table :persons do |t| # use people ? instead of persons (person/persons makes it easier?)
t.string :key, :null => false # import/export key
t.string :name, :null => false
View
2  lib/sportdb/stats.rb
@@ -17,6 +17,8 @@ def tables
puts " #{Person.count} persons / #{Roster.count} rosters (person+team+event recs)"
puts " #{Goal.count} goals (person+game recs)"
+ puts " #{Ground.count} grounds|stadiums"
+
puts " #{Country.count} countries / #{Region.count} regions / #{City.count} cities"
## todo: add tags / taggings from worlddb
View
2  lib/sportdb/version.rb
@@ -1,6 +1,6 @@
module SportDb
- VERSION = '1.8.1'
+ VERSION = '1.8.2'
end
Please sign in to comment.
Something went wrong with that request. Please try again.