sportdb-readers 0.4.0 → 0.4.2
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 -2
- data/lib/sportdb/readers/version.rb +1 -1
- data/lib/sportdb/readers.rb +2 -2
- data/test/test_reader.rb +85 -4
- metadata +2 -4
- data/lib/sportdb/readers/club_props_reader.rb +0 -70
- data/test/test_props.rb +0 -47
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d9ab08e50e95d7fbaf6197f8cea2a7a6dc3cb112
|
4
|
+
data.tar.gz: 68a911b62e1fc80ab12d55874d2e6bc0f3dd63a5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 73241f497262aaeb3b10a694c7af959745254adfcaa825ef577cbfcf89a5c44b1b6dd795e5c216bb69c6923af477b8306614675e7acd7c82729bb55fab39196e
|
7
|
+
data.tar.gz: 19b772c539490c3e41d9d0324ec1b54afe7b5a973065491a0d14798f1b0dc9242974076d278ded95bbdfa146d5a31fcf7e1ecd1a68aba4e2a19472176ee93e24
|
data/Manifest.txt
CHANGED
@@ -3,7 +3,6 @@ Manifest.txt
|
|
3
3
|
README.md
|
4
4
|
Rakefile
|
5
5
|
lib/sportdb/readers.rb
|
6
|
-
lib/sportdb/readers/club_props_reader.rb
|
7
6
|
lib/sportdb/readers/conf_linter.rb
|
8
7
|
lib/sportdb/readers/conf_parser_auto.rb
|
9
8
|
lib/sportdb/readers/conf_reader.rb
|
@@ -18,6 +17,5 @@ test/helper.rb
|
|
18
17
|
test/test_conf_parser_auto.rb
|
19
18
|
test/test_match_parser.rb
|
20
19
|
test/test_package.rb
|
21
|
-
test/test_props.rb
|
22
20
|
test/test_read.rb
|
23
21
|
test/test_reader.rb
|
data/lib/sportdb/readers.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
require 'zip' ## todo/check: if zip is alreay included in a required module
|
3
|
+
require 'zip' ## todo/check: if zip is alreay included in a required module
|
4
|
+
## - move into sportdb-formats and add datafile!!!
|
4
5
|
|
5
6
|
|
6
7
|
|
@@ -19,7 +20,6 @@ require 'sportdb/readers/conf_linter'
|
|
19
20
|
require 'sportdb/readers/match_parser'
|
20
21
|
require 'sportdb/readers/match_reader'
|
21
22
|
require 'sportdb/readers/match_linter'
|
22
|
-
require 'sportdb/readers/club_props_reader'
|
23
23
|
require 'sportdb/readers/datafile'
|
24
24
|
require 'sportdb/readers/package'
|
25
25
|
|
data/test/test_reader.rb
CHANGED
@@ -10,7 +10,88 @@ require 'helper'
|
|
10
10
|
|
11
11
|
class TestReader < MiniTest::Test
|
12
12
|
|
13
|
-
|
13
|
+
|
14
|
+
def test_read_mauritius
|
15
|
+
SportDb.connect( adapter: 'sqlite3', database: ':memory:' )
|
16
|
+
SportDb.create_all ## build schema
|
17
|
+
|
18
|
+
## turn on logging to console
|
19
|
+
ActiveRecord::Base.logger = Logger.new(STDOUT)
|
20
|
+
|
21
|
+
leagues_txt =<<TXT
|
22
|
+
= Mauritius =
|
23
|
+
|
24
|
+
1 Mauritius Premier League
|
25
|
+
cup Mauritius Cup
|
26
|
+
TXT
|
27
|
+
|
28
|
+
|
29
|
+
clubs_txt =<<TXT
|
30
|
+
= Mauritius =
|
31
|
+
|
32
|
+
Cercle de Joachim | Cercle de Joachim SC | Joachim
|
33
|
+
Chamarel SC | Chamarel | Chamarel Sport Club
|
34
|
+
Curepipe Starlight | Curepipe Starlight SC
|
35
|
+
Entente Boulet Rouge | Entente Boulet Rouge SC | Entente Boulet Rouge-Riche Mare Rovers
|
36
|
+
La Cure Sylvester | La Cure Sylvester SC | La Cure
|
37
|
+
Pamplemousses | Pamplemousses SC
|
38
|
+
Petite Rivière Noire | Petite Rivière Noire SC | Petite Rivière
|
39
|
+
AS Port-Louis 2000 | ASPL 2000 | Port-Louis 2000 |Association Sportive Port-Louis 2000
|
40
|
+
AS Quatre Bornes | ASQB | Quatre Bornes
|
41
|
+
Rivière du Rempart | AS Rivière du Rempart
|
42
|
+
Pointe-aux-Sables Mates
|
43
|
+
Savanne SC | Savanne Sporting Club
|
44
|
+
TXT
|
45
|
+
|
46
|
+
recs = SportDb::Import::LeagueReader.parse( leagues_txt )
|
47
|
+
SportDb::Import::config.leagues.add( recs )
|
48
|
+
|
49
|
+
recs = SportDb::Import::ClubReader.parse( clubs_txt )
|
50
|
+
SportDb::Import::config.clubs.add( recs )
|
51
|
+
|
52
|
+
pp recs
|
53
|
+
|
54
|
+
country = SportDb::Import::config.countries[ 'Mauritius']
|
55
|
+
pp country
|
56
|
+
clubs = SportDb::Import::config.clubs.match( 'Chamarel SC' )
|
57
|
+
pp clubs
|
58
|
+
club = SportDb::Import::config.clubs.find_by( name: 'Chamarel SC',
|
59
|
+
country: country )
|
60
|
+
pp club
|
61
|
+
|
62
|
+
txt =<<TXT
|
63
|
+
= Mauritius Premier League 2014/15 =
|
64
|
+
|
65
|
+
Matchday 1
|
66
|
+
[Wed Nov/5]
|
67
|
+
Curepipe Starlight 1-3 Petite Rivière Noire
|
68
|
+
AS Quatre Bornes 1-0 La Cure Sylvester
|
69
|
+
Pamplemousses 0-1 Rivière du Rempart
|
70
|
+
AS Port-Louis 2000 5-1 Entente Boulet Rouge
|
71
|
+
Chamarel SC 2-3 Cercle de Joachim
|
72
|
+
|
73
|
+
Matchday 2
|
74
|
+
[Sun Nov/9]
|
75
|
+
Curepipe Starlight 2-1 AS Quatre Bornes
|
76
|
+
Entente Boulet Rouge 1-2 Chamarel SC
|
77
|
+
Rivière du Rempart 1-1 AS Port-Louis 2000
|
78
|
+
La Cure Sylvester 1-2 Pamplemousses
|
79
|
+
Petite Rivière Noire 2-0 Cercle de Joachim
|
80
|
+
|
81
|
+
Matchday 3
|
82
|
+
[Wed Nov/12]
|
83
|
+
AS Quatre Bornes 1-2 Petite Rivière Noire
|
84
|
+
Pamplemousses 0-4 Curepipe Starlight
|
85
|
+
Chamarel SC 1-1 Rivière du Rempart
|
86
|
+
Cercle de Joachim 2-2 Entente Boulet Rouge
|
87
|
+
AS Port-Louis 2000 1-0 La Cure Sylvester
|
88
|
+
TXT
|
89
|
+
|
90
|
+
SportDb::MatchReaderV2.parse( txt )
|
91
|
+
end # method test_read_mauritius
|
92
|
+
|
93
|
+
|
94
|
+
def xxx_test_read_eng
|
14
95
|
SportDb.connect( adapter: 'sqlite3', database: ':memory:' )
|
15
96
|
SportDb.create_all ## build schema
|
16
97
|
|
@@ -55,10 +136,10 @@ Matchday 2
|
|
55
136
|
TXT
|
56
137
|
|
57
138
|
SportDb::MatchReaderV2.parse( txt )
|
58
|
-
end # method
|
139
|
+
end # method test_read_eng
|
59
140
|
|
60
141
|
|
61
|
-
def
|
142
|
+
def xxx_test_read
|
62
143
|
SportDb.connect( adapter: 'sqlite3', database: ':memory:' )
|
63
144
|
SportDb.create_all ## build schema
|
64
145
|
|
@@ -80,5 +161,5 @@ TXT
|
|
80
161
|
recs = SportDb::MatchReaderV2.read( path )
|
81
162
|
# path = "../../../openfootball/england/2017-18/1-premierleague-ii.txt"
|
82
163
|
#recs = SportDb::MatchReaderV2.read( path )
|
83
|
-
end # method
|
164
|
+
end # method test_read
|
84
165
|
end # class TestReader
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sportdb-readers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.2
|
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-11-
|
11
|
+
date: 2019-11-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sportdb-config
|
@@ -95,7 +95,6 @@ files:
|
|
95
95
|
- README.md
|
96
96
|
- Rakefile
|
97
97
|
- lib/sportdb/readers.rb
|
98
|
-
- lib/sportdb/readers/club_props_reader.rb
|
99
98
|
- lib/sportdb/readers/conf_linter.rb
|
100
99
|
- lib/sportdb/readers/conf_parser_auto.rb
|
101
100
|
- lib/sportdb/readers/conf_reader.rb
|
@@ -110,7 +109,6 @@ files:
|
|
110
109
|
- test/test_conf_parser_auto.rb
|
111
110
|
- test/test_match_parser.rb
|
112
111
|
- test/test_package.rb
|
113
|
-
- test/test_props.rb
|
114
112
|
- test/test_read.rb
|
115
113
|
- test/test_reader.rb
|
116
114
|
homepage: https://github.com/sportdb/sport.db
|
@@ -1,70 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
|
4
|
-
module SportDb
|
5
|
-
module Import
|
6
|
-
|
7
|
-
|
8
|
-
class ClubPropsReader
|
9
|
-
|
10
|
-
def self.config() Import.config; end ## shortcut convenience helper
|
11
|
-
|
12
|
-
def self.read( path ) ## use - rename to read_file or from_file etc. - why? why not?
|
13
|
-
txt = File.open( path, 'r:utf-8' ).read
|
14
|
-
parse( txt )
|
15
|
-
end
|
16
|
-
|
17
|
-
def self.parse( txt )
|
18
|
-
recs = parse_csv( txt )
|
19
|
-
recs.each do |rec|
|
20
|
-
name = rec[:name]
|
21
|
-
if name.nil?
|
22
|
-
puts "** !!! ERROR !!! Name column required / missing / NOT found in row:"
|
23
|
-
pp rec
|
24
|
-
exit 1
|
25
|
-
end
|
26
|
-
|
27
|
-
## find / match club by (canocial) name
|
28
|
-
m = config.clubs.match( name )
|
29
|
-
if m && m.size > 1
|
30
|
-
puts "** !!! WARN !!! ambigious (multiple) club matches (#{m.size}) for name >#{name}< in props row:"
|
31
|
-
pp rec
|
32
|
-
pp m
|
33
|
-
|
34
|
-
## todo/fix: try filter by canonical name if more than one match
|
35
|
-
m = m.select { |club| club.name == name }
|
36
|
-
m = nil if m.empty? ## note: reset to nil if no more matches
|
37
|
-
end
|
38
|
-
|
39
|
-
if m.nil?
|
40
|
-
puts "** !!! ERROR !!! no club match for (canonical) name >#{name}< in props row:"
|
41
|
-
pp rec
|
42
|
-
exit 1
|
43
|
-
elsif m.size > 1
|
44
|
-
puts "** !!! ERROR !!! ambigious (multiple) club matches (#{m.size}) for (canonical) name >#{name}< in props row:"
|
45
|
-
pp rec
|
46
|
-
pp m
|
47
|
-
exit 1
|
48
|
-
else ## assume size == 1, bingo!!!
|
49
|
-
club_rec = m[0]
|
50
|
-
## todo/fix: warn if name differes from (canonical) name
|
51
|
-
## todo/fix: also add props to in-memory structs/records!!!
|
52
|
-
## todo/fix: only updated "on-demand" from in-memory struct/records!!!!
|
53
|
-
|
54
|
-
## update database
|
55
|
-
club = Sync::Club.find_or_create( club_rec )
|
56
|
-
## update attributes
|
57
|
-
attributes = {}
|
58
|
-
attributes[:key] = rec[:key] if rec[:key]
|
59
|
-
attributes[:code] = rec[:code] if rec[:code]
|
60
|
-
|
61
|
-
club.attributes = attributes
|
62
|
-
club.save!
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end # method parse
|
66
|
-
|
67
|
-
end # class ClubPropsReader
|
68
|
-
|
69
|
-
end ## module Import
|
70
|
-
end ## module SportDb
|
data/test/test_props.rb
DELETED
@@ -1,47 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
###
|
4
|
-
# to run use
|
5
|
-
# ruby -I ./lib -I ./test test/test_props.rb
|
6
|
-
|
7
|
-
|
8
|
-
require 'helper'
|
9
|
-
|
10
|
-
class TestProps < MiniTest::Test
|
11
|
-
|
12
|
-
ENG_CLUBS_PROPS_TXT =<<TXT
|
13
|
-
####################################
|
14
|
-
# English League Teams
|
15
|
-
#
|
16
|
-
# note: three letter codes (tags) taken from official premierleague.com site
|
17
|
-
|
18
|
-
Key, Name, Code
|
19
|
-
chelsea, Chelsea FC, CHE
|
20
|
-
arsenal, Arsenal FC, ARS
|
21
|
-
tottenham, Tottenham Hotspur, TOT
|
22
|
-
westham, West Ham United, WHU
|
23
|
-
crystalpalace, Crystal Palace, CRY
|
24
|
-
manutd, Manchester United, MUN
|
25
|
-
mancity, Manchester City, MCI
|
26
|
-
TXT
|
27
|
-
|
28
|
-
def test_parse_csv
|
29
|
-
recs = parse_csv( ENG_CLUBS_PROPS_TXT )
|
30
|
-
pp recs
|
31
|
-
|
32
|
-
assert_equal [{ key: 'chelsea', name: 'Chelsea FC', code: 'CHE' },
|
33
|
-
{ key: 'arsenal', name: 'Arsenal FC', code: 'ARS' }], recs[0..1]
|
34
|
-
end
|
35
|
-
|
36
|
-
|
37
|
-
def test_parse
|
38
|
-
SportDb.connect( adapter: 'sqlite3', database: ':memory:' )
|
39
|
-
SportDb.create_all ## build schema
|
40
|
-
|
41
|
-
## turn on logging to console
|
42
|
-
ActiveRecord::Base.logger = Logger.new(STDOUT)
|
43
|
-
|
44
|
-
SportDb::Import::ClubPropsReader.parse( ENG_CLUBS_PROPS_TXT )
|
45
|
-
end # method test_parse
|
46
|
-
|
47
|
-
end # class TestProps
|