sportdb 1.8.29 → 1.9.0

Sign up to get free protection for your applications and to get access to all the features.
data/Manifest.txt CHANGED
@@ -144,6 +144,7 @@ test/test_lang.rb
144
144
  test/test_load.rb
145
145
  test/test_national_team_reader.rb
146
146
  test/test_reader.rb
147
+ test/test_reader_from_string.rb
147
148
  test/test_round_auto.rb
148
149
  test/test_round_def.rb
149
150
  test/test_round_header.rb
@@ -34,7 +34,6 @@ class GameReader
34
34
 
35
35
  ## reset cached values
36
36
  ## for auto-number rounds etc.
37
-
38
37
  @last_round_pos = nil
39
38
 
40
39
  fixtures.each do |fixture|
@@ -43,16 +42,30 @@ class GameReader
43
42
  end
44
43
 
45
44
 
46
- def read_fixtures_from_string( event_key, text ) # load from string (e.g. passed in via web form)
45
+ def read_fixtures_from_string( event_key, text_or_text_ary ) # load from string (e.g. passed in via web form)
47
46
 
48
- SportDb.lang.lang = SportDb.lang.classify( text )
47
+ if text_or_text_ary.is_a?( String )
48
+ text_ary = [text_or_text_ary]
49
+ else
50
+ text_ary = text_or_text_ary
51
+ end
49
52
 
50
- ## todo/fix: move code into LineReader e.g. use LineReader.fromString() - why? why not?
51
- reader = StringLineReader.new( text )
52
-
53
- read_fixtures_worker( event_key, reader )
53
+ ## reset cached values
54
+ ## for auto-number rounds etc.
55
+ @last_round_pos = nil
56
+
57
+ text_ary.each do |text|
58
+ ## assume en for now? why? why not?
59
+ ## fix (cache) store lang in event table (e.g. auto-add and auto-update)!!!
60
+ SportDb.lang.lang = SportDb.lang.classify( text )
61
+
62
+ ## todo/fix: move code into LineReader e.g. use LineReader.fromString() - why? why not?
63
+ reader = StringLineReader.new( text )
64
+
65
+ load_fixtures_worker( event_key, reader )
66
+ end
54
67
 
55
- ## fix add prop
68
+ ## fix add prop ??
56
69
  ### Prop.create!( key: "db.#{fixture_name_to_prop_key(name)}.version", value: "file.txt.#{File.mtime(path).strftime('%Y.%m.%d')}" )
57
70
  end
58
71
 
@@ -8,7 +8,7 @@ module SportDb
8
8
  ######
9
9
  # NB: make models available in sportdb module by default with namespace
10
10
  # e.g. lets you use Team instead of Model::Team
11
- include SportDb::Models
11
+ include Models
12
12
 
13
13
 
14
14
  def map_event_to_dlurl( event )
@@ -17,10 +17,20 @@ module SportDb
17
17
  season_key = event.season.key
18
18
 
19
19
  repo_path, folder_path = map_key_to_repo_n_folder_path( league_key )
20
+
20
21
  return nil if repo_path.nil? # no match/mapping found; cancel download
21
22
 
22
23
  season_path = season_key.gsub( '/', '_') # convert 2013/14 to 2013_14
23
24
 
25
+ #####
26
+ # quick hack!!!!
27
+ # - find something better e.g. more generic/easy to configure etc.
28
+ if league_key == 'world' # world cup repo mappings include host country e.g. 2014--brazil etc.
29
+ season_path = '2006--germany' if season_path == '2006'
30
+ season_path = '2010--south-africa' if season_path == '2010'
31
+ season_path = '2014--brazil' if season_path == '2014'
32
+ end
33
+
24
34
  ###
25
35
  # e.g. https://raw.github.com/openfootball/at-austria/master/2013_14
26
36
 
@@ -35,22 +45,22 @@ module SportDb
35
45
 
36
46
  ### allow * for regex match w/ .+
