sportdb 1.9.8 → 1.9.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Manifest.txt +2 -0
- data/lib/sportdb.rb +6 -1
- data/lib/sportdb/reader.rb +33 -43
- data/lib/sportdb/reader_file.rb +123 -0
- data/lib/sportdb/reader_zip.rb +12 -0
- data/lib/sportdb/readers/assoc.rb +19 -6
- data/lib/sportdb/readers/event.rb +28 -33
- data/lib/sportdb/readers/game.rb +60 -48
- data/lib/sportdb/readers/ground.rb +18 -4
- data/lib/sportdb/readers/league.rb +21 -5
- data/lib/sportdb/readers/season.rb +19 -6
- data/lib/sportdb/readers/squad_club.rb +24 -23
- data/lib/sportdb/readers/squad_national_team.rb +23 -23
- data/lib/sportdb/readers/team.rb +18 -5
- data/lib/sportdb/version.rb +1 -1
- data/test/helper.rb +54 -1
- data/test/test_assoc_reader.rb +12 -10
- data/test/test_changes.rb +1 -1
- data/test/test_cursor.rb +1 -1
- data/test/test_date.rb +1 -1
- data/test/test_goals.rb +9 -9
- data/test/test_lang.rb +1 -1
- data/test/test_load.rb +5 -5
- data/test/test_reader.rb +18 -16
- data/test/test_reader_from_string.rb +17 -11
- data/test/test_round_auto.rb +37 -37
- data/test/test_round_def.rb +1 -1
- data/test/test_round_header.rb +1 -1
- data/test/test_scores.rb +1 -1
- data/test/test_squad_club_reader.rb +15 -15
- data/test/test_squad_national_team_reader.rb +22 -22
- data/test/test_standings.rb +9 -9
- data/test/test_standings_ii.rb +8 -8
- data/test/test_utils.rb +1 -1
- data/test/test_winner.rb +1 -1
- metadata +126 -82
data/lib/sportdb/readers/game.rb
CHANGED
@@ -17,37 +17,78 @@ class GameReader
|
|
17
17
|
include FixtureHelpers
|
18
18
|
|
19
19
|
|
20
|
-
|
20
|
+
def self.from_zip( zip_file, entry_path, more_attribs={} )
|
21
|
+
## to be done
|
22
|
+
end
|
21
23
|
|
24
|
+
def self.from_file( path, more_attribs={} )
|
22
25
|
|
23
|
-
|
24
|
-
@include_path = include_path
|
25
|
-
end
|
26
|
+
logger = LogKernel::Logger.root
|
26
27
|
|
28
|
+
### NOTE: fix-fix-fix - pass in event path!!!!!!! (not fixture path!!!!)
|
29
|
+
|
30
|
+
## - ## note: assume/enfore utf-8 encoding (with or without BOM - byte order mark)
|
31
|
+
## - ## - see textutils/utils.rb
|
32
|
+
## - text = File.read_utf8( path )
|
27
33
|
|
28
|
-
|
29
|
-
reader
|
30
|
-
reader.read( name )
|
34
|
+
reader = EventReader.from_file( path )
|
35
|
+
reader.read()
|
31
36
|
|
32
37
|
event = reader.event ## was fetch_event( name )
|
33
38
|
fixtures = reader.fixtures ## was fetch_event_fixtures( name )
|
34
39
|
|
35
|
-
## reset cached values
|
36
|
-
## for auto-number rounds etc.
|
37
|
-
@last_round_pos = nil
|
38
40
|
|
39
|
-
fixtures.
|
40
|
-
|
41
|
+
if fixtures.empty?
|
42
|
+
## logger.warn "no fixtures found for event - >#{name}<; assume fixture name is the same as event"
|
43
|
+
## change extension from .yml to .txt
|
44
|
+
fixtures_with_path = [ path.sub('.yml','.txt') ]
|
45
|
+
else
|
46
|
+
## add path to fixtures (use path from event e.g)
|
47
|
+
# - bl + at-austria!/2012_13/bl -> at-austria!/2012_13/bl
|
48
|
+
# - bl_ii + at-austria!/2012_13/bl -> at-austria!/2012_13/bl_ii
|
49
|
+
|
50
|
+
dir = File.dirname( path ) # use dir for fixtures
|
51
|
+
|
52
|
+
fixtures_with_path = fixtures.map do |fx|
|
53
|
+
fx_new = "#{dir}/#{fx}.txt" # add path upfront
|
54
|
+
logger.debug "fx: #{fx_new} | >#{fx}< + >#{dir}<"
|
55
|
+
fx_new
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
## fix-fix-fix: change file extension to ??
|
60
|
+
text_ary = []
|
61
|
+
fixtures_with_path.each do |fixture_path|
|
62
|
+
text_ary << File.read_utf8( fixture_path )
|
41
63
|
end
|
64
|
+
|
65
|
+
self.from_string( event, text_ary, more_attribs )
|
42
66
|
end
|
43
67
|
|
44
68
|
|
45
|
-
def
|
69
|
+
def self.from_string( event, text_or_text_ary, more_attribs={} )
|
70
|
+
### fix - fix -fix:
|
71
|
+
## change event to event_or_event_key !!!!! - allow event_key as string passed in
|
72
|
+
GameReader.new( event, text_or_text_ary, more_attribs )
|
73
|
+
end
|
74
|
+
|
75
|
+
|
76
|
+
def initialize( event, text_or_text_ary, more_attribs={} )
|
77
|
+
### fix - fix -fix:
|
78
|
+
## change event to event_or_event_key !!!!! - allow event_key as string passed in
|
79
|
+
|
80
|
+
## todo/fix: how to add opts={} ???
|
81
|
+
@event = event
|
82
|
+
@text_or_text_ary = text_or_text_ary
|
83
|
+
@more_attribs = more_attribs
|
84
|
+
end
|
85
|
+
|
46
86
|
|
47
|
-
|
48
|
-
|
87
|
+
def read()
|
88
|
+
if @text_or_text_ary.is_a?( String )
|
89
|
+
text_ary = [@text_or_text_ary]
|
49
90
|
else
|
50
|
-
text_ary = text_or_text_ary
|
91
|
+
text_ary = @text_or_text_ary
|
51
92
|
end
|
52
93
|
|
53
94
|
## reset cached values
|
@@ -59,10 +100,9 @@ class GameReader
|
|
59
100
|
## fix (cache) store lang in event table (e.g. auto-add and auto-update)!!!
|
60
101
|
SportDb.lang.lang = SportDb.lang.classify( text )
|
61
102
|
|
62
|
-
|
63
|
-
reader = StringLineReader.new( text )
|
103
|
+
reader = LineReader.from_string( text )
|
64
104
|
|
65
|
-
|
105
|
+
read_fixtures_worker( @event.key, reader )
|
66
106
|
end
|
67
107
|
|
68
108
|
## fix add prop ??
|
@@ -70,35 +110,7 @@ class GameReader
|
|
70
110
|
end
|
71
111
|
|
72
112
|
|
73
|
-
def
|
74
|
-
|
75
|
-
## todo: move name_real_path code to LineReaderV2 ????
|
76
|
-
pos = name.index( '!/')
|
77
|
-
if pos.nil?
|
78
|
-
name_real_path = name # not found; real path is the same as name
|
79
|
-
else
|
80
|
-
# cut off everything until !/ e.g.
|
81
|
-
# at-austria!/w-wien/beers becomes
|
82
|
-
# w-wien/beers
|
83
|
-
name_real_path = name[ (pos+2)..-1 ]
|
84
|
-
end
|
85
|
-
|
86
|
-
|
87
|
-
path = "#{include_path}/#{name_real_path}.txt"
|
88
|
-
|
89
|
-
logger.info "parsing data '#{name}' (#{path})..."
|
90
|
-
|
91
|
-
SportDb.lang.lang = SportDb.lang.classify_file( path )
|
92
|
-
|
93
|
-
reader = LineReader.new( path )
|
94
|
-
|
95
|
-
load_fixtures_worker( event_key, reader )
|
96
|
-
|
97
|
-
Prop.create_from_fixture!( name, path )
|
98
|
-
end
|
99
|
-
|
100
|
-
|
101
|
-
def load_fixtures_worker( event_key, reader )
|
113
|
+
def read_fixtures_worker( event_key, reader )
|
102
114
|
## NB: assume active activerecord connection
|
103
115
|
|
104
116
|
## reset cached values
|
@@ -11,17 +11,31 @@ class GroundReader
|
|
11
11
|
# e.g. lets you use Usage instead of Model::Usage
|
12
12
|
include Models
|
13
13
|
|
14
|
+
def self.from_zip( zip_file, entry_path, more_attribs={} )
|
15
|
+
## to be done
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.from_file( path, more_attribs={} )
|
19
|
+
## note: assume/enfore utf-8 encoding (with or without BOM - byte order mark)
|
20
|
+
## - see textutils/utils.rb
|
21
|
+
text = File.read_utf8( path )
|
22
|
+
self.from_string( text, more_attribs )
|
23
|
+
end
|
14
24
|
|
15
|
-
|
25
|
+
def self.from_string( text, more_attribs={} )
|
26
|
+
GroundReader.new( text, more_attribs )
|
27
|
+
end
|
16
28
|
|
17
29
|
|
18
|
-
def initialize(
|
19
|
-
|
30
|
+
def initialize( text, more_attribs={} )
|
31
|
+
## todo/fix: how to add opts={} ???
|
32
|
+
@text = text
|
33
|
+
@more_attribs = more_attribs
|
20
34
|
end
|
21
35
|
|
22
36
|
|
23
37
|
def read( name, more_attribs={} )
|
24
|
-
reader =
|
38
|
+
reader = ValuesReader.from_string( @text, @more_attribs )
|
25
39
|
|
26
40
|
reader.each_line do |new_attributes, values|
|
27
41
|
Ground.create_or_update_from_values( new_attributes, values )
|
@@ -11,16 +11,32 @@ class LeagueReader
|
|
11
11
|
# e.g. lets you use Usage instead of Model::Usage
|
12
12
|
include Models
|
13
13
|
|
14
|
-
|
14
|
+
|
15
|
+
def self.from_zip( zip_file, entry_path, more_attribs={} )
|
16
|
+
## to be done
|
17
|
+
end
|
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
|
+
self.from_string( text, more_attribs )
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.from_string( text, more_attribs={} )
|
27
|
+
LeagueReader.new( text, more_attribs )
|
28
|
+
end
|
15
29
|
|
16
30
|
|
17
|
-
def initialize(
|
18
|
-
|
31
|
+
def initialize( text, more_attribs={} )
|
32
|
+
## todo/fix: how to add opts={} ???
|
33
|
+
@text = text
|
34
|
+
@more_attribs = more_attribs
|
19
35
|
end
|
20
36
|
|
21
37
|
|
22
|
-
def read(
|
23
|
-
reader =
|
38
|
+
def read()
|
39
|
+
reader = ValuesReader.from_string( @text, @more_attribs )
|
24
40
|
|
25
41
|
reader.each_line do |new_attributes, values|
|
26
42
|
League.create_or_update_from_values( new_attributes, values )
|
@@ -12,16 +12,29 @@ class SeasonReader
|
|
12
12
|
include Models
|
13
13
|
|
14
14
|
|
15
|
-
|
16
|
-
|
15
|
+
def self.from_zip( zip_file, entry_path )
|
16
|
+
## to be done
|
17
|
+
end
|
17
18
|
|
18
|
-
def
|
19
|
-
|
19
|
+
def self.from_file( path )
|
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
|
+
self.from_string( text )
|
20
24
|
end
|
21
25
|
|
26
|
+
def self.from_string( text )
|
27
|
+
SeasonReader.new( text )
|
28
|
+
end
|
29
|
+
|
30
|
+
|
31
|
+
def initialize( text )
|
32
|
+
## todo/fix: how to add opts={} ???
|
33
|
+
@text = text
|
34
|
+
end
|
22
35
|
|
23
|
-
def read(
|
24
|
-
reader =
|
36
|
+
def read()
|
37
|
+
reader = LineReader.from_string( @text )
|
25
38
|
|
26
39
|
####
|
27
40
|
## fix!!!!!
|
@@ -22,39 +22,40 @@ class ClubSquadReader
|
|
22
22
|
include FixtureHelpers
|
23
23
|
|
24
24
|
|
25
|
-
|
26
|
-
|
25
|
+
def self.from_zip( zip_file, entry_path, more_attribs={} )
|
26
|
+
## to be done
|
27
|
+
end
|
27
28
|
|
28
|
-
def
|
29
|
-
|
29
|
+
def self.from_file( path, more_attribs={} )
|
30
|
+
## note: assume/enfore utf-8 encoding (with or without BOM - byte order mark)
|
31
|
+
## - see textutils/utils.rb
|
32
|
+
text = File.read_utf8( path )
|
33
|
+
self.from_string( text, more_attribs )
|
30
34
|
end
|
31
35
|
|
36
|
+
def self.from_string( text, more_attribs={} )
|
37
|
+
ClubSquadReader.new( text, more_attribs )
|
38
|
+
end
|
32
39
|
|
33
|
-
def read( name, more_attribs={} )
|
34
|
-
## note:
|
35
|
-
# event_id and team_id required!!
|
36
40
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
# at-austria!/w-wien/beers becomes
|
44
|
-
# w-wien/beers
|
45
|
-
name_real_path = name[ (pos+2)..-1 ]
|
46
|
-
end
|
41
|
+
def initialize( text, more_attribs={} )
|
42
|
+
## todo/fix: how to add opts={} ???
|
43
|
+
@text = text
|
44
|
+
@more_attribs = more_attribs
|
45
|
+
end
|
46
|
+
|
47
47
|
|
48
|
-
path = "#{include_path}/#{name_real_path}.txt"
|
49
48
|
|
50
|
-
|
49
|
+
def read()
|
50
|
+
## note:
|
51
|
+
# event_id and team_id required!!
|
51
52
|
|
52
53
|
# event
|
53
|
-
@event = Event.find( more_attribs[:event_id] )
|
54
|
+
@event = Event.find( @more_attribs[:event_id] )
|
54
55
|
pp @event
|
55
56
|
|
56
57
|
## note: use @team - share/use in worker method
|
57
|
-
@team = Team.find( more_attribs[:team_id] )
|
58
|
+
@team = Team.find( @more_attribs[:team_id] )
|
58
59
|
pp @team
|
59
60
|
|
60
61
|
### SportDb.lang.lang = LangChecker.new.analyze( name, include_path )
|
@@ -62,11 +63,11 @@ class ClubSquadReader
|
|
62
63
|
## mapping tables for persons per country (indexed by country code); reset
|
63
64
|
@country_persons_cache = {}
|
64
65
|
|
65
|
-
reader = LineReader.
|
66
|
+
reader = LineReader.from_string( @text )
|
66
67
|
|
67
68
|
read_worker( reader )
|
68
69
|
|
69
|
-
Prop.create_from_fixture!( name, path )
|
70
|
+
## Prop.create_from_fixture!( name, path )
|
70
71
|
end
|
71
72
|
|
72
73
|
|
@@ -19,44 +19,44 @@ class NationalTeamSquadReader
|
|
19
19
|
include FixtureHelpers
|
20
20
|
|
21
21
|
|
22
|
-
|
23
|
-
|
22
|
+
def self.from_zip( zip_file, entry_path, more_attribs={} )
|
23
|
+
## to be done
|
24
|
+
end
|
24
25
|
|
25
|
-
def
|
26
|
-
|
26
|
+
def self.from_file( path, more_attribs={} )
|
27
|
+
## note: assume/enfore utf-8 encoding (with or without BOM - byte order mark)
|
28
|
+
## - see textutils/utils.rb
|
29
|
+
text = File.read_utf8( path )
|
30
|
+
self.from_string( text, more_attribs )
|
27
31
|
end
|
28
32
|
|
33
|
+
def self.from_string( text, more_attribs={} )
|
34
|
+
NationalTeamSquadReader.new( text, more_attribs )
|
35
|
+
end
|
29
36
|
|
30
|
-
def read( name, more_attribs={} )
|
31
|
-
## note:
|
32
|
-
# event_id and team_id required!!
|
33
37
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
# cut off everything until !/ e.g.
|
40
|
-
# at-austria!/w-wien/beers becomes
|
41
|
-
# w-wien/beers
|
42
|
-
name_real_path = name[ (pos+2)..-1 ]
|
43
|
-
end
|
38
|
+
def initialize( text, more_attribs={} )
|
39
|
+
## todo/fix: how to add opts={} ???
|
40
|
+
@text = text
|
41
|
+
@more_attribs = more_attribs
|
42
|
+
end
|
44
43
|
|
45
|
-
path = "#{include_path}/#{name_real_path}.txt"
|
46
44
|
|
47
|
-
|
45
|
+
def read()
|
46
|
+
## note:
|
47
|
+
# event_id and team_id required!!
|
48
48
|
|
49
49
|
# event
|
50
|
-
@event = Event.find( more_attribs[:event_id] )
|
50
|
+
@event = Event.find( @more_attribs[:event_id] )
|
51
51
|
pp @event
|
52
52
|
|
53
53
|
## note: use @team - share/use in worker method
|
54
|
-
@team = Team.find( more_attribs[:team_id] )
|
54
|
+
@team = Team.find( @more_attribs[:team_id] )
|
55
55
|
pp @team
|
56
56
|
|
57
57
|
### SportDb.lang.lang = LangChecker.new.analyze( name, include_path )
|
58
58
|
|
59
|
-
reader = LineReader.
|
59
|
+
reader = LineReader.from_string( @text )
|
60
60
|
|
61
61
|
|
62
62
|
##########
|
@@ -71,7 +71,7 @@ class NationalTeamSquadReader
|
|
71
71
|
|
72
72
|
read_worker( reader )
|
73
73
|
|
74
|
-
Prop.create_from_fixture!( name, path )
|
74
|
+
## Prop.create_from_fixture!( name, path )
|
75
75
|
end
|
76
76
|
|
77
77
|
|
data/lib/sportdb/readers/team.rb
CHANGED
@@ -11,17 +11,30 @@ class TeamReader
|
|
11
11
|
# e.g. lets you use Usage instead of Model::Usage
|
12
12
|
include Models
|
13
13
|
|
14
|
+
def self.from_zip( zip_file, entry_path, more_attribs={} )
|
15
|
+
## to be done
|
16
|
+
end
|
14
17
|
|
15
|
-
|
18
|
+
def self.from_file( path, more_attribs={} )
|
19
|
+
## note: assume/enfore utf-8 encoding (with or without BOM - byte order mark)
|
20
|
+
## - see textutils/utils.rb
|
21
|
+
text = File.read_utf8( path )
|
22
|
+
self.from_string( text, more_attribs )
|
23
|
+
end
|
16
24
|
|
25
|
+
def self.from_string( text, more_attribs={} )
|
26
|
+
TeamReader.new( text, more_attribs )
|
27
|
+
end
|
17
28
|
|
18
|
-
def initialize(
|
19
|
-
|
29
|
+
def initialize( text, more_attribs={} )
|
30
|
+
## todo/fix: how to add opts={} ???
|
31
|
+
@text = text
|
32
|
+
@more_attribs = more_attribs
|
20
33
|
end
|
21
34
|
|
22
35
|
|
23
|
-
def read(
|
24
|
-
reader =
|
36
|
+
def read()
|
37
|
+
reader = ValuesReader.from_string( @text, @more_attribs )
|
25
38
|
|
26
39
|
reader.each_line do |new_attributes, values|
|
27
40
|
Team.create_or_update_from_values( new_attributes, values )
|