sportdb-models 1.19.1 → 2.0.0
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 -38
- data/Rakefile +1 -1
- data/lib/sportdb/models.rb +55 -49
- data/lib/sportdb/{deleter.rb → models/deleter.rb} +3 -9
- 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} +16 -60
- 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} +0 -0
- 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} +98 -74
- data/lib/sportdb/{stats.rb → models/stats.rb} +4 -4
- data/lib/sportdb/models/utils.rb +24 -24
- data/lib/sportdb/{version.rb → models/version.rb} +4 -4
- data/test/helper.rb +10 -6
- data/test/test_changes.rb +38 -38
- data/test/test_cursor.rb +15 -15
- data/test/test_winner.rb +75 -70
- metadata +29 -40
- data/lib/sportdb/calc.rb +0 -279
- 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/standings.rb +0 -178
@@ -0,0 +1,20 @@
|
|
1
|
+
module SportDb
|
2
|
+
module Model
|
3
|
+
|
4
|
+
|
5
|
+
class League < ActiveRecord::Base
|
6
|
+
|
7
|
+
## leagues also used for conferences, world series, cups, etc.
|
8
|
+
#
|
9
|
+
## league (or cup/conference/series/etc.) + season (or year) = event
|
10
|
+
|
11
|
+
has_many :events
|
12
|
+
has_many :seasons, :through => :events
|
13
|
+
|
14
|
+
belongs_to :country, :class_name => 'WorldDb::Model::Country', :foreign_key => 'country_id'
|
15
|
+
|
16
|
+
end # class League
|
17
|
+
|
18
|
+
|
19
|
+
end # module Model
|
20
|
+
end # module SportDb
|
@@ -2,16 +2,15 @@
|
|
2
2
|
module SportDb
|
3
3
|
module Model
|
4
4
|
|
5
|
-
### use
|
5
|
+
### use Squad for name? - alias??
|
6
6
|
|
7
|
-
class
|
7
|
+
class Lineup < ActiveRecord::Base
|
8
8
|
|
9
9
|
belongs_to :event
|
10
10
|
belongs_to :team
|
11
11
|
belongs_to :person, class_name: 'PersonDb::Model::Person', foreign_key: 'person_id'
|
12
12
|
|
13
|
-
end # class
|
14
|
-
|
13
|
+
end # class Lineup
|
15
14
|
|
16
15
|
end # module Model
|
17
16
|
end # module SportDb
|
@@ -3,14 +3,18 @@ module SportDb
|
|
3
3
|
module Model
|
4
4
|
|
5
5
|
|
6
|
-
class
|
6
|
+
class Match < ActiveRecord::Base
|
7
|
+
|
8
|
+
self.table_name = 'matches'
|
7
9
|
|
8
10
|
belongs_to :team1, class_name: 'Team', foreign_key: 'team1_id'
|
9
11
|
belongs_to :team2, class_name: 'Team', foreign_key: 'team2_id'
|
10
|
-
|
11
|
-
belongs_to :
|
12
|
+
|
13
|
+
belongs_to :event
|
14
|
+
belongs_to :round # round is optional
|
12
15
|
belongs_to :group # group is optional
|
13
|
-
|
16
|
+
belongs_to :stage # stage is optional
|
17
|
+
|
14
18
|
belongs_to :ground # ground is optional
|
15
19
|
belongs_to :city, class_name: 'WorldDb::Model::City', foreign_key: 'city_id' # city is optioanl (remove?? redundant?? use ground ??)
|
16
20
|
|
@@ -27,7 +31,7 @@ class Game < ActiveRecord::Base
|
|
27
31
|
def toto12x() toto1x2; end # alias for toto12x - todo/fix: use ruby alias helper
|
28
32
|
def toto1x2
|
29
33
|
## note: will return string e.g. 1-X-2 (winner will return int e.g. 1-0-2)
|
30
|
-
|
34
|
+
|
31
35
|
## fix: use switch/when expr/stmt instead of ifs
|
32
36
|
value = winner90 # 1 0 2 1 => team 1 0 => draw 2 => team
|
33
37
|
if value == 0
|
@@ -82,11 +86,11 @@ class Game < ActiveRecord::Base
|
|
82
86
|
end
|
83
87
|
|
84
88
|
## todo/fix:
|
85
|
-
# check for next-
|
89
|
+
# check for next-match/pre-match !!!
|
86
90
|
# use 1st leg and 2nd leg - use for winner too
|
87
91
|
# or add new winner_total or winner_aggregated method ???
|
88
92
|
|
89
|
-
## check for penalty - note: some
|
93
|
+
## check for penalty - note: some matches might only have penalty and no extra time (e.g. copa liberatadores)
|
90
94
|
if score1p.present? && score2p.present?
|
91
95
|
if score1p > score2p
|
92
96
|
self.winner = 1
|
@@ -114,7 +118,7 @@ class Game < ActiveRecord::Base
|
|
114
118
|
|
115
119
|
|
116
120
|
### getter/setters for deprecated attribs (score3,4,5,6) n national
|
117
|
-
|
121
|
+
|
118
122
|
def score1ot() score1et end
|
119
123
|
def score2ot() score2et end
|
120
124
|
|
@@ -122,7 +126,7 @@ class Game < ActiveRecord::Base
|
|
122
126
|
def score2ot=(value) self.score2et = value end
|
123
127
|
|
124
128
|
|
125
|
-
#
|
129
|
+
# match over?
|
126
130
|
def over?() play_at <= Time.now; end
|
127
131
|
|
128
132
|
## fix/todo: already added by ar magic ??? remove code
|
@@ -130,53 +134,6 @@ class Game < ActiveRecord::Base
|
|
130
134
|
def complete?() score1.present? && score2.present?; end
|
131
135
|
|
132
136
|
|
133
|
-
############# convenience helpers for styling
|
134
|
-
##
|
135
|
-
|
136
|
-
def team1_style_class
|
137
|
-
buf = ''
|
138
|
-
## NB: remove if calc?
|
139
|
-
|
140
|
-
### fix: loser
|
141
|
-
## - add method for checking winner/loser on ko pairs using (1st leg/2nd leg totals) ??
|
142
|
-
## use new winner_total method ??
|
143
|
-
|
144
|
-
if complete?
|
145
|
-
if winner1?
|
146
|
-
buf << 'game-team-winner '
|
147
|
-
elsif winner2?
|
148
|
-
buf << 'game-team-loser '
|
149
|
-
else # assume draw
|
150
|
-
buf << 'game-team-draw '
|
151
|
-
end
|
152
|
-
end
|
153
|
-
|
154
|
-
buf << 'game-knockout ' if knockout?
|
155
|
-
buf
|
156
|
-
end
|
157
|
-
|
158
|
-
def team2_style_class
|
159
|
-
buf = ''
|
160
|
-
## NB: remove if calc?
|
161
|
-
|
162
|
-
### fix: loser
|
163
|
-
## - add method for checking winner/loser on ko pairs using (1st leg/2nd leg totals) ??
|
164
|
-
## use new winner_total method ??
|
165
|
-
|
166
|
-
if complete?
|
167
|
-
if winner1?
|
168
|
-
buf << 'game-team-loser '
|
169
|
-
elsif winner2?
|
170
|
-
buf << 'game-team-winner '
|
171
|
-
else # assume draw
|
172
|
-
buf << 'game-team-draw '
|
173
|
-
end
|
174
|
-
end
|
175
|
-
|
176
|
-
buf << 'game-knockout ' if knockout?
|
177
|
-
buf
|
178
|
-
end
|
179
|
-
|
180
137
|
|
181
138
|
def play_at_str( format = nil )
|
182
139
|
## e.g. use like
|
@@ -218,7 +175,7 @@ class Game < ActiveRecord::Base
|
|
218
175
|
|
219
176
|
## todo/fix: find a better name?
|
220
177
|
## todo: move to utils for reuse?
|
221
|
-
|
178
|
+
|
222
179
|
def check_for_changes( new_attributes )
|
223
180
|
changes_counter = 0
|
224
181
|
new_attributes.each do |key,new_value|
|
@@ -231,14 +188,13 @@ class Game < ActiveRecord::Base
|
|
231
188
|
puts "change #{changes_counter} for #{key} old:>#{old_value}< : #{old_value.class.name} new:>#{new_value}< : #{new_value.class.name}"
|
232
189
|
end
|
233
190
|
end
|
234
|
-
|
191
|
+
|
235
192
|
# no changes found for counter==0;
|
236
193
|
# -- otherwise x changes found; return true
|
237
194
|
changes_counter == 0 ? false : true
|
238
195
|
end
|
239
196
|
|
240
|
-
end # class
|
241
|
-
|
197
|
+
end # class Match
|
242
198
|
|
243
199
|
end # module Model
|
244
200
|
end # module SportDb
|
File without changes
|
@@ -5,11 +5,7 @@ module SportDb
|
|
5
5
|
|
6
6
|
class Round < ActiveRecord::Base
|
7
7
|
|
8
|
-
|
9
|
-
has_many :games, :order => 'pos'
|
10
|
-
else
|
11
|
-
has_many :games, -> { order('pos') }
|
12
|
-
end
|
8
|
+
has_many :matches, -> { order('pos') }, class_name: 'Match'
|
13
9
|
|
14
10
|
belongs_to :event
|
15
11
|
|
@@ -19,4 +15,3 @@ end # class Round
|
|
19
15
|
end # module Model
|
20
16
|
end # module SportDb
|
21
17
|
|
22
|
-
|
File without changes
|
@@ -5,11 +5,7 @@ module SportDb
|
|
5
5
|
|
6
6
|
class Stage < ActiveRecord::Base
|
7
7
|
|
8
|
-
|
9
|
-
has_many :games, order: 'pos'
|
10
|
-
else
|
11
|
-
has_many :games, -> { order('pos') }
|
12
|
-
end
|
8
|
+
has_many :matches, -> { order('pos') }, class_name: 'Match'
|
13
9
|
|
14
10
|
belongs_to :event
|
15
11
|
|
@@ -18,5 +14,13 @@ end
|
|
18
14
|
|
19
15
|
end # class Stage
|
20
16
|
|
17
|
+
|
18
|
+
class StageTeam < ActiveRecord::Base
|
19
|
+
self.table_name = 'stages_teams'
|
20
|
+
|
21
|
+
belongs_to :stage
|
22
|
+
belongs_to :team
|
23
|
+
end # class StageTeam
|
24
|
+
|
21
25
|
end # module Model
|
22
26
|
end # module SportDb
|
data/lib/sportdb/models/{stats/alltime_standing_entry.rb → models/stats/alltime_standing.rb}
RENAMED
@@ -4,6 +4,15 @@ module SportDb
|
|
4
4
|
module Model
|
5
5
|
|
6
6
|
|
7
|
+
class AlltimeStanding < ActiveRecord::Base
|
8
|
+
|
9
|
+
self.table_name = 'alltime_standings'
|
10
|
+
|
11
|
+
has_many :entries, class_name: 'SportDb::Model::AlltimeStandingEntry', foreign_key: 'alltime_standing_id', :dependent => :delete_all
|
12
|
+
|
13
|
+
end # class AlltimeStanding
|
14
|
+
|
15
|
+
|
7
16
|
class AlltimeStandingEntry < ActiveRecord::Base
|
8
17
|
|
9
18
|
self.table_name = 'alltime_standing_entries'
|
@@ -15,7 +24,6 @@ class AlltimeStandingEntry < ActiveRecord::Base
|
|
15
24
|
## map standing_id to alltime_standing_id - convenience alias
|
16
25
|
def standing_id=(value) write_attribute(:alltime_standing_id, value); end
|
17
26
|
|
18
|
-
|
19
27
|
end # class AlltimeStandingEntry
|
20
28
|
|
21
29
|
|
@@ -3,6 +3,17 @@
|
|
3
3
|
module SportDb
|
4
4
|
module Model
|
5
5
|
|
6
|
+
|
7
|
+
class EventStanding < ActiveRecord::Base
|
8
|
+
|
9
|
+
self.table_name = 'event_standings'
|
10
|
+
|
11
|
+
has_many :entries, class_name: 'SportDb::Model::EventStandingEntry', foreign_key: 'event_standing_id', :dependent => :delete_all
|
12
|
+
belongs_to :event
|
13
|
+
|
14
|
+
end # class EventStanding
|
15
|
+
|
16
|
+
|
6
17
|
class EventStandingEntry < ActiveRecord::Base
|
7
18
|
|
8
19
|
self.table_name = 'event_standing_entries'
|
@@ -16,6 +27,5 @@ class EventStandingEntry < ActiveRecord::Base
|
|
16
27
|
|
17
28
|
end # class EventStandingEntry
|
18
29
|
|
19
|
-
|
20
30
|
end # module Model
|
21
31
|
end # module SportDb
|
@@ -4,6 +4,16 @@ module SportDb
|
|
4
4
|
module Model
|
5
5
|
|
6
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
|
+
end # class GroupStanding
|
15
|
+
|
16
|
+
|
7
17
|
class GroupStandingEntry < ActiveRecord::Base
|
8
18
|
|
9
19
|
self.table_name = 'group_standing_entries'
|
@@ -17,6 +27,5 @@ class GroupStandingEntry < ActiveRecord::Base
|
|
17
27
|
|
18
28
|
end # class GroupStandingEntry
|
19
29
|
|
20
|
-
|
21
30
|
end # module Model
|
22
31
|
end # module SportDb
|
@@ -0,0 +1,56 @@
|
|
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_matches, class_name: 'Match', foreign_key: 'team1_id'
|
17
|
+
has_many :away_matches, class_name: 'Match', foreign_key: 'team2_id'
|
18
|
+
|
19
|
+
validates :key, format: { with: TEAM_KEY_RE, message: TEAM_KEY_MESSAGE }
|
20
|
+
validates :code, format: { with: TEAM_CODE_RE, message: TEAM_CODE_MESSAGE }, allow_nil: true
|
21
|
+
|
22
|
+
has_many :event_teams, class_name: 'EventTeam' # join table (events+teams)
|
23
|
+
has_many :events, :through => :event_teams
|
24
|
+
|
25
|
+
# note: team belongs_to a single (optinal) assoc for now (national assoc may have many assocs)
|
26
|
+
belongs_to :assoc
|
27
|
+
|
28
|
+
### fix!!! - how to do it with has_many macro? use finder_sql?
|
29
|
+
## finder_sql is depreciated in Rails 4!!!
|
30
|
+
# use -> { where() } etc. -- try it if it works
|
31
|
+
## keep as is! best solution ??
|
32
|
+
## a discussion here -> https://github.com/rails/rails/issues/9726
|
33
|
+
## 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
|
34
|
+
|
35
|
+
def matches
|
36
|
+
Match.where( 'team1_id = ? or team2_id = ?', id, id ).order( 'date' )
|
37
|
+
end
|
38
|
+
|
39
|
+
def upcoming_matches
|
40
|
+
Match.where( 'team1_id = ? or team2_id = ?', id, id ).where( 'date > ?', Date.today ).order( 'date' )
|
41
|
+
end
|
42
|
+
|
43
|
+
def past_matches
|
44
|
+
Match.where( 'team1_id = ? or team2_id = ?', id, id ).where( 'date < ?', Date.today ).order( 'date desc' )
|
45
|
+
end
|
46
|
+
|
47
|
+
|
48
|
+
has_many :badges # Winner, 2nd, Cupsieger, Aufsteiger, Absteiger, etc.
|
49
|
+
|
50
|
+
belongs_to :country, class_name: 'WorldDb::Model::Country', foreign_key: 'country_id'
|
51
|
+
belongs_to :city, class_name: 'WorldDb::Model::City', foreign_key: 'city_id'
|
52
|
+
end # class Team
|
53
|
+
|
54
|
+
|
55
|
+
end # module Model
|
56
|
+
end # module SportDb
|
@@ -6,14 +6,14 @@ module WorldDb
|
|
6
6
|
|
7
7
|
class City
|
8
8
|
has_many :teams, class_name: 'SportDb::Model::Team', foreign_key: 'city_id'
|
9
|
-
|
9
|
+
|
10
10
|
# fix: require active record 4
|
11
11
|
# has_many :clubs, -> { where club: true }, class_name: 'SportDb::Model::Team', foreign_key: 'city_id'
|
12
12
|
# has_many :national_teams, -> { where club: false }, class_name: 'SportDb::Model::Team', foreign_key: 'city_id'
|
13
13
|
|
14
14
|
|
15
15
|
has_many :grounds, class_name: 'SportDb::Model::Ground', foreign_key: 'city_id'
|
16
|
-
has_many :
|
16
|
+
has_many :matches, class_name: 'SportDb::Model::Match', :through => :grounds
|
17
17
|
end
|
18
18
|
|
19
19
|
end # module Model
|
File without changes
|
File without changes
|
File without changes
|
@@ -8,43 +8,58 @@ def up
|
|
8
8
|
|
9
9
|
create_table :teams do |t|
|
10
10
|
t.string :key, null: false # import/export key
|
11
|
-
t.string :
|
12
|
-
|
13
|
-
t.string :code
|
14
|
-
t.string :
|
11
|
+
t.string :name, null: false # "canonical" unique name
|
12
|
+
|
13
|
+
t.string :code # three letter code (short name)
|
14
|
+
t.string :alt_names # comma separated list of alt names / synonyms
|
15
|
+
|
15
16
|
t.references :country, null: false, index: false
|
16
|
-
t.references :city
|
17
|
-
|
17
|
+
t.references :city, index: false # note: city is optional (should be required for clubs e.g. non-national teams)
|
18
|
+
t.references :district, index: false # note: optional district (in city)
|
19
|
+
|
20
|
+
## todo/check/fix: use team type or such e.g. club/national/etc. - why? why not?
|
21
|
+
### or remove and add virtual attribute in model instead - why? why not?
|
18
22
|
t.boolean :club, null: false, default: false # is it a club (not a national team)?
|
23
|
+
t.boolean :national, null: false, default: false # is it a national selection team (not a club)?
|
24
|
+
|
25
|
+
## todo/fix: add team reference for a and b team!!!!
|
26
|
+
|
27
|
+
|
28
|
+
t.integer :start_year # founding year -fix change to start_year / founded - why? why not?
|
29
|
+
t.integer :end_year
|
30
|
+
## add more? - start_year2, end_year2 - why? why not?
|
31
|
+
# e.g. founded = 1946, 2013 (refounded)
|
32
|
+
# dissolved = 1997
|
19
33
|
|
20
|
-
t.integer :since # founding year -fix change to start_year / founded - why? why not?
|
21
34
|
t.string :address
|
22
35
|
t.string :web
|
23
36
|
|
37
|
+
## todo/fix: change to gov / governing body or such!!!
|
24
38
|
t.references :assoc, index: false # optional: national football assoc(iation), for example - used for national teams
|
25
39
|
|
26
|
-
|
27
|
-
|
40
|
+
t.string :comments
|
41
|
+
|
28
42
|
t.timestamps
|
29
43
|
end
|
30
44
|
|
31
45
|
add_index :teams, :key, unique: true
|
32
46
|
|
47
|
+
|
33
48
|
###########
|
34
49
|
# check: use table (rename to) venues / stadiums - why? why not?
|
35
50
|
create_table :grounds do |t|
|
36
51
|
t.string :key, null: false # import/export key
|
37
|
-
t.string :
|
38
|
-
t.string :
|
52
|
+
t.string :name, null: false
|
53
|
+
t.string :alt_names # comma separated list of alt_names / synonyms
|
39
54
|
|
40
55
|
t.references :country, null: false, index: false
|
41
56
|
t.references :city, index: false # todo: make city required ???
|
57
|
+
t.references :district, index: false # note: optional district (in city)
|
42
58
|
|
43
|
-
t.integer :
|
44
|
-
t.integer :capacity
|
59
|
+
t.integer :start_year # founding year
|
60
|
+
t.integer :capacity # attentence capacity e.g. 10_000 or 50_000 etc.
|
45
61
|
t.string :address
|
46
62
|
|
47
|
-
|
48
63
|
### fix/todo: add since/founded/opened/build attrib eg. 2011 or 1987
|
49
64
|
## - add capacity e.g. 40_000
|
50
65
|
## fix: add address !!!! etc
|
@@ -57,10 +72,10 @@ end
|
|
57
72
|
add_index :grounds, :key, unique: true
|
58
73
|
|
59
74
|
|
60
|
-
# join table: person+
|
75
|
+
# join table: person+match(team1+team2+event(season+league))
|
61
76
|
create_table :goals do |t|
|
62
77
|
t.references :person, null: false, index: false
|
63
|
-
t.references :
|
78
|
+
t.references :match, null: false, index: false
|
64
79
|
t.references :team, null: false, index: false ## use integer instead w/ values 1 or 2 for team1 or team2 ?? why? why not?
|
65
80
|
|
66
81
|
t.integer :minute
|
@@ -77,33 +92,30 @@ create_table :goals do |t|
|
|
77
92
|
end
|
78
93
|
|
79
94
|
|
80
|
-
################
|
81
|
-
# fix/todo: rename to squads / lineups
|
82
|
-
|
83
95
|
# join table -> person+team+event(season+league)
|
84
|
-
create_table :
|
96
|
+
create_table :lineups do |t| # use squads as an alternative name? why? why not??
|
85
97
|
t.references :person, null: false, index: false
|
86
98
|
t.references :team, null: false, index: false
|
87
99
|
t.references :event , index: false # make required?
|
88
|
-
t.integer :
|
100
|
+
t.integer :num, # optional - jersey (t-shirt) number
|
89
101
|
|
90
102
|
t.timestamps
|
91
103
|
end
|
92
104
|
|
93
105
|
|
94
106
|
create_table :events do |t|
|
95
|
-
t.string :key,
|
96
|
-
t.references :league,
|
97
|
-
t.references :season,
|
98
|
-
t.date :
|
99
|
-
t.date :
|
107
|
+
t.string :key, null: false # import/export key
|
108
|
+
t.references :league, null: false, index: false
|
109
|
+
t.references :season, null: false, index: false
|
110
|
+
t.date :start_date, null: false # note: only use date (w/o time)
|
111
|
+
t.date :end_date # note: only use date (w/o time)
|
112
|
+
|
113
|
+
t.integer :num ## optional series counter e.g. World Cup No. 2, Bundesliga No. 43 etc. etc.
|
100
114
|
|
101
|
-
t.boolean :team3, null: false, default: true ## e.g. Champions League has no 3rd place (only 1st and 2nd/final)
|
115
|
+
## t.boolean :team3, null: false, default: true ## e.g. Champions League has no 3rd place (only 1st and 2nd/final)
|
102
116
|
## todo: add league/cup flag/flags or to league itself?
|
103
117
|
## or add add a tournament type field - why? why not?
|
104
118
|
|
105
|
-
t.integer :num ## optional series counter e.g. World Cup No. 2, Bundesliga No. 43 etc. etc.
|
106
|
-
|
107
119
|
## auto-added flag (e.g. start_at n end_at dates got calculated)
|
108
120
|
## if auto-added flag is false - do NOT auto-update start_at, end_at etc.
|
109
121
|
t.boolean :auto, null: false, default: true
|
@@ -111,8 +123,8 @@ create_table :events do |t|
|
|
111
123
|
|
112
124
|
#### track 1-n sources (from repos) - # todo move to its own table later
|
113
125
|
## NB: relative to event.yml - use mapper to "resolve" to full path w/ repo; use league+season keys
|
114
|
-
t.string :sources # e.g. cup or bl,bl_ii # NB: for now store all in on string separated by comma
|
115
|
-
t.string :config # e.g. cup or bl # e.g assumes cup.yml, bl.yml etc. for now
|
126
|
+
# t.string :sources # e.g. cup or bl,bl_ii # NB: for now store all in on string separated by comma
|
127
|
+
# t.string :config # e.g. cup or bl # e.g assumes cup.yml, bl.yml etc. for now
|
116
128
|
|
117
129
|
|
118
130
|
t.timestamps
|
@@ -123,19 +135,22 @@ add_index :events, :key, unique: true
|
|
123
135
|
|
124
136
|
create_table :rounds do |t|
|
125
137
|
t.references :event, null: false, index: false ## Note: do NOT auto-add index
|
126
|
-
t.string :
|
127
|
-
t.string :title2
|
138
|
+
t.string :name, null: false
|
128
139
|
t.integer :pos, null: false ## use only for "internal" sort order (defaults to insertion order)
|
129
140
|
|
130
141
|
t.integer :num ## optional match day/week number
|
131
142
|
t.string :key ## optional match day/week number key (as string)
|
132
143
|
|
133
144
|
## add new table stage/stages for grouping rounds in group rounds and playoff rounds, for example???
|
134
|
-
## # "regular" season (group)
|
145
|
+
## # "regular" season (group) matches or post-season (playoff) knockouts (k.o's)
|
135
146
|
t.boolean :knockout, null: false, default: false
|
136
147
|
## todo: add leg (e.g. leg1, leg2, etc. why? why not?)
|
137
|
-
t.date :
|
138
|
-
t.date :
|
148
|
+
t.date :start_date # note: only use date (w/o time) - fix: change to start_date!!!
|
149
|
+
t.date :end_date # note: only use date (w/o time) - fix: change to end_date!!!
|
150
|
+
t.date :start_date2 # note: only use date (w/o time) - fix: change to start_date!!!
|
151
|
+
t.date :end_date2 # note: only use date (w/o time) - fix: change to end_date!!!
|
152
|
+
|
153
|
+
## add last_date/first-date(auto) - for "real" last and first dates - auto-added - why? why not?
|
139
154
|
|
140
155
|
## auto-added flag (e.g. start_at n end_at dates got calculated)
|
141
156
|
## if auto-added flag is false - do NOT auto-update start_at, end_at etc.
|
@@ -149,7 +164,7 @@ add_index :rounds, :event_id # fk event_id index
|
|
149
164
|
|
150
165
|
create_table :groups do |t| # Teamgruppe (zB Gruppe A, Gruppe B, etc.)
|
151
166
|
t.references :event, null: false, index: false ## Note: do NOT auto-add index
|
152
|
-
t.string :
|
167
|
+
t.string :name, null: false
|
153
168
|
t.integer :pos, null: false ## use only for "internal" sort order (defaults to insertion order)
|
154
169
|
|
155
170
|
t.string :key ## optional group key e.g. A, B, C or 1, 2, etc. - use why? why not?
|
@@ -161,7 +176,7 @@ add_index :groups, :event_id # fk event_id index
|
|
161
176
|
|
162
177
|
create_table :stages do |t| # e.g. regular season, champions round, etc.
|
163
178
|
t.references :event, null: false, index: false ## Note: do NOT auto-add index
|
164
|
-
t.string :
|
179
|
+
t.string :name, null: false
|
165
180
|
## todo/check: add pos for use only for "internal" sort order (defaults to insertion order)??
|
166
181
|
t.timestamps
|
167
182
|
end
|
@@ -170,9 +185,7 @@ add_index :stages, :event_id # fk event_id index
|
|
170
185
|
|
171
186
|
|
172
187
|
|
173
|
-
|
174
|
-
# fix: rename table to matches - why? why not?
|
175
|
-
create_table :games do |t|
|
188
|
+
create_table :matches do |t|
|
176
189
|
t.string :key # import/export key
|
177
190
|
t.references :event, null: false, index: false
|
178
191
|
t.integer :pos, null: false ## note: use only for "internal" sort order (defaults to insertion order)
|
@@ -194,17 +207,20 @@ create_table :games do |t|
|
|
194
207
|
t.string :stage_key
|
195
208
|
|
196
209
|
|
197
|
-
t.
|
210
|
+
t.date :date # optioanl play date - todo/fix: split into play_date AND play_time!!!
|
211
|
+
t.time :time
|
212
|
+
|
198
213
|
t.boolean :postponed, null: false, default: false
|
199
|
-
t.
|
200
|
-
t.
|
214
|
+
## t.date :date2 # optional old date (when postponed)
|
215
|
+
## t.date :date3 # optional odl date (when postponed twice)
|
201
216
|
|
202
217
|
t.references :ground, index: false # optional - stadium (lets you get city,region,country,etc)
|
203
218
|
t.references :city, index: false # optional - convenience for ground.city_id ???
|
204
219
|
|
205
|
-
|
206
|
-
t.boolean :knockout, null: false, default: false
|
220
|
+
## change home to neutral - why? why not?
|
207
221
|
t.boolean :home, null: false, default: true # is team1 play at home or neutral (that is, at its home stadium)
|
222
|
+
t.boolean :knockout, null: false, default: false
|
223
|
+
|
208
224
|
t.integer :score1
|
209
225
|
t.integer :score2
|
210
226
|
t.integer :score1et # extratime - team 1 (opt)
|
@@ -215,23 +231,25 @@ create_table :games do |t|
|
|
215
231
|
t.integer :score2i # half time - team 2
|
216
232
|
t.integer :score1ii # second third (opt)
|
217
233
|
t.integer :score2ii # second third - team2 (opt)
|
218
|
-
t.references :
|
219
|
-
t.references :
|
234
|
+
t.references :next_match, index: false ## Note: do NOT auto-add index -- for hinspiel bei rueckspiel in knockout match
|
235
|
+
t.references :prev_match, index: false ## Note: do NOT auto-add index
|
220
236
|
|
221
237
|
t.integer :winner # 1,2,0,nil calculate on save - "real" winner (after 90 or extra time or penalty, aggregated first+second leg?)
|
222
238
|
t.integer :winner90 # 1,2,0,nil calculate on save - winner after 90 mins (or regugular play time depending on sport - add alias or find a better name!)
|
223
239
|
|
240
|
+
t.string :comments
|
241
|
+
|
224
242
|
t.timestamps
|
225
243
|
end
|
226
244
|
|
227
|
-
add_index :
|
228
|
-
add_index :
|
229
|
-
add_index :
|
230
|
-
add_index :
|
231
|
-
add_index :
|
232
|
-
add_index :
|
233
|
-
add_index :
|
234
|
-
add_index :
|
245
|
+
add_index :matches, :key, unique: true
|
246
|
+
add_index :matches, :event_id # fk event_id index
|
247
|
+
add_index :matches, :round_id # fk round_id index
|
248
|
+
add_index :matches, :group_id # fk group_id index
|
249
|
+
add_index :matches, :next_match_id # fk next_match_id index
|
250
|
+
add_index :matches, :prev_match_id # fk next_match_id index
|
251
|
+
add_index :matches, :team1_id
|
252
|
+
add_index :matches, :team2_id
|
235
253
|
|
236
254
|
|
237
255
|
# todo: remove id from join table (without extra fields)? why?? why not??
|
@@ -283,25 +301,29 @@ add_index :groups_teams, :group_id
|
|
283
301
|
|
284
302
|
create_table :seasons do |t| ## also used for years - add a boolean year true/false flag too - why? why not?
|
285
303
|
t.string :key, null: false
|
286
|
-
t.string :
|
304
|
+
t.string :name, null: false # e.g. 2011/12, 2012/13 ### what to do w/ 2012? for world cup etc?
|
287
305
|
t.timestamps
|
288
306
|
end
|
289
307
|
|
290
308
|
|
291
309
|
create_table :leagues do |t| ## also for cups/conferences/tournaments/world series/etc.
|
292
310
|
t.string :key, null: false
|
293
|
-
t.string :
|
294
|
-
t.
|
311
|
+
t.string :name, null: false # e.g. Premier League, Deutsche Bundesliga, World Cup, Champions League, etc.
|
312
|
+
t.string :alt_names # comma separated list of alt names / synonyms
|
313
|
+
|
314
|
+
t.references :country, index: false ## optional for now ### todo: create "virtual" country for international leagues e.g. use int? or world (ww?)/europe (eu)/etc. similar? already taken??
|
295
315
|
|
296
316
|
## fix: rename to :clubs from :club - why? why not?
|
297
317
|
## fix: rename to :intl from :international - why? why not? shorter? better?
|
298
318
|
## todo/check: flip clup to league flag? why? why not?
|
299
|
-
t.boolean :
|
300
|
-
t.boolean :intl,
|
301
|
-
t.boolean :cup,
|
319
|
+
t.boolean :clubs, null: false, default: false # club teams or national teams?
|
320
|
+
t.boolean :intl, null: false, default: false # national league or international?
|
321
|
+
t.boolean :cup, null: false, default: false ## or regular season league?? use a tournament type field with enums - why? why not?
|
322
|
+
|
302
323
|
t.integer :level ## use tier? e.g. level 1, level 2, etc.
|
303
324
|
|
304
|
-
|
325
|
+
t.integer :start_year
|
326
|
+
t.integer :end_year
|
305
327
|
|
306
328
|
## todo: add t.boolean :national flag? for national teams?
|
307
329
|
t.timestamps
|
@@ -314,16 +336,16 @@ create_table :badges do |t|
|
|
314
336
|
## t.references :event, :null => false # event => league+season
|
315
337
|
t.references :league, null: false, index: false
|
316
338
|
t.references :season, null: false, index: false
|
317
|
-
t.string :
|
339
|
+
t.string :name, null: false # Meister, Weltmeister, Europameister, Cupsieger, Vize-Meister, Aufsteiger, Absteiger, etc.
|
318
340
|
t.timestamps
|
319
341
|
end
|
320
342
|
|
321
343
|
|
322
344
|
create_table :assocs do |t|
|
323
345
|
t.string :key, null: false
|
324
|
-
t.string :
|
346
|
+
t.string :name, null: false # e.g. Premier League, Deutsche Bundesliga, World Cup, Champions League, etc.
|
325
347
|
|
326
|
-
t.integer :
|
348
|
+
t.integer :start_year # founding year
|
327
349
|
t.string :web
|
328
350
|
|
329
351
|
### if national assoc - has (optional) country ref
|
@@ -332,6 +354,7 @@ create_table :assocs do |t|
|
|
332
354
|
|
333
355
|
## add :world flag for FIFA? - just check if parent is null? for root assoc(s)? why? why not?
|
334
356
|
## add :regional flag for continental subdivision?
|
357
|
+
## todo: shorten to contl and intercontl - why? why not?
|
335
358
|
t.boolean :continental, null: false, default: false
|
336
359
|
t.boolean :intercontinental, null: false, default: false # e.g. arab football league (africa+western asia/middle east)
|
337
360
|
t.timestamps
|
@@ -365,16 +388,17 @@ create_table :group_standings do |t|
|
|
365
388
|
t.timestamps
|
366
389
|
end
|
367
390
|
|
368
|
-
### use items instead of entries - why (shorter! simple plural e.g. just add s)
|
391
|
+
### use items or lines instead of entries - why (shorter! simple plural e.g. just add s)
|
392
|
+
## use group_table_lines/stats - why? why not?
|
369
393
|
|
370
394
|
create_table :group_standing_entries do |t|
|
371
395
|
t.references :group_standing, null: false, index: false
|
372
396
|
t.references :team, null: false, index: false
|
373
|
-
t.integer :pos
|
374
|
-
t.integer :played
|
375
|
-
t.integer :won
|
376
|
-
t.integer :lost
|
377
|
-
t.integer :drawn
|
397
|
+
t.integer :pos # check/todo: use rank? -- keep/use pos only for "internal" insertation order only - why? why not?
|
398
|
+
t.integer :played ## p/pld
|
399
|
+
t.integer :won ## w
|
400
|
+
t.integer :lost ## l
|
401
|
+
t.integer :drawn ## d or t/tied ??
|
378
402
|
t.integer :goals_for # todo: find a short name - gf? why? why not?
|
379
403
|
t.integer :goals_against # todo: find a shorter name - ga? why? why not?
|
380
404
|
t.integer :pts
|
@@ -408,7 +432,7 @@ end
|
|
408
432
|
## -use (find a better) a different name? why? why not?
|
409
433
|
create_table :alltime_standings do |t|
|
410
434
|
t.string :key, null: false
|
411
|
-
t.string :
|
435
|
+
t.string :name, null: false
|
412
436
|
t.timestamps
|
413
437
|
end
|
414
438
|
|
@@ -423,7 +447,7 @@ create_table :alltime_standing_entries do |t|
|
|
423
447
|
t.integer :goals_for # todo: find a short name - gf? why? why not?
|
424
448
|
t.integer :goals_against # todo: find a shorter name - ga? why? why not?
|
425
449
|
t.integer :pts
|
426
|
-
t.integer :recs # note: specific to alltime - stats records counter (e.g. appearance counter)
|
450
|
+
t.integer :recs # note: specific to alltime - stats records counter (e.g. appearance counter) - find a better name - why? why not?
|
427
451
|
t.string :comments
|
428
452
|
t.timestamps
|
429
453
|
end
|