sportdb-readers 0.2.1 → 0.2.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: b34ccb4d608b438478b0d909f5dad9e5f4807677
4
- data.tar.gz: bb1641c9eb65feebd42fbbecb9b3430c0b6c69ff
3
+ metadata.gz: 46454d349dc5a94aea1f56de0b900244df2607bd
4
+ data.tar.gz: b51de78a375e0a63838e845512c794b2abfdee62
5
5
  SHA512:
6
- metadata.gz: 269f51e9317a5762304ca0e36b9454a47a88e4cf6b7935690e6c2351c475ecfe7a24dffb1ac546af1f8925d3c7173cfb67373d7e46cd0b54923dcdedd8428f8c
7
- data.tar.gz: 1e908059a559669c4a8a15ae6c88778c2b9c4f07e2badb1a3dc1a595d3b58c15ee35c5bd57054859afce2e32da356108035b9be926a7d1274cc277d857e3e0a3
6
+ metadata.gz: 6fde9823e1e243e8f3be5824b1ff8846e7ad2f531551cc49a9e17165927b96305320d497a7385f45d9e56362c3d30fcc271f9d88b288a12df2ef4aab7ebba74b
7
+ data.tar.gz: 06b38e7dbce194808a843fd1b735002c31e5cd574a4c2b2b1c9bbe8d7b29c1c96c2c6690306b9514159f3d797d291d0dd09f7bd11405abae8e19f00be06b2d76
data/Manifest.txt CHANGED
@@ -3,10 +3,12 @@ Manifest.txt
3
3
  README.md
4
4
  Rakefile
5
5
  lib/sportdb/readers.rb
6
- lib/sportdb/readers/event_reader.rb
6
+ lib/sportdb/readers/conf_linter.rb
7
+ lib/sportdb/readers/conf_reader.rb
8
+ lib/sportdb/readers/league_outline_reader.rb
9
+ lib/sportdb/readers/match_linter.rb
7
10
  lib/sportdb/readers/match_parser.rb
8
11
  lib/sportdb/readers/match_reader.rb
9
- lib/sportdb/readers/outline_reader.rb
10
12
  lib/sportdb/readers/version.rb
11
13
  test/helper.rb
12
14
  test/test_match_parser.rb
@@ -9,17 +9,33 @@ require 'sportdb/sync'
9
9
  ###
10
10
  # our own code
11
11
  require 'sportdb/readers/version' # let version always go first
12
- require 'sportdb/readers/outline_reader'
13
- require 'sportdb/readers/event_reader'
12
+ require 'sportdb/readers/league_outline_reader'
13
+ require 'sportdb/readers/conf_reader'
14
+ require 'sportdb/readers/conf_linter'
14
15
  require 'sportdb/readers/match_parser'
15
16
  require 'sportdb/readers/match_reader'
17
+ require 'sportdb/readers/match_linter'
18
+
16
19
 
17
20
 
18
21
  ##
19
22
  ## add convenience shortcut helpers
20
23
  module SportDb
21
24
 
22
- def self.read( path )
25
+ def self.read_conf( path, sync: true ) ## note: sync is dry run (for lint checking)
26
+ sync ? ConfReaderV2.read( path ) : ConfLinter.read( path )
27
+ end
28
+
29
+ ### todo: add alias read_matches - why? why not?
30
+ def self.read_match( path, sync: true ) ## note: sync is dry run (for lint checking)
31
+ sync ? MatchReaderV2.read( path ) : MatchLinter.read( path )
32
+ end
33
+
34
+ def self.lint_conf( path ) read_conf( path, sync: false ); end
35
+ def self.lint_match( path ) read_match( path, sync: false ); end
36
+
37
+
38
+ def self.read( path, sync: true )
23
39
  ## step 1: collect all datafiles
24
40
  if File.directory?( path ) ## if directory read complete package
25
41
  datafiles_conf = Datafile.find_conf( path )
@@ -27,21 +43,20 @@ module SportDb
27
43
  /[a-z0-9_-]+\.txt$ ## txt e.g /1-premierleague.txt
28
44
  }x )
29
45
 
30
- datafiles_conf.each { |datafile| EventReaderV2.read( datafile ) }
31
- datafiles.each { |datafile| MatchReaderV2.read( datafile ) }
46
+ datafiles_conf.each { |datafile| read_conf( datafile, sync: sync ) }
47
+ datafiles.each { |datafile| read_match( datafile, sync: sync ) }
32
48
  else
