sportdb 1.9.8 → 1.9.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c13885608b50ec48f29c56dc3429313008d3461c
4
+ data.tar.gz: 04a9877e31779ca9d2d0a6487798a9c3bd12064c
5
+ SHA512:
6
+ metadata.gz: 7f1d24676dd2a3eeb115b508fc63def91b9384720d64f74ce6ab2f8ef7252b4c0d6db83829ad78d6c917f0fd9fa8ef83943983da78ddfde5d95526bd51853218
7
+ data.tar.gz: 2741036308c8e6491867c3967a4e9c741fff68df5bec4b6c5051e1de66109ded0a187ca84f54dd5a92e0bebbcfb3063c491bfe179afd72ccc19929608d5603b6
@@ -54,6 +54,8 @@ lib/sportdb/models/world/country.rb
54
54
  lib/sportdb/models/world/region.rb
55
55
  lib/sportdb/patterns.rb
56
56
  lib/sportdb/reader.rb
57
+ lib/sportdb/reader_file.rb
58
+ lib/sportdb/reader_zip.rb
57
59
  lib/sportdb/readers/assoc.rb
58
60
  lib/sportdb/readers/event.rb
59
61
  lib/sportdb/readers/game.rb
@@ -99,6 +99,8 @@ require 'sportdb/readers/squad_club' # roster
99
99
  require 'sportdb/readers/squad_national_team'
100
100
  require 'sportdb/readers/team'
101
101
  require 'sportdb/reader'
102
+ require 'sportdb/reader_file'
103
+ require 'sportdb/reader_zip'
102
104
 
103
105
 
104
106
 
@@ -232,9 +234,12 @@ end # module SportDb
232
234
  #####
233
235
  # auto-load/require some addons
234
236
 
237
+ ## puts 'before auto-load (require) sportdb addons'
238
+ ## puts ' before sportdb/update'
235
239
  require 'sportdb/update'
240
+ ## puts ' before sportdb/service'
236
241
  require 'sportdb/service'
237
-
242
+ ## puts 'after auto-load (require) sportdb addons'
238
243
 
239
244
 
240
245
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  module SportDb
4
4
 
5
- class Reader
5
+ class ReaderBase
6
6
 
7
7
  include LogUtils::Logging
8
8
 
@@ -13,18 +13,8 @@ class Reader
13
13
  include SportDb::Matcher # lets us use match_teams_for_country etc.
14
14
 
15
15
 
16
- attr_reader :include_path
17
-
18
- def initialize( include_path, opts={})
19
- @include_path = include_path
20
- end
21
-
22
16
  def load_setup( name )
23
- path = "#{include_path}/#{name}.txt"
24
-
25
- logger.info "parsing data '#{name}' (#{path})..."
26
-
27
- reader = FixtureReader.new( path )
17
+ reader = create_fixture_reader( name )
28
18
 
29
19
  reader.each do |fixture_name|
30
20
  load( fixture_name )
@@ -34,20 +24,20 @@ class Reader
34
24
 
35
25
  def load( name ) # convenience helper for all-in-one reader
36
26
 
37
- logger.debug "enter load( name=>>#{name}<<, include_path=>>#{include_path}<<)"
38
-
27
+ logger.debug "enter load( name=>>#{name}<<)" ## formerly also printed -> include_path=>>#{include_path}<<
39
28
 
40
29
  if match_players_for_country( name ) do |country_key|
41
- country = Country.find_by_key!( country_key )
42
- reader = PersonDb::PersonReader.new( include_path )
43
- reader.read( name, country_id: country.id )
30
+ ## country = Country.find_by_key!( country_key )
31
+ ## fix-fix-fix-fix-fix-fix: change to new format e.g. from_file, from_zip etc!!!
32
+ ## reader = PersonDb::PersonReader.new( include_path )
33
+ ## reader.read( name, country_id: country.id )
44
34
  end
45
35
  elsif name =~ /\/squads\/([a-z0-9]{3,})$/ # e.g. ajax.txt bayern.txt etc.
