sportdb-models 1.15.1 → 1.15.2
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 +4 -4
- data/Manifest.txt +4 -0
- data/lib/sportdb/models.rb +2 -1
- data/lib/sportdb/readers/event_table.rb +188 -0
- data/lib/sportdb/version.rb +1 -1
- data/test/data/at-austria/2015_16/1-bundesliga-v2.conf.txt +20 -0
- data/test/data/at-austria/2015_16/1-bundesliga.conf.txt +20 -0
- data/test/helper.rb +8 -0
- data/test/test_event_table_reader.rb +61 -0
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8297074a244e15a0faa0e79815af71b73c93ea68
|
4
|
+
data.tar.gz: 3b74416dac9a999b96998f8f34f3240fe14038ee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1a43679c3e1444aef940475e28ba250a98d2f25146a819d373fc5e7c8a87c2358cf1246548661b000a26251158597f4b91d8b47148018fde684091f2be829be9
|
7
|
+
data.tar.gz: 1b244eeaab111bcfb6e5fcbf3c74b587494425dddce4370f30b74449e68c815d4eebe318a208fafe21b479cd4457af5c1a3085ddc6009daaede7eea2a622168b
|
data/Manifest.txt
CHANGED
@@ -58,6 +58,7 @@ lib/sportdb/reader_file.rb
|
|
58
58
|
lib/sportdb/reader_zip.rb
|
59
59
|
lib/sportdb/readers/assoc.rb
|
60
60
|
lib/sportdb/readers/event.rb
|
61
|
+
lib/sportdb/readers/event_table.rb
|
61
62
|
lib/sportdb/readers/game.rb
|
62
63
|
lib/sportdb/readers/ground.rb
|
63
64
|
lib/sportdb/readers/league.rb
|
@@ -87,7 +88,9 @@ test/data/at-austria/2013_14/squads/austria.txt
|
|
87
88
|
test/data/at-austria/2013_14/squads/salzburg.txt
|
88
89
|
test/data/at-austria/2014_15/1-bundesliga-ii.txt
|
89
90
|
test/data/at-austria/2014_15/1-bundesliga.yml
|
91
|
+
test/data/at-austria/2015_16/1-bundesliga-v2.conf.txt
|
90
92
|
test/data/at-austria/2015_16/1-bundesliga-v2.yml
|
93
|
+
test/data/at-austria/2015_16/1-bundesliga.conf.txt
|
91
94
|
test/data/at-austria/2015_16/1-bundesliga.yml
|
92
95
|
test/data/at-austria/2015_16/cup.yml
|
93
96
|
test/data/at-austria/leagues.txt
|
@@ -142,6 +145,7 @@ test/test_csv_reader.rb
|
|
142
145
|
test/test_cursor.rb
|
143
146
|
test/test_date.rb
|
144
147
|
test/test_event_reader.rb
|
148
|
+
test/test_event_table_reader.rb
|
145
149
|
test/test_goals.rb
|
146
150
|
test/test_lang.rb
|
147
151
|
test/test_load.rb
|
data/lib/sportdb/models.rb
CHANGED
@@ -71,7 +71,8 @@ require 'sportdb/mapper_teams'
|
|
71
71
|
require 'sportdb/finders/goals' # no: requires FixturesHelpers
|
72
72
|
|
73
73
|
require 'sportdb/readers/assoc'
|
74
|
-
require 'sportdb/readers/event'
|
74
|
+
require 'sportdb/readers/event' ## old event reader (remove later??)
|
75
|
+
require 'sportdb/readers/event_table' ## new "standard" event reader
|
75
76
|
require 'sportdb/readers/game'
|
76
77
|
require 'sportdb/readers/ground'
|
77
78
|
require 'sportdb/readers/league'
|
@@ -0,0 +1,188 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
module SportDb
|
4
|
+
|
5
|
+
|
6
|
+
class EventTableReader
|
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
|
+
attr_reader :event # returns event record; call read first
|
15
|
+
|
16
|
+
|
17
|
+
## todo/fix: add from_zip()
|
18
|
+
|
19
|
+
def self.from_file( path, more_attribs={} )
|
20
|
+
## note: assume/enfore utf-8 encoding (with or without BOM - byte order mark)
|
21
|
+
## - see textutils/utils.rb
|
22
|
+
text = File.read_utf8( path )
|
23
|
+
|
24
|
+
self.from_string( text, more_attribs )
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.from_string( text, more_attribs={} )
|
28
|
+
self.new( text, more_attribs )
|
29
|
+
end
|
30
|
+
|
31
|
+
def initialize( text, more_attribs={} )
|
32
|
+
## todo/fix: how to add opts={} ???
|
33
|
+
@text = text
|
34
|
+
@more_attribs = more_attribs
|
35
|
+
|
36
|
+
@event = nil
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
## split into league + season
|
41
|
+
## e.g. Österr. Bundesliga 2015/16
|
42
|
+
## World Cup 2018
|
43
|
+
EVENT_HEADER_REGEX = /^
|
44
|
+
(?<league>.+?) ## non-greedy
|
45
|
+
\s
|
46
|
+
(?<season>\d{4}
|
47
|
+
(?:\/\d{2})? ## optional 2nd date in season
|
48
|
+
)
|
49
|
+
$/x
|
50
|
+
|
51
|
+
def read
|
52
|
+
@event = nil # reset cached event rec
|
53
|
+
event_attribs={}
|
54
|
+
|
55
|
+
reader = LineReader.from_string( @text )
|
56
|
+
|
57
|
+
header = false
|
58
|
+
season = nil
|
59
|
+
league = nil
|
60
|
+
|
61
|
+
reader.each_line do |line|
|
62
|
+
puts " line: >#{line}<"
|
63
|
+
|
64
|
+
## assume first line is event header (league+season)
|
65
|
+
## e.g. Österr. Bundesliga 2015/16
|
66
|
+
## World Cup 2018
|
67
|
+
if header == false
|
68
|
+
line = line.strip
|
69
|
+
m = EVENT_HEADER_REGEX.match( line )
|
70
|
+
if m
|
71
|
+
league_title = m[:league]
|
72
|
+
season_key = m[:season]
|
73
|
+
puts " trying event lookup - league: >#{league_title}<, season: >#{season_key}<"
|
74
|
+
|
75
|
+
season = Season.find_by( key: season_key )
|
76
|
+
|
77
|
+
## check if it exists
|
78
|
+
if season.present?
|
79
|
+
event_attribs['season_id'] = season.id
|
80
|
+
else
|
81
|
+
logger.error "season with key >>#{season_key}<< missing"
|
82
|
+
exit 1
|
83
|
+
end
|
84
|
+
|
85
|
+
league = League.find_by( title: league_title )
|
86
|
+
|
87
|
+
## check if it exists
|
88
|
+
if league.present? ## todo: just use if league (no present?) ???
|
89
|
+
event_attribs['league_id'] = league.id
|
90
|
+
else
|
91
|
+
logger.error "league with title >>#{league_title}<< missing"
|
92
|
+
exit 1
|
93
|
+
end
|
94
|
+
else
|
95
|
+
fail "[EventTableReader] event header must match league+season pattern: >#{line}<"
|
96
|
+
end
|
97
|
+
header = true
|
98
|
+
else
|
99
|
+
### process regular team lines
|
100
|
+
|
101
|
+
line = line.strip
|
102
|
+
scan = StringScanner.new( line )
|
103
|
+
|
104
|
+
if scan.check( /-/ ) # option 1) list entry e.g. - Rapid Wien
|
105
|
+
puts " list entry >#{line}<"
|
106
|
+
scan.skip( /-\s+/)
|
107
|
+
team_title = scan.rest.strip ## assume the rest is the team name
|
108
|
+
elsif scan.check( /\d{1,2}\./ ) ## option 2) table entry e.g. 1. Rapid Wien
|
109
|
+
puts " table entry >#{line}<"
|
110
|
+
rank = scan.scan( /\d{1,2}/ )
|
111
|
+
scan.skip( /\.\s+/)
|
112
|
+
|
113
|
+
## note: uses look ahead scan until we hit at least two spaces
|
114
|
+
## or the end of string (standing records for now optional)
|
115
|
+
team_title = scan.scan_until( /(?=\s{2})|$/ )
|
116
|
+
if scan.eos?
|
117
|
+
standing = nil
|
118
|
+
else
|
119
|
+
scan.skip( /\s+/ )
|
120
|
+
standing = scan.rest
|
121
|
+
end
|
122
|
+
puts " rank: >#{rank}<, standing: >#{standing}<"
|
123
|
+
else
|
124
|
+
fail "[EventTableReader] event line must match team pattern: >#{line}<"
|
125
|
+
end
|
126
|
+
|
127
|
+
puts " team: >#{team_title}<"
|
128
|
+
|
129
|
+
team = Team.find_by( title: team_title )
|
130
|
+
## next try synonyms (if not found/no match)
|
131
|
+
team = Team.where( "synonyms LIKE ?", "%#{team_title}%" ).first if team.nil?
|
132
|
+
|
133
|
+
|
134
|
+
if team.nil?
|
135
|
+
### print better error message than just
|
136
|
+
## *** error: Couldn't find SportDb::Model::Team
|
137
|
+
puts "[fatal] event reader - record for team title >#{team_title}< not found"
|
138
|
+
exit 1
|
139
|
+
### fix/todo: throw exception/error
|
140
|
+
end
|
141
|
+
|
142
|
+
team_ids = event_attribs['team_ids'] || []
|
143
|
+
team_ids << team.id
|
144
|
+
event_attribs['team_ids'] = team_ids
|
145
|
+
end
|
146
|
+
end # each_line
|
147
|
+
|
148
|
+
pp event_attribs
|
149
|
+
|
150
|
+
|
151
|
+
league_id = event_attribs['league_id']
|
152
|
+
season_id = event_attribs['season_id']
|
153
|
+
|
154
|
+
logger.debug "find event - league_id: #{league_id}, season_id: #{season_id}"
|
155
|
+
|
156
|
+
event = Event.find_by( league_id: league_id,
|
157
|
+
season_id: season_id )
|
158
|
+
|
159
|
+
## check if it exists
|
160
|
+
if event.present?
|
161
|
+
logger.debug "*** update event #{event.id}-#{event.key}:"
|
162
|
+
else
|
163
|
+
logger.debug "*** create event:"
|
164
|
+
event = Event.new
|
165
|
+
|
166
|
+
## hack: fix/todo1!!
|
167
|
+
## add "fake" start_at date for now
|
168
|
+
if season.key.size == '4' ## e.g. assume 2018 etc.
|
169
|
+
year = season.key.to_i
|
170
|
+
start_at = Date.new( year, 1, 1 )
|
171
|
+
else ## assume 2014/15 etc.
|
172
|
+
year = season.key[0..3].to_i
|
173
|
+
start_at = Date.new( year, 7, 1 )
|
174
|
+
end
|
175
|
+
event_attribs['start_at'] = start_at
|
176
|
+
end
|
177
|
+
|
178
|
+
logger.debug event_attribs.to_json
|
179
|
+
|
180
|
+
event.update_attributes!( event_attribs )
|
181
|
+
|
182
|
+
# keep a cached reference for later use
|
183
|
+
@event = event
|
184
|
+
end # method read
|
185
|
+
|
186
|
+
|
187
|
+
end # class EventTableReader
|
188
|
+
end # module SportDb
|
data/lib/sportdb/version.rb
CHANGED
@@ -0,0 +1,20 @@
|
|
1
|
+
#########################################################################
|
2
|
+
# Österreichische Bundesliga 2015/16 (104. Meisterschaft / 42. Saison)
|
3
|
+
#
|
4
|
+
# Start Date: 2015-07-25
|
5
|
+
# 10 Teams
|
6
|
+
|
7
|
+
|
8
|
+
Österr. Bundesliga 2015/16 ## No. 42
|
9
|
+
|
10
|
+
1. RB Salzburg
|
11
|
+
2. Rapid Wien
|
12
|
+
3. Sturm Graz
|
13
|
+
4. Wolfsberger AC
|
14
|
+
5. SV Ried
|
15
|
+
6. Austria Wien
|
16
|
+
7. Admira Wacker
|
17
|
+
8. SCR Altach
|
18
|
+
9. SV Grödig 19 10 12 5 4-4 8 [-2]
|
19
|
+
10. SV Mattersburg 20 11 10 4 5-5 4 ## Aufsteiger
|
20
|
+
|
@@ -0,0 +1,20 @@
|
|
1
|
+
#########################################################################
|
2
|
+
# Österreichische Bundesliga 2015/16 (104. Meisterschaft / 42. Saison)
|
3
|
+
#
|
4
|
+
# Start Date: 2015-07-25
|
5
|
+
# 10 Teams
|
6
|
+
|
7
|
+
|
8
|
+
Österr. Bundesliga 2015/16
|
9
|
+
|
10
|
+
- RB Salzburg
|
11
|
+
- Rapid Wien
|
12
|
+
- Sturm Graz
|
13
|
+
- Wolfsberger AC
|
14
|
+
- SV Ried
|
15
|
+
- Austria Wien
|
16
|
+
- Admira Wacker
|
17
|
+
- SCR Altach
|
18
|
+
- SV Grödig
|
19
|
+
- SV Mattersburg ## Aufsteiger
|
20
|
+
|
data/test/helper.rb
CHANGED
@@ -50,6 +50,7 @@ AssocReader = SportDb::AssocReader
|
|
50
50
|
SeasonReader = SportDb::SeasonReader
|
51
51
|
LeagueReader = SportDb::LeagueReader
|
52
52
|
EventReader = SportDb::EventReader
|
53
|
+
EventTableReader = SportDb::EventTableReader
|
53
54
|
GameReader = SportDb::GameReader
|
54
55
|
NationalTeamSquadReader = SportDb::NationalTeamSquadReader
|
55
56
|
ClubSquadReader = SportDb::ClubSquadReader
|
@@ -105,6 +106,13 @@ module TestEventReader
|
|
105
106
|
end
|
106
107
|
end
|
107
108
|
|
109
|
+
module TestEventTableReader
|
110
|
+
def self.from_file( name )
|
111
|
+
EventTableReader.from_file( "#{SportDb.test_data_path}/#{name}.txt" )
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
|
108
116
|
module TestGameReader
|
109
117
|
## NOTE: pass in .yml as path (that is, event config!!!!)
|
110
118
|
def self.from_file( name, more_attribs={} )
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
###
|
4
|
+
# to run use
|
5
|
+
# ruby -I ./lib -I ./test test/test_event_table_reader.rb
|
6
|
+
# or better
|
7
|
+
# rake -I ./lib test
|
8
|
+
|
9
|
+
|
10
|
+
require 'helper'
|
11
|
+
|
12
|
+
class TestEventTableReaderXX < MiniTest::Test # note: TestEventTableReader alreay defined, thus, add xx
|
13
|
+
|
14
|
+
def setup
|
15
|
+
WorldDb.delete!
|
16
|
+
SportDb.delete!
|
17
|
+
PersonDb.delete!
|
18
|
+
|
19
|
+
## setup österr. bundesliga
|
20
|
+
at = Country.create!( key: 'at', name: 'Austria', code: 'AUT', pop: 1, area: 1)
|
21
|
+
season = Season.create!( key: '2015/16', title: '2015/16' )
|
22
|
+
bl = League.create!( key: 'at', title: 'Österr. Bundesliga', club: true, country_id: at.id )
|
23
|
+
|
24
|
+
## read teams (required for db key lookup)
|
25
|
+
teamreader = TestTeamReader.from_file( 'at-austria/teams', country_id: at.id )
|
26
|
+
teamreader.read
|
27
|
+
teamreader = TestTeamReader.from_file( 'at-austria/teams_2', country_id: at.id )
|
28
|
+
teamreader.read
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_bl
|
32
|
+
r = TestEventTableReader.from_file( 'at-austria/2015_16/1-bundesliga.conf' )
|
33
|
+
r.read
|
34
|
+
|
35
|
+
assert true ## if we get here; assume everything ok
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_bl_v2
|
39
|
+
r = TestEventTableReader.from_file( 'at-austria/2015_16/1-bundesliga-v2.conf' )
|
40
|
+
r.read
|
41
|
+
|
42
|
+
assert true ## if we get here; assume everything ok
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
### fix/todo:
|
47
|
+
## to be done - add support for Wiener Sportklub (RL Ost) => Wiener Sportklub lookups
|
48
|
+
def xxxx_test_cup
|
49
|
+
at = Country.create!( key: 'at', name: 'Austria', code: 'AUT', pop: 1, area: 1)
|
50
|
+
season = Season.create!( key: '2015/16', title: '2015/16' )
|
51
|
+
cup = League.create!( key: 'at.cup', title: 'Cup', club: true, country_id: at.id )
|
52
|
+
|
53
|
+
r = TestEventReader.from_file( 'at-austria/2015_16/cup' )
|
54
|
+
r.read
|
55
|
+
|
56
|
+
assert true ## if we get here; assume everything ok
|
57
|
+
end
|
58
|
+
|
59
|
+
end # class TestEventReader
|
60
|
+
|
61
|
+
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sportdb-models
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.15.
|
4
|
+
version: 1.15.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gerald Bauer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-12-
|
11
|
+
date: 2015-12-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: worlddb-models
|
@@ -135,6 +135,7 @@ files:
|
|
135
135
|
- lib/sportdb/reader_zip.rb
|
136
136
|
- lib/sportdb/readers/assoc.rb
|
137
137
|
- lib/sportdb/readers/event.rb
|
138
|
+
- lib/sportdb/readers/event_table.rb
|
138
139
|
- lib/sportdb/readers/game.rb
|
139
140
|
- lib/sportdb/readers/ground.rb
|
140
141
|
- lib/sportdb/readers/league.rb
|
@@ -164,7 +165,9 @@ files:
|
|
164
165
|
- test/data/at-austria/2013_14/squads/salzburg.txt
|
165
166
|
- test/data/at-austria/2014_15/1-bundesliga-ii.txt
|
166
167
|
- test/data/at-austria/2014_15/1-bundesliga.yml
|
168
|
+
- test/data/at-austria/2015_16/1-bundesliga-v2.conf.txt
|
167
169
|
- test/data/at-austria/2015_16/1-bundesliga-v2.yml
|
170
|
+
- test/data/at-austria/2015_16/1-bundesliga.conf.txt
|
168
171
|
- test/data/at-austria/2015_16/1-bundesliga.yml
|
169
172
|
- test/data/at-austria/2015_16/cup.yml
|
170
173
|
- test/data/at-austria/leagues.txt
|
@@ -219,6 +222,7 @@ files:
|
|
219
222
|
- test/test_cursor.rb
|
220
223
|
- test/test_date.rb
|
221
224
|
- test/test_event_reader.rb
|
225
|
+
- test/test_event_table_reader.rb
|
222
226
|
- test/test_goals.rb
|
223
227
|
- test/test_lang.rb
|
224
228
|
- test/test_load.rb
|