sportdb-sync 1.0.2 → 1.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 415893e89d2c9d1a8dfa9b493ecff8452095f94f
4
- data.tar.gz: 9e55c19b40ee247d6b3b9e286b9dc799fe95c5d7
3
+ metadata.gz: 1d6f63ecc82fe0773b77ffac62a59b62a70ac018
4
+ data.tar.gz: cf11d7385ccde200b85638cd1de92b830ab2696c
5
5
  SHA512:
6
- metadata.gz: 4e4487b6d40e296e9de680f99cb331693ccff0aac5dc3d73a55cae418f6ba9410966da1542bfa090fefa3e60123ab5822745041ab132d0876e7d89fa44ae7da7
7
- data.tar.gz: b59e3712eb51503aee9cc7c56c604fd8c5b0513a75995b7ceefe383f67820cd25ab17f97bd32f1ca6e0dfdacab49f4333eaa5b6af82102198714f7429d0b9ea9
6
+ metadata.gz: e7ed1a5553ff8d1a79dcbc56efbe9b681dd6aeaa20c18fb1e1a85541329163ef53afc2217609955e66e295155c58edb0e247308b93cfa15e143e86e3d7e5e700
7
+ data.tar.gz: e21fed2e8925f362b9c5b135db21f5d466e4758f04d8f591762db3e37ad4f55814c0337a7c256ec8c8c398dd7d767cb221a51f8c1dd71bb830c4b35999afc1a0
data/Rakefile CHANGED
@@ -8,7 +8,7 @@ Hoe.spec 'sportdb-sync' do
8
8
  self.summary = "sportdb-sync - sport.db sync helpers for leagues, seasons, clubs, match schedules and results, and more"
9
9
  self.description = summary
10
10
 
11
- self.urls = ['https://github.com/sportdb/sport.db']
11
+ self.urls = { home: 'https://github.com/sportdb/sport.db' }
12
12
 
13
13
  self.author = 'Gerald Bauer'
14
14
  self.email = 'opensport@googlegroups.com'
@@ -20,8 +20,8 @@ Hoe.spec 'sportdb-sync' do
20
20
  self.licenses = ['Public Domain']
21
21
 
22
22
  self.extra_deps = [
23
- ['sportdb-config', '>= 1.0.4'],
24
- ['sportdb-models', '>= 1.19.0'],
23
+ ['sportdb-catalogs', '>= 1.0.0'],
24
+ ['sportdb-models', '>= 2.0.2'],
25
25
  ]
26
26
 