37
47
  map = [
38
- [ 'at', 'at-austria' ],
39
- [ 'at.*', 'at-austria' ],
40
- [ 'de', 'de-deutschland' ],
41
- [ 'de.*', 'de-deutschland' ],
42
- [ 'en', 'en-england' ],
43
- [ 'es', 'es-espana' ],
44
- [ 'it', 'it-italy' ],
45
- [ 'be', 'europe', 'be-belgium' ], # NB: europe/be-belgium
46
- [ 'ro', 'europe', 'ro-romania' ],
47
- [ 'cl', 'europe-champions-league' ],
48
- [ 'el', 'europe-champions-league' ],
49
- [ 'br', 'br-brazil' ],
50
- [ 'mx', 'mx-mexico' ], # todo: add mx.* for clausura etc ??
51
- [ 'euro', 'euro-cup', ],
52
- [ 'world', 'world-cup' ],
53
- [ 'world.*', 'world-cup' ]]
48
+ [ 'at', 'at-austria' ],
49
+ [ 'at.*', 'at-austria' ],
50
+ [ 'de', 'de-deutschland' ],
51
+ [ 'de.*', 'de-deutschland' ],
52
+ [ 'en', 'en-england' ],
53
+ [ 'es', 'es-espana' ],
54
+ [ 'it', 'it-italy' ],
55
+ [ 'be', 'europe', 'be-belgium' ], # NB: europe/be-belgium
56
+ [ 'ro', 'europe', 'ro-romania' ],
57
+ [ 'cl', 'europe-champions-league' ],
58
+ [ 'el', 'europe-champions-league' ],
59
+ [ 'br', 'br-brazil' ],
60
+ [ 'mx', 'mx-mexico' ], # todo: add mx.* for clausura etc ??
61
+ [ 'euro', 'euro-cup' ],
62
+ [ 'world', 'world-cup' ],
63
+ [ 'world.*', 'world-cup' ]]
54
64
 
55
65
  map.each do |entry|
56
66
  pattern = entry[0]
@@ -68,25 +78,30 @@ module SportDb
68
78
  end
69
79
 
70
80
  def update_event( event )
71
- puts "update event >>#{event.title}<< (#{event.league.key}+#{event.season.key})"
81
+ logger.info "update event >>#{event.title}<< (#{event.league.key}+#{event.season.key})"
72
82
 
73
83
  dlbase = map_event_to_dlurl( event )
74
84
  if dlbase.nil?
75
- puts " skip download; no download source mapping found"
85
+ logger.warn " [Updater] skip download; no download source mapping found for >#{event.key}<"
76
86
  return # cancel download; no mapping found
77
87
  end
78
88
 
79
89
  puts " using dlbase >>#{dlbase}<<"
80
90
 
81
91
  if event.sources.nil?
82
- puts " skip download; no download event source configured/found"
92
+ logger.warn " [Updater] skip download; no download event source configured/found for >#{event.key}<"
83
93
  return
84
94
  end
85
95
 
86
96
  sources = event.sources.gsub(' ','').split(',') # NB: remove all blanks (leading,trailing,inside)
97
+
98
+
99
+ text_ary = [] # array of fixtures (text)
100
+
101
+ ## collect all fixtures (text)
87
102
  sources.each_with_index do |source,i|
88
103
  dlurl = "#{dlbase}/#{source}.txt"
89
- puts " downloading source (#{i+1}/#{sources.length}) >>#{dlurl}<< ..." # todo/check: use size for ary or length - does it matter?
104
+ logger.info " downloading source (#{i+1}/#{sources.length}) >>#{dlurl}<< ..." # todo/check: use size for ary or length - does it matter?
90
105
 
91
106
  # download fixtures into string
92
107
  text = Fetcher.read( dlurl )
@@ -107,15 +122,18 @@ module SportDb
107
122
  text = text.force_encoding( Encoding::UTF_8 )
108
123
  logger.debug "text.encoding.name (after): #{text.encoding.name}"
109
124
 
125
+ text_ary << text
126
+ end
110
127
 
128
+ ## note: need to pass in all fixtures at once (e.g as array) for @last_pos calc etc to work
129
+ ## if multipe "files"/strings are used
130
+ unless text_ary.empty?
111
131
  puts " importing/reading source..."
112
132
  # passing dummy include_path (not needed for reading from string)
113
133
  # fix: use/add proper api for reading from string e.g. read and read_file ?? etc.
114
134
  reader= GameReader.new( '/tmp' )
115
-
116
- ## todo/fix: offer a version that lets us pass in event (not event.key)
117
- # no need for another event lookup
118
- reader.read_fixtures_from_string( event.key, text )
135
+ ### fix: allow to pass in event (to avoid lookup)
136
+ reader.read_fixtures_from_string( event.key, text_ary )
119
137
  end
120
138
  end
121
139
 
@@ -1,6 +1,6 @@
1
1
 
2
2
  module SportDb
3
- VERSION = '1.8.29'
3
+ VERSION = '1.9.0'
4
4
  end
5
5
 
6
6
 
