sportdb-readers 0.4.3 → 0.4.4
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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d00cca5fea7e84fd30f67fc79ecf764ce1e900c0
|
4
|
+
data.tar.gz: 8a10004745355d8aeaa98ba4d765a05e17a812ba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f654094b67436cce1f8931416ca088b263ef1e6e410e1252ef255938ada337449d960300d258adcbe5604af5194339413d008dd7aad6782b12c0c049548e88cf
|
7
|
+
data.tar.gz: 2b7382754ead0df285a33b7fa7f7993fdbfe93dea386c013ad7c81ded6282a0b2382c9becf93fe7e91f15998cb4b46df59120dcd340a82d742e81412ebe60b0e
|
@@ -22,19 +22,26 @@ class AutoConfParser
|
|
22
22
|
|
23
23
|
def parse
|
24
24
|
## try to find all clubs in match schedule
|
25
|
-
@
|
25
|
+
@last_round = nil
|
26
|
+
@rounds = {} ## track usage counter and match (two clubs) counter
|
27
|
+
@clubs = Hash.new(0) ## keep track of usage counter
|
28
|
+
|
26
29
|
|
27
30
|
@lines.each do |line|
|
28
31
|
if is_round?( line )
|
29
32
|
logger.info "skipping matched round line: >#{line}<"
|
33
|
+
|
34
|
+
round = @rounds[ line ] ||= {count: 0, match_count: 0} ## usage counter, match counter
|
35
|
+
round[:count] +=1
|
36
|
+
@last_round = round
|
30
37
|
elsif try_parse_game( line )
|
31
38
|
# do nothing here
|
32
39
|
else
|
33
|
-
logger.
|
40
|
+
logger.warn "skipping line (no match found): >#{line}<"
|
34
41
|
end
|
35
42
|
end # lines.each
|
36
43
|
|
37
|
-
@clubs
|
44
|
+
[@clubs, @rounds]
|
38
45
|
end
|
39
46
|
|
40
47
|
def is_round?( line )
|
@@ -128,9 +135,12 @@ class AutoConfParser
|
|
128
135
|
|
129
136
|
puts "(auto config) try matching clubs:"
|
130
137
|
pp values
|
138
|
+
|
131
139
|
@clubs[ values[0] ] += 1 ## update usage counters
|
132
140
|
@clubs[ values[1] ] += 1
|
133
141
|
|
142
|
+
@last_round[ :match_count ] += 1
|
143
|
+
|
134
144
|
true
|
135
145
|
end
|
136
146
|
|
@@ -21,6 +21,26 @@ class MatchReaderV2 ## todo/check: rename to MatchReaderV2 (use plural?) why?
|
|
21
21
|
league = Sync::League.find_or_create( rec[:league] )
|
22
22
|
season = Sync::Season.find_or_create( rec[:season] )
|
23
23
|
|
24
|
+
## hack for now: switch lang
|
25
|
+
if ['de', 'at'].include?( league.country.key )
|
26
|
+
SportDb.lang.lang = 'de'
|
27
|
+
DateFormats.lang = 'de'
|
28
|
+
elsif ['fr'].include?( league.country.key )
|
29
|
+
SportDb.lang.lang = 'fr'
|
30
|
+
DateFormats.lang = 'fr'
|
31
|
+
elsif ['it'].include?( league.country.key )
|
32
|
+
SportDb.lang.lang = 'it'
|
33
|
+
DateFormats.lang = 'it'
|
34
|
+
elsif ['es', 'mx'].include?( league.country.key )
|
35
|
+
SportDb.lang.lang = 'es'
|
36
|
+
DateFormats.lang = 'es'
|
37
|
+
elsif ['pt', 'br'].include?( league.country.key )
|
38
|
+
SportDb.lang.lang = 'pt'
|
39
|
+
DateFormats.lang = 'pt'
|
40
|
+
else
|
41
|
+
SportDb.lang.lang = 'en'
|
42
|
+
DateFormats.lang = 'en'
|
43
|
+
end
|
24
44
|
|
25
45
|
## todo/fix:
|
26
46
|
## always auto create
|
@@ -36,8 +56,8 @@ class MatchReaderV2 ## todo/check: rename to MatchReaderV2 (use plural?) why?
|
|
36
56
|
## fix: just use Stage.create
|
37
57
|
stage = Sync::Stage.find_or_create( rec[:stage], event: event )
|
38
58
|
|
39
|
-
auto_conf_clubs = AutoConfParser.parse( rec[:lines],
|
40
|
-
|
59
|
+
auto_conf_clubs, _ = AutoConfParser.parse( rec[:lines],
|
60
|
+
start: event.start_at )
|
41
61
|
end
|
42
62
|
else
|
43
63
|
event = Sync::Event.find( league: league, season: season )
|
@@ -45,8 +65,8 @@ class MatchReaderV2 ## todo/check: rename to MatchReaderV2 (use plural?) why?
|
|
45
65
|
## fix: just use Event.create
|
46
66
|
event = Sync::Event.find_or_create( league: league, season: season )
|
47
67
|
|
48
|
-
auto_conf_clubs = AutoConfParser.parse( rec[:lines],
|
49
|
-
|
68
|
+
auto_conf_clubs, _ = AutoConfParser.parse( rec[:lines],
|
69
|
+
start: event.start_at )
|
50
70
|
end
|
51
71
|
end
|
52
72
|
|
@@ -82,27 +102,6 @@ class MatchReaderV2 ## todo/check: rename to MatchReaderV2 (use plural?) why?
|
|
82
102
|
teams = event.teams
|
83
103
|
end
|
84
104
|
|
85
|
-
## hack for now: switch lang
|
86
|
-
if ['de', 'at'].include?( league.country.key )
|
87
|
-
SportDb.lang.lang = 'de'
|
88
|
-
DateFormats.lang = 'de'
|
89
|
-
elsif ['fr'].include?( league.country.key )
|
90
|
-
SportDb.lang.lang = 'fr'
|
91
|
-
DateFormats.lang = 'fr'
|
92
|
-
elsif ['it'].include?( league.country.key )
|
93
|
-
SportDb.lang.lang = 'it'
|
94
|
-
DateFormats.lang = 'it'
|
95
|
-
elsif ['es', 'mx'].include?( league.country.key )
|
96
|
-
SportDb.lang.lang = 'es'
|
97
|
-
DateFormats.lang = 'es'
|
98
|
-
elsif ['pt', 'br'].include?( league.country.key )
|
99
|
-
SportDb.lang.lang = 'pt'
|
100
|
-
DateFormats.lang = 'pt'
|
101
|
-
else
|
102
|
-
SportDb.lang.lang = 'en'
|
103
|
-
DateFormats.lang = 'en'
|
104
|
-
end
|
105
|
-
|
106
105
|
## todo/fix: set lang for now depending on league country!!!
|
107
106
|
parser = MatchParserSimpleV2.new( rec[:lines],
|
108
107
|
teams, ## note: use event OR stage teams (if stage is present)
|
@@ -36,19 +36,23 @@ class TestAutoConfParser < MiniTest::Test
|
|
36
36
|
|
37
37
|
TXT
|
38
38
|
|
39
|
-
clubs = parse( txt, lang: 'de' )
|
39
|
+
clubs, rounds = parse( txt, lang: 'de' )
|
40
40
|
|
41
41
|
assert_equal Hash(
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
42
|
+
'RB Salzburg' => 2,
|
43
|
+
'Wacker Innsbruck' => 2,
|
44
|
+
'SV Ried' => 2,
|
45
|
+
'Austria Wien' => 2,
|
46
|
+
'Kapfenberger SV' => 2,
|
47
|
+
'Admira Wacker' => 2,
|
48
|
+
'Rapid Wien' => 2,
|
49
|
+
'Wr. Neustadt' => 2,
|
50
|
+
'SV Mattersburg' => 2,
|
51
|
+
'Sturm Graz' => 2 ), clubs
|
52
|
+
|
53
|
+
assert_equal Hash(
|
54
|
+
'29. Runde' => { count: 1, match_count: 5 },
|
55
|
+
'30. Runde' => { count: 1, match_count: 5 } ), rounds
|
52
56
|
end
|
53
57
|
|
54
58
|
def test_es
|
@@ -81,9 +85,9 @@ Jornada 2
|
|
81
85
|
25.08.2012 Atlético Athletic 4-0
|
82
86
|
TXT
|
83
87
|
|
84
|
-
clubs = parse( txt, lang: 'es' )
|
88
|
+
clubs, rounds = parse( txt, lang: 'es' )
|
85
89
|
|
86
|
-
assert_equal Hash(
|
90
|
+
assert_equal Hash(
|
87
91
|
'Barcelona' => 2,
|
88
92
|
'R. Sociedad' => 2,
|
89
93
|
'Levante' => 2,
|
@@ -104,6 +108,10 @@ TXT
|
|
104
108
|
'Granada' => 2,
|
105
109
|
'Deportivo' => 2,
|
106
110
|
'Osasuna' => 2), clubs
|
111
|
+
|
112
|
+
assert_equal Hash(
|
113
|
+
'Jornada 1' => {count: 1, match_count: 10},
|
114
|
+
'Jornada 2' => {count: 1, match_count: 10} ), rounds
|
107
115
|
end
|
108
116
|
|
109
117
|
|
@@ -142,7 +150,7 @@ Journée 2
|
|
142
150
|
21h00 Girondins de Bordeaux 4-1 AS Monaco FC
|
143
151
|
TXT
|
144
152
|
|
145
|
-
clubs = parse( txt, lang: 'fr' )
|
153
|
+
clubs, rounds = parse( txt, lang: 'fr' )
|
146
154
|
|
147
155
|
assert_equal Hash(
|
148
156
|
'Stade de Reims' => 2,
|
@@ -165,8 +173,13 @@ TXT
|
|
165
173
|
'Stade Rennais FC' => 2,
|
166
174
|
'AS Monaco FC' => 2,
|
167
175
|
'FC Lorient' => 2), clubs
|
176
|
+
|
177
|
+
assert_equal Hash(
|
178
|
+
'Journée 1' => { count: 1, match_count: 10 },
|
179
|
+
'Journée 2' => { count: 1, match_count: 10 } ), rounds
|
168
180
|
end
|
169
181
|
|
182
|
+
|
170
183
|
def test_eng
|
171
184
|
txt = <<TXT
|
172
185
|
Matchday 1
|
@@ -203,7 +216,7 @@ Matchday 2
|
|
203
216
|
Manchester City 1-1 Everton FC
|
204
217
|
TXT
|
205
218
|
|
206
|
-
clubs = parse( txt )
|
219
|
+
clubs, rounds = parse( txt )
|
207
220
|
|
208
221
|
assert_equal Hash(
|
209
222
|
'Arsenal FC' => 2,
|
@@ -227,6 +240,10 @@ TXT
|
|
227
240
|
'Manchester United' => 2,
|
228
241
|
'West Ham United' => 2 ), clubs
|
229
242
|
|
243
|
+
assert_equal Hash(
|
244
|
+
'Matchday 1' => { count: 1, match_count: 10},
|
245
|
+
'Matchday 2' => { count: 1, match_count: 10} ), rounds
|
246
|
+
|
230
247
|
|
231
248
|
txt =<<TXT
|
232
249
|
Round 38
|
@@ -255,7 +272,7 @@ May/14 Blackpool 4-3 Bolton
|
|
255
272
|
May/14 Sunderland 1-3 Wolves
|
256
273
|
May/14 West Brom 1-0 Everton
|
257
274
|
TXT
|
258
|
-
clubs = parse( txt )
|
275
|
+
clubs, rounds = parse( txt )
|
259
276
|
|
260
277
|
assert_equal Hash(
|
261
278
|
'Aston Villa' => 2,
|
@@ -278,6 +295,10 @@ TXT
|
|
278
295
|
'Sunderland' => 2,
|
279
296
|
'Wolves' => 2,
|
280
297
|
'Blackburn' => 2), clubs
|
298
|
+
|
299
|
+
assert_equal Hash(
|
300
|
+
'Round 38' => { count: 1, match_count: 10 },
|
301
|
+
'Round 37' => { count: 1, match_count: 10 } ), rounds
|
281
302
|
end # method test_parse
|
282
303
|
|
283
304
|
|
@@ -306,7 +327,7 @@ Final
|
|
306
327
|
Petite Rivière Noire 2-0 Pamplemousses @ New George V Stadium, Curepipe
|
307
328
|
TXT
|
308
329
|
|
309
|
-
clubs = parse( txt )
|
330
|
+
clubs, rounds = parse( txt )
|
310
331
|
|
311
332
|
assert_equal Hash(
|
312
333
|
'Pointe-aux-Sables Mates' => 1,
|
@@ -318,6 +339,12 @@ TXT
|
|
318
339
|
'Pamplemousses' => 3,
|
319
340
|
'Savanne SC' => 1,
|
320
341
|
'Entente Boulet Rouge' => 2), clubs
|
342
|
+
|
343
|
+
assert_equal Hash(
|
344
|
+
'Preliminary Round' => {count: 1, match_count: 1},
|
345
|
+
'Quarterfinals' => {count: 1, match_count: 4},
|
346
|
+
'Semifinals' => {count: 1, match_count: 2},
|
347
|
+
'Final' => {count: 1, match_count: 1} ), rounds
|
321
348
|
end
|
322
349
|
|
323
350
|
|
@@ -329,10 +356,13 @@ def parse( txt, lang: 'en' )
|
|
329
356
|
|
330
357
|
start = Date.new( 2017, 7, 1 )
|
331
358
|
|
332
|
-
DateFormats.lang
|
359
|
+
DateFormats.lang = lang # e.g. 'en'
|
360
|
+
SportDb.lang.lang = lang
|
361
|
+
|
333
362
|
parser = SportDb::AutoConfParser.new( lines, start )
|
334
|
-
clubs = parser.parse
|
363
|
+
clubs, rounds = parser.parse
|
364
|
+
pp rounds
|
335
365
|
pp clubs
|
336
|
-
clubs
|
366
|
+
[clubs, rounds]
|
337
367
|
end
|
338
368
|
end # class AutoConfParser
|