46
36
  ## note: for now assume club (e.g. no dash (-) allowed for country code e.g. br-brazil etc.)
47
37
  team = Team.find_by_key!( $1 )
48
38
  ## note: pass in @event.id - that is, last seen event (e.g. parsed via GameReader/MatchReader)
49
- reader = ClubSquadReader.new( include_path )
50
- reader.read( name, team_id: team.id, event_id: @event.id )
39
+ reader = create_club_squad_reader( name, team_id: team.id, event_id: @event.id )
40
+ reader.read()
51
41
  elsif name =~ /\/squads\/([a-z]{2,3})-[^\/]+$/
52
42
  ## fix: add to country matcher new format
53
43
  ## name is country! and parent folder is type name e.g. /squads/br-brazil
@@ -70,65 +60,65 @@ class Reader
70
60
  team = Team.find_by_key!( $1 )
71
61
  end
72
62
  ## note: pass in @event.id - that is, last seen event (e.g. parsed via GameReader/MatchReader)
73
- reader = NationalTeamSquadReader.new( include_path )
74
- reader.read( name, team_id: team.id, event_id: @event.id )
63
+ reader = create_national_team_squad_reader( name, team_id: team.id, event_id: @event.id )
64
+ reader.read()
75
65
  elsif name =~ /(?:^|\/)seasons/ # NB: ^seasons or also possible at-austria!/seasons
76
- reader = SeasonReader.new( include_path )
77
- reader.read( name )
66
+ reader = create_season_reader( name )
67
+ reader.read()
78
68
  elsif name =~ /(?:^|\/)assocs/ # NB: ^assocs or also possible national-teams!/assocs
79
- reader = AssocReader.new( include_path )
80
- reader.read( name )
69
+ reader = create_assoc_reader( name )
70
+ reader.read()
81
71
  elsif match_stadiums_for_country( name ) do |country_key|
82
72
  country = Country.find_by_key!( country_key )
83
- reader = GroundReader.new( include_path )
84
- reader.read( name, country_id: country.id )
73
+ reader = create_ground_reader( name, country_id: country.id )
74
+ reader.read()
85
75
  end
86
76
  elsif match_leagues_for_country( name ) do |country_key| # name =~ /^([a-z]{2})\/leagues/
87
77
  # auto-add country code (from folder structure) for country-specific leagues
88
78
  # e.g. at/leagues
89
79
  country = Country.find_by_key!( country_key )
90
- reader = LeagueReader.new( include_path )
91
- reader.read( name, club: true, country_id: country.id )
80
+ reader = create_league_reader( name, club: true, country_id: country.id )
81
+ reader.read()
92
82
  end
93
83
  elsif name =~ /(?:^|\/)leagues/ # NB: ^leagues or also possible world!/leagues - NB: make sure goes after leagues_for_country!!
94
- reader = LeagueReader.new( include_path )
95
- reader.read( name )
84
+ reader = create_league_reader( name )
85
+ reader.read()
96
86
  elsif match_teams_for_country( name ) do |country_key| # name =~ /^([a-z]{2})\/teams/
97
87
  # auto-add country code (from folder structure) for country-specific teams
98
88
  # e.g. at/teams at/teams.2 de/teams etc.
99
89
  country = Country.find_by_key!( country_key )
100
- reader = TeamReader.new( include_path )
101
- reader.read( name, country_id: country.id )
90
+ reader = create_team_reader( name, country_id: country.id )
91
+ reader.read()
102
92
  end
103
93
  elsif match_clubs_for_country( name ) do |country_key| # name =~ /^([a-z]{2})\/clubs/
104
94
  # auto-add country code (from folder structure) for country-specific clubs
105
95
  # e.g. at/teams at/teams.2 de/teams etc.
106
96
  country = Country.find_by_key!( country_key )
