sportdb-config 0.8.1 → 0.9.0
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 +3 -3
- data/lib/sportdb/config.rb +0 -2
- data/lib/sportdb/config/config.rb +6 -40
- data/lib/sportdb/config/version.rb +2 -2
- data/lib/sportdb/config/wiki_index.rb +1 -1
- metadata +8 -11
- data/lib/sportdb/config/season_utils.rb +0 -116
- data/test/test_find_datafiles.rb +0 -57
- data/test/test_season_utils.rb +0 -29
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 852d0106724079d3a82da39eee4c35c2c8223444
|
4
|
+
data.tar.gz: 829732d0ed84b32ce414e2eda2853c124363412c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ea39a32a35b38ada3df0f0189683c1d18817c9e9e1e02b948dd3619b0511dcea53d4c391f2a28fb43ce10df09e29b88d8e602bf2825c3441d7cd42a1bb9eb328
|
7
|
+
data.tar.gz: 85fe045bcadba1577dad41c1732f564479f88795e8bc3d3335d4c57598167e57163fab65bfa4b3c78eed3559c9a451947df2f97fb4119166367221deb1c53bee
|
data/Manifest.txt
CHANGED
@@ -5,13 +5,10 @@ README.md
|
|
5
5
|
Rakefile
|
6
6
|
lib/sportdb/config.rb
|
7
7
|
lib/sportdb/config/config.rb
|
8
|
-
lib/sportdb/config/season_utils.rb
|
9
8
|
lib/sportdb/config/version.rb
|
10
9
|
lib/sportdb/config/wiki_index.rb
|
11
10
|
test/helper.rb
|
12
11
|
test/test_clubs.rb
|
13
12
|
test/test_countries.rb
|
14
|
-
test/test_find_datafiles.rb
|
15
13
|
test/test_leagues.rb
|
16
|
-
test/test_season_utils.rb
|
17
14
|
test/test_wiki_index.rb
|
data/Rakefile
CHANGED
@@ -20,9 +20,9 @@ Hoe.spec 'sportdb-config' do
|
|
20
20
|
self.licenses = ['Public Domain']
|
21
21
|
|
22
22
|
self.extra_deps = [
|
23
|
-
['sportdb-countries',
|
24
|
-
['sportdb-clubs',
|
25
|
-
['sportdb-leagues',
|
23
|
+
['sportdb-countries', '>= 0.5.1'],
|
24
|
+
['sportdb-clubs', '>= 0.2.3'],
|
25
|
+
['sportdb-leagues', '>= 0.2.1'],
|
26
26
|
## dataset libs / gems
|
27
27
|
['fifa', '>= 1.2.1'], ## for (builtin/default) countries
|
28
28
|
['footballdb-clubs', '>= 1.0.0'], ## for (builtin/default) clubs
|
data/lib/sportdb/config.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
+
|
3
4
|
module SportDb
|
4
5
|
module Import
|
5
6
|
|
@@ -8,9 +9,9 @@ class ClubIndex
|
|
8
9
|
|
9
10
|
def self.build( path )
|
10
11
|
recs = []
|
11
|
-
datafiles =
|
12
|
+
datafiles = Datafile.find_clubs( path )
|
12
13
|
datafiles.each do |datafile|
|
13
|
-
recs +=
|
14
|
+
recs += Club.read( datafile )
|
14
15
|
end
|
15
16
|
recs
|
16
17
|
|
@@ -19,7 +20,7 @@ class ClubIndex
|
|
19
20
|
|
20
21
|
## add wiki(pedia) anchored links
|
21
22
|
recs = []
|
22
|
-
datafiles =
|
23
|
+
datafiles = Datafile.find_clubs_wiki( path )
|
23
24
|
datafiles.each do |datafile|
|
24
25
|
recs += WikiReader.read( datafile )
|
25
26
|
end
|
@@ -35,9 +36,9 @@ class LeagueIndex
|
|
35
36
|
|
36
37
|
def self.build( path )
|
37
38
|
recs = []
|
38
|
-
datafiles =
|
39
|
+
datafiles = Datafile.find_leagues( path )
|
39
40
|
datafiles.each do |datafile|
|
40
|
-
recs +=
|
41
|
+
recs += League.read( datafile )
|
41
42
|
end
|
42
43
|
recs
|
43
44
|
|
@@ -87,41 +88,6 @@ class Configuration
|
|
87
88
|
def leagues_dir() @leagues_dir; end
|
88
89
|
|
89
90
|
|
90
|
-
CLUBS_REGEX = %r{ (?:^|/) # beginning (^) or beginning of path (/)
|
91
|
-
(?:[a-z]{1,3}\.)? # optional country code/key e.g. eng.clubs.txt
|
92
|
-
clubs\.txt$
|
93
|
-
}x
|
94
|
-
|
95
|
-
CLUBS_WIKI_REGEX = %r{ (?:^|/) # beginning (^) or beginning of path (/)
|
96
|
-
(?:[a-z]{1,3}\.)? # optional country code/key e.g. eng.clubs.wiki.txt
|
97
|
-
clubs\.wiki\.txt$
|
98
|
-
}x
|
99
|
-
|
100
|
-
LEAGUES_REGEX = %r{ (?:^|/) # beginning (^) or beginning of path (/)
|
101
|
-
(?:[a-z]{1,3}\.)? # optional country code/key e.g. eng.clubs.txt
|
102
|
-
leagues\.txt$
|
103
|
-
}x
|
104
|
-
|
105
|
-
|
106
|
-
def self.find_datafiles( path, pattern )
|
107
|
-
datafiles = [] ## note: [country, path] pairs for now
|
108
|
-
|
109
|
-
## check all txt files as candidates (MUST include country code for now)
|
110
|
-
candidates = Dir.glob( "#{path}/**/*.txt" )
|
111
|
-
pp candidates
|
112
|
-
candidates.each do |candidate|
|
113
|
-
datafiles << candidate if pattern.match( candidate )
|
114
|
-
end
|
115
|
-
|
116
|
-
pp datafiles
|
117
|
-
datafiles
|
118
|
-
end
|
119
|
-
|
120
|
-
def self.find_datafiles_clubs( path ) find_datafiles( path, CLUBS_REGEX ); end
|
121
|
-
def self.find_datafiles_clubs_wiki( path ) find_datafiles( path, CLUBS_WIKI_REGEX ); end
|
122
|
-
|
123
|
-
def self.find_datafiles_leagues( path ) find_datafiles( path, LEAGUES_REGEX ); end
|
124
|
-
|
125
91
|
|
126
92
|
def build_club_index
|
127
93
|
## unify team names; team (builtin/known/shared) name mappings
|
@@ -7,8 +7,8 @@ module Boot ## note: use a different module than Config to avoid confusion
|
|
7
7
|
## maybe rename later gem itself to sportdb-boot - why? why not?
|
8
8
|
|
9
9
|
MAJOR = 0 ## todo: namespace inside version or something - why? why not??
|
10
|
-
MINOR =
|
11
|
-
PATCH =
|
10
|
+
MINOR = 9
|
11
|
+
PATCH = 0
|
12
12
|
VERSION = [MAJOR,MINOR,PATCH].join('.')
|
13
13
|
|
14
14
|
def self.version
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sportdb-config
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.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: 2019-10-
|
11
|
+
date: 2019-10-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sportdb-countries
|
@@ -16,42 +16,42 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.
|
19
|
+
version: 0.5.1
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.
|
26
|
+
version: 0.5.1
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: sportdb-clubs
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 0.2.
|
33
|
+
version: 0.2.3
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 0.2.
|
40
|
+
version: 0.2.3
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: sportdb-leagues
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 0.
|
47
|
+
version: 0.2.1
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 0.
|
54
|
+
version: 0.2.1
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: fifa
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -139,15 +139,12 @@ files:
|
|
139
139
|
- Rakefile
|
140
140
|
- lib/sportdb/config.rb
|
141
141
|
- lib/sportdb/config/config.rb
|
142
|
-
- lib/sportdb/config/season_utils.rb
|
143
142
|
- lib/sportdb/config/version.rb
|
144
143
|
- lib/sportdb/config/wiki_index.rb
|
145
144
|
- test/helper.rb
|
146
145
|
- test/test_clubs.rb
|
147
146
|
- test/test_countries.rb
|
148
|
-
- test/test_find_datafiles.rb
|
149
147
|
- test/test_leagues.rb
|
150
|
-
- test/test_season_utils.rb
|
151
148
|
- test/test_wiki_index.rb
|
152
149
|
homepage: https://github.com/sportdb/sport.db
|
153
150
|
licenses:
|
@@ -1,116 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
|
4
|
-
module SeasonHelper ## use Helpers why? why not?
|
5
|
-
def prev( season )
|
6
|
-
## todo: add 1964-1965 format too!!!
|
7
|
-
if season =~ /^(\d{4})-(\d{2})$/ ## season format is 1964-65
|
8
|
-
fst = $1.to_i - 1
|
9
|
-
snd = (100 + $2.to_i - 1) % 100 ## note: add 100 to turn 00 => 99
|
10
|
-
"%4d-%02d" % [fst,snd]
|
11
|
-
elsif season =~ /^(\d{4})$/
|
12
|
-
fst = $1.to_i - 1
|
13
|
-
"%4d" % [fst]
|
14
|
-
else
|
15
|
-
puts "*** !!!! wrong season format >>#{season}<<; exit; sorry"
|
16
|
-
exit 1
|
17
|
-
end
|
18
|
-
end # method prev
|
19
|
-
|
20
|
-
|
21
|
-
def key( basename )
|
22
|
-
if basename =~ /^(\d{4})[\-\/](\d{4})$/ ## e.g. 2011-2012 or 2011/2012 => 2011/12
|
23
|
-
"%4d/%02d" % [$1.to_i, $2.to_i % 100]
|
24
|
-
elsif basename =~ /^(\d{4})[\-\/](\d{2})$/ ## e.g. 2011-12 or 2011/12 => 2011/12
|
25
|
-
"#{$1}/#{$2}"
|
26
|
-
elsif basename =~ /^(\d{4})$/
|
27
|
-
$1
|
28
|
-
else
|
29
|
-
puts "*** !!!! wrong season format >>#{basename}<<; exit; sorry"
|
30
|
-
exit 1
|
31
|
-
end
|
32
|
-
end # method key
|
33
|
-
|
34
|
-
|
35
|
-
def directory( season, format: nil )
|
36
|
-
## todo: find better names for formats - why? why not?:
|
37
|
-
## long | archive | decade(?) => 1980s/1988-89, 2010s/2017-18, ...
|
38
|
-
## short | std(?) => 1988-89, 2017-18, ...
|
39
|
-
|
40
|
-
## convert season name to "standard" season name for directory
|
41
|
-
|
42
|
-
## todo/fix: move to parse / validate season (for (re)use)!!!! - why? why not?
|
43
|
-
if season =~ /^(\d{4})[\-\/](\d{4})$/ ## e.g. 2011-2012 or 2011/2012 => 2011-12
|
44
|
-
years = [$1.to_i, $2.to_i]
|
45
|
-
elsif season =~ /^(\d{4})[\-\/](\d{2})$/ ## e.g. 2011-12 or 2011/12 => 2011-12
|
46
|
-
years = [$1.to_i, $1.to_i+1]
|
47
|
-
## note: check that season end year is (always) season start year + 1
|
48
|
-
if ($1.to_i+1) % 100 != $2.to_i
|
49
|
-
puts "*** !!!! wrong season format >>#{season}<<; season end year MUST (always) equal season start year + 1; exit; sorry"
|
50
|
-
exit 1
|
51
|
-
end
|
52
|
-
elsif season =~ /^(\d{4})$/
|
53
|
-
years = [$1.to_i]
|
54
|
-
else
|
55
|
-
puts "*** !!!! wrong season format >>#{season}<<; exit; sorry"
|
56
|
-
exit 1
|
57
|
-
end
|
58
|
-
|
59
|
-
|
60
|
-
if ['l', 'long', 'archive' ].include?( format.to_s ) ## note: allow passing in of symbol to e.g. 'long' or :long
|
61
|
-
if years.size == 2
|
62
|
-
"%3d0s/%4d-%02d" % [years[0] / 10, years[0], years[1] % 100] ## e.g. 2000s/2001-02
|
63
|
-
else ## assume size 1 (single year season)
|
64
|
-
"%3d0s/%4d" % [years[0] / 10, years[0]]
|
65
|
-
end
|
66
|
-
else ## default 'short' format / fallback
|
67
|
-
if years.size == 2
|
68
|
-
"%4d-%02d" % [years[0], years[1] % 100] ## e.g. 2001-02
|
69
|
-
else ## assume size 1 (single year season)
|
70
|
-
"%4d" % years[0]
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end # method directory
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
def start_year( season ) ## get start year
|
78
|
-
## convert season name to "standard" season name for directory
|
79
|
-
|
80
|
-
## todo/check: just return year from first for chars - keep it simple - why? why not?
|
81
|
-
if season =~ /^(\d{4})[\-\/](\d{4})$/ ## e.g. 2011-2010 or 2011/2011 => 2011-10
|
82
|
-
$1
|
83
|
-
elsif season =~ /^(\d{4})[\-\/](\d{2})$/
|
84
|
-
$1
|
85
|
-
elsif season =~ /^(\d{4})$/
|
86
|
-
$1
|
87
|
-
else
|
88
|
-
puts "*** !!!! wrong season format >>#{season}<<; exit; sorry"
|
89
|
-
exit 1
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
def end_year( season ) ## get end year
|
94
|
-
## convert season name to "standard" season name for directory
|
95
|
-
if season =~ /^(\d{4})[\-\/](\d{4})$/ ## e.g. 2011-2010 or 2011/2011 => 2011-10
|
96
|
-
$2
|
97
|
-
elsif season =~ /^(\d{4})[\-\/](\d{2})$/
|
98
|
-
## note: assume second year is always +1
|
99
|
-
## todo/fix: add assert/check - why? why not?
|
100
|
-
## eg. 1999-00 => 2000 or 1899-00 => 1900
|
101
|
-
($1.to_i+1).to_s
|
102
|
-
elsif season =~ /^(\d{4})$/
|
103
|
-
$1
|
104
|
-
else
|
105
|
-
puts "*** !!!! wrong season format >>#{season}<<; exit; sorry"
|
106
|
-
exit 1
|
107
|
-
end
|
108
|
-
end
|
109
|
-
end # module SeasonHelper
|
110
|
-
|
111
|
-
|
112
|
-
module SeasonUtils
|
113
|
-
extend SeasonHelper
|
114
|
-
## lets you use SeasonHelper as "globals" eg.
|
115
|
-
## SeasonUtils.prev( season ) etc.
|
116
|
-
end # SeasonUtils
|
data/test/test_find_datafiles.rb
DELETED
@@ -1,57 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
###
|
4
|
-
# to run use
|
5
|
-
# ruby -I ./lib -I ./test test/test_find_datafiles.rb
|
6
|
-
|
7
|
-
|
8
|
-
require 'helper'
|
9
|
-
|
10
|
-
class TestFindDatafiles < MiniTest::Test
|
11
|
-
|
12
|
-
def match_clubs( txt ) SportDb::Import::Configuration::CLUBS_REGEX.match( txt ); end
|
13
|
-
def match_clubs_wiki( txt ) SportDb::Import::Configuration::CLUBS_WIKI_REGEX.match( txt ); end
|
14
|
-
|
15
|
-
def match_leagues( txt ) SportDb::Import::Configuration::LEAGUES_REGEX.match( txt ); end
|
16
|
-
|
17
|
-
def test_find_clubs
|
18
|
-
assert match_clubs( 'de.clubs.txt' )
|
19
|
-
assert match_clubs( 'deutschland/de.clubs.txt' )
|
20
|
-
assert match_clubs( 'europe/de-deutschland/clubs.txt' )
|
21
|
-
assert match_clubs( 'de-deutschland/clubs.txt' )
|
22
|
-
assert match_clubs( 'clubs.txt' )
|
23
|
-
assert match_clubs( 'deutschland/clubs.txt' )
|
24
|
-
|
25
|
-
assert !match_clubs( 'de.clubs.wiki.txt' )
|
26
|
-
assert !match_clubs( 'deutschland/de.clubs.wiki.txt' )
|
27
|
-
assert !match_clubs( 'europe/de-deutschland/clubs.wiki.txt' )
|
28
|
-
assert !match_clubs( 'de-deutschland/clubs.wiki.txt' )
|
29
|
-
assert !match_clubs( 'clubs.wiki.txt' )
|
30
|
-
assert !match_clubs( 'deutschland/clubs.wiki.txt' )
|
31
|
-
end
|
32
|
-
|
33
|
-
def test_find_clubs_wiki
|
34
|
-
assert !match_clubs_wiki( 'de.clubs.txt' )
|
35
|
-
assert !match_clubs_wiki( 'deutschland/de.clubs.txt' )
|
36
|
-
assert !match_clubs_wiki( 'europe/de-deutschland/clubs.txt' )
|
37
|
-
assert !match_clubs_wiki( 'de-deutschland/clubs.txt' )
|
38
|
-
assert !match_clubs_wiki( 'clubs.txt' )
|
39
|
-
assert !match_clubs_wiki( 'deutschland/clubs.txt' )
|
40
|
-
|
41
|
-
assert match_clubs_wiki( 'de.clubs.wiki.txt' )
|
42
|
-
assert match_clubs_wiki( 'deutschland/de.clubs.wiki.txt' )
|
43
|
-
assert match_clubs_wiki( 'europe/de-deutschland/clubs.wiki.txt' )
|
44
|
-
assert match_clubs_wiki( 'de-deutschland/clubs.wiki.txt' )
|
45
|
-
assert match_clubs_wiki( 'clubs.wiki.txt' )
|
46
|
-
assert match_clubs_wiki( 'deutschland/clubs.wiki.txt' )
|
47
|
-
end
|
48
|
-
|
49
|
-
def test_find_leagues
|
50
|
-
assert match_leagues( 'eng.leagues.txt' )
|
51
|
-
assert match_leagues( 'england/eng.leagues.txt' )
|
52
|
-
assert match_leagues( 'europe/england/leagues.txt' )
|
53
|
-
assert match_leagues( 'england/leagues.txt' )
|
54
|
-
assert match_leagues( 'leagues.txt' )
|
55
|
-
end
|
56
|
-
|
57
|
-
end # class TestFindDatafiles
|
data/test/test_season_utils.rb
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
###
|
4
|
-
# to run use
|
5
|
-
# ruby -I ./lib -I ./test test/test_season_utils.rb
|
6
|
-
|
7
|
-
|
8
|
-
require 'helper'
|
9
|
-
|
10
|
-
class TestSeasonUtils < MiniTest::Test
|
11
|
-
|
12
|
-
def test_directory
|
13
|
-
assert_equal '2010-11', SeasonUtils.directory( '2010-11' )
|
14
|
-
assert_equal '2010-11', SeasonUtils.directory( '2010-2011' )
|
15
|
-
assert_equal '2010-11', SeasonUtils.directory( '2010/11' )
|
16
|
-
assert_equal '2010-11', SeasonUtils.directory( '2010/2011' )
|
17
|
-
assert_equal '2010', SeasonUtils.directory( '2010' )
|
18
|
-
|
19
|
-
assert_equal '2010s/2010-11', SeasonUtils.directory( '2010-11', format: 'long' )
|
20
|
-
assert_equal '2010s/2010-11', SeasonUtils.directory( '2010-2011', format: 'long' )
|
21
|
-
assert_equal '2010s/2010', SeasonUtils.directory( '2010', format: 'long' )
|
22
|
-
|
23
|
-
assert_equal '1999-00', SeasonUtils.directory( '1999-00' )
|
24
|
-
assert_equal '1999-00', SeasonUtils.directory( '1999-2000' )
|
25
|
-
assert_equal '1990s/1999-00', SeasonUtils.directory( '1999-00', format: 'long' )
|
26
|
-
assert_equal '1990s/1999-00', SeasonUtils.directory( '1999-2000', format: 'long' )
|
27
|
-
end # method test_diretory
|
28
|
-
|
29
|
-
end # class TestSeasonlUtils
|