27
27
  self.spec_extras = {
@@ -1,6 +1,6 @@
1
1
  # encoding: utf-8
2
2
 
3
- require 'sportdb/config'
3
+ require 'sportdb/catalogs'
4
4
  require 'sportdb/models' ## add sql database support
5
5
 
6
6
 
@@ -50,8 +50,8 @@ module SportDb
50
50
  # finders
51
51
 
52
52
  def self.find_or_create( club )
53
- ## note: assume "canonical uniquie" names/titles for now for clubs
54
- rec = Model::Team.find_by( title: club.name )
53
+ ## note: assume "canonical uniquie" names for now for clubs
54
+ rec = Model::Team.find_by( name: club.name )
55
55
  if rec.nil?
56
56
 
57
57
  ## todo/fix: move auto-key gen to structs for re(use)!!!!!!
@@ -61,7 +61,7 @@ module SportDb
61
61
 
62
62
  attribs = {
63
63
  key: key,
64
- title: club.name,
64
+ name: club.name,
65
65
  country_id: Sync::Country.find_or_create( club.country ).id,
66
66
  club: true,
67
67
  national: false ## check -is default anyway - use - why? why not?
@@ -71,7 +71,7 @@ module SportDb
71
71
  attribs[:code] = club.code if club.code ## add code (abbreviation) if present
72
72
 
73
73
  if club.alt_names.empty? == false
74
- attribs[:synonyms] = club.alt_names.join('|')
74
+ attribs[:alt_names] = club.alt_names.join('|')
75
75
  end
76
76
 
77
77
  rec = Model::Team.create!( attribs )
@@ -79,8 +79,8 @@ module SportDb
79
79
  ## otherwise use 2017, 7, 1
80
80
  ## start_at use year and 7,1 e.g. Date.new( 2017, 7, 1 )
81
81
  ## hack: fix/todo1!!
82
- ## add "fake" start_at date for now
83
- attribs[:start_at] = if season.year? ## e.g. assume 2018 etc.
82
+ ## add "fake" start_date for now
83
+ attribs[:start_date] = if season.year? ## e.g. assume 2018 etc.
84
84
  Date.new( season.start_year, 1, 1 )
85
85
  else ## assume 2014/15 etc.
86
86
  Date.new( season.start_year, 7, 1 )
@@ -40,11 +40,8 @@ module SportDb
40
40
  def self.find_or_create( league )
41
41
  rec = find( league )
42
42
  if rec.nil?
43
- ## use title and not name - why? why not?
44
- ## quick fix: change name to title
45
-
46
43
  attribs = { key: league.key,
47
- title: league.name }
44
+ name: league.name }
48
45
 
49
46
  if league.country
50
47
  attribs[ :country_id ] = Sync::Country.find_or_create( league.country ).id
@@ -43,7 +43,7 @@ module SportDb
43
43
  rec = find( season )
44
44
  if rec.nil?
45
45
  attribs = { key: season.key,
46
- title: season.name }
46
+ name: season.name }
47
47
  rec = Model::Season.create!( attribs )
48
48
  end
49
49
  rec
@@ -6,14 +6,14 @@ module SportDb
6
6
 
7
7
  class NationalTeam
8
8
  def self.find_or_create( team )
9
- rec = Model::Team.find_by( title: team.name )
9
+ rec = Model::Team.find_by( name: team.name )
10
10
  if rec.nil?
11
11
  puts "add national team: #{team.key}, #{team.name}, #{team.country.name} (#{team.country.key})"
12
12
 
13
13
  ### note: key expected three or more lowercase letters a-z /\A[a-z]{3,}\z/
14
14
  attribs = {
15
15
  key: team.key, ## note: always use downcase fifa code for now!!!
16
- title: team.name,
16
+ name: team.name,
17
17
  code: team.code,
18
18
  country_id: Sync::Country.find_or_create( team.country ).id,
19
19
  club: false,
@@ -21,7 +21,7 @@ module SportDb
21
21
  }
22
22
 
23
23
  if team.alt_names.empty? == false
24
- attribs[:synonyms] = team.alt_names.join('|')
24
+ attribs[:alt_names] = team.alt_names.join('|')
25
25
  end
26
26
 
27
27
  rec = Model::Team.create!( attribs )
@@ -64,19 +64,19 @@ module SportDb
64
64
 
65
65
  class Round
66
66
  def self.find_or_create( round, event: )
67
- rec = Model::Round.find_by( title: round.title, event_id: event.id )
67
+ rec = Model::Round.find_by( name: round.name, event_id: event.id )
68
68
  if rec.nil?
69
69
  ## find last pos - check if it can be nil?
70
70
  max_pos = Model::Round.where( event_id: event.id ).maximum( 'pos' )
71
71
  max_pos = max_pos ? max_pos+1 : 1
72
72
 
73
73
  attribs = { event_id: event.id,
74
- title: round.title,
74
+ name: round.name,
75
75
  pos: max_pos
76
76
  }
77
77
 
78
78
  ## todo/fix: check if round has (optional) start or end date and add!!!
79
- ## attribs[ :start_at] = round.start_at.to_date
79
+ ## attribs[ :start_date] = round.start_date.to_date
80
80
 
81
81
  rec = Model::Round.create!( attribs )
82
82
  end