107
- reader = TeamReader.new( include_path )
108
- reader.read( name, club: true, country_id: country.id ) ## note: always sets club flag to true
97
+ reader = create_team_reader( name, club: true, country_id: country.id ) ## note: always sets club flag to true
98
+ reader.read()
109
99
  end
110
100
  elsif name =~ /(?:^|\/)teams/ ## fix: check if teams rule above (e.g. /^teams/ )conflicts/matches first ???
111
101
  ### fix: use new NationalTeamReader ??? why? why not?
112
- reader = TeamReader.new( include_path )
113
- reader.read( name ) ## note: always sets club flag to true / national to true
102
+ reader = create_team_reader( name ) ## note: always sets club flag to true / national to true
103
+ reader.read()
114
104
  elsif name =~ /(?:^|\/)clubs/
115
105
  ### fix: use new ClubReader ??? why? why not?
116
- reader = TeamReader.new( include_path )
117
- reader.read( name, club: true ) ## note: always sets club flag to true / national to false
106
+ reader = create_team_reader( name, club: true ) ## note: always sets club flag to true / national to false
107
+ reader.read()
118
108
  elsif name =~ /\/(\d{4}|\d{4}[_\-]\d{2})(--[^\/]+)?\// ||
119
109
  name =~ /\/(\d{4}|\d{4}[_\-]\d{2})$/
120
110
 
121
111
  # note: allow 2013_14 or 2013-14 (that, is dash or underscore)
122
112
 
123
113
  # note: keep a "public" reference of last event in @event - e.g. used/required by squads etc.
124
- eventreader = EventReader.new( include_path )
125
- eventreader.read( name )
114
+ eventreader = create_event_reader( name )
115
+ eventreader.read()
126
116
  @event = eventreader.event
127
117
 
128
118
  # e.g. must match /2012/ or /2012_13/ or /2012--xxx/ or /2012_13--xx/
129
119
  # or /2012 or /2012_13 e.g. brazil/2012 or brazil/2012_13
130
- reader = GameReader.new( include_path )
131
- reader.read( name )
120
+ reader = create_game_reader( name )
121
+ reader.read()
132
122
  else
133
123
  logger.error "unknown sportdb fixture type >#{name}<"
134
124
  # todo/fix: exit w/ error
