sportdb-models 1.18.6 → 1.19.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 -106
- data/Rakefile +0 -1
- data/lib/sportdb/deleter.rb +1 -1
- data/lib/sportdb/models.rb +3 -88
- data/lib/sportdb/version.rb +2 -2
- data/test/helper.rb +0 -108
- metadata +2 -122
- data/lib/sportdb/indexers/team.rb +0 -87
- data/lib/sportdb/matcher.rb +0 -31
- data/lib/sportdb/pretty_printer.rb +0 -175
- data/lib/sportdb/reader.rb +0 -132
- data/lib/sportdb/reader_file.rb +0 -131
- data/lib/sportdb/reader_zip.rb +0 -172
- data/lib/sportdb/readers/assoc.rb +0 -54
- data/lib/sportdb/readers/event.rb +0 -253
- data/lib/sportdb/readers/event_meta.rb +0 -133
- data/lib/sportdb/readers/event_table.rb +0 -196
- data/lib/sportdb/readers/game.rb +0 -912
- data/lib/sportdb/readers/ground.rb +0 -53
- data/lib/sportdb/readers/league.rb +0 -54
- data/lib/sportdb/readers/season.rb +0 -83
- data/lib/sportdb/readers/squad_club.rb +0 -201
- data/lib/sportdb/readers/squad_national_team.rb +0 -173
- data/lib/sportdb/readers/team.rb +0 -53
- data/lib/sportdb/rsssf_reader.rb +0 -367
- data/lib/sportdb/utils.rb +0 -89
- data/lib/sportdb/utils_date.rb +0 -26
- data/lib/sportdb/utils_goals.rb +0 -20
- data/lib/sportdb/utils_group.rb +0 -63
- data/lib/sportdb/utils_map.rb +0 -44
- data/lib/sportdb/utils_round.rb +0 -165
- data/lib/sportdb/utils_scores.rb +0 -17
- data/lib/sportdb/utils_teams.rb +0 -48
- data/test/data/at-austria/2013_14/bl.txt +0 -227
- data/test/data/at-austria/2013_14/bl.yml +0 -30
- data/test/data/at-austria/2013_14/bl_ii.txt +0 -154
- data/test/data/at-austria/2013_14/el.txt +0 -4
- data/test/data/at-austria/2013_14/el.yml +0 -25
- data/test/data/at-austria/2013_14/squads/austria.txt +0 -40
- data/test/data/at-austria/2013_14/squads/salzburg.txt +0 -35
- data/test/data/at-austria/2014_15/1-bundesliga-ii.txt +0 -158
- data/test/data/at-austria/2014_15/1-bundesliga.yml +0 -18
- data/test/data/at-austria/2015_16/1-bundesliga-v2.conf.txt +0 -20
- data/test/data/at-austria/2015_16/1-bundesliga-v2.yml +0 -20
- data/test/data/at-austria/2015_16/1-bundesliga.conf.txt +0 -20
- data/test/data/at-austria/2015_16/1-bundesliga.yml +0 -24
- data/test/data/at-austria/2015_16/cup.yml +0 -77
- data/test/data/at-austria/leagues.txt +0 -11
- data/test/data/at-austria/teams.txt +0 -68
- data/test/data/at-austria/teams_2.txt +0 -21
- data/test/data/csv/de-2013-14--1-bundesliga.txt +0 -307
- data/test/data/de-deutschland/2013-14/1-bundesliga.yml +0 -26
- data/test/data/de-deutschland/leagues.txt +0 -4
- data/test/data/de-deutschland/teams.txt +0 -53
- data/test/data/eng-england/2015-16/1-premierleague-v2.yml +0 -2
- data/test/data/eng-england/2015-16/1-premierleague.yml +0 -5
- data/test/data/national-teams/assocs.txt +0 -231
- data/test/data/national-teams/europe/assocs.txt +0 -13
- data/test/data/national-teams/europe/teams.txt +0 -13
- data/test/data/national-teams/north-america/assocs.txt +0 -10
- data/test/data/national-teams/north-america/teams.txt +0 -7
- data/test/data/national-teams/teams.txt +0 -19
- data/test/data/players/europe/at-austria/players.txt +0 -45
- data/test/data/players/europe/de-deutschland/players.txt +0 -41
- data/test/data/players/south-america/br-brazil/players.txt +0 -51
- data/test/data/rsssf/at-2014-15--1-bundesliga.txt +0 -339
- data/test/data/rsssf/at-2015-16--1-bundesliga.txt +0 -18
- data/test/data/world-cup/1930/cup.txt +0 -71
- data/test/data/world-cup/1930/cup.yml +0 -23
- data/test/data/world-cup/1930/cup_goals.txt +0 -47
- data/test/data/world-cup/1930/cup_goals.yml +0 -23
- data/test/data/world-cup/1954/cup.txt +0 -90
- data/test/data/world-cup/1954/cup.yml +0 -30
- data/test/data/world-cup/1962/cup.txt +0 -86
- data/test/data/world-cup/1962/cup.yml +0 -32
- data/test/data/world-cup/1974/cup.yml +0 -35
- data/test/data/world-cup/1974/cup_finals.txt +0 -14
- data/test/data/world-cup/1974/cup_i.txt +0 -55
- data/test/data/world-cup/1974/cup_ii.txt +0 -34
- data/test/data/world-cup/2014/cup.txt +0 -5
- data/test/data/world-cup/2014/cup.yml +0 -54
- data/test/data/world-cup/2014/squads/br-brazil.txt +0 -46
- data/test/data/world-cup/2014/squads/de-deutschland.txt +0 -8
- data/test/data/world-cup/2014/squads/jp-japan.txt +0 -30
- data/test/data/world-cup/2014/squads/uy-uruguay.txt +0 -32
- data/test/data/world-cup/leagues.txt +0 -5
- data/test/data/world-cup/seasons_1930.txt +0 -4
- data/test/data/world-cup/seasons_1954.txt +0 -4
- data/test/data/world-cup/seasons_1962.txt +0 -4
- data/test/data/world-cup/seasons_1974.txt +0 -5
- data/test/data/world-cup/teams_1930.txt +0 -26
- data/test/data/world-cup/teams_1954.txt +0 -30
- data/test/data/world-cup/teams_1962.txt +0 -29
- data/test/data/world-cup/teams_1974.txt +0 -29
- data/test/test_assoc_reader.rb +0 -199
- data/test/test_event_meta_reader.rb +0 -47
- data/test/test_event_reader.rb +0 -64
- data/test/test_event_table_reader.rb +0 -57
- data/test/test_goals.rb +0 -107
- data/test/test_indexer_team.rb +0 -34
- data/test/test_load.rb +0 -61
- data/test/test_pp.rb +0 -35
- data/test/test_reader.rb +0 -88
- data/test/test_reader_from_string.rb +0 -63
- data/test/test_round_auto.rb +0 -370
- data/test/test_round_def.rb +0 -109
- data/test/test_round_header.rb +0 -183
- data/test/test_rsssf_reader.rb +0 -76
- data/test/test_squad_club_reader.rb +0 -76
- data/test/test_squad_national_team_reader.rb +0 -116
- data/test/test_standings.rb +0 -279
- data/test/test_standings_ii.rb +0 -46
- data/test/test_utils.rb +0 -124
data/lib/sportdb/readers/team.rb
DELETED
@@ -1,53 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
module SportDb
|
4
|
-
|
5
|
-
|
6
|
-
class TeamReader
|
7
|
-
|
8
|
-
include LogUtils::Logging
|
9
|
-
|
10
|
-
## make models available by default with namespace
|
11
|
-
# e.g. lets you use Usage instead of Model::Usage
|
12
|
-
include Models
|
13
|
-
|
14
|
-
def self.from_zip( zip_file, entry_path, more_attribs={} )
|
15
|
-
## get text content from zip
|
16
|
-
entry = zip_file.find_entry( entry_path )
|
17
|
-
|
18
|
-
text = entry.get_input_stream().read()
|
19
|
-
text = text.force_encoding( Encoding::UTF_8 )
|
20
|
-
|
21
|
-
self.from_string( text, more_attribs )
|
22
|
-
end
|
23
|
-
|
24
|
-
def self.from_file( path, more_attribs={} )
|
25
|
-
## note: assume/enfore utf-8 encoding (with or without BOM - byte order mark)
|
26
|
-
## - see textutils/utils.rb
|
27
|
-
text = File.read_utf8( path )
|
28
|
-
self.from_string( text, more_attribs )
|
29
|
-
end
|
30
|
-
|
31
|
-
def self.from_string( text, more_attribs={} )
|
32
|
-
TeamReader.new( text, more_attribs )
|
33
|
-
end
|
34
|
-
|
35
|
-
def initialize( text, more_attribs={} )
|
36
|
-
## todo/fix: how to add opts={} ???
|
37
|
-
@text = text
|
38
|
-
@more_attribs = more_attribs
|
39
|
-
end
|
40
|
-
|
41
|
-
|
42
|
-
def read
|
43
|
-
reader = ValuesReader.from_string( @text, @more_attribs )
|
44
|
-
|
45
|
-
reader.each_line do |new_attributes, values|
|
46
|
-
Team.create_or_update_from_values( new_attributes, values )
|
47
|
-
end # each lines
|
48
|
-
end
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
end # class TeamReader
|
53
|
-
end # module SportDb
|
data/lib/sportdb/rsssf_reader.rb
DELETED
@@ -1,367 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
##
|
4
|
-
## note: for now lets only support leagues with rounds (no cups/knockout rounds n groups)
|
5
|
-
## (re)add later when needed (e.g. for playoffs etc.)
|
6
|
-
|
7
|
-
|
8
|
-
module SportDb
|
9
|
-
|
10
|
-
|
11
|
-
class RsssfGameReader ### todo: rename to RsssfLeagueMatchReader ( or use league/cup option?) - why? why not??
|
12
|
-
|
13
|
-
include LogUtils::Logging
|
14
|
-
|
15
|
-
## make models available by default with namespace
|
16
|
-
# e.g. lets you use Usage instead of Model::Usage
|
17
|
-
include Models
|
18
|
-
|
19
|
-
##
|
20
|
-
## todo: add from_file and from_zip too
|
21
|
-
|
22
|
-
def self.from_string( event_or_event_key, text )
|
23
|
-
self.new( event_or_event_key, text )
|
24
|
-
end
|
25
|
-
|
26
|
-
def initialize( event_or_event_key, text )
|
27
|
-
## todo/fix: how to add opts={} ???
|
28
|
-
@event_or_event_key = event_or_event_key
|
29
|
-
@text = text
|
30
|
-
end
|
31
|
-
|
32
|
-
|
33
|
-
def read
|
34
|
-
## note: assume active activerecord connection
|
35
|
-
|
36
|
-
if @event_or_event_key.kind_of?( Event )
|
37
|
-
@event= @event_or_event_key
|
38
|
-
else ## assume string
|
39
|
-
@event = Event.find_by!( key: @event_or_event_key )
|
40
|
-
end
|
41
|
-
|
42
|
-
logger.debug "Event #{@event.key} >#{@event.title}<"
|
43
|
-
|
44
|
-
@mapper_teams = TeamMapper.new( @event.teams )
|
45
|
-
|
46
|
-
## reset cached values
|
47
|
-
@patch_round_ids = []
|
48
|
-
|
49
|
-
@last_round = nil
|
50
|
-
@last_date = nil
|
51
|
-
|
52
|
-
reader = LineReader.from_string( @text )
|
53
|
-
parse_fixtures( reader )
|
54
|
-
end # method load_fixtures
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
RSSSF_FT_REGEX = /\b
|
59
|
-
(?<score1>\d{1,2})
|
60
|
-
-
|
61
|
-
(?<score2>\d{1,2})
|
62
|
-
\b/x
|
63
|
-
|
64
|
-
def find_rsssf_scores!( line )
|
65
|
-
# e.g. 1-1 or 0-2 or 3-3
|
66
|
-
|
67
|
-
m = RSSSF_FT_REGEX.match( line )
|
68
|
-
if m
|
69
|
-
score1 = m[:score1].to_i
|
70
|
-
score2 = m[:score2].to_i
|
71
|
-
|
72
|
-
logger.debug " score: >#{score1}-#{score2}<"
|
73
|
-
|
74
|
-
line.sub!( m[0], '[SCORE]' )
|
75
|
-
else
|
76
|
-
score1 = nil
|
77
|
-
score2 = nil
|
78
|
-
end
|
79
|
-
|
80
|
-
scores = [score1, score2]
|
81
|
-
scores
|
82
|
-
end # method find_rsssf_scores!
|
83
|
-
|
84
|
-
|
85
|
-
def find_rsssf_date!( line, opts={} )
|
86
|
-
finder = RsssfDateFinder.new
|
87
|
-
finder.find!( line, opts )
|
88
|
-
end
|
89
|
-
|
90
|
-
|
91
|
-
RSSSF_ROUND_REGEX = /\b
|
92
|
-
(?<round>Round)
|
93
|
-
\s
|
94
|
-
(?<pos>\d{1,3})
|
95
|
-
\b/x
|
96
|
-
|
97
|
-
def is_rsssf_round?( line )
|
98
|
-
RSSSF_ROUND_REGEX.match( line ).nil? == false ## match found if not nil
|
99
|
-
end
|
100
|
-
|
101
|
-
def find_rsssf_round!( line )
|
102
|
-
## todo: check if \b works for run on [Apr 13] too ??
|
103
|
-
## todo: allow multiple spaces after round ??
|
104
|
-
|
105
|
-
m = RSSSF_ROUND_REGEX.match( line )
|
106
|
-
if m
|
107
|
-
title = m[0] ## note: title is complete match e.g. Round 1, Round 2, etc.
|
108
|
-
pos = m[:pos].to_i
|
109
|
-
|
110
|
-
logger.debug " title: >#{title}<, pos: >#{pos}<"
|
111
|
-
|
112
|
-
line.sub!( m[0], '[ROUND]' )
|
113
|
-
else
|
114
|
-
## fix: add logger.warn no round pos found in line
|
115
|
-
title = nil
|
116
|
-
pos = nil
|
117
|
-
end
|
118
|
-
|
119
|
-
[title,pos] ## return array; note: [nil,nil] if nothing found
|
120
|
-
end # method find_rsssf_round!
|
121
|
-
|
122
|
-
|
123
|
-
def parse_round_header( line )
|
124
|
-
|
125
|
-
## todo/fix:
|
126
|
-
## simplify - for now round number always required
|
127
|
-
# e.g. no auto-calculation supported here
|
128
|
-
# fail if round found w/o number/pos !!!
|
129
|
-
#
|
130
|
-
# also remove knockout flag for now (set to always false for now)
|
131
|
-
|
132
|
-
logger.debug "parsing round header line: >#{line}<"
|
133
|
-
|
134
|
-
## check for date in header first e.g. Round 36 [Jul 20] !!
|
135
|
-
## avoid "conflict" with getting "wrong" round number from date etc.
|
136
|
-
date = find_rsssf_date!( line, start_at: @event.start_at )
|
137
|
-
if date
|
138
|
-
@last_date = date
|
139
|
-
end
|
140
|
-
|
141
|
-
title, pos = find_rsssf_round!( line )
|
142
|
-
|
143
|
-
## check if pos available; if not auto-number/calculate
|
144
|
-
if pos.nil?
|
145
|
-
logger.error( " no round pos found in line >#{line}<; round pos required in rsssf; sorry" )
|
146
|
-
fail( "round pos required in rsssf; sorry")
|
147
|
-
end
|
148
|
-
|
149
|
-
logger.debug " line: >#{line}<"
|
150
|
-
|
151
|
-
## Note: dummy/placeholder start_at, end_at date
|
152
|
-
## replace/patch after adding all games for round
|
153
|
-
|
154
|
-
round_attribs = {
|
155
|
-
title: title,
|
156
|
-
title2: nil,
|
157
|
-
knockout: false
|
158
|
-
}
|
159
|
-
|
160
|
-
round = Round.find_by( event_id: @event.id,
|
161
|
-
pos: pos )
|
162
|
-
|
163
|
-
if round.present?
|
164
|
-
logger.debug "update round #{round.id}:"
|
165
|
-
else
|
166
|
-
logger.debug "create round:"
|
167
|
-
round = Round.new
|
168
|
-
|
169
|
-
round_attribs = round_attribs.merge( {
|
170
|
-
event_id: @event.id,
|
171
|
-
pos: pos,
|
172
|
-
## todo: add num e.g. num == pos for round 1, round 2, etc. - why? why not??
|
173
|
-
start_at: Date.parse('1911-11-11'),
|
174
|
-
end_at: Date.parse('1911-11-11')
|
175
|
-
})
|
176
|
-
end
|
177
|
-
|
178
|
-
logger.debug round_attribs.to_json
|
179
|
-
|
180
|
-
round.update_attributes!( round_attribs )
|
181
|
-
|
182
|
-
### store list of round ids for patching start_at/end_at at the end
|
183
|
-
@patch_round_ids << round.id
|
184
|
-
@last_round = round ## keep track of last seen round for matches that follow etc.
|
185
|
-
end
|
186
|
-
|
187
|
-
|
188
|
-
def try_parse_game( line )
|
189
|
-
# note: clone line; for possible test do NOT modify in place for now
|
190
|
-
# note: returns true if parsed, false if no match
|
191
|
-
parse_game( line.dup )
|
192
|
-
end
|
193
|
-
|
194
|
-
def parse_game( line )
|
195
|
-
logger.debug "parsing game (fixture) line: >#{line}<"
|
196
|
-
|
197
|
-
@mapper_teams.map_teams!( line )
|
198
|
-
team_keys = @mapper_teams.find_teams!( line )
|
199
|
-
team1_key = team_keys[0]
|
200
|
-
team2_key = team_keys[1]
|
201
|
-
|
202
|
-
## note: if we do NOT find two teams; return false - no match found
|
203
|
-
if team1_key.nil? || team2_key.nil?
|
204
|
-
logger.debug " no game match (two teams required) found for line: >#{line}<"
|
205
|
-
return false
|
206
|
-
end
|
207
|
-
|
208
|
-
date = find_rsssf_date!( line, start_at: @event.start_at )
|
209
|
-
|
210
|
-
###
|
211
|
-
# check if date found?
|
212
|
-
# note: ruby falsey is nil & false only (not 0 or empty array etc.)
|
213
|
-
if date
|
214
|
-
@last_date = date # keep a reference for later use
|
215
|
-
else
|
216
|
-
date = @last_date # no date found; (re)use last seen date
|
217
|
-
end
|
218
|
-
|
219
|
-
scores = find_rsssf_scores!( line )
|
220
|
-
|
221
|
-
logger.debug " line: >#{line}<"
|
222
|
-
|
223
|
-
|
224
|
-
### todo: cache team lookups in hash?
|
225
|
-
team1 = Team.find_by!( key: team1_key )
|
226
|
-
team2 = Team.find_by!( key: team2_key )
|
227
|
-
|
228
|
-
round = @last_round
|
229
|
-
|
230
|
-
### check if games exists
|
231
|
-
## with this teams in this round if yes only update
|
232
|
-
##
|
233
|
-
## todo: add replay flag (true/false) !!!!!!!!
|
234
|
-
## allows same match fixture in round !!!!!!!!
|
235
|
-
game = Game.find_by( round_id: round.id,
|
236
|
-
team1_id: team1.id,
|
237
|
-
team2_id: team2.id )
|
238
|
-
|
239
|
-
game_attribs = {
|
240
|
-
score1: scores[0],
|
241
|
-
score2: scores[1],
|
242
|
-
score1et: scores[2],
|
243
|
-
score2et: scores[3],
|
244
|
-
score1p: scores[4],
|
245
|
-
score2p: scores[5],
|
246
|
-
play_at: date,
|
247
|
-
play_at_v2: nil,
|
248
|
-
postponed: false,
|
249
|
-
knockout: false, ## round.knockout, ## note: for now always use knockout flag from round - why? why not??
|
250
|
-
ground_id: nil,
|
251
|
-
group_id: nil
|
252
|
-
}
|
253
|
-
|
254
|
-
if game.present?
|
255
|
-
logger.debug "update game #{game.id}:"
|
256
|
-
else
|
257
|
-
logger.debug "create game:"
|
258
|
-
game = Game.new
|
259
|
-
|
260
|
-
## Note: use round.games.count for pos
|
261
|
-
## lets us add games out of order if later needed
|
262
|
-
more_game_attribs = {
|
263
|
-
round_id: round.id,
|
264
|
-
team1_id: team1.id,
|
265
|
-
team2_id: team2.id,
|
266
|
-
pos: round.games.count+1
|
267
|
-
}
|
268
|
-
game_attribs = game_attribs.merge( more_game_attribs )
|
269
|
-
end
|
270
|
-
|
271
|
-
logger.debug game_attribs.to_json
|
272
|
-
game.update_attributes!( game_attribs )
|
273
|
-
|
274
|
-
return true # game match found
|
275
|
-
end # method parse_game
|
276
|
-
|
277
|
-
|
278
|
-
def try_parse_date_header( line )
|
279
|
-
# note: clone line; for possible test do NOT modify in place for now
|
280
|
-
# note: returns true if parsed, false if no match
|
281
|
-
parse_date_header( line.dup )
|
282
|
-
end
|
283
|
-
|
284
|
-
def parse_date_header( line )
|
285
|
-
# note: returns true if parsed, false if no match
|
286
|
-
|
287
|
-
# line with NO teams plus include date e.g.
|
288
|
-
# [Jun 17] etc.
|
289
|
-
|
290
|
-
@mapper_teams.map_teams!( line )
|
291
|
-
team_keys= @mapper_teams.find_teams!( line )
|
292
|
-
team1_key = team_keys[0]
|
293
|
-
team2_key = team_keys[1]
|
294
|
-
|
295
|
-
date = find_rsssf_date!( line, start_at: @event.start_at )
|
296
|
-
|
297
|
-
if date && team1_key.nil? && team2_key.nil?
|
298
|
-
logger.debug( "date header line found: >#{line}<")
|
299
|
-
logger.debug( " date: #{date}")
|
300
|
-
|
301
|
-
@last_date = date # keep a reference for later use
|
302
|
-
return true
|
303
|
-
else
|
304
|
-
return false
|
305
|
-
end
|
306
|
-
end
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
def parse_fixtures( reader )
|
311
|
-
|
312
|
-
reader.each_line do |line|
|
313
|
-
|
314
|
-
if is_rsssf_round?( line )
|
315
|
-
parse_round_header( line )
|
316
|
-
elsif try_parse_game( line )
|
317
|
-
# do nothing here
|
318
|
-
elsif try_parse_date_header( line )
|
319
|
-
# do nothing here
|
320
|
-
else
|
321
|
-
logger.info "skipping line (no match found): >#{line}<"
|
322
|
-
end
|
323
|
-
end # lines.each
|
324
|
-
|
325
|
-
###########################
|
326
|
-
# backtrack and patch round dates (start_at/end_at)
|
327
|
-
|
328
|
-
unless @patch_round_ids.empty?
|
329
|
-
###
|
330
|
-
# note: use uniq - to allow multiple round headers (possible?)
|
331
|
-
|
332
|
-
Round.find( @patch_round_ids.uniq ).each do |r|
|
333
|
-
logger.debug "patch round start_at/end_at date for #{r.title}:"
|
334
|
-
|
335
|
-
## note:
|
336
|
-
## will add "scope" pos first e.g
|
337
|
-
#
|
338
|
-
## SELECT "games".* FROM "games" WHERE "games"."round_id" = ?
|
339
|
-
# ORDER BY pos, play_at asc [["round_id", 7]]
|
340
|
-
# thus will NOT order by play_at but by pos first!!!
|
341
|
-
# =>
|
342
|
-
# need to unscope pos!!! or use unordered_games - games_by_play_at_date etc.??
|
343
|
-
# thus use reorder()!!! - not just order('play_at asc')
|
344
|
-
|
345
|
-
games = r.games.reorder( 'play_at asc' ).all
|
346
|
-
|
347
|
-
## skip rounds w/ no games
|
348
|
-
|
349
|
-
## todo/check/fix: what's the best way for checking assoc w/ 0 recs?
|
350
|
-
next if games.size == 0
|
351
|
-
|
352
|
-
# note: make sure start_at/end_at is date only (e.g. use play_at.to_date)
|
353
|
-
# sqlite3 saves datetime in date field as datetime, for example (will break date compares later!)
|
354
|
-
|
355
|
-
round_attribs = {
|
356
|
-
start_at: games[0].play_at.to_date, # use games.first ?
|
357
|
-
end_at: games[-1].play_at.to_date # use games.last ? why? why not?
|
358
|
-
}
|
359
|
-
|
360
|
-
logger.debug round_attribs.to_json
|
361
|
-
r.update_attributes!( round_attribs )
|
362
|
-
end
|
363
|
-
end
|
364
|
-
end # method parse_fixtures
|
365
|
-
|
366
|
-
end # class RsssfGameReader
|
367
|
-
end # module SportDb
|
data/lib/sportdb/utils.rb
DELETED
@@ -1,89 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
### note: some utils moved to worldbdb/utils for reuse
|
4
|
-
|
5
|
-
|
6
|
-
####
|
7
|
-
## move to folder matcher(s)/finder(s)
|
8
|
-
# -- rename to FixtureFinder or FixtureFinders
|
9
|
-
# or just GeneralFinder
|
10
|
-
# TeamFinder etc. ???
|
11
|
-
|
12
|
-
|
13
|
-
module SportDb
|
14
|
-
module FixtureHelpers
|
15
|
-
|
16
|
-
|
17
|
-
def cut_off_end_of_line_comment!( line )
|
18
|
-
# cut off (that is, remove) optional end of line comment starting w/ #
|
19
|
-
|
20
|
-
line.sub!( /#.*$/ ) do |_|
|
21
|
-
logger.debug " cutting off end of line comment - >>#{$&}<<"
|
22
|
-
''
|
23
|
-
end
|
24
|
-
|
25
|
-
# NB: line = line.sub will NOT work - thus, lets use line.sub!
|
26
|
-
end
|
27
|
-
|
28
|
-
|
29
|
-
def find_nationality!( line )
|
30
|
-
# extract optional nationality - three-letter country code from line e.g. Lionel Messi (ARG)
|
31
|
-
# and return it
|
32
|
-
# NB: side effect - removes num from line string
|
33
|
-
|
34
|
-
regex = /\(([A-Z]{3})\)/ # e.g. (ARG)
|
35
|
-
if line =~ regex
|
36
|
-
logger.debug " nationality: >#{$1}<"
|
37
|
-
|
38
|
-
line.sub!( regex, '[NATIONALITY]' )
|
39
|
-
return $1.to_s
|
40
|
-
else
|
41
|
-
return nil
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
|
46
|
-
def find_leading_num!( line )
|
47
|
-
# extract optional leading num from line e.g. 9 Lionel Messi
|
48
|
-
# and return it
|
49
|
-
# NB: side effect - removes num from line string
|
50
|
-
|
51
|
-
# e.g. 9 Lionel Messi - must start line
|
52
|
-
## note: use lookahead (?=) for trailing spaces - do NOT cosume
|
53
|
-
regex = /^[ \t]*(\d{1,3})(?=[ \t]+)/
|
54
|
-
if line =~ regex
|
55
|
-
logger.debug " num: >#{$1}<"
|
56
|
-
|
57
|
-
line.sub!( regex, '[NUM]' )
|
58
|
-
return $1.to_i
|
59
|
-
else
|
60
|
-
return nil
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
def find_leading_pos!( line )
|
65
|
-
# extract optional game pos from line
|
66
|
-
# and return it
|
67
|
-
# NB: side effect - removes pos from line string
|
68
|
-
|
69
|
-
# e.g. (1) - must start line
|
70
|
-
regex = /^[ \t]*\((\d{1,3})\)[ \t]+/
|
71
|
-
if line =~ regex
|
72
|
-
logger.debug " pos: >#{$1}<"
|
73
|
-
|
74
|
-
line.sub!( regex, '[POS] ' ) # NB: add trailing space
|
75
|
-
return $1.to_i
|
76
|
-
else
|
77
|
-
return nil
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
def find_game_pos!( line )
|
82
|
-
## fix: add depreciation warning - remove - use find_leading_pos!
|
83
|
-
find_leading_pos!( line )
|
84
|
-
end
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
end # module FixtureHelpers
|
89
|
-
end # module SportDb
|