33
- ## check if datafile matches configuration naming (e.g. .conf.txt)
49
+ ## check if datafile matches conf(iguration) naming (e.g. .conf.txt)
34
50
  if Datafile.match_conf( path )
35
- EventReaderV2.read( path )
51
+ read_conf( path, sync: sync )
36
52
  else ## assume "regular" match datafile
37
- MatchReaderV2.read( path )
53
+ read_match( path, sync: sync )
38
54
  end
39
55
  end
40
56
  end # method read
41
57
 
42
- ########################################
43
- ## more convenience alias
44
- ConfReaderV2 = EventReaderV2 ## add why? why not?
58
+ def self.lint( path ) read( path, sync: false ); end
59
+
45
60
  end # module SportDb
46
61
 
47
62
 
@@ -0,0 +1,103 @@
1
+ # encoding: utf-8
2
+
3
+ module SportDb
4
+
5
+
6
+ class ConfLinter
7
+
8
+ def self.config() Import.config; end ## shortcut convenience helper
9
+
10
+
11
+ def self.read( path ) ## use - rename to read_file or from_file etc. - why? why not?
12
+ puts "reading conf(iguration) datafile >#{path}<..."
13
+ txt = File.open( path, 'r:utf-8' ).read
14
+ parse( txt )
15
+ end
16
+
17
+ def self.parse( txt )
18
+ recs = LeagueOutlineReader.parse( txt )
19
+
20
+ if recs.empty?
21
+ puts " ** !!! WARN !!! - no league headings found"
22
+ else
23
+ puts " found #{recs.size} league (+season+stage) headings"
24
+ recs.each do |rec|
25
+ ## rec[:league] )
26
+ ## rec[:season] )
27
+ ## rec[:stage]
28
+ puts " league: >#{rec[:league]}<, season: >#{rec[:season]}<, stage: >#{rec[:stage]}<"
29
+ end
30
+ end
31
+
32
+ ## pass 2 - check & map; replace inline (string with record)
33
+ recs.each do |rec|
34
+ league = rec[:league]
35
+ clubs = [] ## convert lines to clubs
36
+ rec[:lines].each do |line|
37
+
38
+ next if line =~ /^[ -]+$/ ## skip decorative lines with dash only (e.g. ---- or - - - -) etc.
39
+
40
+ scan = StringScanner.new( line )
41
+
42
+ if scan.check( /\d{1,2}[ ]+/ ) ## entry with standaning starts with ranking e.g. 1,2,3, etc.
43
+ puts " table entry >#{line}<"
44
+ rank = scan.scan( /\d{1,2}[ ]+/ ).strip # note: strip trailing spaces
45
+
46
+ ## note: uses look ahead scan until we hit at least two spaces
47
+ ## or the end of string (standing records for now optional)
48
+ name = scan.scan_until( /(?=\s{2})|$/ )
49
+ if scan.eos?
50
+ standing = nil
51
+ else
52
+ standing = scan.rest.strip # note: strip leading and trailing spaces
53
+ end
54
+ puts " rank: >#{rank}<, name: >#{name}<, standing: >#{standing}<"
55
+
56
+ ## note: rank and standing gets ignored (not used) for now
57
+ else
58
+ ## assume club is full line
59
+ name = line
60
+ end
61
+
62
+ clubs << find_club( name, league.country )
63
+ end
64
+
65
+ rec[:clubs] = clubs
66
+ rec.delete( :lines ) ## remove lines entry
67
+ end
68
+
69
+ recs
70
+ end # method read
71
+
72
+
73
+ ### todo/fix: move to clubs for sharing!!!!!!! use clubs.find_by!( name:, country: )
74
+ def self.find_club( name, country ) ## todo/fix: add international or league flag?
75
+ club = nil
76
+ m = config.clubs.match_by( name: name, country: country )
77
+
78
+ if m.nil?
79
+ ## (re)try with second country - quick hacks for known leagues
80
+ ## todo/fix: add league flag to activate!!!
81
+ m = config.clubs.match_by( name: name, country: config.countries['wal']) if country.key == 'eng'
82
+ m = config.clubs.match_by( name: name, country: config.countries['nir']) if country.key == 'ie'
83
+ m = config.clubs.match_by( name: name, country: config.countries['mc']) if country.key == 'fr'
84
+ m = config.clubs.match_by( name: name, country: config.countries['li']) if country.key == 'ch'
85
+ m = config.clubs.match_by( name: name, country: config.countries['ca']) if country.key == 'us'
86
+ end
87
+
88
+ if m.nil?
89
+ puts "** !!! ERROR !!! no match for club >#{name}<"
90
+ exit 1
91
+ elsif m.size > 1
92
+ puts "** !!! ERROR !!! too many matches (#{m.size}) for club >#{name}<:"
93
+ pp m
94
+ exit 1
95
+ else # bingo; match - assume size == 1
96
+ club = m[0]
97
+ end
98
+
99
+ club
100
+ end
101
+
102
+ end # class ConfLinter
103
+ end # module SportDb
@@ -3,7 +3,7 @@
3
3
  module SportDb