@@ -87,14 +87,14 @@ module SportDb
87
87
 
88
88
  class Group
89
89
  def self.find_or_create( group, event: )
90
- rec = Model::Group.find_by( title: group.title, event_id: event.id )
90
+ rec = Model::Group.find_by( name: group.name, event_id: event.id )
91
91
  if rec.nil?
92
92
  ## find last pos - check if it can be nil?
93
93
  max_pos = Model::Group.where( event_id: event.id ).maximum( 'pos' )
94
94
  max_pos = max_pos ? max_pos+1 : 1
95
95
 
96
96
  attribs = { event_id: event.id,
97
- title: group.title,
97
+ name: group.name,
98
98
  pos: max_pos
99
99
  }
100
100
 
@@ -109,7 +109,7 @@ module SportDb
109
109
 
110
110
  class Stage
111
111
  def self.find( name, event: )
112
- Model::Stage.find_by( title: name, event_id: event.id )
112
+ Model::Stage.find_by( name: name, event_id: event.id )
113
113
  end
114
114
  def self.find!( name, event: )
115
115
  rec = find( name, event: event )
@@ -125,10 +125,8 @@ module SportDb
125
125
  def self.find_or_create( name, event: )
126
126
  rec = find( name, event: event )
127
127
  if rec.nil?
128
- ## use title and not name - why? why not?
129
- ## quick fix: change name to title
130
128
  attribs = { event_id: event.id,
131
- title: name,
129
+ name: name,
132
130
  }
133
131
  rec = Model::Stage.create!( attribs )
134
132
  end
@@ -138,21 +136,38 @@ module SportDb
138
136
 
139
137
 
140
138
 
141
- class Match ## todo/check: add alias for Game class - why? why not?
139
+ class Match
140
+ ### todo/fix: rename to create!! (add update support later) !!!!
141
+ ## use update_by_round or update_by_date or update_by_teams or such
142
+ ## NO easy (unique always auto-id match) possible!!!!!!
142
143
  def self.create_or_update( match, event: )
143
144
  ## note: MUST find round, thus, use bang (!)
144
145
 
145
146
  ## todo/check: allow strings too - why? why not?
146
147
 
147
- ## query for round - allow string or round rec
148
- round_title = match.round.is_a?( String ) ? match.round : match.round.title
149
- round_rec = Model::Round.find_by!( event_id: event.id,
150
- title: round_title )
148
+
149
+ ## todo/check:
150
+ ## how to model "same" rounds in different stages
151
+ ## e.g. Belgium
152
+ ## in regular season (stage) - round 1, round 2, etc.
153
+ ## in playoff (stage) - round 1, round 2, etc.
154
+ ## reference same round or create a new one for each stage!!???
155
+ ## and lookup by name AND stage??
156
+
157
+
158
+ round_rec = if match.round
159
+ ## query for round - allow string or round rec
160
+ round_name = match.round.is_a?( String ) ? match.round : match.round.name
161
+ Model::Round.find_by!( event_id: event.id,
162
+ name: round_name )
163
+ else # note: allow matches WITHOUT rounds too (e.g. England Football League 1888 and others)
164
+ nil
165
+ end
151
166
 
152
167
  ## todo/check: allow fallback with db lookup if NOT found in cache - why? why not?
153
168
  ## or better use Sync::Team.find_or_create( team ) !!!!!!! to auto-create on first hit!
154
169
  ## || Team.find_or_create( team1 ) -- note: does NOT work for string (only recs) - what to do?
155
- ## || Model::Team.find_by!( title: team1_name )
170
+ ## || Model::Team.find_by!( name: team1_name )
156
171
  team1_name = match.team1.is_a?( String ) ? match.team1 : match.team1.name
157
172
  team1_rec = Team.cache[ team1_name ]
158
173
  team2_name = match.team2.is_a?( String ) ? match.team2 : match.team2.name
