sportdb-models 1.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gemtest +0 -0
- data/HISTORY.md +21 -0
- data/Manifest.txt +142 -0
- data/README.md +28 -0
- data/Rakefile +59 -0
- data/config/fixtures/de.yml +46 -0
- data/config/fixtures/en.yml +54 -0
- data/config/fixtures/es.yml +48 -0
- data/config/fixtures/fr.yml +53 -0
- data/config/fixtures/it.yml +55 -0
- data/config/fixtures/pt.yml +46 -0
- data/config/fixtures/ro.yml +55 -0
- data/data/seasons.txt +74 -0
- data/data/setups/all.txt +5 -0
- data/lib/sportdb/calc.rb +279 -0
- data/lib/sportdb/deleter.rb +52 -0
- data/lib/sportdb/finders/date.rb +374 -0
- data/lib/sportdb/finders/goals.rb +260 -0
- data/lib/sportdb/finders/scores.rb +122 -0
- data/lib/sportdb/lang.rb +216 -0
- data/lib/sportdb/matcher.rb +31 -0
- data/lib/sportdb/models.rb +259 -0
- data/lib/sportdb/models/assoc.rb +106 -0
- data/lib/sportdb/models/assoc_assoc.rb +15 -0
- data/lib/sportdb/models/badge.rb +14 -0
- data/lib/sportdb/models/event.rb +65 -0
- data/lib/sportdb/models/event_ground.rb +15 -0
- data/lib/sportdb/models/event_team.rb +16 -0
- data/lib/sportdb/models/forward.rb +55 -0
- data/lib/sportdb/models/game.rb +244 -0
- data/lib/sportdb/models/goal.rb +15 -0
- data/lib/sportdb/models/ground.rb +100 -0
- data/lib/sportdb/models/group.rb +23 -0
- data/lib/sportdb/models/group_team.rb +14 -0
- data/lib/sportdb/models/league.rb +83 -0
- data/lib/sportdb/models/person.rb +21 -0
- data/lib/sportdb/models/roster.rb +18 -0
- data/lib/sportdb/models/round.rb +22 -0
- data/lib/sportdb/models/season.rb +14 -0
- data/lib/sportdb/models/stats/alltime_standing.rb +44 -0
- data/lib/sportdb/models/stats/alltime_standing_entry.rb +23 -0
- data/lib/sportdb/models/stats/event_standing.rb +55 -0
- data/lib/sportdb/models/stats/event_standing_entry.rb +21 -0
- data/lib/sportdb/models/stats/group_standing.rb +50 -0
- data/lib/sportdb/models/stats/group_standing_entry.rb +22 -0
- data/lib/sportdb/models/team.rb +119 -0
- data/lib/sportdb/models/team_comp.rb +64 -0
- data/lib/sportdb/models/utils.rb +78 -0
- data/lib/sportdb/models/world/city.rb +21 -0
- data/lib/sportdb/models/world/continent.rb +20 -0
- data/lib/sportdb/models/world/country.rb +19 -0
- data/lib/sportdb/models/world/region.rb +19 -0
- data/lib/sportdb/patterns.rb +38 -0
- data/lib/sportdb/reader.rb +130 -0
- data/lib/sportdb/reader_file.rb +123 -0
- data/lib/sportdb/reader_zip.rb +165 -0
- data/lib/sportdb/readers/assoc.rb +54 -0
- data/lib/sportdb/readers/event.rb +200 -0
- data/lib/sportdb/readers/game.rb +877 -0
- data/lib/sportdb/readers/ground.rb +53 -0
- data/lib/sportdb/readers/league.rb +54 -0
- data/lib/sportdb/readers/season.rb +83 -0
- data/lib/sportdb/readers/squad_club.rb +201 -0
- data/lib/sportdb/readers/squad_national_team.rb +173 -0
- data/lib/sportdb/readers/team.rb +53 -0
- data/lib/sportdb/schema.rb +373 -0
- data/lib/sportdb/standings.rb +178 -0
- data/lib/sportdb/stats.rb +27 -0
- data/lib/sportdb/utils.rb +89 -0
- data/lib/sportdb/utils_date.rb +26 -0
- data/lib/sportdb/utils_goals.rb +20 -0
- data/lib/sportdb/utils_group.rb +63 -0
- data/lib/sportdb/utils_map.rb +44 -0
- data/lib/sportdb/utils_round.rb +165 -0
- data/lib/sportdb/utils_scores.rb +17 -0
- data/lib/sportdb/utils_teams.rb +43 -0
- data/lib/sportdb/version.rb +23 -0
- data/test/data/at-austria/2013_14/bl.txt +227 -0
- data/test/data/at-austria/2013_14/bl.yml +30 -0
- data/test/data/at-austria/2013_14/bl_ii.txt +154 -0
- data/test/data/at-austria/2013_14/el.txt +4 -0
- data/test/data/at-austria/2013_14/el.yml +25 -0
- data/test/data/at-austria/2013_14/squads/austria.txt +40 -0
- data/test/data/at-austria/2013_14/squads/salzburg.txt +35 -0
- data/test/data/at-austria/leagues.txt +11 -0
- data/test/data/at-austria/teams.txt +75 -0
- data/test/data/at-austria/teams_2.txt +34 -0
- data/test/data/national-teams/assocs.txt +231 -0
- data/test/data/national-teams/europe/assocs.txt +13 -0
- data/test/data/national-teams/europe/teams.txt +13 -0
- data/test/data/national-teams/north-america/assocs.txt +10 -0
- data/test/data/national-teams/north-america/teams.txt +7 -0
- data/test/data/national-teams/teams.txt +19 -0
- data/test/data/players/europe/at-austria/players.txt +45 -0
- data/test/data/players/europe/de-deutschland/players.txt +41 -0
- data/test/data/players/south-america/br-brazil/players.txt +51 -0
- data/test/data/world-cup/1930/cup.txt +71 -0
- data/test/data/world-cup/1930/cup.yml +23 -0
- data/test/data/world-cup/1930/cup_goals.txt +47 -0
- data/test/data/world-cup/1930/cup_goals.yml +23 -0
- data/test/data/world-cup/1954/cup.txt +90 -0
- data/test/data/world-cup/1954/cup.yml +30 -0
- data/test/data/world-cup/1962/cup.txt +86 -0
- data/test/data/world-cup/1962/cup.yml +32 -0
- data/test/data/world-cup/1974/cup.yml +35 -0
- data/test/data/world-cup/1974/cup_finals.txt +14 -0
- data/test/data/world-cup/1974/cup_i.txt +55 -0
- data/test/data/world-cup/1974/cup_ii.txt +34 -0
- data/test/data/world-cup/2014/cup.txt +5 -0
- data/test/data/world-cup/2014/cup.yml +54 -0
- data/test/data/world-cup/2014/squads/br-brazil.txt +46 -0
- data/test/data/world-cup/2014/squads/de-deutschland.txt +8 -0
- data/test/data/world-cup/2014/squads/jp-japan.txt +30 -0
- data/test/data/world-cup/2014/squads/uy-uruguay.txt +32 -0
- data/test/data/world-cup/leagues.txt +5 -0
- data/test/data/world-cup/seasons_1930.txt +4 -0
- data/test/data/world-cup/seasons_1954.txt +4 -0
- data/test/data/world-cup/seasons_1962.txt +4 -0
- data/test/data/world-cup/seasons_1974.txt +5 -0
- data/test/data/world-cup/teams_1930.txt +26 -0
- data/test/data/world-cup/teams_1954.txt +30 -0
- data/test/data/world-cup/teams_1962.txt +29 -0
- data/test/data/world-cup/teams_1974.txt +29 -0
- data/test/helper.rb +120 -0
- data/test/test_assoc_reader.rb +201 -0
- data/test/test_changes.rb +74 -0
- data/test/test_cursor.rb +50 -0
- data/test/test_date.rb +100 -0
- data/test/test_goals.rb +109 -0
- data/test/test_lang.rb +130 -0
- data/test/test_load.rb +61 -0
- data/test/test_reader.rb +88 -0
- data/test/test_reader_from_string.rb +65 -0
- data/test/test_round_auto.rb +370 -0
- data/test/test_round_def.rb +109 -0
- data/test/test_round_header.rb +183 -0
- data/test/test_scores.rb +70 -0
- data/test/test_squad_club_reader.rb +76 -0
- data/test/test_squad_national_team_reader.rb +116 -0
- data/test/test_standings.rb +279 -0
- data/test/test_standings_ii.rb +46 -0
- data/test/test_utils.rb +124 -0
- data/test/test_winner.rb +95 -0
- metadata +378 -0
@@ -0,0 +1,21 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module SportDb
|
4
|
+
module Model
|
5
|
+
|
6
|
+
class EventStandingEntry < ActiveRecord::Base
|
7
|
+
|
8
|
+
self.table_name = 'event_standing_entries'
|
9
|
+
|
10
|
+
belongs_to :standing, class_name: 'SportDb::Model::EventStanding', foreign_key: 'event_standing_id'
|
11
|
+
belongs_to :team
|
12
|
+
|
13
|
+
## note:
|
14
|
+
## map standing_id to group_standing_id - convenience alias
|
15
|
+
def standing_id=(value) write_attribute(:event_standing_id, value); end
|
16
|
+
|
17
|
+
end # class EventStandingEntry
|
18
|
+
|
19
|
+
|
20
|
+
end # module Model
|
21
|
+
end # module SportDb
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module SportDb
|
4
|
+
module Model
|
5
|
+
|
6
|
+
|
7
|
+
class GroupStanding < ActiveRecord::Base
|
8
|
+
|
9
|
+
self.table_name = 'group_standings'
|
10
|
+
|
11
|
+
has_many :entries, class_name: 'SportDb::Model::GroupStandingEntry', foreign_key: 'group_standing_id', :dependent => :delete_all
|
12
|
+
belongs_to :group
|
13
|
+
|
14
|
+
## convenience helper; recalcs all records
|
15
|
+
def self.recalc!( opts={} ) self.order(:id).each { |rec| rec.recalc!(opts) }; end
|
16
|
+
|
17
|
+
|
18
|
+
def recalc!( opts={} )
|
19
|
+
## will calculate group standing e.g.
|
20
|
+
|
21
|
+
## calc points (pts) - loop over all group games/matches
|
22
|
+
# group.games.each do |game|
|
23
|
+
# end
|
24
|
+
recs = StandingsHelper.calc( group.games, opts )
|
25
|
+
|
26
|
+
## - remove (if exit) old entries and add new entries
|
27
|
+
entries.delete_all # note: assoc dependent set to :delete_all (defaults to :nullify)
|
28
|
+
|
29
|
+
## add empty entries
|
30
|
+
group.teams.each do |team|
|
31
|
+
puts " adding entry for team #{team.title} (#{team.code})"
|
32
|
+
rec = recs[ team.key ] # find (in-memory) stats records
|
33
|
+
entries.create!(
|
34
|
+
team_id: team.id,
|
35
|
+
pos: rec.pos,
|
36
|
+
played: rec.played,
|
37
|
+
won: rec.won,
|
38
|
+
drawn: rec.drawn,
|
39
|
+
lost: rec.lost,
|
40
|
+
goals_for: rec.goals_for,
|
41
|
+
goals_against: rec.goals_against,
|
42
|
+
pts: rec.pts )
|
43
|
+
end
|
44
|
+
end # method recalc!
|
45
|
+
|
46
|
+
|
47
|
+
end # class GroupStanding
|
48
|
+
end # module Model
|
49
|
+
|
50
|
+
end # module SportDb
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module SportDb
|
4
|
+
module Model
|
5
|
+
|
6
|
+
|
7
|
+
class GroupStandingEntry < ActiveRecord::Base
|
8
|
+
|
9
|
+
self.table_name = 'group_standing_entries'
|
10
|
+
|
11
|
+
belongs_to :standing, class_name: 'SportDb::Model::GroupStanding', foreign_key: 'group_standing_id'
|
12
|
+
belongs_to :team
|
13
|
+
|
14
|
+
## note:
|
15
|
+
## map standing_id to group_standing_id - convenience alias
|
16
|
+
def standing_id=(value) write_attribute(:group_standing_id, value); end
|
17
|
+
|
18
|
+
end # class GroupStandingEntry
|
19
|
+
|
20
|
+
|
21
|
+
end # module Model
|
22
|
+
end # module SportDb
|
@@ -0,0 +1,119 @@
|
|
1
|
+
|
2
|
+
module SportDb
|
3
|
+
module Model
|
4
|
+
|
5
|
+
##################
|
6
|
+
# FIX: add ?
|
7
|
+
#
|
8
|
+
# use single table inheritance STI ????
|
9
|
+
# - to mark two dervided classes e.g.
|
10
|
+
# - Club ??? - why? why not?
|
11
|
+
# - NationalTeam ??? - why? why not?
|
12
|
+
|
13
|
+
|
14
|
+
class Team < ActiveRecord::Base
|
15
|
+
|
16
|
+
has_many :home_games, class_name: 'Game', foreign_key: 'team1_id'
|
17
|
+
has_many :away_games, class_name: 'Game', foreign_key: 'team2_id'
|
18
|
+
|
19
|
+
## todo/fix: must be 3 or more letters (plus allow digits e.g. salzburgii, muenchen1980, etc.) - why? why not??
|
20
|
+
validates :key, format: { with: /#{TEAM_KEY_PATTERN}/, message: TEAM_KEY_PATTERN_MESSAGE }
|
21
|
+
validates :code, format: { with: /#{TEAM_CODE_PATTERN}/, message: TEAM_CODE_PATTERN_MESSAGE }, allow_nil: true
|
22
|
+
|
23
|
+
has_many :event_teams, class_name: 'EventTeam' # join table (events+teams)
|
24
|
+
has_many :events, :through => :event_teams
|
25
|
+
|
26
|
+
# note: team belongs_to a single (optinal) assoc for now (national assoc may have many assocs)
|
27
|
+
belongs_to :assoc
|
28
|
+
|
29
|
+
### fix!!! - how to do it with has_many macro? use finder_sql?
|
30
|
+
## finder_sql is depreciated in Rails 4!!!
|
31
|
+
# use -> { where() } etc. -- try it if it works
|
32
|
+
## keep as is! best solution ??
|
33
|
+
## a discussion here -> https://github.com/rails/rails/issues/9726
|
34
|
+
## a discussion here (not really helpful) -> http://stackoverflow.com/questions/2125440/activerecord-has-many-where-two-columns-in-table-a-are-primary-keys-in-table-b
|
35
|
+
|
36
|
+
def games
|
37
|
+
Game.where( 'team1_id = ? or team2_id = ?', id, id ).order( 'play_at' )
|
38
|
+
end
|
39
|
+
|
40
|
+
def upcoming_games
|
41
|
+
Game.where( 'team1_id = ? or team2_id = ?', id, id ).where( 'play_at > ?', Time.now ).order( 'play_at' )
|
42
|
+
end
|
43
|
+
|
44
|
+
def past_games
|
45
|
+
Game.where( 'team1_id = ? or team2_id = ?', id, id ).where( 'play_at < ?', Time.now ).order( 'play_at desc' )
|
46
|
+
end
|
47
|
+
|
48
|
+
|
49
|
+
has_many :badges # Winner, 2nd, Cupsieger, Aufsteiger, Absteiger, etc.
|
50
|
+
|
51
|
+
belongs_to :country, class_name: 'WorldDb::Model::Country', foreign_key: 'country_id'
|
52
|
+
belongs_to :city, class_name: 'WorldDb::Model::City', foreign_key: 'city_id'
|
53
|
+
|
54
|
+
|
55
|
+
## fix/todo: change title to name; title2 to name2 etc.
|
56
|
+
def name() title; end
|
57
|
+
|
58
|
+
|
59
|
+
def self.create_or_update_from_values( new_attributes, values )
|
60
|
+
|
61
|
+
## fix: add/configure logger for ActiveRecord!!!
|
62
|
+
logger = LogUtils::Logger.root
|
63
|
+
|
64
|
+
|
65
|
+
## check optional values
|
66
|
+
values.each_with_index do |value, index|
|
67
|
+
if value =~ /^city:/ ## city:
|
68
|
+
value_city_key = value[5..-1] ## cut off city: prefix
|
69
|
+
value_city = City.find_by_key( value_city_key )
|
70
|
+
if value_city.present?
|
71
|
+
new_attributes[ :city_id ] = value_city.id
|
72
|
+
else
|
73
|
+
## todo/fix: add strict mode flag - fail w/ exit 1 in strict mode
|
74
|
+
logger.warn "city with key #{value_city_key} missing"
|
75
|
+
## todo: log errors to db log???
|
76
|
+
end
|
77
|
+
elsif value =~ /^(18|19|20)[0-9]{2}$/ ## assume founding year -- allow 18|19|20
|
78
|
+
## logger.info " founding/opening year #{value}"
|
79
|
+
new_attributes[ :since ] = value.to_i
|
80
|
+
elsif value =~ /\/{2}/ # assume it's an address line e.g. xx // xx
|
81
|
+
## logger.info " found address line #{value}"
|
82
|
+
new_attributes[ :address ] = value
|
83
|
+
elsif value =~ /^(?:[a-z]{2}\.)?wikipedia:/ # assume it's wikipedia e.g. [es.]wikipedia:
|
84
|
+
logger.info " found wikipedia line #{value}; skipping for now"
|
85
|
+
elsif value =~ /(^www\.)|(\.com$)/ # FIX: !!!! use a better matcher not just www. and .com
|
86
|
+
new_attributes[ :web ] = value
|
87
|
+
elsif value =~ /^[A-Z][A-Z0-9][A-Z0-9_]?$/ ## assume two or three-letter code e.g. FCB, RBS, etc.
|
88
|
+
new_attributes[ :code ] = value
|
89
|
+
elsif value =~ /^[a-z]{2,3}$/ ## assume two or three-letter country key e.g. at,de,mx, or eng,sco,wal,nir etc.
|
90
|
+
## fix: if country does NOT match / NOT found - just continue w/ next match!!!!
|
91
|
+
# - just issue an error/warn do NOT crash
|
92
|
+
value_country = Country.find_by_key!( value )
|
93
|
+
new_attributes[ :country_id ] = value_country.id
|
94
|
+
else
|
95
|
+
## todo: assume title2 ??
|
96
|
+
# issue warning: unknown type for value
|
97
|
+
logger.warn "unknown type for value >#{value}< - key #{new_attributes[:key]}"
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
rec = Team.find_by_key( new_attributes[ :key ] )
|
102
|
+
if rec.present?
|
103
|
+
logger.debug "update Team #{rec.id}-#{rec.key}:"
|
104
|
+
else
|
105
|
+
logger.debug "create Team:"
|
106
|
+
rec = Team.new
|
107
|
+
end
|
108
|
+
|
109
|
+
logger.debug new_attributes.to_json
|
110
|
+
|
111
|
+
rec.update_attributes!( new_attributes )
|
112
|
+
|
113
|
+
end # create_or_update_from_values
|
114
|
+
|
115
|
+
end # class Team
|
116
|
+
|
117
|
+
|
118
|
+
end # module Model
|
119
|
+
end # module SportDb
|
@@ -0,0 +1,64 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module SportDb
|
4
|
+
module Model
|
5
|
+
|
6
|
+
#############################################################
|
7
|
+
# collect depreciated or methods for future removal here
|
8
|
+
# - keep for now for compatibility (for old code)
|
9
|
+
|
10
|
+
class Team
|
11
|
+
|
12
|
+
|
13
|
+
def self.create_from_ary!( teams, more_values={} )
|
14
|
+
teams.each do |values|
|
15
|
+
|
16
|
+
## key & title required
|
17
|
+
attr = {
|
18
|
+
key: values[0]
|
19
|
+
}
|
20
|
+
|
21
|
+
## title (split of optional synonyms)
|
22
|
+
# e.g. FC Bayern Muenchen|Bayern Muenchen|Bayern
|
23
|
+
titles = values[1].split('|')
|
24
|
+
|
25
|
+
attr[ :title ] = titles[0]
|
26
|
+
## add optional synonyms
|
27
|
+
attr[ :synonyms ] = titles[1..-1].join('|') if titles.size > 1
|
28
|
+
|
29
|
+
|
30
|
+
attr = attr.merge( more_values )
|
31
|
+
|
32
|
+
## check for optional values
|
33
|
+
values[2..-1].each do |value|
|
34
|
+
if value.is_a? Country
|
35
|
+
attr[ :country_id ] = value.id
|
36
|
+
elsif value.is_a? City
|
37
|
+
attr[ :city_id ] = value.id
|
38
|
+
elsif value =~ /#{TEAM_CODE_PATTERN}/ ## assume its three letter code (e.g. ITA or S04 etc.)
|
39
|
+
attr[ :code ] = value
|
40
|
+
elsif value =~ /^city:/ ## city:
|
41
|
+
value_city_key = value[5..-1] ## cut off city: prefix
|
42
|
+
value_city = City.find_by_key!( value_city_key )
|
43
|
+
attr[ :city_id ] = value_city.id
|
44
|
+
else
|
45
|
+
attr[ :title2 ] = value
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
## check if exists
|
50
|
+
team = Team.find_by_key( values[0] )
|
51
|
+
if team.present?
|
52
|
+
puts "*** warning team with key '#{values[0]}' exists; skipping create"
|
53
|
+
else
|
54
|
+
Team.create!( attr )
|
55
|
+
end
|
56
|
+
end # each team
|
57
|
+
end
|
58
|
+
|
59
|
+
end # class Team
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
end # module Model
|
64
|
+
end # module SportDb
|
@@ -0,0 +1,78 @@
|
|
1
|
+
module SportDb
|
2
|
+
module Model
|
3
|
+
|
4
|
+
|
5
|
+
class GameCursor
|
6
|
+
|
7
|
+
def initialize( games )
|
8
|
+
@games = games
|
9
|
+
end
|
10
|
+
|
11
|
+
def each
|
12
|
+
state = GameCursorState.new
|
13
|
+
|
14
|
+
@games.each do |game|
|
15
|
+
state.next( game )
|
16
|
+
yield( game, state ) # e.g. lets you use state.new_date? or state.new_week? or state.new_year? etc.
|
17
|
+
end
|
18
|
+
end # method each
|
19
|
+
end # class GameCursor
|
20
|
+
|
21
|
+
|
22
|
+
class GameCursorState
|
23
|
+
|
24
|
+
def initialize
|
25
|
+
@last_play_at = DateTime.new( 1971, 1, 1 )
|
26
|
+
@new_date = true
|
27
|
+
@new_year = true
|
28
|
+
@new_week = true
|
29
|
+
@index = -1 # zero-based index; thus start off with -1 (e.g. -1+=1 => 0)
|
30
|
+
end
|
31
|
+
|
32
|
+
attr_reader :index
|
33
|
+
|
34
|
+
def new_date?() @new_date; end
|
35
|
+
def new_year?() @new_year; end
|
36
|
+
def new_week?() @new_week; end
|
37
|
+
|
38
|
+
|
39
|
+
## add new league ?
|
40
|
+
## add new round ?
|
41
|
+
## add new time ?
|
42
|
+
|
43
|
+
def next( game )
|
44
|
+
@index += 1 # zero-based index; start off with -1 (undefined/uninitialized)
|
45
|
+
game_play_at = game.play_at # cache play_at value ref
|
46
|
+
|
47
|
+
if @last_play_at.year == game_play_at.year &&
|
48
|
+
@last_play_at.month == game_play_at.month &&
|
49
|
+
@last_play_at.day == game_play_at.day
|
50
|
+
@new_date = false
|
51
|
+
else
|
52
|
+
@new_date = true
|
53
|
+
|
54
|
+
# check for new_year
|
55
|
+
if @last_play_at.year == game_play_at.year
|
56
|
+
@new_year = false
|
57
|
+
else
|
58
|
+
@new_year = true
|
59
|
+
end
|
60
|
+
|
61
|
+
# check for new_week
|
62
|
+
# -- todo: find a method for week number; do NOT use strftime; there must be something easier
|
63
|
+
# -- check if activesupport adds .week or similar ??? use it if it exists
|
64
|
+
if @last_play_at.strftime('%V') == game_play_at.strftime('%V')
|
65
|
+
@new_week = false
|
66
|
+
else
|
67
|
+
@new_week = true
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
@last_play_at = game.play_at
|
72
|
+
end # method next
|
73
|
+
|
74
|
+
end # class GameCursorState
|
75
|
+
|
76
|
+
|
77
|
+
end # module Model
|
78
|
+
end # module SportDb
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
|
4
|
+
module WorldDb
|
5
|
+
module Model
|
6
|
+
|
7
|
+
class City
|
8
|
+
has_many :teams, class_name: 'SportDb::Model::Team', foreign_key: 'city_id'
|
9
|
+
|
10
|
+
# fix: require active record 4
|
11
|
+
# has_many :clubs, -> { where club: true }, class_name: 'SportDb::Model::Team', foreign_key: 'city_id'
|
12
|
+
# has_many :national_teams, -> { where club: false }, class_name: 'SportDb::Model::Team', foreign_key: 'city_id'
|
13
|
+
|
14
|
+
|
15
|
+
has_many :grounds, class_name: 'SportDb::Model::Ground', foreign_key: 'city_id'
|
16
|
+
has_many :games, :through => :grounds
|
17
|
+
end
|
18
|
+
|
19
|
+
end # module Model
|
20
|
+
end # module WorldDb
|
21
|
+
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module WorldDb
|
4
|
+
module Model
|
5
|
+
|
6
|
+
class Continent
|
7
|
+
has_many :teams, :through => :countries
|
8
|
+
|
9
|
+
# fix: require active record 4
|
10
|
+
# has_many :clubs, :through => :countries
|
11
|
+
# has_many :national_teams, :through => :countries
|
12
|
+
|
13
|
+
|
14
|
+
has_many :leagues, :through => :countries
|
15
|
+
has_many :grounds, :through => :countries
|
16
|
+
end # class Continent
|
17
|
+
|
18
|
+
end # module Model
|
19
|
+
end # module WorldDb
|
20
|
+
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module WorldDb
|
4
|
+
module Model
|
5
|
+
|
6
|
+
class Country
|
7
|
+
has_many :teams, class_name: 'SportDb::Model::Team', foreign_key: 'country_id'
|
8
|
+
has_one :assoc, class_name: 'SportDb::Model::Assoc', foreign_key: 'country_id'
|
9
|
+
|
10
|
+
# fix: require active record 4
|
11
|
+
# has_many :clubs, -> { where club: true }, class_name: 'SportDb::Model::Team', foreign_key: 'country_id'
|
12
|
+
# has_many :national_teams, -> { where club: false }, class_name: 'SportDb::Model::Team', foreign_key: 'country_id'
|
13
|
+
|
14
|
+
has_many :leagues, class_name: 'SportDb::Model::League', foreign_key: 'country_id'
|
15
|
+
has_many :grounds, class_name: 'SportDb::Model::Ground', foreign_key: 'country_id'
|
16
|
+
end # class Country
|
17
|
+
|
18
|
+
end # module Model
|
19
|
+
end # module WorldDb
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
|
4
|
+
module WorldDb
|
5
|
+
module Model
|
6
|
+
|
7
|
+
class Region
|
8
|
+
has_many :teams, class_name: 'SportDb::Model::Team', :through => :cities
|
9
|
+
|
10
|
+
# fix: require active record 4
|
11
|
+
# has_many :clubs, class_name: 'SportDb::Model::Team', :through => :cities
|
12
|
+
# has_many :national_teams, class_name: 'SportDb::Model::Team', :through => :cities
|
13
|
+
|
14
|
+
has_many :grounds, class_name: 'SportDb::Model::Ground', :through => :cities
|
15
|
+
end # class Region
|
16
|
+
|
17
|
+
end # module Model
|
18
|
+
end # module WorldDb
|
19
|
+
|