data/test/helper.rb CHANGED
@@ -50,6 +50,7 @@ TeamReader = SportDb::TeamReader
50
50
  AssocReader = SportDb::AssocReader
51
51
  SeasonReader = SportDb::SeasonReader
52
52
  LeagueReader = SportDb::LeagueReader
53
+ EventReader = SportDb::EventReader
53
54
  GameReader = SportDb::GameReader
54
55
  NationalTeamReader = SportDb::NationalTeamReader
55
56
  RaceTeamReader = SportDb::RaceTeamReader
data/test/test_reader.rb CHANGED
@@ -27,6 +27,7 @@ class TestReader < MiniTest::Unit::TestCase
27
27
  leaguereader.read( 'at-austria/leagues', country_id: at.id )
28
28
 
29
29
  gamereader = GameReader.new( SportDb.test_data_path )
30
+ ## check/fix: is country_id more_attribs needed? why? why not?
30
31
  gamereader.read( 'at-austria/2013_14/bl', country_id: at.id )
31
32
 
32
33
  bl = Event.find_by_key!( 'at.2013/14' )
@@ -68,6 +69,7 @@ class TestReader < MiniTest::Unit::TestCase
68
69
  assert_equal 'ÖFB Cup', atcup.title
69
70
 
70
71
  gamereader = GameReader.new( SportDb.test_data_path )
72
+ ## check/fix: is country_id more_attribs needed? why? why not?
71
73
  gamereader.read( 'at-austria/2013_14/bl', country_id: at.id )
72
74
  gamereader.read( 'at-austria/2013_14/el', country_id: at.id )
73
75
 
@@ -0,0 +1,59 @@
1
+ # encoding: utf-8
2
+
3
+ ###
4
+ # to run use
5
+ # ruby -I ./lib -I ./test test/test_reader_from_string.rb
6
+ # or better
7
+ # rake -I ./lib test
8
+
9
+
10
+ require 'helper'
11
+
12
+ class TestReaderFromString < MiniTest::Unit::TestCase
13
+
14
+ def setup
15
+ WorldDb.delete!
16
+ SportDb.delete!
17
+ SportDb.read_builtin
18
+ end
19
+
20
+ def test_bl
21
+ at = Country.create!( key: 'at', name: 'Austria', code: 'AUT', pop: 1, area: 1)
22
+
23
+ teamreader = TeamReader.new( SportDb.test_data_path )
24
+ teamreader.read( 'at-austria/teams', country_id: at.id )
25
+
26
+ leaguereader = LeagueReader.new( SportDb.test_data_path )
27
+ leaguereader.read( 'at-austria/leagues', country_id: at.id )
28
+
29
+ eventreader = EventReader.new( SportDb.test_data_path )
30
+ eventreader.read( 'at-austria/2013_14/bl' )
31
+
32
+ bl = Event.find_by_key!( 'at.2013/14' )
33
+
34
+ assert_equal 10, bl.teams.count
35
+ assert_equal 0, bl.rounds.count
36
+ assert_equal 0, bl.games.count # 36x5 = 180
37
+
38
+
39
+ bl_txt = File.read( "#{SportDb.test_data_path}/at-austria/2013_14/bl.txt" )
40
+ bl_txt_ii = File.read( "#{SportDb.test_data_path}/at-austria/2013_14/bl_ii.txt" )
41
+
42
+ text_ary = [bl_txt,bl_txt_ii]
43
+
44
+ ## try reading from string -- fix: /tmp is a placeholder/remove
45
+ gamereader = GameReader.new( '/tmp' )
46
+ gamereader.read_fixtures_from_string( bl.key, text_ary )
47
+
48
+ assert_equal 36, bl.rounds.count
49
+ assert_equal 180, bl.games.count # 36x5 = 180
50
+
51
+ ## check if is stable (update will not create new matches and rounds) on second pass/rerun
52
+ gamereader.read_fixtures_from_string( bl.key, text_ary )
53
+
54
+ assert_equal 36, bl.rounds.count
55
+ assert_equal 180, bl.games.count # 36x5 = 180
56
+ end
57
+
58
+
59
+ end # class TestReaderFromString
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sportdb
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.29
4
+ version: 1.9.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-06-08 00:00:00.000000000 Z
12
+ date: 2014-06-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: props
16
- requirement: &81770130 !ruby/object:Gem::Requirement
16
+ requirement: &73799290 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *81770130
24
+ version_requirements: *73799290
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: logutils
27
- requirement: &81769260 !ruby/object:Gem::Requirement
27
+ requirement: &73798730 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *81769260
35
+ version_requirements: *73798730
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: textutils
38
- requirement: &81768320 !ruby/object:Gem::Requirement
38
+ requirement: &73860180 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *81768320
46
+ version_requirements: *73860180
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: worlddb
49
- requirement: &81767630 !ruby/object:Gem::Requirement
49
+ requirement: &73859880 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 2.0.2
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *81767630
57
+ version_requirements: *73859880
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: tagutils
60
- requirement: &81767310 !ruby/object:Gem::Requirement
60
+ requirement: &73859690 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :runtime
67
67
  prerelease: false