@@ -0,0 +1,123 @@
1
+ # encoding: utf-8
2
+
3
+ module SportDb
4
+
5
+ ## todo: "old" classic reader - rename to FileReader ?? why? why not?
6
+
7
+ class Reader < ReaderBase
8
+
9
+ attr_reader :include_path
10
+
11
+ def initialize( include_path, opts={})
12
+ @include_path = include_path
13
+ end
14
+
15
+ def create_fixture_reader( name )
16
+ path = "#{@include_path}/#{name}.txt"
17
+
18
+ logger.info "parsing data (setup) '#{name}' (#{path})..."
19
+
20
+ FixtureReader.from_file( path )
21
+ end
22
+
23
+ def create_club_squad_reader( name, more_attribs={} )
24
+ real_name = name_to_real_name( name )
25
+ path = "#{@include_path}/#{real_name}.txt"
26
+
27
+ logger.info "parsing data (club squad) '#{name}' (#{path})..."
28
+ ClubSquadReader.from_file( path, more_attribs )
29
+ end
30
+
31
+ def create_national_team_squad_reader( name, more_attribs={} )
32
+ real_name = name_to_real_name( name )
33
+ path = "#{@include_path}/#{real_name}.txt"
34
+
35
+ logger.info "parsing data (national team squad) '#{name}' (#{path})..."
36
+ NationalTeamSquadReader.from_file( path, more_attribs )
37
+ end
38
+
39
+ def create_season_reader( name )
40
+ real_name = name_to_real_name( name )
41
+ path = "#{@include_path}/#{real_name}.txt"
42
+
43
+ logger.info "parsing data (season) '#{name}' (#{path})..."
44
+ SeasonReader.from_file( path )
45
+ end
46
+
47
+ def create_assoc_reader( name )
48
+ real_name = name_to_real_name( name )
49
+ path = "#{@include_path}/#{real_name}.txt"
50
+
51
+ logger.info "parsing data (assoc) '#{name}' (#{path})..."
52
+ AssocReader.from_file( path )
53
+ end
54
+
55
+ def create_ground_reader( name, more_attribs={} )
56
+ real_name = name_to_real_name( name )
57
+ path = "#{@include_path}/#{real_name}.txt"
58
+
59
+ logger.info "parsing data (ground) '#{name}' (#{path})..."
60
+ GroundReader.from_file( path, more_attribs )
61
+ end
62
+
63
+ def create_league_reader( name, more_attribs={} )
64
+ real_name = name_to_real_name( name )
65
+ path = "#{@include_path}/#{real_name}.txt"
66
+
67
+ logger.info "parsing data (league) '#{name}' (#{path})..."
68
+ LeagueReader.from_file( path, more_attribs )
69
+ end
70
+
71
+ def create_team_reader( name, more_attribs={} )
72
+ real_name = name_to_real_name( name )
73
+ path = "#{@include_path}/#{real_name}.txt"
74
+
75
+ logger.info "parsing data (team) '#{name}' (#{path})..."
76
+ TeamReader.from_file( path, more_attribs )
77
+ end
78
+
79
+ def create_event_reader( name, more_attribs={} )
80
+ real_name = name_to_real_name( name )
81
+ path = "#{@include_path}/#{real_name}.yml"
82
+
83
+ logger.info "parsing data (event) '#{name}' (#{path})..."
84
+ EventReader.from_file( path, more_attribs )
85
+ end
86
+
87
+ def create_game_reader( name, more_attribs={} )
88
+ real_name = name_to_real_name( name )
89
+
90
+ ## NOTE: pass in .yml as path (that is, event config!!!!)
91
+ path = "#{@include_path}/#{real_name}.yml"
92
+
93
+ logger.info "parsing data (fixture) '#{name}' (#{path})..."
94
+ GameReader.from_file( path, more_attribs )
95
+ end
96
+
97
+
98
+ def create_person_reader( name, more_attribs={} )
99
+ ## fix-fix-fix: change to new format e.g. from_file, from_zip etc!!!
100
+ ## reader = PersonDb::PersonReader.new( include_path )
101
+ # reader.read( name, country_id: country.id )
102
+ end
103
+
104
+ private
105
+
106
+ def name_to_real_name( name )
107
+ # map name to real_name path
108
+ # name might include !/ for virtual path (gets cut off)
109
+ # e.g. at-austria!/w-wien/beers becomse w-wien/beers
110
+ pos = name.index( '!/')
111
+ if pos.nil?
112
+ name # not found; real path is the same as name
113
+ else
114
+ # cut off everything until !/ e.g.
115
+ # at-austria!/w-wien/beers becomes
116
+ # w-wien/beers
117
+ name[ (pos+2)..-1 ]
118
+ end
119
+ end # method name_to_real_name
120
+
121
+
122
+ end # class Reader
123
+ end # module SportDb
@@ -0,0 +1,12 @@
1
+ # encoding: utf-8
2
+
3
+ module SportDb
4
+
5
+
6
+ class ZipReader < ReaderBase
7
+
8
+
9
+
10
+ end # class ZipReader
11
+
12
+ end # module SportDb
@@ -11,17 +11,31 @@ class AssocReader
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
- attr_reader :include_path
25
+ def self.from_string( text, more_attribs={} )
26
+ AssocReader.new( text, more_attribs )
27
+ end
16
28
 
17
29
 
18
- def initialize( include_path, opts = {} )
19
- @include_path = include_path
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
- def read( name, more_attribs={} )
24
- reader = ValuesReaderV2.new( name, include_path, more_attribs )
37
+ def read()
38
+ reader = ValuesReader.from_string( @text, @more_attribs )
25
39
 
26
40
  reader.each_line do |new_attributes, values|
27
41
  Assoc.create_or_update_from_values( new_attributes, values )
