sportdb-readers 0.1.2 → 0.2.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 +0 -1
- data/Rakefile +1 -0
- data/lib/sportdb/readers/version.rb +2 -2
- data/lib/sportdb/readers.rb +2 -3
- metadata +16 -3
- data/lib/sportdb/readers/sync.rb +0 -241
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 065c28caeef803aeb7d27a41dbd4d552265975c7
|
4
|
+
data.tar.gz: 5324561f854b1831397fc17254d861044a23b95d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 809e28ed7c09f28c6610de3f02650c265b29f39ac5dec03d12ae3ab31476b917a91315b8fc8554b2e97bcde2016deb41ea9d912915749e4d8255c0143250ccdf
|
7
|
+
data.tar.gz: 4a1b726b10f56c25fe10ca94803601b351d1085dd7c0608ee6b5e2efd7841e90d70a2db15a0b0ce26595f0a3656a0ef0fc7d6587f767b7c4b5329902283f3ca1
|
data/Manifest.txt
CHANGED
data/Rakefile
CHANGED
data/lib/sportdb/readers.rb
CHANGED
@@ -1,15 +1,14 @@
|
|
1
|
-
# encoding:
|
1
|
+
# encoding: utf-8
|
2
2
|
|
3
3
|
|
4
4
|
require 'sportdb/config'
|
5
5
|
require 'sportdb/models' ## add sql database support
|
6
|
-
|
6
|
+
require 'sportdb/sync'
|
7
7
|
|
8
8
|
|
9
9
|
###
|
10
10
|
# our own code
|
11
11
|
require 'sportdb/readers/version' # let version always go first
|
12
|
-
require 'sportdb/readers/sync'
|
13
12
|
require 'sportdb/readers/outline_reader'
|
14
13
|
require 'sportdb/readers/event_reader'
|
15
14
|
require 'sportdb/readers/match_parser'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sportdb-readers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gerald Bauer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-11-
|
11
|
+
date: 2019-11-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sportdb-config
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 1.18.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: sportdb-sync
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.0.1
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.0.1
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: rdoc
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -85,7 +99,6 @@ files:
|
|
85
99
|
- lib/sportdb/readers/match_parser.rb
|
86
100
|
- lib/sportdb/readers/match_reader.rb
|
87
101
|
- lib/sportdb/readers/outline_reader.rb
|
88
|
-
- lib/sportdb/readers/sync.rb
|
89
102
|
- lib/sportdb/readers/version.rb
|
90
103
|
- test/helper.rb
|
91
104
|
- test/test_match_parser.rb
|
data/lib/sportdb/readers/sync.rb
DELETED
@@ -1,241 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
|
4
|
-
module SportDb
|
5
|
-
|
6
|
-
module Sync
|
7
|
-
class Country
|
8
|
-
def self.find_or_create( country )
|
9
|
-
rec = WorldDb::Model::Country.find_by( key: country.key )
|
10
|
-
if rec.nil?
|
11
|
-
attribs = {
|
12
|
-
key: country.key,
|
13
|
-
name: country.name,
|
14
|
-
code: country.fifa, ## fix: uses fifa code now (should be iso-alpha3 if available)
|
15
|
-
fifa: country.fifa,
|
16
|
-
area: 1,
|
17
|
-
pop: 1
|
18
|
-
}
|
19
|
-
rec = WorldDb::Model::Country.create!( attribs )
|
20
|
-
end
|
21
|
-
rec
|
22
|
-
end
|
23
|
-
end # class Country
|
24
|
-
|
25
|
-
|
26
|
-
class League
|
27
|
-
def self.find( league )
|
28
|
-
SportDb::Model::League.find_by( key: league.key )
|
29
|
-
end
|
30
|
-
def self.find!( league )
|
31
|
-
rec = find( league )
|
32
|
-
if rec.nil?
|
33
|
-
puts "** !!!ERROR!!! db sync - no league match found for:"
|
34
|
-
pp league
|
35
|
-
exit 1
|
36
|
-
end
|
37
|
-
rec
|
38
|
-
end
|
39
|
-
|
40
|
-
def self.find_or_create( league )
|
41
|
-
rec = find( league )
|
42
|
-
if rec.nil?
|
43
|
-
## use title and not name - why? why not?
|
44
|
-
## quick fix: change name to title
|
45
|
-
attribs = { key: league.key,
|
46
|
-
title: league.name }
|
47
|
-
if league.country
|
48
|
-
attribs[ :country_id ] = Country.find_or_create( league.country ).id
|
49
|
-
end
|
50
|
-
|
51
|
-
rec = SportDb::Model::League.create!( attribs )
|
52
|
-
end
|
53
|
-
rec
|
54
|
-
end
|
55
|
-
end # class League
|
56
|
-
|
57
|
-
|
58
|
-
class Season
|
59
|
-
def self.normalize_key( key ) ## helper for season key (rename to norm_key ???)
|
60
|
-
## note: "normalize" season key
|
61
|
-
## always use 2017/18 (and not 2017-18 or 2017-2018 or 2017/2018)
|
62
|
-
## 1) change 2017-18 to 2017/18
|
63
|
-
key = key.tr( '-', '/' )
|
64
|
-
## 2) check for 2017/2018 - change to 2017/18
|
65
|
-
if key.length == 9
|
66
|
-
key = "#{key[0..3]}/#{key[7..8]}"
|
67
|
-
end
|
68
|
-
key
|
69
|
-
end
|
70
|
-
|
71
|
-
def self.find( key )
|
72
|
-
key = normalize_key( key )
|
73
|
-
SportDb::Model::Season.find_by( key: key )
|
74
|
-
end
|
75
|
-
def self.find!( key )
|
76
|
-
rec = find( key )
|
77
|
-
if rec.nil?
|
78
|
-
puts "** !!!ERROR!!! db sync - no season match found for >#{normalize_key(key)}<:"
|
79
|
-
pp key
|
80
|
-
exit 1
|
81
|
-
end
|
82
|
-
rec
|
83
|
-
end
|
84
|
-
|
85
|
-
def self.find_or_create( key ) ## e.g. key = '2017/18'
|
86
|
-
rec = find( key )
|
87
|
-
if rec.nil?
|
88
|
-
key = normalize_key( key ) ## note: do NOT forget to normalize key e.g. always use slash (2019/20) etc.
|
89
|
-
attribs = { key: key,
|
90
|
-
title: key }
|
91
|
-
rec = SportDb::Model::Season.create!( attribs )
|
92
|
-
end
|
93
|
-
rec
|
94
|
-
end
|
95
|
-
end # class Season
|
96
|
-
|
97
|
-
class Club
|
98
|
-
def self.find_or_create( club )
|
99
|
-
rec = SportDb::Model::Team.find_by( title: club.name )
|
100
|
-
if rec.nil?
|
101
|
-
## remove all non-ascii a-z chars
|
102
|
-
key = club.name.downcase.gsub( /[^a-z]/, '' )
|
103
|
-
puts "add club: #{key}, #{club.name}, #{club.country.name} (#{club.country.key})"
|
104
|
-
|
105
|
-
attribs = {
|
106
|
-
key: key,
|
107
|
-
title: club.name,
|
108
|
-
country_id: Country.find_or_create( club.country ).id,
|
109
|
-
club: true,
|
110
|
-
national: false ## check -is default anyway - use - why? why not?
|
111
|
-
## todo/fix: add city if present - why? why not?
|
112
|
-
}
|
113
|
-
if club.alt_names.empty? == false
|
114
|
-
attribs[:synonyms] = club.alt_names.join('|')
|
115
|
-
end
|
116
|
-
|
117
|
-
rec = SportDb::Model::Team.create!( attribs )
|
118
|
-
end
|
119
|
-
rec
|
120
|
-
end
|
121
|
-
end # class Club
|
122
|
-
|
123
|
-
class Event
|
124
|
-
def self.find( league:, season: )
|
125
|
-
SportDb::Model::Event.find_by( league_id: league.id, season_id: season.id )
|
126
|
-
end
|
127
|
-
def self.find!( league:, season: )
|
128
|
-
rec = find( league: league, season: season )
|
129
|
-
if rec.nil?
|
130
|
-
puts "** !!!ERROR!!! db sync - no event match found for:"
|
131
|
-
pp league
|
132
|
-
pp season
|
133
|
-
exit 1
|
134
|
-
end
|
135
|
-
rec
|
136
|
-
end
|
137
|
-
|
138
|
-
def self.find_or_create( league:, season: )
|
139
|
-
rec = find( league: league, season: season )
|
140
|
-
if rec.nil?
|
141
|
-
## quick hack/change later !!
|
142
|
-
## todo/fix: check season - if is length 4 (single year) use 2017, 1, 1
|
143
|
-
## otherwise use 2017, 7, 1
|
144
|
-
## start_at use year and 7,1 e.g. Date.new( 2017, 7, 1 )
|
145
|
-
## hack: fix/todo1!!
|
146
|
-
## add "fake" start_at date for now
|
147
|
-
if season.key.size == '4' ## e.g. assume 2018 etc.
|
148
|
-
year = season.key.to_i
|
149
|
-
start_at = Date.new( year, 1, 1 )
|
150
|
-
else ## assume 2014/15 etc.
|
151
|
-
year = season.key[0..3].to_i
|
152
|
-
start_at = Date.new( year, 7, 1 )
|
153
|
-
end
|
154
|
-
|
155
|
-
attribs = {
|
156
|
-
league_id: league.id,
|
157
|
-
season_id: season.id,
|
158
|
-
start_at: start_at }
|
159
|
-
|
160
|
-
rec = SportDb::Model::Event.create!( attribs )
|
161
|
-
end
|
162
|
-
rec
|
163
|
-
end
|
164
|
-
end # class Event
|
165
|
-
|
166
|
-
class Round
|
167
|
-
def self.find_or_create( round, event: )
|
168
|
-
rec = SportDb::Model::Round.find_by( title: round.title, event_id: event.id )
|
169
|
-
if rec.nil?
|
170
|
-
attribs = { event_id: event.id,
|
171
|
-
title: round.title,
|
172
|
-
pos: round.pos,
|
173
|
-
start_at: event.start_at.to_date
|
174
|
-
}
|
175
|
-
rec = SportDb::Model::Round.create!( attribs )
|
176
|
-
end
|
177
|
-
rec
|
178
|
-
end
|
179
|
-
end # class Round
|
180
|
-
|
181
|
-
|
182
|
-
class Stage
|
183
|
-
def self.find( name, event: )
|
184
|
-
SportDb::Model::Stage.find_by( title: name, event_id: event.id )
|
185
|
-
end
|
186
|
-
def self.find!( name, event: )
|
187
|
-
rec = find( name, event: event )
|
188
|
-
if rec.nil?
|
189
|
-
puts "** !!!ERROR!!! db sync - no stage match found for:"
|
190
|
-
pp name
|
191
|
-
pp event
|
192
|
-
exit 1
|
193
|
-
end
|
194
|
-
rec
|
195
|
-
end
|
196
|
-
|
197
|
-
def self.find_or_create( name, event: )
|
198
|
-
rec = find( name, event: event )
|
199
|
-
if rec.nil?
|
200
|
-
## use title and not name - why? why not?
|
201
|
-
## quick fix: change name to title
|
202
|
-
attribs = { event_id: event.id,
|
203
|
-
title: name,
|
204
|
-
}
|
205
|
-
rec = SportDb::Model::Stage.create!( attribs )
|
206
|
-
end
|
207
|
-
rec
|
208
|
-
end
|
209
|
-
end # class Stage
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
class Match ## todo/check: add alias for Game class - why? why not?
|
214
|
-
def self.create_or_update( match, event: )
|
215
|
-
## note: MUST find round, thus, use bang (!)
|
216
|
-
round_rec = SportDb::Model::Round.find_by!( event_id: event.id,
|
217
|
-
title: match.round.title )
|
218
|
-
|
219
|
-
rec = SportDb::Model::Game.find_by( round_id: round_rec.id,
|
220
|
-
team1_id: match.team1.id,
|
221
|
-
team2_id: match.team2.id )
|
222
|
-
if rec.nil?
|
223
|
-
attribs = { round_id: round_rec.id,
|
224
|
-
team1_id: match.team1.id,
|
225
|
-
team2_id: match.team2.id,
|
226
|
-
pos: 999, ## make optional why? why not? - change to num?
|
227
|
-
play_at: match.date.to_date,
|
228
|
-
score1: match.score1,
|
229
|
-
score2: match.score2,
|
230
|
-
score1i: match.score1i,
|
231
|
-
score2i: match.score2i }
|
232
|
-
rec = SportDb::Model::Game.create!( attribs )
|
233
|
-
else
|
234
|
-
# update - todo
|
235
|
-
end
|
236
|
-
rec
|
237
|
-
end
|
238
|
-
end # class Match
|
239
|
-
|
240
|
-
end # module Sync
|
241
|
-
end # module SportDb
|