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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 34f6b00e00c0ff63899b32ef86eefd077d54315a
4
- data.tar.gz: 6da90ea9439ed32f442fb148ce79d3184bfa7e32
3
+ metadata.gz: d9ab08e50e95d7fbaf6197f8cea2a7a6dc3cb112
4
+ data.tar.gz: 68a911b62e1fc80ab12d55874d2e6bc0f3dd63a5
5
5
  SHA512:
6
- metadata.gz: 8ea4888386c7ae6c371d5145728a04516de88d6aa3d392feb1a141301215fd0268338e944415137ea7ded6e740ff37256da584ef53c411c6f0b2441eef96d9ee
7
- data.tar.gz: f43c9e976a1ad41d5096bc7205799eb7371a980f8753dd6f5507e3e68ea46576e971cf41f347a0e369c83c4b4c2f52c6f7d430f1609343bc0a24213aedd2bb15
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
@@ -6,7 +6,7 @@ module Readers
6
6
 
7
7
  MAJOR = 0 ## todo: namespace inside version or something - why? why not??
8
8
  MINOR = 4
9
- PATCH = 0
9
+ PATCH = 2
10
10
  VERSION = [MAJOR,MINOR,PATCH].join('.')
11
11
 
12
12
  def self.version
@@ -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 - move into sportdb-formats and add datafile!!!
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
- def test_read_i
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 test_read_i
139
+ end # method test_read_eng
59
140
 
60
141
 
61
- def xxx_test_read_ii
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 test_read_ii
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.0
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-26 00:00:00.000000000 Z
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