@@ -29,6 +43,5 @@ class AssocReader
29
43
  end
30
44
 
31
45
 
32
-
33
46
  end # class AssocReader
34
47
  end # module SportDb
@@ -11,48 +11,43 @@ class EventReader
11
11
  # e.g. lets you use Usage instead of Model::Usage
12
12
  include Models
13
13
 
14
-
15
- attr_reader :include_path
16
14
  attr_reader :event # returns event record; call read first
15
+ attr_reader :fixtures # fixtures/sources entry from event config
17
16
 
18
- def initialize( include_path, opts = {} )
19
- @include_path = include_path
20
-
21
- @name = nil
22
- @event = nil
23
- @fixtures = []
17
+ def self.from_zip( zip_file, entry_path, more_attribs={} )
18
+ ## to be done
24
19
  end
25
20
 
21
+ def self.from_file( path, more_attribs={} )
22
+ ## note: assume/enfore utf-8 encoding (with or without BOM - byte order mark)
23
+ ## - see textutils/utils.rb
24
+ text = File.read_utf8( path )
25
+
26
+ config = File.basename( name ) # name a of .yml file
27
+
28
+ self.from_string( text, config, more_attribs )
29
+ end
26
30
 
27
- def fixtures
28
- ## note: needs to call read first (to set @name, @fixtures, etc.)
29
-
30
- if @fixtures.empty?
31
- ## logger.warn "no fixtures found for event - >#{name}<; assume fixture name is the same as event"
32
- fixtures_with_path = [ @name ]
33
- else
34
- ## add path to fixtures (use path from event e.g)
35
- # - bl + at-austria!/2012_13/bl -> at-austria!/2012_13/bl
36
- # - bl_ii + at-austria!/2012_13/bl -> at-austria!/2012_13/bl_ii
31
+ def self.from_string( text, config, more_attribs={} )
32
+ EventReader.new( text, config, more_attribs )
33
+ end
37
34
 
38
- dir = File.dirname( @name ) # use dir for fixtures
35
+ def initialize( text, config, more_attribs={} )
36
+ ## todo/fix: how to add opts={} ???
37
+ @text = text
38
+ @more_attribs = more_attribs
39
39
 
40
- fixtures_with_path = @fixtures.map do |fx|
41
- fx_new = "#{dir}/#{fx}" # add path upfront
42
- logger.debug "fx: #{fx_new} | >#{fx}< + >#{dir}<"
43
- fx_new
44
- end
45
- end
40
+ @config = config # name of event configuration (relative basename w/o path or string)
41
+ @sources_default = config # note: use same a config for now
46
42
 
47
- fixtures_with_path
43
+ @event = nil
44
+ @fixtures = []
48
45
  end
49
46
 
50
47
 
51
-
52
- def read( name, more_attribs={} )
48
+ def read()
53
49
  @fixtures = [] # reset cached fixtures
54
50
  @event = nil # reset cached event rec
55
- @name = name # keep name (needed for fixtures attrib getter)
56
51
 
57
52
  ####
58
53
  ## fix!!!!!
@@ -60,17 +55,17 @@ class EventReader
60
55
  ## use Event.create_or_update_from_hash_reader?? or similar
61
56
  # move parsing code to model
62
57
 
63
- reader = HashReaderV2.new( name, include_path )
58
+ reader = HashReader.from_string( @text )
64
59
 
65
60
  event_attribs = {}
66
-
61
+
67
62
  ## set default sources to basename by convention
68
63
  # e.g 2013_14/bl => bl
69
64
  # etc.
70
65
  # use fixtures/sources: to override default
71
66
 
72
- event_attribs[ 'sources' ] = File.basename( name )
73
- event_attribs[ 'config' ] = File.basename( name ) # name a of .yml file
67
+ event_attribs[ 'sources' ] = @sources_default
68
+ event_attribs[ 'config' ] = @config # name a of .yml file
74
69
 
75
70
  reader.each_typed do |key, value|
76
71