@@ -160,37 +175,73 @@ module SportDb
160
175
 
161
176
  ## check optional group (e.g. Group A, etc.)
162
177
  group_rec = if match.group
163
- group_title = match.group.is_a?( String ) ? match.group : match.group.title
178
+ group_name = match.group.is_a?( String ) ? match.group : match.group.name
164
179
  Model::Group.find_by!( event_id: event.id,
165
- title: group_title )
180
+ name: group_name )
166
181
  else
167
182
  nil
168
183
  end
169
184
 
185
+ ## check optional stage (e.g. Regular, Play Off, Relegation, etc. )
186
+ stage_rec = if match.stage
187
+ stage_name = match.stage.is_a?( String ) ? match.stage : match.stage.name
188
+ Model::Stage.find_by!( event_id: event.id,
189
+ name: stage_name )
190
+ else
191
+ nil
192
+ end
193
+
194
+ ### todo/check: what happens if there's more than one match? exception raised??
195
+ rec = if ['N. N.'].include?( team1_name ) && ## some special cases - always assume new record for now (to avoid ambigious update conflict)
196
+ ['N. N.'].include?( team2_name )
197
+ ## always assume new record for now
198
+ ## check for date or such - why? why not?
199
+ nil
200
+ elsif round_rec
201
+ ## add match status too? allows [abandoned] and [replay] in same round
202
+ find_attributes = { round_id: round_rec.id,
203
+ team1_id: team1_rec.id,
204
+ team2_id: team2_rec.id }
205
+
206
+ ## add stage if present to query
207
+ find_attributes[ :stage_id] = stage_rec.id if stage_rec
208
+
209
+ Model::Match.find_by( find_attributes )
210
+ else
211
+ ## always assume new record for now
212
+ ## check for date or such - why? why not?
213
+ nil
214
+ end
170
215
 
171
- rec = Model::Game.find_by( round_id: round_rec.id,
172
- team1_id: team1_rec.id,
173
- team2_id: team2_rec.id )
174
216
  if rec.nil?
175
- ## find last pos - check if it can be nil?
176
- max_pos = Model::Game.where( event_id: event.id ).maximum( 'pos' )
217
+ ## find last pos - check if it can be nil? yes, is nil if no records found
218
+ max_pos = Model::Match.where( event_id: event.id ).maximum( 'pos' )
177
219
  max_pos = max_pos ? max_pos+1 : 1
178
220
 
179
221
  attribs = { event_id: event.id, ## todo/fix: change to data struct too?
180
- round_id: round_rec.id,
181
222
  team1_id: team1_rec.id,
182
223
  team2_id: team2_rec.id,
183
224
  pos: max_pos,
184
- play_at: match.date.to_date,
225
+ date: match.date.to_date, ## todo/fix: split and add date & time!!!!
185
226
  score1: match.score1,
186
227
  score2: match.score2,
187
228
  score1i: match.score1i,
188
- score2i: match.score2i }
229
+ score2i: match.score2i,
230
+ score1et: match.score1et,
231
+ score2et: match.score2et,
232
+ score1p: match.score1p,
233
+ score2p: match.score2p,
234
+ status: match.status }
235
+
236
+ attribs[ :round_id ] = round_rec.id if round_rec
189
237
  attribs[ :group_id ] = group_rec.id if group_rec
238
+ attribs[ :stage_id ] = stage_rec.id if stage_rec
190
239
 
191
- rec = Model::Game.create!( attribs )
240
+ rec = Model::Match.create!( attribs )
192
241
  else
193
242
  # update - todo
243
+ puts "!! ERROR - match updates not yet supported (only inserts); sorry"
244
+ exit 1
194
245
  end
195
246
  rec
196
247
  end
@@ -6,8 +6,8 @@ module Module
6
6
  module Sync
7
7
 
8
8
  MAJOR = 1 ## todo: namespace inside version or something - why? why not??