68
- version_requirements: *81767310
68
+ version_requirements: *73859690
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: persondb
71
- requirement: &81767040 !ruby/object:Gem::Requirement
71
+ requirement: &73859420 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0'
77
77
  type: :runtime
78
78
  prerelease: false
79
- version_requirements: *81767040
79
+ version_requirements: *73859420
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: activerecord-utils
82
- requirement: &81766780 !ruby/object:Gem::Requirement
82
+ requirement: &73859210 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: '0'
88
88
  type: :runtime
89
89
  prerelease: false
90
- version_requirements: *81766780
90
+ version_requirements: *73859210
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: fetcher
93
- requirement: &81766370 !ruby/object:Gem::Requirement
93
+ requirement: &73858900 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ! '>='
@@ -98,10 +98,10 @@ dependencies:
98
98
  version: '0.3'
99
99
  type: :runtime
100
100
  prerelease: false
101
- version_requirements: *81766370
101
+ version_requirements: *73858900
102
102
  - !ruby/object:Gem::Dependency
103
103
  name: gli
104
- requirement: &81765650 !ruby/object:Gem::Requirement
104
+ requirement: &73858630 !ruby/object:Gem::Requirement
105
105
  none: false
106
106
  requirements:
107
107
  - - ! '>='
@@ -109,10 +109,10 @@ dependencies:
109
109
  version: 2.5.6
110
110
  type: :runtime
111
111
  prerelease: false
112
- version_requirements: *81765650
112
+ version_requirements: *73858630
113
113
  - !ruby/object:Gem::Dependency
114
114
  name: activerecord
115
- requirement: &81765420 !ruby/object:Gem::Requirement
115
+ requirement: &73858440 !ruby/object:Gem::Requirement
116
116
  none: false
117
117
  requirements:
118
118
  - - ! '>='
@@ -120,10 +120,10 @@ dependencies:
120
120
  version: '0'
121
121
  type: :runtime
122
122
  prerelease: false
123
- version_requirements: *81765420
123
+ version_requirements: *73858440
124
124
  - !ruby/object:Gem::Dependency
125
125
  name: rdoc
126
- requirement: &81764700 !ruby/object:Gem::Requirement
126
+ requirement: &73858130 !ruby/object:Gem::Requirement
127
127
  none: false
128
128
  requirements:
129
129
  - - ~>
@@ -131,10 +131,10 @@ dependencies:
131
131
  version: '4.0'
132
132
  type: :development
133
133
  prerelease: false
134
- version_requirements: *81764700
134
+ version_requirements: *73858130
135
135
  - !ruby/object:Gem::Dependency
136
136
  name: hoe
137
- requirement: &81764370 !ruby/object:Gem::Requirement
137
+ requirement: &73857850 !ruby/object:Gem::Requirement
138
138
  none: false
139
139
  requirements:
140
140
  - - ~>
@@ -142,7 +142,7 @@ dependencies:
142
142
  version: '3.11'
143
143
  type: :development
144
144
  prerelease: false
145
- version_requirements: *81764370
145
+ version_requirements: *73857850
146
146
  description: sportdb - sport.db command line tool
147
147
  email: opensport@googlegroups.com
148
148
  executables:
@@ -299,6 +299,7 @@ files:
299
299
  - test/test_load.rb
300
300
  - test/test_national_team_reader.rb
301
301
  - test/test_reader.rb
302
+ - test/test_reader_from_string.rb
302
303
  - test/test_round_auto.rb
303
304
  - test/test_round_def.rb
304
305
  - test/test_round_header.rb
@@ -354,6 +355,7 @@ test_files:
354
355
  - test/test_winner.rb
355
356
  - test/test_round_def.rb
356
357
  - test/test_utils.rb
358
+ - test/test_reader_from_string.rb
357
359
  - test/test_round_header.rb
358
360
  - test/test_round_auto.rb
359
361
  - test/test_national_team_reader.rb