sportdb-models 1.18.5 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Manifest.txt +27 -145
- data/Rakefile +4 -5
- data/lib/sportdb/models.rb +93 -160
- data/lib/sportdb/{deleter.rb → models/deleter.rb} +4 -10
- data/lib/sportdb/models/formats.rb +23 -0
- data/lib/sportdb/models/models/assoc.rb +38 -0
- data/lib/sportdb/models/{badge.rb → models/badge.rb} +1 -1
- data/lib/sportdb/models/models/event.rb +55 -0
- data/lib/sportdb/models/{forward.rb → models/forward.rb} +3 -3
- data/lib/sportdb/models/{goal.rb → models/goal.rb} +1 -1
- data/lib/sportdb/models/models/ground.rb +16 -0
- data/lib/sportdb/models/{group.rb → models/group.rb} +10 -7
- data/lib/sportdb/models/models/league.rb +20 -0
- data/lib/sportdb/models/{roster.rb → models/lineup.rb} +3 -4
- data/lib/sportdb/models/{game.rb → models/match.rb} +18 -61
- data/lib/sportdb/models/{person.rb → models/person.rb} +0 -0
- data/lib/sportdb/models/{round.rb → models/round.rb} +1 -6
- data/lib/sportdb/models/{season.rb → models/season.rb} +2 -1
- data/lib/sportdb/models/{stage.rb → models/stage.rb} +9 -5
- data/lib/sportdb/models/{stats/alltime_standing_entry.rb → models/stats/alltime_standing.rb} +9 -1
- data/lib/sportdb/models/{stats/event_standing_entry.rb → models/stats/event_standing.rb} +11 -1
- data/lib/sportdb/models/{stats/group_standing_entry.rb → models/stats/group_standing.rb} +10 -1
- data/lib/sportdb/models/models/team.rb +56 -0
- data/lib/sportdb/models/{world → models/world}/city.rb +2 -2
- data/lib/sportdb/models/{world → models/world}/continent.rb +0 -0
- data/lib/sportdb/models/{world → models/world}/country.rb +0 -0
- data/lib/sportdb/models/{world → models/world}/state.rb +0 -0
- data/lib/sportdb/{schema.rb → models/schema.rb} +165 -100
- data/lib/sportdb/models/stats.rb +23 -0
- data/lib/sportdb/models/utils.rb +24 -24
- data/lib/sportdb/{version.rb → models/version.rb} +12 -5
- data/test/helper.rb +10 -114
- data/test/test_changes.rb +38 -38
- data/test/test_cursor.rb +15 -15
- data/test/test_winner.rb +75 -70
- metadata +29 -161
- data/lib/sportdb/calc.rb +0 -279
- data/lib/sportdb/indexers/team.rb +0 -87
- data/lib/sportdb/mapper_teams.rb +0 -24
- data/lib/sportdb/matcher.rb +0 -31
- data/lib/sportdb/models/assoc.rb +0 -106
- data/lib/sportdb/models/assoc_assoc.rb +0 -15
- data/lib/sportdb/models/event.rb +0 -66
- data/lib/sportdb/models/event_ground.rb +0 -15
- data/lib/sportdb/models/event_team.rb +0 -16
- data/lib/sportdb/models/ground.rb +0 -100
- data/lib/sportdb/models/group_team.rb +0 -14
- data/lib/sportdb/models/league.rb +0 -83
- data/lib/sportdb/models/stage_team.rb +0 -14
- data/lib/sportdb/models/stats/alltime_standing.rb +0 -44
- data/lib/sportdb/models/stats/event_standing.rb +0 -55
- data/lib/sportdb/models/stats/group_standing.rb +0 -50
- data/lib/sportdb/models/team.rb +0 -119
- data/lib/sportdb/models/team_compat.rb +0 -64
- data/lib/sportdb/patterns.rb +0 -37
- data/lib/sportdb/pretty_printer.rb +0 -175
- data/lib/sportdb/reader.rb +0 -132
- data/lib/sportdb/reader_file.rb +0 -131
- data/lib/sportdb/reader_zip.rb +0 -172
- data/lib/sportdb/readers/assoc.rb +0 -54
- data/lib/sportdb/readers/event.rb +0 -253
- data/lib/sportdb/readers/event_meta.rb +0 -133
- data/lib/sportdb/readers/event_table.rb +0 -196
- data/lib/sportdb/readers/game.rb +0 -912
- data/lib/sportdb/readers/ground.rb +0 -53
- data/lib/sportdb/readers/league.rb +0 -54
- data/lib/sportdb/readers/season.rb +0 -83
- data/lib/sportdb/readers/squad_club.rb +0 -201
- data/lib/sportdb/readers/squad_national_team.rb +0 -173
- data/lib/sportdb/readers/team.rb +0 -53
- data/lib/sportdb/rsssf_reader.rb +0 -367
- data/lib/sportdb/standings.rb +0 -178
- data/lib/sportdb/stats.rb +0 -27
- data/lib/sportdb/utils.rb +0 -89
- data/lib/sportdb/utils_date.rb +0 -26
- data/lib/sportdb/utils_goals.rb +0 -20
- data/lib/sportdb/utils_group.rb +0 -63
- data/lib/sportdb/utils_map.rb +0 -44
- data/lib/sportdb/utils_round.rb +0 -165
- data/lib/sportdb/utils_scores.rb +0 -17
- data/lib/sportdb/utils_teams.rb +0 -48
- data/test/data/at-austria/2013_14/bl.txt +0 -227
- data/test/data/at-austria/2013_14/bl.yml +0 -30
- data/test/data/at-austria/2013_14/bl_ii.txt +0 -154
- data/test/data/at-austria/2013_14/el.txt +0 -4
- data/test/data/at-austria/2013_14/el.yml +0 -25
- data/test/data/at-austria/2013_14/squads/austria.txt +0 -40
- data/test/data/at-austria/2013_14/squads/salzburg.txt +0 -35
- data/test/data/at-austria/2014_15/1-bundesliga-ii.txt +0 -158
- data/test/data/at-austria/2014_15/1-bundesliga.yml +0 -18
- data/test/data/at-austria/2015_16/1-bundesliga-v2.conf.txt +0 -20
- data/test/data/at-austria/2015_16/1-bundesliga-v2.yml +0 -20
- data/test/data/at-austria/2015_16/1-bundesliga.conf.txt +0 -20
- data/test/data/at-austria/2015_16/1-bundesliga.yml +0 -24
- data/test/data/at-austria/2015_16/cup.yml +0 -77
- data/test/data/at-austria/leagues.txt +0 -11
- data/test/data/at-austria/teams.txt +0 -68
- data/test/data/at-austria/teams_2.txt +0 -21
- data/test/data/csv/de-2013-14--1-bundesliga.txt +0 -307
- data/test/data/de-deutschland/2013-14/1-bundesliga.yml +0 -26
- data/test/data/de-deutschland/leagues.txt +0 -4
- data/test/data/de-deutschland/teams.txt +0 -53
- data/test/data/eng-england/2015-16/1-premierleague-v2.yml +0 -2
- data/test/data/eng-england/2015-16/1-premierleague.yml +0 -5
- data/test/data/national-teams/assocs.txt +0 -231
- data/test/data/national-teams/europe/assocs.txt +0 -13
- data/test/data/national-teams/europe/teams.txt +0 -13
- data/test/data/national-teams/north-america/assocs.txt +0 -10
- data/test/data/national-teams/north-america/teams.txt +0 -7
- data/test/data/national-teams/teams.txt +0 -19
- data/test/data/players/europe/at-austria/players.txt +0 -45
- data/test/data/players/europe/de-deutschland/players.txt +0 -41
- data/test/data/players/south-america/br-brazil/players.txt +0 -51
- data/test/data/rsssf/at-2014-15--1-bundesliga.txt +0 -339
- data/test/data/rsssf/at-2015-16--1-bundesliga.txt +0 -18
- data/test/data/world-cup/1930/cup.txt +0 -71
- data/test/data/world-cup/1930/cup.yml +0 -23
- data/test/data/world-cup/1930/cup_goals.txt +0 -47
- data/test/data/world-cup/1930/cup_goals.yml +0 -23
- data/test/data/world-cup/1954/cup.txt +0 -90
- data/test/data/world-cup/1954/cup.yml +0 -30
- data/test/data/world-cup/1962/cup.txt +0 -86
- data/test/data/world-cup/1962/cup.yml +0 -32
- data/test/data/world-cup/1974/cup.yml +0 -35
- data/test/data/world-cup/1974/cup_finals.txt +0 -14
- data/test/data/world-cup/1974/cup_i.txt +0 -55
- data/test/data/world-cup/1974/cup_ii.txt +0 -34
- data/test/data/world-cup/2014/cup.txt +0 -5
- data/test/data/world-cup/2014/cup.yml +0 -54
- data/test/data/world-cup/2014/squads/br-brazil.txt +0 -46
- data/test/data/world-cup/2014/squads/de-deutschland.txt +0 -8
- data/test/data/world-cup/2014/squads/jp-japan.txt +0 -30
- data/test/data/world-cup/2014/squads/uy-uruguay.txt +0 -32
- data/test/data/world-cup/leagues.txt +0 -5
- data/test/data/world-cup/seasons_1930.txt +0 -4
- data/test/data/world-cup/seasons_1954.txt +0 -4
- data/test/data/world-cup/seasons_1962.txt +0 -4
- data/test/data/world-cup/seasons_1974.txt +0 -5
- data/test/data/world-cup/teams_1930.txt +0 -26
- data/test/data/world-cup/teams_1954.txt +0 -30
- data/test/data/world-cup/teams_1962.txt +0 -29
- data/test/data/world-cup/teams_1974.txt +0 -29
- data/test/test_assoc_reader.rb +0 -199
- data/test/test_event_meta_reader.rb +0 -47
- data/test/test_event_reader.rb +0 -64
- data/test/test_event_table_reader.rb +0 -57
- data/test/test_goals.rb +0 -107
- data/test/test_indexer_team.rb +0 -34
- data/test/test_load.rb +0 -61
- data/test/test_pp.rb +0 -35
- data/test/test_reader.rb +0 -88
- data/test/test_reader_from_string.rb +0 -63
- data/test/test_round_auto.rb +0 -370
- data/test/test_round_def.rb +0 -109
- data/test/test_round_header.rb +0 -183
- data/test/test_rsssf_reader.rb +0 -76
- data/test/test_squad_club_reader.rb +0 -76
- data/test/test_squad_national_team_reader.rb +0 -116
- data/test/test_standings.rb +0 -279
- data/test/test_standings_ii.rb +0 -46
- data/test/test_utils.rb +0 -124
@@ -1,87 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
module SportDb
|
4
|
-
|
5
|
-
|
6
|
-
##
|
7
|
-
# todo/check:
|
8
|
-
# simply add index() method to TeamReader (and remove this class) - why? why not??
|
9
|
-
|
10
|
-
|
11
|
-
class TeamIndexer
|
12
|
-
|
13
|
-
include LogUtils::Logging
|
14
|
-
|
15
|
-
## make models available by default with namespace
|
16
|
-
# e.g. lets you use Usage instead of Model::Usage
|
17
|
-
include Models
|
18
|
-
|
19
|
-
|
20
|
-
def self.from_file( path, more_attribs={} )
|
21
|
-
## note: assume/enfore utf-8 encoding (with or without BOM - byte order mark)
|
22
|
-
## - see textutils/utils.rb
|
23
|
-
text = File.read_utf8( path )
|
24
|
-
self.from_string( text, more_attribs )
|
25
|
-
end
|
26
|
-
|
27
|
-
def self.from_string( text, more_attribs={} )
|
28
|
-
self.new( text, more_attribs )
|
29
|
-
end
|
30
|
-
|
31
|
-
def initialize( text, more_attribs={} )
|
32
|
-
## todo/fix: how to add opts={} ???
|
33
|
-
@text = text
|
34
|
-
@more_attribs = more_attribs
|
35
|
-
end
|
36
|
-
|
37
|
-
|
38
|
-
def read
|
39
|
-
## return a hash (with all records) e.g.
|
40
|
-
## {"austria"=>
|
41
|
-
## {:title=>"FK Austria Wien",
|
42
|
-
## :synonyms=>["Austria Wien", "Austria"],
|
43
|
-
## :values=>
|
44
|
-
## ["1911",
|
45
|
-
## "AUS",
|
46
|
-
## "www.fk-austria.at",
|
47
|
-
## "Fischhofgasse 12 // 1100 Wien",
|
48
|
-
## "city:wien"]},
|
49
|
-
## "rapid"=>
|
50
|
-
## {:title=>"SK Rapid Wien",
|
51
|
-
## :synonyms=>["Rapid Wien", "Rapid"],
|
52
|
-
## :values=>
|
53
|
-
## ["1899",
|
54
|
-
## "RAP",
|
55
|
-
## "www.skrapid.at",
|
56
|
-
## "Keisslergasse 3 // 1140 Wien",
|
57
|
-
## "city:wien"]},
|
58
|
-
## ...
|
59
|
-
|
60
|
-
reader = ValuesReader.from_string( @text, @more_attribs )
|
61
|
-
|
62
|
-
h = {}
|
63
|
-
|
64
|
-
reader.each_line do |new_attributes, values|
|
65
|
-
puts "attribs:"
|
66
|
-
pp new_attributes
|
67
|
-
|
68
|
-
key = new_attributes.delete( :key ) ## remove key
|
69
|
-
|
70
|
-
## turn synonyms into an array
|
71
|
-
synonyms = new_attributes[ :synonyms ]
|
72
|
-
if synonyms
|
73
|
-
new_attributes[ :synonyms ] = synonyms.split('|')
|
74
|
-
end
|
75
|
-
|
76
|
-
new_attributes[ :values ] = values
|
77
|
-
|
78
|
-
h[ key ] = new_attributes
|
79
|
-
|
80
|
-
end # each lines
|
81
|
-
|
82
|
-
h ## return hash with all records (indexed by key)
|
83
|
-
end
|
84
|
-
|
85
|
-
|
86
|
-
end # class TeamIndexer
|
87
|
-
end # module SportDb
|
data/lib/sportdb/mapper_teams.rb
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
module SportDb
|
4
|
-
|
5
|
-
class TeamMapper
|
6
|
-
def initialize( recs )
|
7
|
-
@mapper = TextUtils::TitleMapper2.new( recs, 'team' )
|
8
|
-
end
|
9
|
-
|
10
|
-
def find_teams!( line ) # Note: returns an array - note: plural! (teamsssss)
|
11
|
-
@mapper.find_keys!( line )
|
12
|
-
end
|
13
|
-
|
14
|
-
def find_team!( line ) # Note: returns key (string or nil)
|
15
|
-
@mapper.find_key!( line )
|
16
|
-
end
|
17
|
-
|
18
|
-
def map_teams!( line )
|
19
|
-
@mapper.map_titles!( line )
|
20
|
-
end
|
21
|
-
end # class TeamMapper
|
22
|
-
|
23
|
-
end # module SportDb
|
24
|
-
|
data/lib/sportdb/matcher.rb
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
module SportDb
|
4
|
-
|
5
|
-
module Matcher
|
6
|
-
|
7
|
-
include WorldDb::Matcher
|
8
|
-
|
9
|
-
def match_leagues_for_country( name, &blk )
|
10
|
-
match_xxx_for_country( name, 'leagues', &blk )
|
11
|
-
end
|
12
|
-
|
13
|
-
def match_teams_for_country( name, &blk )
|
14
|
-
match_xxx_for_country( name, 'teams', &blk )
|
15
|
-
end
|
16
|
-
|
17
|
-
def match_clubs_for_country( name, &blk )
|
18
|
-
match_xxx_for_country( name, 'clubs', &blk )
|
19
|
-
end
|
20
|
-
|
21
|
-
def match_players_for_country( name, &blk )
|
22
|
-
match_xxx_for_country( name, 'players', &blk )
|
23
|
-
end
|
24
|
-
|
25
|
-
def match_stadiums_for_country( name, &blk )
|
26
|
-
match_xxx_for_country( name, 'stadiums', &blk )
|
27
|
-
end
|
28
|
-
|
29
|
-
end # module Matcher
|
30
|
-
|
31
|
-
end # module SportDb
|
data/lib/sportdb/models/assoc.rb
DELETED
@@ -1,106 +0,0 @@
|
|
1
|
-
module SportDb
|
2
|
-
module Model
|
3
|
-
|
4
|
-
class Assoc < ActiveRecord::Base
|
5
|
-
|
6
|
-
has_many :parent_assoc_assocs, class_name: 'AssocAssoc', foreign_key: 'assoc2_id'
|
7
|
-
## child_assocs - use child_assocs? - (direct) member/child assocs instead of member?
|
8
|
-
has_many :member_assoc_assocs, class_name: 'AssocAssoc', foreign_key: 'assoc1_id'
|
9
|
-
|
10
|
-
|
11
|
-
## note: split member_assocs into two sets (into national=true and national=false)
|
12
|
-
# e.g. fifa has six member confederations (non-national) and 216 national assocs
|
13
|
-
if ActiveRecord::VERSION::MAJOR == 3
|
14
|
-
has_many :all_assocs, class_name: 'Assoc', :source => :assoc2, :through => :member_assoc_assocs
|
15
|
-
has_many :sub_assocs, class_name: 'Assoc', :source => :assoc2, :through => :member_assoc_assocs, conditions: { national: false }
|
16
|
-
has_many :national_assocs, class_name: 'Assoc', :source => :assoc2, :through => :member_assoc_assocs, conditions: { national: true }
|
17
|
-
else
|
18
|
-
## note: includes all member (sub assocs + national assocs) - rename to member_assocs?
|
19
|
-
has_many :all_assocs, class_name: 'Assoc', :source => :assoc2, :through => :member_assoc_assocs
|
20
|
-
## use zone/region as name instead of sub ( for confederatons,zones,etc.)
|
21
|
-
has_many :sub_assocs, -> { where( national: false ) }, class_name: 'Assoc', :source => :assoc2, :through => :member_assoc_assocs
|
22
|
-
has_many :national_assocs, -> { where( national: true ) }, class_name: 'Assoc', :source => :assoc2, :through => :member_assoc_assocs
|
23
|
-
end
|
24
|
-
|
25
|
-
## for now can have more than one (direct) parent assoc
|
26
|
-
## e.g. Africa Fed and Arab League Fed
|
27
|
-
has_many :parent_assocs, class_name: 'Assoc', :source => :assoc1, :through => :parent_assoc_assocs
|
28
|
-
|
29
|
-
# assoc only can have one direct team for now (uses belongs_to on other side)
|
30
|
-
# has_one :team
|
31
|
-
|
32
|
-
|
33
|
-
def self.create_or_update_from_values( new_attributes, values )
|
34
|
-
|
35
|
-
## fix: add/configure logger for ActiveRecord!!!
|
36
|
-
logger = LogUtils::Logger.root
|
37
|
-
|
38
|
-
assoc_keys = [] # by default no association (e.g. fifa,uefa,etc.)
|
39
|
-
|
40
|
-
## check optional values
|
41
|
-
values.each_with_index do |value, index|
|
42
|
-
if value =~ /^(18|19|20)[0-9]{2}$/ ## assume founding year -- allow 18|19|20
|
43
|
-
## logger.info " founding/opening year #{value}"
|
44
|
-
new_attributes[ :since ] = value.to_i
|
45
|
-
elsif value =~ /\/{2}/ # assume it's an address line e.g. xx // xx
|
46
|
-
logger.info " found address line #{value}"
|
47
|
-
## new_attributes[ :address ] = value
|
48
|
-
elsif value =~ /^(?:[a-z]{2}\.)?wikipedia:/ # assume it's wikipedia e.g. [es.]wikipedia:
|
49
|
-
logger.info " found wikipedia line #{value}; skipping for now"
|
50
|
-
elsif value =~ /(^www\.)|(\.com$)/ # FIX: !!!! use a better matcher not just www. and .com
|
51
|
-
new_attributes[ :web ] = value
|
52
|
-
## elsif value =~ /^[a-z]{2}$/ ## assume two-letter country key e.g. at,de,mx,etc.
|
53
|
-
## ## fix: allow country letter with three e.g. eng,sco,wal,nir, etc. !!!
|
54
|
-
## value_country = Country.find_by_key!( value )
|
55
|
-
## new_attributes[ :country_id ] = value_country.id
|
56
|
-
elsif value =~ /^[a-z]{2}$/ ## assume two-letter country key e.g. at,de,mx,etc.
|
57
|
-
## fix: allow country letter with three e.g. eng,sco,wal,nir, etc. !!!
|
58
|
-
## fix: if country does NOT match / NOT found - just coninue w/ next match!!!!
|
59
|
-
# - just issue an error/warn do NOT crash
|
60
|
-
value_country = Country.find_by_key!( value )
|
61
|
-
new_attributes[ :country_id ] = value_country.id
|
62
|
-
## note: if country present - assume it's a national assoc, thus, set flag to true
|
63
|
-
new_attributes[ :national ] = true
|
64
|
-
elsif value =~ /^[a-z|]+$/ ## looks like a tag list e.g. fifa|uefa or fifa|caf or ocf?
|
65
|
-
logger.info " trying adding assocs using keys >#{value}<"
|
66
|
-
assoc_keys = value.split('|')
|
67
|
-
else
|
68
|
-
## todo: assume title2 ??
|
69
|
-
# issue warning: unknown type for value
|
70
|
-
logger.warn "unknown type for value >#{value}< - key #{new_attributes[:key]}"
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
rec = Assoc.find_by_key( new_attributes[ :key ] )
|
75
|
-
if rec.present?
|
76
|
-
logger.debug "update Assoc #{rec.id}-#{rec.key}:"
|
77
|
-
else
|
78
|
-
logger.debug "create Assoc:"
|
79
|
-
rec = Assoc.new
|
80
|
-
end
|
81
|
-
|
82
|
-
logger.debug new_attributes.to_json
|
83
|
-
|
84
|
-
rec.update_attributes!( new_attributes )
|
85
|
-
|
86
|
-
unless assoc_keys.empty?
|
87
|
-
## add team to assocs
|
88
|
-
assoc_keys.each do |assoc_key|
|
89
|
-
assoc = Assoc.find_by_key!( assoc_key )
|
90
|
-
logger.debug " adding assoc to assoc >#{assoc.title}<"
|
91
|
-
|
92
|
-
### todo/fix: how can we delete assoc_assocs? for now only update n create
|
93
|
-
assoc_assoc = AssocAssoc.where( assoc1_id: assoc.id, assoc2_id: rec.id ).first
|
94
|
-
if assoc_assoc.nil? ## create if does NOT exist yet
|
95
|
-
AssocAssoc.create!( assoc1_id: assoc.id, assoc2_id: rec.id )
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
end # create_or_update_from_values
|
101
|
-
|
102
|
-
end # class Assoc
|
103
|
-
|
104
|
-
|
105
|
-
end # module Model
|
106
|
-
end # module SportDb
|
@@ -1,15 +0,0 @@
|
|
1
|
-
module SportDb
|
2
|
-
module Model
|
3
|
-
|
4
|
-
|
5
|
-
class AssocAssoc < ActiveRecord::Base
|
6
|
-
self.table_name = 'assocs_assocs'
|
7
|
-
|
8
|
-
belongs_to :assoc1, class_name: 'Assoc', foreign_key: 'assoc1_id' # parent assoc
|
9
|
-
belongs_to :assoc2, class_name: 'Assoc', foreign_key: 'assoc2_id' # child assoc is_member_of parent assoc
|
10
|
-
|
11
|
-
end # class AssocAssoc
|
12
|
-
|
13
|
-
|
14
|
-
end # module Model
|
15
|
-
end # module SportDb
|
data/lib/sportdb/models/event.rb
DELETED
@@ -1,66 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
module SportDb
|
4
|
-
module Model
|
5
|
-
|
6
|
-
class Event < ActiveRecord::Base
|
7
|
-
|
8
|
-
belongs_to :league
|
9
|
-
belongs_to :season
|
10
|
-
|
11
|
-
if ActiveRecord::VERSION::MAJOR == 3
|
12
|
-
has_many :rounds, order: 'pos' # all (fix and flex) rounds
|
13
|
-
has_many :groups, order: 'pos'
|
14
|
-
else
|
15
|
-
has_many :rounds, -> { order('pos') } # all (fix and flex) rounds
|
16
|
-
has_many :groups, -> { order('pos') }
|
17
|
-
end
|
18
|
-
has_many :stages
|
19
|
-
|
20
|
-
has_many :games, :through => :rounds
|
21
|
-
|
22
|
-
has_many :event_teams, class_name: 'EventTeam'
|
23
|
-
has_many :teams, :through => :event_teams
|
24
|
-
|
25
|
-
has_many :event_grounds, class_name: 'EventGround'
|
26
|
-
has_many :grounds, :through => :event_grounds
|
27
|
-
|
28
|
-
|
29
|
-
before_save :on_before_save
|
30
|
-
|
31
|
-
|
32
|
-
def add_teams_from_ary!( team_keys )
|
33
|
-
## move to depreciated? used in event reader? why? why not?
|
34
|
-
team_keys.each do |team_key|
|
35
|
-
team = Team.find_by_key!( team_key )
|
36
|
-
self.teams << team
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
def on_before_save
|
41
|
-
# event key is composite of league + season (e.g. at.2012/13) etc.
|
42
|
-
self.key = "#{league.key}.#{season.key}"
|
43
|
-
end
|
44
|
-
|
45
|
-
def title
|
46
|
-
"#{league.title} #{season.title}"
|
47
|
-
end
|
48
|
-
|
49
|
-
|
50
|
-
#####################
|
51
|
-
## convenience helper for text parser/reader
|
52
|
-
|
53
|
-
###
|
54
|
-
## fix: use/add to_teams_table( rec ) for reuse
|
55
|
-
#
|
56
|
-
## @known_teams = @event.known_teams_table
|
57
|
-
|
58
|
-
|
59
|
-
def known_teams_table
|
60
|
-
@known_teams_table ||= TextUtils.build_title_table_for( teams )
|
61
|
-
end # method known_teams_table
|
62
|
-
|
63
|
-
end # class Event
|
64
|
-
|
65
|
-
end # module Model
|
66
|
-
end # module SportDb
|
@@ -1,100 +0,0 @@
|
|
1
|
-
|
2
|
-
module SportDb
|
3
|
-
module Model
|
4
|
-
|
5
|
-
class Ground < ActiveRecord::Base
|
6
|
-
|
7
|
-
belongs_to :country, class_name: 'WorldDb::Model::Country', foreign_key: 'country_id'
|
8
|
-
belongs_to :city, class_name: 'WorldDb::Model::City', foreign_key: 'city_id'
|
9
|
-
|
10
|
-
has_many :games
|
11
|
-
|
12
|
-
|
13
|
-
def self.create_or_update_from_values( new_attributes, values )
|
14
|
-
|
15
|
-
## fix: add/configure logger for ActiveRecord!!!
|
16
|
-
logger = LogKernel::Logger.root
|
17
|
-
|
18
|
-
## check optional values
|
19
|
-
logger.debug " [Ground] values >#{values.join('<>')}<"
|
20
|
-
|
21
|
-
city_title = ''
|
22
|
-
|
23
|
-
values.each_with_index do |value, index|
|
24
|
-
if value =~ /^(19|20)[0-9]{2}$/ ## assume founding year -- allow 19|20
|
25
|
-
logger.info " founding/opening year #{value}"
|
26
|
-
new_attributes[ :since ] = value.to_i
|
27
|
-
elsif value =~ /^[1-9][0-9_]+[0-9]$/ # number; assume capacity e.g. 12_541 or similar
|
28
|
-
# todo/fix: check how to differentiate between founding year
|
29
|
-
# and capacity if capcity islike year
|
30
|
-
# need to use _ e.g. 1_999 not 1999 and will get added as capacity !!!
|
31
|
-
# - by position ?? year is first entry, capacity is second ??? -add/fix
|
32
|
-
|
33
|
-
logger.info " found capacity #{value}"
|
34
|
-
new_attributes[ :capacity ] = value.gsub('_', '').to_i
|
35
|
-
elsif value =~ /^[A-Z]{1,3}$/ # assume; state/region code e-g B | TX etc.
|
36
|
-
# skip region/state code
|
37
|
-
logger.info " found region/state code #{value}; skipping for now"
|
38
|
-
elsif value =~ /\/{2}/ # assume it's an address line e.g. xx // xx
|
39
|
-
logger.info " found address line #{value}"
|
40
|
-
new_attributes[ :address ] = value
|
41
|
-
elsif value =~ /^clubs:/ # assume it's clubs line e.g. clubs: Santos
|
42
|
-
logger.info " found clubs line #{value}; skipping for now"
|
43
|
-
elsif value =~ /^(?:[a-z]{2}\.)?wikipedia:/ # assume it's wikipedia e.g. [es.]wikipedia:
|
44
|
-
logger.info " found wikipedia line #{value}; skipping for now"
|
45
|
-
else
|
46
|
-
logger.info " found city >#{value}< for ground >#{new_attributes[ :key ]}<"
|
47
|
-
|
48
|
-
city_title = value.dup # remember for auto-add city
|
49
|
-
|
50
|
-
## todo: assume title2 ??
|
51
|
-
## assume title2 if title2 is empty (not already in use)
|
52
|
-
## and if it title2 contains at least two letter e.g. [a-zA-Z].*[a-zA-Z]
|
53
|
-
# issue warning: unknown type for value
|
54
|
-
# logger.warn "unknown type for value >#{value}< - key #{new_attributes[:key]}"
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
logger.debug " find ground key: #{new_attributes[ :key ]}"
|
59
|
-
|
60
|
-
rec = Ground.find_by_key( new_attributes[ :key ] )
|
61
|
-
if rec.present?
|
62
|
-
logger.debug "update Ground #{rec.id}-#{rec.key}:"
|
63
|
-
else
|
64
|
-
logger.debug "create Ground:"
|
65
|
-
rec = Ground.new
|
66
|
-
end
|
67
|
-
|
68
|
-
logger.debug new_attributes.to_json
|
69
|
-
|
70
|
-
rec.update_attributes!( new_attributes )
|
71
|
-
|
72
|
-
#### try to auto-add city
|
73
|
-
|
74
|
-
if city_title.present?
|
75
|
-
|
76
|
-
### todo/fix: strip city_title subtitles e.g. Hamburg (Hafen) becomes Hamburg etc.
|
77
|
-
city_values = [city_title]
|
78
|
-
city_attributes = {
|
79
|
-
country_id: rec.country_id,
|
80
|
-
# region_id: rec.region_id ### todo/fix: add region if present
|
81
|
-
}
|
82
|
-
|
83
|
-
# todo: add convenience helper create_or_update_from_title
|
84
|
-
city = City.create_or_update_from_values( city_values, city_attributes )
|
85
|
-
|
86
|
-
### fix/todo: set new autoadd flag too?
|
87
|
-
## e.g. check if updated? e.g. timestamp created <> updated otherwise assume created?
|
88
|
-
|
89
|
-
## now at last add city_id to brewery!
|
90
|
-
rec.city_id = city.id
|
91
|
-
rec.save!
|
92
|
-
end
|
93
|
-
end # create_or_update_from_values
|
94
|
-
|
95
|
-
|
96
|
-
end # class Ground
|
97
|
-
|
98
|
-
end # module Model
|
99
|
-
end # module SportDb
|
100
|
-
|