sportdb 1.9.13 → 1.9.14
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Manifest.txt +0 -3
- data/Rakefile +1 -0
- data/lib/sportdb.rb +0 -4
- data/lib/sportdb/cli/main.rb +27 -13
- data/lib/sportdb/version.rb +1 -1
- metadata +15 -5
- data/lib/sportdb/builder/builder.rb +0 -58
- data/lib/sportdb/builder/dataset.rb +0 -90
- data/test/test_builder.rb +0 -36
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d2db12336a3fae247a22d4efee7d6c180b28d942
|
4
|
+
data.tar.gz: 26987264b067348f1e273e9f2ad37ccc90184de2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: db796999c6b36d8cda1ab638a3e271cfebe6bdb3872632a2d6d0185a0a0761859a4d84d552a20e781c5e7cb6585eb6757d22ee72bdf76f1e25929a96c031a551
|
7
|
+
data.tar.gz: d16a231df7b59e3916e8aab32732b082784406adb78b36b91cc62515d3c65d94360534532b2a93210f02da3371a7042907980e97a28a97baaf698a64be5ef184
|
data/Manifest.txt
CHANGED
@@ -13,8 +13,6 @@ config/fixtures/ro.yml
|
|
13
13
|
data/seasons.txt
|
14
14
|
data/setups/all.txt
|
15
15
|
lib/sportdb.rb
|
16
|
-
lib/sportdb/builder/builder.rb
|
17
|
-
lib/sportdb/builder/dataset.rb
|
18
16
|
lib/sportdb/calc.rb
|
19
17
|
lib/sportdb/cli/main.rb
|
20
18
|
lib/sportdb/cli/opts.rb
|
@@ -127,7 +125,6 @@ test/data/world-cup/teams_1962.txt
|
|
127
125
|
test/data/world-cup/teams_1974.txt
|
128
126
|
test/helper.rb
|
129
127
|
test/test_assoc_reader.rb
|
130
|
-
test/test_builder.rb
|
131
128
|
test/test_changes.rb
|
132
129
|
test/test_cursor.rb
|
133
130
|
test/test_date.rb
|
data/Rakefile
CHANGED
data/lib/sportdb.rb
CHANGED
data/lib/sportdb/cli/main.rb
CHANGED
@@ -17,8 +17,10 @@ include GLI::App
|
|
17
17
|
|
18
18
|
require 'logutils/db'
|
19
19
|
require 'sportdb/cli/opts'
|
20
|
-
|
21
|
-
|
20
|
+
|
21
|
+
require 'datafile' ## lets us use Datafile::Builder,Datafile etc.
|
22
|
+
|
23
|
+
|
22
24
|
program_desc 'sport.db command line tool'
|
23
25
|
|
24
26
|
version SportDb::VERSION
|
@@ -79,6 +81,14 @@ def connect_to_db( options )
|
|
79
81
|
:database => "#{options.db_path}/#{options.db_name}"
|
80
82
|
}
|
81
83
|
|
84
|
+
## todo/check: use if defined?( JRUBY_VERSION ) instead ??
|
85
|
+
if RUBY_PLATFORM =~ /java/ && db_config[:adapter] == 'sqlite3'
|
86
|
+
# quick hack for JRuby sqlite3 support via jdbc
|
87
|
+
require 'jdbc/sqlite3'
|
88
|
+
## todo: check if require for activerecord jdbc adapter for sqlite is required to
|
89
|
+
end
|
90
|
+
|
91
|
+
|
82
92
|
puts "Connecting to db using settings: "
|
83
93
|
pp db_config
|
84
94
|
|
@@ -113,8 +123,9 @@ command [:build,:b] do |c|
|
|
113
123
|
|
114
124
|
c.action do |g,o,args|
|
115
125
|
|
116
|
-
builder =
|
117
|
-
builder.
|
126
|
+
builder = Datafile::Builder.load_file( './Datafile' )
|
127
|
+
datafile = builder.datafile
|
128
|
+
datafile.download # datafile step 1 - download all datasets/zips
|
118
129
|
|
119
130
|
connect_to_db( opts )
|
120
131
|
|
@@ -127,7 +138,7 @@ command [:build,:b] do |c|
|
|
127
138
|
|
128
139
|
SportDb.read_builtin # e.g. seasons.txt etc
|
129
140
|
|
130
|
-
|
141
|
+
datafile.read # datafile step 2 - read all datasets
|
131
142
|
|
132
143
|
puts 'Done.'
|
133
144
|
end # action
|
@@ -141,8 +152,9 @@ command [:read,:r] do |c|
|
|
141
152
|
|
142
153
|
connect_to_db( opts )
|
143
154
|
|
144
|
-
builder =
|
145
|
-
builder.
|
155
|
+
builder = Datafile::Builder.load_file( './Datafile' )
|
156
|
+
datafile = builder.datafile
|
157
|
+
datafile.read
|
146
158
|
|
147
159
|
puts 'Done.'
|
148
160
|
end # action
|
@@ -155,8 +167,9 @@ command [:download,:dl] do |c|
|
|
155
167
|
|
156
168
|
# note: no database connection needed (check - needed for logs?? - not setup by default???)
|
157
169
|
|
158
|
-
builder =
|
159
|
-
builder.
|
170
|
+
builder = Datafile::Builder.load_file( './Datafile' )
|
171
|
+
datafile = builder.datafile
|
172
|
+
datafile.download
|
160
173
|
|
161
174
|
puts 'Done.'
|
162
175
|
end # action
|
@@ -176,8 +189,9 @@ command [:new,:n] do |c|
|
|
176
189
|
worker.copy( "https://github.com/openfootball/datafile/raw/master/#{setup}.rb", './Datafile' )
|
177
190
|
|
178
191
|
## step 2: same as command build (todo - reuse code)
|
179
|
-
builder =
|
180
|
-
builder.
|
192
|
+
builder = Datafile::Builder.load_file( './Datafile' )
|
193
|
+
datafile = builder.datafile
|
194
|
+
datafile.download # datafile step 1 - download all datasets/zips
|
181
195
|
|
182
196
|
connect_to_db( opts ) ### todo: check let connect go first?? - for logging (logs) to db ???
|
183
197
|
|
@@ -190,8 +204,8 @@ command [:new,:n] do |c|
|
|
190
204
|
|
191
205
|
SportDb.read_builtin # e.g. seasons.txt etc
|
192
206
|
|
193
|
-
|
194
|
-
|
207
|
+
datafile.read # datafile step 2 - read all datasets
|
208
|
+
|
195
209
|
puts 'Done.'
|
196
210
|
end # action
|
197
211
|
end # command setup
|
data/lib/sportdb/version.rb
CHANGED
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.9.
|
4
|
+
version: 1.9.14
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gerald Bauer
|
@@ -122,6 +122,20 @@ dependencies:
|
|
122
122
|
- - ">="
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '0.3'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: datafile
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :runtime
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
125
139
|
- !ruby/object:Gem::Dependency
|
126
140
|
name: sportdb-keys
|
127
141
|
requirement: !ruby/object:Gem::Requirement
|
@@ -260,8 +274,6 @@ files:
|
|
260
274
|
- data/seasons.txt
|
261
275
|
- data/setups/all.txt
|
262
276
|
- lib/sportdb.rb
|
263
|
-
- lib/sportdb/builder/builder.rb
|
264
|
-
- lib/sportdb/builder/dataset.rb
|
265
277
|
- lib/sportdb/calc.rb
|
266
278
|
- lib/sportdb/cli/main.rb
|
267
279
|
- lib/sportdb/cli/opts.rb
|
@@ -374,7 +386,6 @@ files:
|
|
374
386
|
- test/data/world-cup/teams_1974.txt
|
375
387
|
- test/helper.rb
|
376
388
|
- test/test_assoc_reader.rb
|
377
|
-
- test/test_builder.rb
|
378
389
|
- test/test_changes.rb
|
379
390
|
- test/test_cursor.rb
|
380
391
|
- test/test_date.rb
|
@@ -438,7 +449,6 @@ test_files:
|
|
438
449
|
- test/test_round_def.rb
|
439
450
|
- test/test_utils.rb
|
440
451
|
- test/test_reader_from_string.rb
|
441
|
-
- test/test_builder.rb
|
442
452
|
- test/test_round_header.rb
|
443
453
|
- test/test_round_auto.rb
|
444
454
|
- test/test_goals.rb
|
@@ -1,58 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
module SportDb
|
4
|
-
|
5
|
-
class Builder
|
6
|
-
|
7
|
-
include LogUtils::Logging
|
8
|
-
|
9
|
-
def initialize()
|
10
|
-
@datasets = []
|
11
|
-
end
|
12
|
-
|
13
|
-
def self.load_file( path )
|
14
|
-
code = File.read_utf8( path )
|
15
|
-
self.load( code )
|
16
|
-
end
|
17
|
-
|
18
|
-
def self.load( code )
|
19
|
-
builder = Builder.new
|
20
|
-
builder.instance_eval( code )
|
21
|
-
builder
|
22
|
-
end
|
23
|
-
|
24
|
-
|
25
|
-
def football( name, opts={} )
|
26
|
-
logger.info( "[builder] add football-dataset '#{@name}'" )
|
27
|
-
@datasets << FootballDataset.new( name, opts )
|
28
|
-
end
|
29
|
-
|
30
|
-
def world( name, opts={} )
|
31
|
-
logger.info( "[builder] add world-dataset '#{@name}'" )
|
32
|
-
@datasets << WorldDataset.new( name, opts )
|
33
|
-
end
|
34
|
-
|
35
|
-
|
36
|
-
def run()
|
37
|
-
logger.info( "[builder] begin - run" )
|
38
|
-
download() # step 1 - download zips for datasets
|
39
|
-
read() # step 2 - read in datasets from zips
|
40
|
-
logger.info( "[builder] end - run" )
|
41
|
-
end
|
42
|
-
|
43
|
-
def download()
|
44
|
-
logger.info( "[builder] dowload" )
|
45
|
-
@datasets.each do |dataset|
|
46
|
-
dataset.download()
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
def read()
|
51
|
-
logger.info( "[builder] read" )
|
52
|
-
@datasets.each do |dataset|
|
53
|
-
dataset.read()
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
end # class Builder
|
58
|
-
end # module SportDb
|
@@ -1,90 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
module SportDb
|
4
|
-
|
5
|
-
class Dataset
|
6
|
-
include LogUtils::Logging
|
7
|
-
|
8
|
-
def initialize( name, opts={} )
|
9
|
-
@name = name
|
10
|
-
@opts = opts
|
11
|
-
end
|
12
|
-
|
13
|
-
def setup()
|
14
|
-
value = @opts[:setup] || 'all'
|
15
|
-
"setups/#{value}"
|
16
|
-
end
|
17
|
-
|
18
|
-
def remote_zip_url() # remote zip url
|
19
|
-
"https://github.com/#{@name}/archive/master.zip"
|
20
|
-
end
|
21
|
-
|
22
|
-
def local_zip_name()
|
23
|
-
### note: replace / in name w/ --I--
|
24
|
-
## e.g. flatten the filename, that is, do NOT include any folders
|
25
|
-
@name.gsub('/', '--I--') # note: will NOT include/return .zip extension
|
26
|
-
end
|
27
|
-
|
28
|
-
def local_zip_root()
|
29
|
-
"./tmp"
|
30
|
-
end
|
31
|
-
|
32
|
-
def local_zip_path() # local zip path
|
33
|
-
"#{local_zip_root}/#{local_zip_name}.zip"
|
34
|
-
end
|
35
|
-
|
36
|
-
|
37
|
-
def download()
|
38
|
-
logger.info( "[builder] download dataset '#{@name}'" )
|
39
|
-
logger.info( "[builder] from '#{remote_zip_url}'" )
|
40
|
-
logger.info( "[builder] to '#{local_zip_path}'..." )
|
41
|
-
|
42
|
-
download_blob( remote_zip_url, local_zip_path )
|
43
|
-
end
|
44
|
-
|
45
|
-
####
|
46
|
-
# download tasks for zips
|
47
|
-
def download_blob( url, dest )
|
48
|
-
logger.info "downloading #{url} to #{dest}..."
|
49
|
-
|
50
|
-
## make sure dest path exists
|
51
|
-
dest_p = File.dirname( dest )
|
52
|
-
FileUtils.mkdir_p( dest_p ) unless File.exists?( dest_p ) ## use Dir.exists?? why? why not??
|
53
|
-
|
54
|
-
worker = Fetcher::Worker.new
|
55
|
-
worker.copy( url, dest )
|
56
|
-
## print some file stats
|
57
|
-
logger.debug " size: #{File.size(dest)} bytes"
|
58
|
-
end
|
59
|
-
|
60
|
-
end # class Dataset
|
61
|
-
|
62
|
-
|
63
|
-
class WorldDataset < Dataset
|
64
|
-
|
65
|
-
def initialize( name, opts={} )
|
66
|
-
super( name, opts )
|
67
|
-
end
|
68
|
-
|
69
|
-
def read()
|
70
|
-
logger.info( "[builder] read world-dataset '#{@name}', '#{setup}'" )
|
71
|
-
|
72
|
-
WorldDb.read_setup_from_zip( local_zip_name(), setup(), local_zip_root(), { skip_tags: true } )
|
73
|
-
end
|
74
|
-
end # class WorldDataset
|
75
|
-
|
76
|
-
class FootballDataset < Dataset
|
77
|
-
|
78
|
-
def initialize( name, opts={} )
|
79
|
-
super( name, opts )
|
80
|
-
end
|
81
|
-
|
82
|
-
def read()
|
83
|
-
logger.info( "[builder] read football-dataset '#{@name}', '#{setup}'" )
|
84
|
-
|
85
|
-
SportDb.read_setup_from_zip( local_zip_name(), setup(), local_zip_root() )
|
86
|
-
end
|
87
|
-
end # class FootballDataset
|
88
|
-
|
89
|
-
|
90
|
-
end # module SportDb
|
data/test/test_builder.rb
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
###
|
4
|
-
# to run use
|
5
|
-
# ruby -I ./lib -I ./test test/test_builder.rb
|
6
|
-
|
7
|
-
require 'helper'
|
8
|
-
|
9
|
-
class TestBuilder < MiniTest::Test
|
10
|
-
|
11
|
-
def test_builder
|
12
|
-
code =<<EOS
|
13
|
-
## comments
|
14
|
-
|
15
|
-
world 'openmundi/world.db', setup: 'countries'
|
16
|
-
|
17
|
-
football 'openfootball/national-teams' ## NOTE: default is setup: 'all'
|
18
|
-
|
19
|
-
### todo/fix: download archive only once(!!) even if included more than once
|
20
|
-
## football 'openfootball/world-cup', setup: '2014_quali'
|
21
|
-
|
22
|
-
football 'openfootball/world-cup', setup: '2014'
|
23
|
-
|
24
|
-
## more comments
|
25
|
-
|
26
|
-
EOS
|
27
|
-
|
28
|
-
builder = SportDb::Builder.load( code )
|
29
|
-
## builder.run
|
30
|
-
## builder.download
|
31
|
-
builder.read
|
32
|
-
|
33
|
-
assert true # if we get here - test success
|
34
|
-
end
|
35
|
-
|
36
|
-
end # class TestBuilder
|