4
4
 
5
5
 
6
- class EventReaderV2 ## todo/check: rename to EventsReaderV2 (use plural?) why? why not?
6
+ class ConfReaderV2 ## todo/check: rename to EventsReaderV2 (use plural?) why? why not?
7
7
 
8
8
  def self.config() Import.config; end ## shortcut convenience helper
9
9
 
@@ -114,5 +114,5 @@ class EventReaderV2 ## todo/check: rename to EventsReaderV2 (use plural?) why
114
114
  club
115
115
  end
116
116
 
117
- end # class EventReaderV2
117
+ end # class ConfReaderV2
118
118
  end # module SportDb
@@ -82,6 +82,7 @@ class LeagueOutlineReader
82
82
  known_stages = ['regular season',
83
83
  'championship round',
84
84
  'relegation round',
85
+ 'play-offs'
85
86
  ]
86
87
 
87
88
  if known_stages.include?( name.downcase )
@@ -0,0 +1,30 @@
1
+ # encoding: utf-8
2
+
3
+ module SportDb
4
+
5
+ class MatchLinter
6
+
7
+ def self.read( path ) ## use - rename to read_file or from_file etc. - why? why not?
8
+ puts "reading match datafile >#{path}<..."
9
+ txt = File.open( path, 'r:utf-8' ).read
10
+ parse( txt )
11
+ end
12
+
13
+ def self.parse( txt )
14
+ recs = LeagueOutlineReader.parse( txt )
15
+
16
+ if recs.empty?
17
+ puts " ** !!! WARN !!! - no league headings found"
18
+ else
19
+ puts " found #{recs.size} league (+season+stage) headings"
20
+ recs.each do |rec|
21
+ ## rec[:league] )
22
+ ## rec[:season] )
23
+ ## rec[:stage]
24
+ puts " league: >#{rec[:league]}<, season: >#{rec[:season]}<, stage: >#{rec[:stage]}<"
25
+ end
26
+ end
27
+ recs
28
+ end # method read
29
+ end # class MatchLinter
30
+ end # module SportDb
@@ -6,7 +6,7 @@ module Readers
6
6
 
7
7
  MAJOR = 0 ## todo: namespace inside version or something - why? why not??
8
8
  MINOR = 2
9
- PATCH = 1
9
+ PATCH = 2
10
10
  VERSION = [MAJOR,MINOR,PATCH].join('.')
11
11
 
12
12
  def self.version
data/test/test_reader.rb CHANGED
@@ -24,7 +24,7 @@ class TestReader < MiniTest::Test
24
24
  # path = "../../../openfootball/england/2017-18/.conf.txt"
25
25
  # path = "../../../openfootball/england/2018-19/.conf.txt"
26
26
  # path = "../../../openfootball/england/2019-20/.conf.txt"
27
- recs = SportDb::EventReaderV2.read( path )
27
+ recs = SportDb::ConfReaderV2.read( path )
28
28
  # path = "../../../openfootball/austria/2018-19/1-bundesliga.txt"
29
29
  path = "../../../openfootball/england/2015-16/1-premierleague-i.txt"
30
30
  # path = "../../../openfootball/england/2017-18/1-premierleague-i.txt"
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.2.1
4
+ version: 0.2.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-09 00:00:00.000000000 Z
11
+ date: 2019-11-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sportdb-config
@@ -95,10 +95,12 @@ files:
95
95
  - README.md
96
96
  - Rakefile
97
97
  - lib/sportdb/readers.rb
98
- - lib/sportdb/readers/event_reader.rb
98
+ - lib/sportdb/readers/conf_linter.rb
99
+ - lib/sportdb/readers/conf_reader.rb
100
+ - lib/sportdb/readers/league_outline_reader.rb
101
+ - lib/sportdb/readers/match_linter.rb
99
102
  - lib/sportdb/readers/match_parser.rb
100
103
  - lib/sportdb/readers/match_reader.rb
101
- - lib/sportdb/readers/outline_reader.rb
102
104
  - lib/sportdb/readers/version.rb
103
105
  - test/helper.rb
104
106
  - test/test_match_parser.rb