9
- MINOR = 0
10
- PATCH = 2
9
+ MINOR = 1
10
+ PATCH = 3
11
11
  VERSION = [MAJOR,MINOR,PATCH].join('.')
12
12
 
13
13
  def self.version
@@ -1,6 +1,6 @@
1
1
  ## note: use the local version of sportdb gems
2
2
  $LOAD_PATH.unshift( File.expand_path( '../sportdb-formats/lib' ))
3
- $LOAD_PATH.unshift( File.expand_path( '../sportdb-config/lib' ))
3
+ $LOAD_PATH.unshift( File.expand_path( '../sportdb-catalogs/lib' ))
4
4
  $LOAD_PATH.unshift( File.expand_path( '../sportdb-models/lib' ))
5
5
 
6
6
 
@@ -14,25 +14,25 @@ class TestLeague < MiniTest::Test
14
14
 
15
15
  def test_search
16
16
  rec = League.search_or_create!( 'eng' )
17
- assert_equal 'Premier League', rec.title ## fix: add name alias (rename title to name!!)
17
+ assert_equal 'Premier League', rec.name
18
18
  assert_equal 'eng.1', rec.key
19
19
  assert_equal 'eng', rec.country.key
20
20
  assert_equal 'England', rec.country.name
21
- # assert_equal true, rec.club
21
+ # assert_equal true, rec.clubs
22
22
 
23
23
  rec = League.search!( 'eng' )
24
- assert_equal 'Premier League', rec.title ## fix: add name alias (rename title to name!!)
24
+ assert_equal 'Premier League', rec.name
25
25
  assert_equal 'eng.1', rec.key
26
26
  assert_equal 'eng', rec.country.key
27
27
  assert_equal 'England', rec.country.name
28
- ## assert_equal true, rec.club
28
+ ## assert_equal true, rec.clubs
29
29
 
30
30
  ## try 2nd call (just lookup)
31
31
  rec = League.search_or_create!( 'eng' )
32
- assert_equal 'Premier League', rec.title ## fix: add name alias (rename title to name!!)
32
+ assert_equal 'Premier League', rec.name
33
33
  assert_equal 'eng.1', rec.key
34
34
  assert_equal 'eng', rec.country.key
35
35
  assert_equal 'England', rec.country.name
36
- ## assert_equal true, rec.club
36
+ ## assert_equal true, rec.clubs
37
37
  end
38
38
  end # class TestLeague
@@ -14,15 +14,15 @@ class TestMisc < MiniTest::Test
14
14
 
15
15
  def test_season
16
16
  rec = Season.search_or_create( '2017-18' )
17
- assert_equal '2017/18', rec.title ## fix: add name alias (rename title to name!!)
17
+ assert_equal '2017/18', rec.name
18
18
  assert_equal '2017/18', rec.key
19
19
 
20
20
  rec = Season.search_or_create( '2017/2018' )
21
- assert_equal '2017/18', rec.title ## fix: add name alias (rename title to name!!)
21
+ assert_equal '2017/18', rec.name
22
22
  assert_equal '2017/18', rec.key
23
23
 
24
24
  rec = Season.search_or_create( '2017/8' )
25
- assert_equal '2017/18', rec.title ## fix: add name alias (rename title to name!!)
25
+ assert_equal '2017/18', rec.name
26
26
  assert_equal '2017/18', rec.key
27
27
  end
28
28
 
metadata CHANGED
@@ -1,43 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sportdb-sync
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gerald Bauer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-23 00:00:00.000000000 Z
11
+ date: 2020-09-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: sportdb-config
14
+ name: sportdb-catalogs
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 1.0.4
19
+ version: 1.0.0
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: 1.0.4
26
+ version: 1.0.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: sportdb-models
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 1.19.0
33
+ version: 2.0.2
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: 1.19.0
40
+ version: 2.0.2
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rdoc
43
43
  requirement: !ruby/object:Gem::Requirement