sportdb-models 1.19.1 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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
@@ -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
|
-
|
@@ -1,83 +0,0 @@
|
|
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
|
-
|
17
|
-
def self.create_or_update_from_values( new_attributes, values )
|
18
|
-
|
19
|
-
## fix: add/configure logger for ActiveRecord!!!
|
20
|
-
logger = LogKernel::Logger.root
|
21
|
-
|
22
|
-
## check optional values
|
23
|
-
values.each_with_index do |value, index|
|
24
|
-
if value =~ /^club$/ # club flag
|
25
|
-
new_attributes[ :club ] = true
|
26
|
-
elsif value =~ /^[a-z]{2}$/ ## assume two-letter country key e.g. at,de,mx,etc.
|
27
|
-
value_country = Country.find_by_key!( value )
|
28
|
-
new_attributes[ :country_id ] = value_country.id
|
29
|
-
else
|
30
|
-
## todo: assume title2 ??
|
31
|
-
## assume title2 if title2 is empty (not already in use)
|
32
|
-
## and if it title2 contains at least two letter e.g. [a-zA-Z].*[a-zA-Z]
|
33
|
-
# issue warning: unknown type for value
|
34
|
-
logger.warn "unknown type for value >#{value}< - key #{new_attributes[:key]}"
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
logger.debug " find league key: #{new_attributes[ :key ]}"
|
39
|
-
|
40
|
-
rec = League.find_by_key( new_attributes[ :key ] )
|
41
|
-
if rec.present?
|
42
|
-
logger.debug "update League #{rec.id}-#{rec.key}:"
|
43
|
-
else
|
44
|
-
logger.debug "create League:"
|
45
|
-
rec = League.new
|
46
|
-
end
|
47
|
-
|
48
|
-
logger.debug new_attributes.to_json
|
49
|
-
|
50
|
-
rec.update_attributes!( new_attributes )
|
51
|
-
end # create_or_update_from_values
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
def self.create_from_ary!( leagues, more_values={} )
|
56
|
-
leagues.each do |values|
|
57
|
-
|
58
|
-
## key & title required
|
59
|
-
attr = {
|
60
|
-
key: values[0],
|
61
|
-
title: values[1]
|
62
|
-
}
|
63
|
-
|
64
|
-
attr = attr.merge( more_values )
|
65
|
-
|
66
|
-
## check for optional values
|
67
|
-
values[2..-1].each do |value|
|
68
|
-
if value.is_a? Country
|
69
|
-
attr[ :country_id ] = value.id
|
70
|
-
else
|
71
|
-
# issue warning: unknown type for value
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
League.create!( attr )
|
76
|
-
end # each league
|
77
|
-
end
|
78
|
-
|
79
|
-
end # class League
|
80
|
-
|
81
|
-
|
82
|
-
end # module Model
|
83
|
-
end # module SportDb
|
@@ -1,44 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
module SportDb
|
4
|
-
module Model
|
5
|
-
|
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
|
-
|
14
|
-
def recalc_for_league!( league, opts={} )
|
15
|
-
|
16
|
-
recs = StandingsHelper.calc_for_events( league.events, opts )
|
17
|
-
|
18
|
-
## - remove (if exit) old entries and add new entries
|
19
|
-
entries.delete_all # note: assoc dependent set to :delete_all (defaults to :nullify)
|
20
|
-
|
21
|
-
recs.each do |team_key,rec|
|
22
|
-
|
23
|
-
team = Team.find_by_key!( team_key )
|
24
|
-
### note: we also add rec.recs (appearance counter) - not included w/ group or event standings, for example
|
25
|
-
entries.create!(
|
26
|
-
team_id: team.id,
|
27
|
-
pos: rec.pos,
|
28
|
-
played: rec.played,
|
29
|
-
won: rec.won,
|
30
|
-
drawn: rec.drawn,
|
31
|
-
lost: rec.lost,
|
32
|
-
goals_for: rec.goals_for,
|
33
|
-
goals_against: rec.goals_against,
|
34
|
-
pts: rec.pts,
|
35
|
-
recs: rec.recs )
|
36
|
-
end
|
37
|
-
end # method recalc_for_league!
|
38
|
-
|
39
|
-
|
40
|
-
end # class AlltimeStanding
|
41
|
-
|
42
|
-
|
43
|
-
end # module Model
|
44
|
-
end # module SportDb
|
@@ -1,55 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
module SportDb
|
4
|
-
module Model
|
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
|
-
## 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 event standing e.g.
|
20
|
-
|
21
|
-
## calc points (pts) - loop over all group games/matches
|
22
|
-
# group.games.each do |game|
|
23
|
-
# end
|
24
|
-
|
25
|
-
# todo/fix!!!!!!!!!!:
|
26
|
-
# skip knockout rounds - why? why not?
|
27
|
-
# make it configure-able?
|
28
|
-
|
29
|
-
recs = StandingsHelper.calc( event.games, opts )
|
30
|
-
|
31
|
-
## - remove (if exit) old entries and add new entries
|
32
|
-
entries.delete_all # note: assoc dependent set to :delete_all (defaults to :nullify)
|
33
|
-
|
34
|
-
## add empty entries
|
35
|
-
event.teams.each do |team|
|
36
|
-
puts " adding entry for team #{team.title} (#{team.code})"
|
37
|
-
rec = recs[ team.key ] # find (in-memory) stats records
|
38
|
-
entries.create!(
|
39
|
-
team_id: team.id,
|
40
|
-
pos: rec.pos,
|
41
|
-
played: rec.played,
|
42
|
-
won: rec.won,
|
43
|
-
drawn: rec.drawn,
|
44
|
-
lost: rec.lost,
|
45
|
-
goals_for: rec.goals_for,
|
46
|
-
goals_against: rec.goals_against,
|
47
|
-
pts: rec.pts )
|
48
|
-
end
|
49
|
-
end # method recalc!
|
50
|
-
|
51
|
-
|
52
|
-
end # class EventStanding
|
53
|
-
end # module Model
|
54
|
-
|
55
|
-
end # module SportDb
|
@@ -1,50 +0,0 @@
|
|
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
|