datafile 0.2.5 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/{HISTORY.md → CHANGELOG.md} +0 -0
- data/Manifest.txt +23 -30
- data/Rakefile +2 -3
- data/data/football.txt +20 -11
- data/lib/datafile.rb +29 -19
- data/lib/datafile/builder.rb +1 -24
- data/lib/datafile/datafile.rb +25 -144
- data/lib/datafile/{datasets/dataset.rb → dataset.rb} +17 -25
- data/lib/datafile/version.rb +7 -4
- data/lib/datafile/workers/file/dataset.rb +20 -57
- data/lib/datafile/workers/file/registry.rb +18 -18
- data/lib/datafile/workers/file/worker.rb +4 -24
- data/lib/datafile/workers/zip/dataset.rb +19 -8
- data/lib/datafile/workers/zip/worker.rb +6 -22
- data/test/test_builder.rb +9 -9
- data/test/test_file_dataset_registry.rb +2 -3
- data/test/test_file_worker.rb +4 -5
- data/test/test_football_dataset.rb +9 -9
- metadata +10 -37
- data/.gemtest +0 -0
- data/lib/datafile/builder2.rb +0 -90
- data/lib/datafile/workers/dataset.rb +0 -40
- data/lib/datafile/workers/zip/beer.rb +0 -18
- data/lib/datafile/workers/zip/football.rb +0 -18
- data/lib/datafile/workers/zip/world.rb +0 -18
- data/test/datafile2/at.rb +0 -51
- data/test/test_builder2.rb +0 -36
data/test/test_builder.rb
CHANGED
@@ -15,8 +15,8 @@ class TestBuilder < MiniTest::Test
|
|
15
15
|
|
16
16
|
world 'world.db', setup: 'countries'
|
17
17
|
|
18
|
-
football 'national-teams' ## NOTE: default is setup: 'all
|
19
|
-
|
18
|
+
football 'national-teams' ## NOTE: default is setup: 'all
|
19
|
+
|
20
20
|
### todo/fix: download archive only once(!!) even if included more than once
|
21
21
|
## football 'world-cup', setup: '2014_quali'
|
22
22
|
|
@@ -27,16 +27,16 @@ class TestBuilder < MiniTest::Test
|
|
27
27
|
EOS
|
28
28
|
|
29
29
|
builder = Datafile::Builder.load( code )
|
30
|
-
|
30
|
+
|
31
31
|
datafile = builder.datafile
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
32
|
+
datafile.run
|
33
|
+
|
34
|
+
datafile.download
|
35
|
+
datafile.read
|
36
36
|
datafile.dump
|
37
|
-
|
37
|
+
|
38
38
|
## change worker (defaults to ZipWorker)
|
39
|
-
datafile.worker = Datafile::FileWorker
|
39
|
+
datafile.worker = Datafile::FileWorker
|
40
40
|
datafile.dump
|
41
41
|
|
42
42
|
assert true # if we get here - test success
|
@@ -13,10 +13,10 @@ class TestFileDatasetRegistry < MiniTest::Test
|
|
13
13
|
registry = Datafile::FileDatasetRegistry.new
|
14
14
|
registry.merge( openfootball: '../../openfootball' )
|
15
15
|
|
16
|
-
assert_equal '../../openfootball/
|
16
|
+
assert_equal '../../openfootball/austria', registry.lookup( 'openfootball/austria')
|
17
17
|
assert_equal '../../openmundi/world.db', registry.lookup( 'openmundi/world.db' )
|
18
18
|
|
19
|
-
assert_equal '../../openfootball/
|
19
|
+
assert_equal '../../openfootball/austria', registry.lookup!( 'openfootball/austria')
|
20
20
|
assert_equal '../../openmundi/world.db', registry.lookup!( 'openmundi/world.db' )
|
21
21
|
|
22
22
|
assert_equal '../../openfootball/national-teams', registry.lookup( 'openfootball/national-teams')
|
@@ -24,4 +24,3 @@ class TestFileDatasetRegistry < MiniTest::Test
|
|
24
24
|
end
|
25
25
|
|
26
26
|
end # class TestFileDatasetRegistry
|
27
|
-
|
data/test/test_file_worker.rb
CHANGED
@@ -21,19 +21,18 @@ class TestFileWorker < MiniTest::Test
|
|
21
21
|
ActiveRecord::Base.establish_connection( adapter: 'sqlite3',
|
22
22
|
database: ':memory:' )
|
23
23
|
SportDb.create_all
|
24
|
-
SportDb.read_builtin
|
25
24
|
|
26
25
|
## change worker (defaults to ZipWorker)
|
27
|
-
world_datafile.worker = Datafile::FileWorker
|
26
|
+
world_datafile.worker = Datafile::FileWorker
|
28
27
|
world_datafile.dump
|
29
|
-
world_datafile.read
|
28
|
+
## world_datafile.read
|
30
29
|
|
31
30
|
registry = Datafile::FileDataset.registry
|
32
31
|
registry.merge( openfootball: '../../openfootball' )
|
33
32
|
|
34
|
-
eurocup_datafile.worker = Datafile::FileWorker
|
33
|
+
eurocup_datafile.worker = Datafile::FileWorker
|
35
34
|
eurocup_datafile.dump
|
36
|
-
eurocup_datafile.read
|
35
|
+
## eurocup_datafile.read
|
37
36
|
|
38
37
|
assert true # if we get here - test success
|
39
38
|
end
|
@@ -12,13 +12,13 @@ class TestFootballDataset < MiniTest::Test
|
|
12
12
|
def test_names
|
13
13
|
pp Datafile::FootballDataset.known_datasets
|
14
14
|
|
15
|
-
at = Datafile::FootballDataset.new( '
|
16
|
-
at2 = Datafile::FootballDataset.new( 'openfootball/
|
15
|
+
at = Datafile::FootballDataset.new( 'austria' )
|
16
|
+
at2 = Datafile::FootballDataset.new( 'openfootball/austria' )
|
17
17
|
xxx = Datafile::FootballDataset.new( 'xxx' )
|
18
18
|
xxx2 = Datafile::FootballDataset.new( 'openfootball/xxx' )
|
19
19
|
|
20
|
-
assert_equal 'openfootball/
|
21
|
-
assert_equal 'openfootball/
|
20
|
+
assert_equal 'openfootball/austria', at.name
|
21
|
+
assert_equal 'openfootball/austria', at2.name
|
22
22
|
|
23
23
|
assert_equal 'openfootball/xxx', xxx.name
|
24
24
|
assert_equal 'openfootball/xxx', xxx2.name
|
@@ -27,7 +27,7 @@ class TestFootballDataset < MiniTest::Test
|
|
27
27
|
## move to test datasets - why, why not ??
|
28
28
|
def test_world
|
29
29
|
at = Datafile::WorldDataset.new( 'austria.db' )
|
30
|
-
at2 = Datafile::WorldDataset.new( 'openmundi/austria.db' )
|
30
|
+
at2 = Datafile::WorldDataset.new( 'openmundi/austria.db' )
|
31
31
|
xxx = Datafile::WorldDataset.new( 'xxx' )
|
32
32
|
xxx2 = Datafile::WorldDataset.new( 'openmundi/xxx' )
|
33
33
|
|
@@ -39,13 +39,13 @@ class TestFootballDataset < MiniTest::Test
|
|
39
39
|
end
|
40
40
|
|
41
41
|
def test_beer
|
42
|
-
at = Datafile::BeerDataset.new( '
|
43
|
-
at2 = Datafile::BeerDataset.new( 'openbeer/
|
42
|
+
at = Datafile::BeerDataset.new( 'austria' )
|
43
|
+
at2 = Datafile::BeerDataset.new( 'openbeer/austria' )
|
44
44
|
xxx = Datafile::BeerDataset.new( 'xxx' )
|
45
45
|
xxx2 = Datafile::BeerDataset.new( 'openbeer/xxx' )
|
46
46
|
|
47
|
-
assert_equal 'openbeer/
|
48
|
-
assert_equal 'openbeer/
|
47
|
+
assert_equal 'openbeer/austria', at.name
|
48
|
+
assert_equal 'openbeer/austria', at2.name
|
49
49
|
|
50
50
|
assert_equal 'openbeer/xxx', xxx.name
|
51
51
|
assert_equal 'openbeer/xxx', xxx2.name
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: datafile
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gerald Bauer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-11-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: logutils
|
@@ -24,20 +24,6 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: textutils
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - ">="
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
34
|
-
type: :runtime
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - ">="
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
41
27
|
- !ruby/object:Gem::Dependency
|
42
28
|
name: fetcher
|
43
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -72,51 +58,43 @@ dependencies:
|
|
72
58
|
requirements:
|
73
59
|
- - "~>"
|
74
60
|
- !ruby/object:Gem::Version
|
75
|
-
version: '3.
|
61
|
+
version: '3.16'
|
76
62
|
type: :development
|
77
63
|
prerelease: false
|
78
64
|
version_requirements: !ruby/object:Gem::Requirement
|
79
65
|
requirements:
|
80
66
|
- - "~>"
|
81
67
|
- !ruby/object:Gem::Version
|
82
|
-
version: '3.
|
68
|
+
version: '3.16'
|
83
69
|
description: datafile - builder for downloading n reading datasets
|
84
70
|
email: opensport@googlegroups.com
|
85
71
|
executables: []
|
86
72
|
extensions: []
|
87
73
|
extra_rdoc_files:
|
88
|
-
-
|
74
|
+
- CHANGELOG.md
|
89
75
|
- Manifest.txt
|
90
76
|
- README.md
|
91
77
|
files:
|
92
|
-
-
|
93
|
-
- HISTORY.md
|
78
|
+
- CHANGELOG.md
|
94
79
|
- Manifest.txt
|
95
80
|
- README.md
|
96
81
|
- Rakefile
|
97
82
|
- data/football.txt
|
98
83
|
- lib/datafile.rb
|
99
84
|
- lib/datafile/builder.rb
|
100
|
-
- lib/datafile/builder2.rb
|
101
85
|
- lib/datafile/datafile.rb
|
102
|
-
- lib/datafile/
|
86
|
+
- lib/datafile/dataset.rb
|
103
87
|
- lib/datafile/version.rb
|
104
|
-
- lib/datafile/workers/dataset.rb
|
105
88
|
- lib/datafile/workers/file/dataset.rb
|
106
89
|
- lib/datafile/workers/file/registry.rb
|
107
90
|
- lib/datafile/workers/file/worker.rb
|
108
|
-
- lib/datafile/workers/zip/beer.rb
|
109
91
|
- lib/datafile/workers/zip/dataset.rb
|
110
|
-
- lib/datafile/workers/zip/football.rb
|
111
92
|
- lib/datafile/workers/zip/worker.rb
|
112
|
-
- lib/datafile/workers/zip/world.rb
|
113
93
|
- test/datafile/eurocup.rb
|
114
94
|
- test/datafile/stadiums.rb
|
115
95
|
- test/datafile/world.rb
|
116
|
-
- test/datafile2/at.rb
|
117
96
|
- test/helper.rb
|
118
97
|
- test/test_builder.rb
|
119
|
-
- test/test_builder2.rb
|
120
98
|
- test/test_file_dataset_registry.rb
|
121
99
|
- test/test_file_worker.rb
|
122
100
|
- test/test_football_dataset.rb
|
@@ -134,7 +112,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
134
112
|
requirements:
|
135
113
|
- - ">="
|
136
114
|
- !ruby/object:Gem::Version
|
137
|
-
version:
|
115
|
+
version: 2.2.2
|
138
116
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
139
117
|
requirements:
|
140
118
|
- - ">="
|
@@ -142,13 +120,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
142
120
|
version: '0'
|
143
121
|
requirements: []
|
144
122
|
rubyforge_project:
|
145
|
-
rubygems_version: 2.
|
123
|
+
rubygems_version: 2.5.2
|
146
124
|
signing_key:
|
147
125
|
specification_version: 4
|
148
126
|
summary: datafile - builder for downloading n reading datasets
|
149
|
-
test_files:
|
150
|
-
- test/test_builder2.rb
|
151
|
-
- test/test_builder.rb
|
152
|
-
- test/test_file_dataset_registry.rb
|
153
|
-
- test/test_football_dataset.rb
|
154
|
-
- test/test_file_worker.rb
|
127
|
+
test_files: []
|
data/.gemtest
DELETED
File without changes
|
data/lib/datafile/builder2.rb
DELETED
@@ -1,90 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
module Datafile
|
4
|
-
|
5
|
-
|
6
|
-
###
|
7
|
-
## check/todo: rename to BatchBuilder, MultiBuilder,etc - find better name - why, why not??
|
8
|
-
|
9
|
-
class BuilderEx
|
10
|
-
|
11
|
-
def self.load_file( path )
|
12
|
-
code = File.read_utf8( path )
|
13
|
-
self.load( code )
|
14
|
-
end
|
15
|
-
|
16
|
-
def self.load( code )
|
17
|
-
builder = BuilderEx.new
|
18
|
-
builder.instance_eval( code )
|
19
|
-
builder
|
20
|
-
end
|
21
|
-
|
22
|
-
|
23
|
-
include LogUtils::Logging
|
24
|
-
|
25
|
-
def initialize
|
26
|
-
@datafiles = []
|
27
|
-
@datafile = nil
|
28
|
-
end
|
29
|
-
|
30
|
-
attr_reader :datafiles
|
31
|
-
|
32
|
-
|
33
|
-
def task( arg )
|
34
|
-
|
35
|
-
logger.info( "[builder] add task '#{arg.inspect}' : #{arg.class.name}" )
|
36
|
-
|
37
|
-
if arg.kind_of?( String ) || arg.kind_of?( Symbol ) # e.g. 'at' or :at
|
38
|
-
name = arg.to_s
|
39
|
-
## note: always default to FileWorker for now
|
40
|
-
## -- use file: true -- find better name e.g. worker/source: file - why? why not??
|
41
|
-
@datafile = Datafile.new( name: name, deps: [], file: true )
|
42
|
-
yield ### execute block in context
|
43
|
-
## b = Builder.new
|
44
|
-
## block.call( b ) ## same as b.instance_eval( &block) ???
|
45
|
-
## b.instance_eval( code )
|
46
|
-
## b = Builder.load( &block )
|
47
|
-
elsif arg.kind_of?( Hash ) ## Hash e.g. :at_calc => :at etc.
|
48
|
-
key = arg.keys.first
|
49
|
-
value = arg[key] ## todo: check if single value? always turn into array
|
50
|
-
|
51
|
-
name = key.to_s ## get first key (assume it's name)
|
52
|
-
if value.kind_of?( Array )
|
53
|
-
deps = value.map { |v| v.to_s } ## convert to strings
|
54
|
-
else ## assume single string/symbol -- convert to array
|
55
|
-
deps = [value.to_s]
|
56
|
-
end
|
57
|
-
@datafile = Datafile.new( name: name, deps: deps, file: true ) ## note: always default to FileWorker for now
|
58
|
-
yield ### execute block in context
|
59
|
-
## to be done
|
60
|
-
else
|
61
|
-
## fix: report error: unknown type
|
62
|
-
end
|
63
|
-
|
64
|
-
@datafiles << @datafile
|
65
|
-
end
|
66
|
-
|
67
|
-
def calc( &block )
|
68
|
-
logger.info( "[builder] add script calc-block" )
|
69
|
-
@datafile.scripts << Script.new( block )
|
70
|
-
end
|
71
|
-
|
72
|
-
################################
|
73
|
-
# "classic/standard" datasets
|
74
|
-
def beer( name, opts={} )
|
75
|
-
logger.info( "[builder] add beer-dataset '#{name}'" )
|
76
|
-
@datafile.datasets << BeerDataset.new( name, opts )
|
77
|
-
end
|
78
|
-
|
79
|
-
def football( name, opts={} )
|
80
|
-
logger.info( "[builder] add football-dataset '#{name}'" )
|
81
|
-
@datafile.datasets << FootballDataset.new( name, opts )
|
82
|
-
end
|
83
|
-
|
84
|
-
def world( name, opts={} )
|
85
|
-
logger.info( "[builder] add world-dataset '#{name}'" )
|
86
|
-
@datafile.datasets << WorldDataset.new( name, opts )
|
87
|
-
end
|
88
|
-
|
89
|
-
end # class Builder2
|
90
|
-
end # module Datafile
|
@@ -1,40 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
module Datafile
|
4
|
-
|
5
|
-
class Error < StandardError
|
6
|
-
end
|
7
|
-
|
8
|
-
####
|
9
|
-
# todo/check:
|
10
|
-
# rename to DatasetNotFound or similar??
|
11
|
-
# use "common" error class - why? why not?
|
12
|
-
class DatasetNotFoundError < Error
|
13
|
-
attr_reader :message
|
14
|
-
|
15
|
-
def initialize( message )
|
16
|
-
@message = message
|
17
|
-
end
|
18
|
-
|
19
|
-
def to_s
|
20
|
-
"datset not found => #{@message}"
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
|
25
|
-
class DatasetNode ### find a better name (e.g. DatasetWorker, DatasetBase, DatasetRef, DatasetWrapper ???) ???
|
26
|
-
|
27
|
-
include LogUtils::Logging
|
28
|
-
|
29
|
-
def initialize( dataset )
|
30
|
-
@dataset = dataset
|
31
|
-
end
|
32
|
-
|
33
|
-
def name() @dataset.name; end
|
34
|
-
def opts() @dataset.opts; end
|
35
|
-
def setup() @dataset.setup; end
|
36
|
-
|
37
|
-
end # class DatasetNode
|
38
|
-
|
39
|
-
|
40
|
-
end # module Datafile
|
@@ -1,18 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
module Datafile
|
4
|
-
|
5
|
-
class BeerZipDataset < ZipDataset
|
6
|
-
|
7
|
-
def initialize( dataset )
|
8
|
-
super( dataset )
|
9
|
-
end
|
10
|
-
|
11
|
-
def read
|
12
|
-
logger.info( "read beer-dataset (zip) '#{name}', '#{setup}'" )
|
13
|
-
|
14
|
-
BeerDb.read_setup_from_zip( local_zip_name, setup, local_zip_root )
|
15
|
-
end
|
16
|
-
end # class BeerZipDataset
|
17
|
-
|
18
|
-
end # module Datafile
|
@@ -1,18 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
module Datafile
|
4
|
-
|
5
|
-
class FootballZipDataset < ZipDataset
|
6
|
-
|
7
|
-
def initialize( dataset )
|
8
|
-
super( dataset )
|
9
|
-
end
|
10
|
-
|
11
|
-
def read
|
12
|
-
logger.info( "read football-dataset (zip) '#{name}', '#{setup}'" )
|
13
|
-
|
14
|
-
SportDb.read_setup_from_zip( local_zip_name, setup, local_zip_root )
|
15
|
-
end
|
16
|
-
end # class FootballZipDataset
|
17
|
-
|
18
|
-
end # module Datafile
|
@@ -1,18 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
module Datafile
|
4
|
-
|
5
|
-
class WorldZipDataset < ZipDataset
|
6
|
-
|
7
|
-
def initialize( dataset )
|
8
|
-
super( dataset )
|
9
|
-
end
|
10
|
-
|
11
|
-
def read
|
12
|
-
logger.info( "read world-dataset (zip) '#{name}', '#{setup}'" )
|
13
|
-
|
14
|
-
WorldDb.read_setup_from_zip( local_zip_name, setup, local_zip_root, { skip_tags: true } )
|
15
|
-
end
|
16
|
-
end # class WorldZipDataset
|
17
|
-
|
18
|
-
end # module Datafile
|
data/test/datafile2/at.rb
DELETED
@@ -1,51 +0,0 @@
|
|
1
|
-
|
2
|
-
puts "[eval] self in top = #{self.class.name}"
|
3
|
-
|
4
|
-
task :at => :importbuiltin do
|
5
|
-
puts "[eval] self in data (enter) = #{self.class.name}"
|
6
|
-
football 'at-austria'
|
7
|
-
puts "[eval] self in data (leave) = #{self.class.name}"
|
8
|
-
end
|
9
|
-
|
10
|
-
task :at_2014_15 => :importbuiltin do
|
11
|
-
football 'at-austria', setup: '2014-15'
|
12
|
-
end
|
13
|
-
|
14
|
-
|
15
|
-
task :at_recalc => :at do
|
16
|
-
calc do
|
17
|
-
[['at.2012/13'],
|
18
|
-
['at.2013/14'],
|
19
|
-
['at.2014/15', 'at.2.2014/15']].each do |event_key|
|
20
|
-
recalc_standings( event_key, out_root: './build/at-autria' )
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
task :at_2014_15_recalc => :at_2014_15 do
|
26
|
-
calc do
|
27
|
-
recalc_standings( ['at.2014/15', 'at.2.2014/15'], out_root: './build/at-autria' )
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
|
32
|
-
task :test_at_recalc => :env do
|
33
|
-
calc do
|
34
|
-
recalc_standings( ['at.2014/15', 'at.2.2014/15'], out_root: './build/at-autria' )
|
35
|
-
## debug verison - write to ./build/at-austria
|
36
|
-
## recalc_standings( ['at.2014/15', 'at.2.2014/15'], out_root: './build/at-austria' )
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
|
41
|
-
## check if method def works too
|
42
|
-
|
43
|
-
puts "[eval] another self in top = #{self.class.name}"
|
44
|
-
|
45
|
-
|
46
|
-
def test_hello()
|
47
|
-
puts "[eval] self in method test_hello = #{self.class.name}"
|
48
|
-
puts "hello from test_hello"
|
49
|
-
end
|
50
|
-
|
51
|
-
test_hello()
|