sportdb-readers 1.2.1 → 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/CHANGELOG.md +1 -1
- data/Manifest.txt +7 -0
- data/Rakefile +3 -2
- data/lib/sportdb/readers/match_reader.rb +15 -10
- data/lib/sportdb/readers/sync/club.rb +47 -0
- data/lib/sportdb/readers/sync/country.rb +39 -0
- data/lib/sportdb/readers/sync/event.rb +72 -0
- data/lib/sportdb/readers/sync/league.rb +40 -0
- data/lib/sportdb/readers/sync/match.rb +147 -0
- data/lib/sportdb/readers/sync/more.rb +136 -0
- data/lib/sportdb/readers/sync/season.rb +36 -0
- data/lib/sportdb/readers/version.rb +4 -2
- data/lib/sportdb/readers.rb +14 -4
- metadata +26 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dbb28e300a9554870b241ebd71e204914caae0dcdfd299ad4fb9ce8c29b8a48e
|
4
|
+
data.tar.gz: cfd60853ca4a88aad6a652a7d1f26a8d131d9f540f16d89411a851b275b2f997
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7bd415167e8969b605682f74d3b420f3aae0dc6db8925f0db872a6753fdd79e593eb5dc479b3cd9a9c5d040eea81da6f274ad2739cd2116fad445cb3452ad8a8
|
7
|
+
data.tar.gz: 860bc2949679d7b5654ced5ff3c20d59e1c77ac41253d5924612669dab800560a58886b1de8b1079d591a35a55176cd0200edf72e25449b23147b58f694e3e67
|
data/CHANGELOG.md
CHANGED
data/Manifest.txt
CHANGED
@@ -7,4 +7,11 @@ lib/sportdb/readers.rb
|
|
7
7
|
lib/sportdb/readers/conf_reader.rb
|
8
8
|
lib/sportdb/readers/match_reader.rb
|
9
9
|
lib/sportdb/readers/package.rb
|
10
|
+
lib/sportdb/readers/sync/club.rb
|
11
|
+
lib/sportdb/readers/sync/country.rb
|
12
|
+
lib/sportdb/readers/sync/event.rb
|
13
|
+
lib/sportdb/readers/sync/league.rb
|
14
|
+
lib/sportdb/readers/sync/match.rb
|
15
|
+
lib/sportdb/readers/sync/more.rb
|
16
|
+
lib/sportdb/readers/sync/season.rb
|
10
17
|
lib/sportdb/readers/version.rb
|
data/Rakefile
CHANGED
@@ -3,7 +3,7 @@ require './lib/sportdb/readers/version.rb'
|
|
3
3
|
|
4
4
|
Hoe.spec 'sportdb-readers' do
|
5
5
|
|
6
|
-
self.version = SportDb::Readers::VERSION
|
6
|
+
self.version = SportDb::Module::Readers::VERSION
|
7
7
|
|
8
8
|
self.summary = "sportdb-readers - sport.db readers for leagues, seasons, clubs, match schedules and results, and more"
|
9
9
|
self.description = summary
|
@@ -20,7 +20,8 @@ Hoe.spec 'sportdb-readers' do
|
|
20
20
|
self.licenses = ['Public Domain']
|
21
21
|
|
22
22
|
self.extra_deps = [
|
23
|
-
['sportdb-
|
23
|
+
['sportdb-formats', '>= 2.0.1'],
|
24
|
+
['sportdb-models', '>= 2.1.0'],
|
24
25
|
]
|
25
26
|
|
26
27
|
self.spec_extras = {
|
@@ -1,8 +1,18 @@
|
|
1
1
|
|
2
2
|
module SportDb
|
3
|
-
|
4
3
|
class MatchReader ## todo/check: rename to MatchReaderV2 (use plural?) why? why not?
|
5
4
|
|
5
|
+
|
6
|
+
### fix - remove catalog reference!!!
|
7
|
+
## use classes with "augmented" static methods
|
8
|
+
## e.g. Club.match_by etc.
|
9
|
+
def catalog
|
10
|
+
puts "[deprecated] do NOT use catalog reference; use classes with enhanced search static methods!"
|
11
|
+
Import.catalog
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
|
6
16
|
def self.read( path, season: nil ) ## use - rename to read_file or from_file etc. - why? why not?
|
7
17
|
txt = File.open( path, 'r:utf-8' ) {|f| f.read }
|
8
18
|
parse( txt, season: season )
|
@@ -72,10 +82,10 @@ class MatchReader ## todo/check: rename to MatchReaderV2 (use plural?) why? w
|
|
72
82
|
if league.clubs? && league.intl? ## todo/fix: add intl? to ActiveRecord league!!!
|
73
83
|
|
74
84
|
## quick hack - use "dynamic" keys for keys
|
75
|
-
uefa_el_q =
|
76
|
-
uefa_cl_q =
|
77
|
-
uefa_cl =
|
78
|
-
uefa_el =
|
85
|
+
uefa_el_q = Import::League.match_by( code: 'uefa.el.quali' )[0]
|
86
|
+
uefa_cl_q = Import::League.match_by( code: 'uefa.cl.quali' )[0]
|
87
|
+
uefa_cl = Import::League.match_by( code: 'uefa.cl' )[0]
|
88
|
+
uefa_el = Import::League.match_by( code: 'uefa.el' )[0]
|
79
89
|
|
80
90
|
pp [uefa_el_q, uefa_cl_q, uefa_cl, uefa_el]
|
81
91
|
|
@@ -213,10 +223,5 @@ class MatchReader ## todo/check: rename to MatchReaderV2 (use plural?) why? w
|
|
213
223
|
end # method parse
|
214
224
|
|
215
225
|
|
216
|
-
######################
|
217
|
-
# (convenience) helpers
|
218
|
-
|
219
|
-
def catalog() Import.catalog; end
|
220
|
-
|
221
226
|
end # class MatchReader
|
222
227
|
end # module SportDb
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module SportDb
|
2
|
+
module Sync
|
3
|
+
class Club
|
4
|
+
|
5
|
+
## auto-cache all clubs by find_or_create for later mapping / lookup
|
6
|
+
def self.cache() @cache ||= {}; end
|
7
|
+
|
8
|
+
|
9
|
+
##################################
|
10
|
+
# finders
|
11
|
+
|
12
|
+
def self.find_or_create( club )
|
13
|
+
## note: assume "canonical unique" names for now for clubs
|
14
|
+
rec = Model::Team.find_by( name: club.name )
|
15
|
+
if rec.nil?
|
16
|
+
|
17
|
+
## todo/fix: move auto-key gen to structs for re(use)!!!!!!
|
18
|
+
## check if key is present otherwise generate e.g. remove all non-ascii a-z chars
|
19
|
+
key = club.key || club.name.downcase.gsub( /[^a-z]/, '' )
|
20
|
+
puts "add club: #{key}, #{club.name}, #{club.country.name} (#{club.country.key})"
|
21
|
+
|
22
|
+
attribs = {
|
23
|
+
key: key,
|
24
|
+
name: club.name,
|
25
|
+
country_id: Sync::Country.find_or_create( club.country ).id,
|
26
|
+
club: true,
|
27
|
+
national: false ## check -is default anyway - use - why? why not?
|
28
|
+
## todo/fix: add city if present - why? why not?
|
29
|
+
}
|
30
|
+
|
31
|
+
attribs[:code] = club.code if club.code ## add code (abbreviation) if present
|
32
|
+
|
33
|
+
if club.alt_names.empty? == false
|
34
|
+
attribs[:alt_names] = club.alt_names.join('|')
|
35
|
+
end
|
36
|
+
|
37
|
+
rec = Model::Team.create!( attribs )
|
38
|
+
end
|
39
|
+
## auto-add to cache
|
40
|
+
cache[club.name] = rec
|
41
|
+
|
42
|
+
rec
|
43
|
+
end
|
44
|
+
|
45
|
+
end # class Club
|
46
|
+
end # module Sync
|
47
|
+
end # module SportDb
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module SportDb
|
2
|
+
module Sync
|
3
|
+
class Country
|
4
|
+
|
5
|
+
#############################
|
6
|
+
# finders
|
7
|
+
|
8
|
+
def self.find( country )
|
9
|
+
WorldDb::Model::Country.find_by( key: country.key )
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.find!( country )
|
13
|
+
rec = find( country )
|
14
|
+
if rec.nil?
|
15
|
+
puts "** !!! ERROR !!! - country for key >#{country.key}< not found; sorry - add to COUNTRIES table"
|
16
|
+
exit 1
|
17
|
+
end
|
18
|
+
rec
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.find_or_create( country )
|
22
|
+
rec = find( country )
|
23
|
+
if rec.nil?
|
24
|
+
attribs = {
|
25
|
+
key: country.key,
|
26
|
+
name: country.name,
|
27
|
+
code: country.code, ## fix: uses fifa code now (should be iso-alpha3 if available)
|
28
|
+
## fifa: country.fifa,
|
29
|
+
area: 1,
|
30
|
+
pop: 1
|
31
|
+
}
|
32
|
+
rec = WorldDb::Model::Country.create!( attribs )
|
33
|
+
end
|
34
|
+
rec
|
35
|
+
end
|
36
|
+
end # class Country
|
37
|
+
|
38
|
+
end # module Sync
|
39
|
+
end # module SportDb
|
@@ -0,0 +1,72 @@
|
|
1
|
+
module SportDb
|
2
|
+
module Sync
|
3
|
+
|
4
|
+
class Event
|
5
|
+
|
6
|
+
##################################################
|
7
|
+
# finders
|
8
|
+
def self.find_by( league:, season: )
|
9
|
+
## note: allow passing in of activerecord db records too - why? why not?
|
10
|
+
## fix - change ArgumentError to TypeError !! (if TypeError exists)
|
11
|
+
raise ArgumentError, "league struct record expected; got #{league.class.name}" unless league.is_a?( Import::League )
|
12
|
+
raise ArgumentError, "season struct record expected; got #{season.class.name}" unless season.is_a?( Import::Season )
|
13
|
+
|
14
|
+
## auto-create league and season (db) records if missing? - why? why not?
|
15
|
+
season_rec = Season.find( season )
|
16
|
+
league_rec = League.find( league )
|
17
|
+
|
18
|
+
rec = nil
|
19
|
+
rec = Model::Event.find_by( league_id: league_rec.id,
|
20
|
+
season_id: season_rec.id ) if season_rec && league_rec
|
21
|
+
rec
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.find_by!( league:, season: )
|
25
|
+
rec = find_by( league: league, season: season )
|
26
|
+
if rec.nil?
|
27
|
+
puts "** !!!ERROR!!! db sync - no event match found for:"
|
28
|
+
pp league
|
29
|
+
pp season
|
30
|
+
exit 1
|
31
|
+
end
|
32
|
+
rec
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.find_or_create_by( league:, season: )
|
36
|
+
## note: allow passing in of activerecord db records too - why? why not?
|
37
|
+
raise ArgumentError, "league struct record expected; got #{league.class.name}" unless league.is_a?( Import::League )
|
38
|
+
raise ArgumentError, "season struct record expected; got #{season.class.name}" unless season.is_a?( Import::Season )
|
39
|
+
|
40
|
+
## note: auto-creates league and season (db) records if missing - why? why not?
|
41
|
+
season_rec = Season.find_or_create( season )
|
42
|
+
league_rec = League.find_or_create( league )
|
43
|
+
|
44
|
+
rec = Model::Event.find_by( league_id: league_rec.id,
|
45
|
+
season_id: season_rec.id )
|
46
|
+
if rec.nil?
|
47
|
+
attribs = {
|
48
|
+
league_id: league_rec.id,
|
49
|
+
season_id: season_rec.id,
|
50
|
+
}
|
51
|
+
|
52
|
+
## quick hack/change later !!
|
53
|
+
## todo/fix: check season - if is length 4 (single year) use 2017, 1, 1
|
54
|
+
## otherwise use 2017, 7, 1
|
55
|
+
## start_at use year and 7,1 e.g. Date.new( 2017, 7, 1 )
|
56
|
+
## hack: fix/todo1!!
|
57
|
+
## add "fake" start_date for now
|
58
|
+
attribs[:start_date] = if season.year? ## e.g. assume 2018 etc.
|
59
|
+
Date.new( season.start_year, 1, 1 )
|
60
|
+
else ## assume 2014/15 etc.
|
61
|
+
Date.new( season.start_year, 7, 1 )
|
62
|
+
end
|
63
|
+
|
64
|
+
rec = Model::Event.create!( attribs )
|
65
|
+
end
|
66
|
+
rec
|
67
|
+
end
|
68
|
+
end # class Event
|
69
|
+
|
70
|
+
end # module Sync
|
71
|
+
end # module SportDb
|
72
|
+
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module SportDb
|
2
|
+
module Sync
|
3
|
+
class League
|
4
|
+
|
5
|
+
###################################
|
6
|
+
# finders
|
7
|
+
|
8
|
+
def self.find( league )
|
9
|
+
Model::League.find_by( key: league.key )
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.find!( league )
|
13
|
+
rec = find( league )
|
14
|
+
if rec.nil?
|
15
|
+
puts "** !!!ERROR!!! db sync - no league match found for:"
|
16
|
+
pp league
|
17
|
+
exit 1
|
18
|
+
end
|
19
|
+
rec
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.find_or_create( league )
|
23
|
+
rec = find( league )
|
24
|
+
if rec.nil?
|
25
|
+
attribs = { key: league.key,
|
26
|
+
name: league.name }
|
27
|
+
|
28
|
+
if league.country
|
29
|
+
attribs[ :country_id ] = Sync::Country.find_or_create( league.country ).id
|
30
|
+
end
|
31
|
+
|
32
|
+
rec = Model::League.create!( attribs )
|
33
|
+
end
|
34
|
+
rec
|
35
|
+
end
|
36
|
+
|
37
|
+
end # class League
|
38
|
+
end # module Sync
|
39
|
+
end # module SportDb
|
40
|
+
|
@@ -0,0 +1,147 @@
|
|
1
|
+
module SportDb
|
2
|
+
module Sync
|
3
|
+
|
4
|
+
class Match
|
5
|
+
### todo/fix: rename to create!! (add update support later) !!!!
|
6
|
+
## use update_by_round or update_by_date or update_by_teams or such
|
7
|
+
## NO easy (unique always auto-id match) possible!!!!!!
|
8
|
+
def self.create_or_update( match, event: )
|
9
|
+
## note: MUST find round, thus, use bang (!)
|
10
|
+
|
11
|
+
## todo/check: allow strings too - why? why not?
|
12
|
+
|
13
|
+
|
14
|
+
## todo/check:
|
15
|
+
## how to model "same" rounds in different stages
|
16
|
+
## e.g. Belgium
|
17
|
+
## in regular season (stage) - round 1, round 2, etc.
|
18
|
+
## in playoff (stage) - round 1, round 2, etc.
|
19
|
+
## reference same round or create a new one for each stage!!???
|
20
|
+
## and lookup by name AND stage??
|
21
|
+
|
22
|
+
|
23
|
+
round_rec = if match.round
|
24
|
+
## query for round - allow string or round rec
|
25
|
+
round_name = match.round.is_a?( String ) ? match.round : match.round.name
|
26
|
+
Model::Round.find_by!( event_id: event.id,
|
27
|
+
name: round_name )
|
28
|
+
else # note: allow matches WITHOUT rounds too (e.g. England Football League 1888 and others)
|
29
|
+
nil
|
30
|
+
end
|
31
|
+
|
32
|
+
## todo/check: allow fallback with db lookup if NOT found in cache - why? why not?
|
33
|
+
## or better use Sync::Team.find_or_create( team ) !!!!!!! to auto-create on first hit!
|
34
|
+
## || Team.find_or_create( team1 ) -- note: does NOT work for string (only recs) - what to do?
|
35
|
+
## || Model::Team.find_by!( name: team1_name )
|
36
|
+
team1_name = match.team1.is_a?( String ) ? match.team1 : match.team1.name
|
37
|
+
team1_rec = Team.cache[ team1_name ]
|
38
|
+
team2_name = match.team2.is_a?( String ) ? match.team2 : match.team2.name
|
39
|
+
team2_rec = Team.cache[ team2_name ]
|
40
|
+
|
41
|
+
## check optional group (e.g. Group A, etc.)
|
42
|
+
group_rec = if match.group
|
43
|
+
group_name = match.group.is_a?( String ) ? match.group : match.group.name
|
44
|
+
Model::Group.find_by!( event_id: event.id,
|
45
|
+
name: group_name )
|
46
|
+
else
|
47
|
+
nil
|
48
|
+
end
|
49
|
+
|
50
|
+
## check optional stage (e.g. Regular, Play Off, Relegation, etc. )
|
51
|
+
stage_rec = if match.stage
|
52
|
+
stage_name = match.stage.is_a?( String ) ? match.stage : match.stage.name
|
53
|
+
Model::Stage.find_by!( event_id: event.id,
|
54
|
+
name: stage_name )
|
55
|
+
else
|
56
|
+
nil
|
57
|
+
end
|
58
|
+
|
59
|
+
### todo/check: what happens if there's more than one match? exception raised??
|
60
|
+
rec = if ['N. N.'].include?( team1_name ) && ## some special cases - always assume new record for now (to avoid ambigious update conflict)
|
61
|
+
['N. N.'].include?( team2_name )
|
62
|
+
## always assume new record for now
|
63
|
+
## check for date or such - why? why not?
|
64
|
+
nil
|
65
|
+
elsif round_rec
|
66
|
+
## add match status too? allows [abandoned] and [replay] in same round
|
67
|
+
find_attributes = { round_id: round_rec.id,
|
68
|
+
team1_id: team1_rec.id,
|
69
|
+
team2_id: team2_rec.id }
|
70
|
+
|
71
|
+
## add stage if present to query
|
72
|
+
find_attributes[ :stage_id] = stage_rec.id if stage_rec
|
73
|
+
|
74
|
+
Model::Match.find_by( find_attributes )
|
75
|
+
else
|
76
|
+
## always assume new record for now
|
77
|
+
## check for date or such - why? why not?
|
78
|
+
nil
|
79
|
+
end
|
80
|
+
|
81
|
+
if rec.nil?
|
82
|
+
## find last pos - check if it can be nil? yes, is nil if no records found
|
83
|
+
max_pos = Model::Match.where( event_id: event.id ).maximum( 'pos' )
|
84
|
+
max_pos = max_pos ? max_pos+1 : 1
|
85
|
+
|
86
|
+
attribs = { event_id: event.id, ## todo/fix: change to data struct too?
|
87
|
+
team1_id: team1_rec.id,
|
88
|
+
team2_id: team2_rec.id,
|
89
|
+
pos: max_pos,
|
90
|
+
num: match.num, ## note - might be nil (not nil for euro, world cup, etc.)
|
91
|
+
# date: match.date.to_date, ## todo/fix: split and add date & time!!!!
|
92
|
+
date: match.date, # assume iso format as string e.g. 2021-07-10 !!!
|
93
|
+
time: match.time, # assume iso format as string e.g. 21:00 !!!
|
94
|
+
score1: match.score1,
|
95
|
+
score2: match.score2,
|
96
|
+
score1i: match.score1i,
|
97
|
+
score2i: match.score2i,
|
98
|
+
score1et: match.score1et,
|
99
|
+
score2et: match.score2et,
|
100
|
+
score1p: match.score1p,
|
101
|
+
score2p: match.score2p,
|
102
|
+
status: match.status }
|
103
|
+
|
104
|
+
attribs[ :round_id ] = round_rec.id if round_rec
|
105
|
+
attribs[ :group_id ] = group_rec.id if group_rec
|
106
|
+
attribs[ :stage_id ] = stage_rec.id if stage_rec
|
107
|
+
|
108
|
+
rec = Model::Match.create!( attribs )
|
109
|
+
|
110
|
+
|
111
|
+
#############################################
|
112
|
+
### try to update goals
|
113
|
+
#### quick & dirty v0 - redo !!!!
|
114
|
+
goals = match.goals
|
115
|
+
if goals && goals.size > 0
|
116
|
+
goals.each do |goal|
|
117
|
+
person_rec = Model::Person.find_by(
|
118
|
+
name: goal.player )
|
119
|
+
if person_rec.nil?
|
120
|
+
person_rec = Model::Person.create!(
|
121
|
+
key: goal.player.downcase.gsub( /[^a-z]/, '' ),
|
122
|
+
name: goal.player
|
123
|
+
)
|
124
|
+
end
|
125
|
+
Model::Goal.create!(
|
126
|
+
match_id: rec.id,
|
127
|
+
person_id: person_rec.id,
|
128
|
+
team_id: goal.team == 1 ? rec.team1.id
|
129
|
+
: rec.team2.id,
|
130
|
+
minute: goal.minute,
|
131
|
+
offset: goal.offset || 0,
|
132
|
+
penalty: goal.penalty,
|
133
|
+
owngoal: goal.owngoal,
|
134
|
+
)
|
135
|
+
end
|
136
|
+
end
|
137
|
+
else
|
138
|
+
# update - todo
|
139
|
+
puts "!! ERROR - match updates not yet supported (only inserts); sorry"
|
140
|
+
exit 1
|
141
|
+
end
|
142
|
+
rec
|
143
|
+
end
|
144
|
+
end # class Match
|
145
|
+
|
146
|
+
end # module Sync
|
147
|
+
end # module SportDb
|
@@ -0,0 +1,136 @@
|
|
1
|
+
|
2
|
+
module SportDb
|
3
|
+
module Sync
|
4
|
+
|
5
|
+
|
6
|
+
class NationalTeam
|
7
|
+
def self.find_or_create( team )
|
8
|
+
rec = Model::Team.find_by( name: team.name )
|
9
|
+
if rec.nil?
|
10
|
+
puts "add national team: #{team.key}, #{team.name}, #{team.country.name} (#{team.country.key})"
|
11
|
+
|
12
|
+
### note: key expected three or more lowercase letters a-z /\A[a-z]{3,}\z/
|
13
|
+
attribs = {
|
14
|
+
key: team.key, ## note: always use downcase fifa code for now!!!
|
15
|
+
name: team.name,
|
16
|
+
code: team.code,
|
17
|
+
country_id: Sync::Country.find_or_create( team.country ).id,
|
18
|
+
club: false,
|
19
|
+
national: true ## check -is default anyway - use - why? why not?
|
20
|
+
}
|
21
|
+
|
22
|
+
if team.alt_names.empty? == false
|
23
|
+
attribs[:alt_names] = team.alt_names.join('|')
|
24
|
+
end
|
25
|
+
|
26
|
+
rec = Model::Team.create!( attribs )
|
27
|
+
end
|
28
|
+
rec
|
29
|
+
end
|
30
|
+
end # class NationalTeam
|
31
|
+
|
32
|
+
|
33
|
+
class Team
|
34
|
+
## auto-cache all clubs by find_or_create for later mapping / lookup
|
35
|
+
def self.cache() @cache ||= {}; end
|
36
|
+
|
37
|
+
def self.find_or_create( team_or_teams )
|
38
|
+
if team_or_teams.is_a?( Array )
|
39
|
+
recs = []
|
40
|
+
teams = team_or_teams
|
41
|
+
teams.each do |team|
|
42
|
+
recs << __find_or_create( team )
|
43
|
+
end
|
44
|
+
recs
|
45
|
+
else # assome single rec
|
46
|
+
team = team_or_teams
|
47
|
+
__find_or_create( team )
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.__find_or_create( team ) ## todo/check: use find_or_create_worker instead of _find - why? why not?
|
52
|
+
rec = if team.is_a?( Import::NationalTeam )
|
53
|
+
NationalTeam.find_or_create( team )
|
54
|
+
else ## assume Club
|
55
|
+
Club.find_or_create( team )
|
56
|
+
end
|
57
|
+
cache[ team.name ] = rec ## note: assume "canonical" unique team name
|
58
|
+
rec
|
59
|
+
end
|
60
|
+
end # class Team
|
61
|
+
|
62
|
+
|
63
|
+
|
64
|
+
class Round
|
65
|
+
def self.find_or_create( round, event: )
|
66
|
+
rec = Model::Round.find_by( name: round.name, event_id: event.id )
|
67
|
+
if rec.nil?
|
68
|
+
## find last pos - check if it can be nil?
|
69
|
+
max_pos = Model::Round.where( event_id: event.id ).maximum( 'pos' )
|
70
|
+
max_pos = max_pos ? max_pos+1 : 1
|
71
|
+
|
72
|
+
attribs = { event_id: event.id,
|
73
|
+
name: round.name,
|
74
|
+
pos: max_pos
|
75
|
+
}
|
76
|
+
|
77
|
+
## todo/fix: check if round has (optional) start or end date and add!!!
|
78
|
+
## attribs[ :start_date] = round.start_date.to_date
|
79
|
+
|
80
|
+
rec = Model::Round.create!( attribs )
|
81
|
+
end
|
82
|
+
rec
|
83
|
+
end
|
84
|
+
end # class Round
|
85
|
+
|
86
|
+
|
87
|
+
class Group
|
88
|
+
def self.find_or_create( group, event: )
|
89
|
+
rec = Model::Group.find_by( name: group.name, event_id: event.id )
|
90
|
+
if rec.nil?
|
91
|
+
## find last pos - check if it can be nil?
|
92
|
+
max_pos = Model::Group.where( event_id: event.id ).maximum( 'pos' )
|
93
|
+
max_pos = max_pos ? max_pos+1 : 1
|
94
|
+
|
95
|
+
attribs = { event_id: event.id,
|
96
|
+
name: group.name,
|
97
|
+
pos: max_pos
|
98
|
+
}
|
99
|
+
|
100
|
+
## todo/fix: check/add optional group key (was: pos before)!!!!
|
101
|
+
rec = Model::Group.create!( attribs )
|
102
|
+
end
|
103
|
+
## todo/fix: add/update teams in group too!!!!!
|
104
|
+
rec
|
105
|
+
end
|
106
|
+
end # class Group
|
107
|
+
|
108
|
+
|
109
|
+
class Stage
|
110
|
+
def self.find( name, event: )
|
111
|
+
Model::Stage.find_by( name: name, event_id: event.id )
|
112
|
+
end
|
113
|
+
def self.find!( name, event: )
|
114
|
+
rec = find( name, event: event )
|
115
|
+
if rec.nil?
|
116
|
+
puts "** !!!ERROR!!! db sync - no stage match found for:"
|
117
|
+
pp name
|
118
|
+
pp event
|
119
|
+
exit 1
|
120
|
+
end
|
121
|
+
rec
|
122
|
+
end
|
123
|
+
|
124
|
+
def self.find_or_create( name, event: )
|
125
|
+
rec = find( name, event: event )
|
126
|
+
if rec.nil?
|
127
|
+
attribs = { event_id: event.id,
|
128
|
+
name: name,
|
129
|
+
}
|
130
|
+
rec = Model::Stage.create!( attribs )
|
131
|
+
end
|
132
|
+
rec
|
133
|
+
end
|
134
|
+
end # class Stage
|
135
|
+
end # module Sync
|
136
|
+
end # module SportDb
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module SportDb
|
2
|
+
module Sync
|
3
|
+
class Season
|
4
|
+
|
5
|
+
################
|
6
|
+
# finders
|
7
|
+
|
8
|
+
def self.find( season )
|
9
|
+
season = Season( season ) ## auto-convert for now (for old compat) - why? why not?
|
10
|
+
Model::Season.find_by( key: season.key )
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.find!( season )
|
14
|
+
season = Season( season ) ## auto-convert for now (for old compat) - why? why not?
|
15
|
+
rec = find( season )
|
16
|
+
if rec.nil?
|
17
|
+
puts "** !!!ERROR!!! db sync - no season match found for >#{season.key}<:"
|
18
|
+
exit 1
|
19
|
+
end
|
20
|
+
rec
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.find_or_create( season )
|
24
|
+
season = Season( season ) ## auto-convert for now (for old compat) - why? why not?
|
25
|
+
rec = find( season )
|
26
|
+
if rec.nil?
|
27
|
+
attribs = { key: season.key,
|
28
|
+
name: season.name }
|
29
|
+
rec = Model::Season.create!( attribs )
|
30
|
+
end
|
31
|
+
rec
|
32
|
+
end
|
33
|
+
end # class Season
|
34
|
+
end # module Sync
|
35
|
+
end # module SportDb
|
36
|
+
|
@@ -1,10 +1,11 @@
|
|
1
1
|
|
2
2
|
|
3
3
|
module SportDb
|
4
|
+
module Module
|
4
5
|
module Readers
|
5
6
|
|
6
|
-
MAJOR =
|
7
|
-
MINOR =
|
7
|
+
MAJOR = 2 ## todo: namespace inside version or something - why? why not??
|
8
|
+
MINOR = 0
|
8
9
|
PATCH = 1
|
9
10
|
VERSION = [MAJOR,MINOR,PATCH].join('.')
|
10
11
|
|
@@ -21,4 +22,5 @@ module Readers
|
|
21
22
|
end
|
22
23
|
|
23
24
|
end # module Readers
|
25
|
+
end # module Module
|
24
26
|
end # module SportDb
|
data/lib/sportdb/readers.rb
CHANGED
@@ -1,10 +1,21 @@
|
|
1
|
-
|
2
|
-
require 'sportdb/
|
1
|
+
require 'sportdb/formats'
|
2
|
+
require 'sportdb/models'
|
3
3
|
|
4
4
|
|
5
5
|
###
|
6
6
|
# our own code
|
7
7
|
require_relative 'readers/version' # let version always go first
|
8
|
+
|
9
|
+
## add sync stuff
|
10
|
+
require_relative 'readers/sync/country'
|
11
|
+
require_relative 'readers/sync/league'
|
12
|
+
require_relative 'readers/sync/season'
|
13
|
+
require_relative 'readers/sync/event'
|
14
|
+
require_relative 'readers/sync/club'
|
15
|
+
require_relative 'readers/sync/more'
|
16
|
+
require_relative 'readers/sync/match' ## note - let match sync go last
|
17
|
+
|
18
|
+
## add readers & friends
|
8
19
|
require_relative 'readers/conf_reader'
|
9
20
|
require_relative 'readers/match_reader'
|
10
21
|
require_relative 'readers/package'
|
@@ -12,7 +23,6 @@ require_relative 'readers/package'
|
|
12
23
|
|
13
24
|
|
14
25
|
|
15
|
-
|
16
26
|
##
|
17
27
|
## add convenience shortcut helpers
|
18
28
|
module SportDb
|
@@ -57,4 +67,4 @@ end # module SportDb
|
|
57
67
|
|
58
68
|
|
59
69
|
|
60
|
-
puts SportDb::Readers.banner # say hello
|
70
|
+
puts SportDb::Module::Readers.banner # say hello
|
metadata
CHANGED
@@ -1,29 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sportdb-readers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gerald Bauer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-08-
|
11
|
+
date: 2024-08-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name: sportdb-
|
14
|
+
name: sportdb-formats
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 2.0.1
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 2.0.1
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: sportdb-models
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 2.1.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 2.1.0
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: rdoc
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -78,6 +92,13 @@ files:
|
|
78
92
|
- lib/sportdb/readers/conf_reader.rb
|
79
93
|
- lib/sportdb/readers/match_reader.rb
|
80
94
|
- lib/sportdb/readers/package.rb
|
95
|
+
- lib/sportdb/readers/sync/club.rb
|
96
|
+
- lib/sportdb/readers/sync/country.rb
|
97
|
+
- lib/sportdb/readers/sync/event.rb
|
98
|
+
- lib/sportdb/readers/sync/league.rb
|
99
|
+
- lib/sportdb/readers/sync/match.rb
|
100
|
+
- lib/sportdb/readers/sync/more.rb
|
101
|
+
- lib/sportdb/readers/sync/season.rb
|
81
102
|
- lib/sportdb/readers/version.rb
|
82
103
|
homepage: https://github.com/sportdb/sport.db
|
83
104
|
licenses:
|