sportdb-models 1.12.0 → 1.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 942cefb9499f99a5fc881b0d5ea1fb6d36315151
4
- data.tar.gz: 0d2638fe812b34d2e1d56a759bbd79434c9b14ac
3
+ metadata.gz: 6581b2503f64b81e2e13054cfd6fcdc82ef1cd92
4
+ data.tar.gz: 53c61cb4597030a55359c09a8952d2ffa3b3d0ee
5
5
  SHA512:
6
- metadata.gz: d1005ea0b22cb6aa7a411a3cfdbebb4637ef8d850b379de2d3395d0053001882b342353cbb88ecc322ae991fbb8472e4663bd89d23a6379c399eb4baaf7c1408
7
- data.tar.gz: 90ff71d8d400abb55a5d7b2dd69b474175a1dfbdaac5d302e9e9f76fbc29684a5679632c091d55bde3b4fa9cfe715e455e2cba5f2483afb19ec7bf46a9669dd7
6
+ metadata.gz: 8e07c41d35dbd0beff9d7ac7d90256d83d5d176140b246f9271afaf246b2ddeef7082632743e8db3f3bdb9364d93e19357541d4509d53b897ce68643e4cbb7ef
7
+ data.tar.gz: c5240235260c31b5968e2069b0797b6d8f56d5c9aa271f6e0e55e8255da43829e874cb8b5afa4489c15fc0ac9b6cdeffdcc7f768055e290578c9fa66f89f577b
data/Manifest.txt CHANGED
@@ -50,6 +50,7 @@ lib/sportdb/models/world/continent.rb
50
50
  lib/sportdb/models/world/country.rb
51
51
  lib/sportdb/models/world/state.rb
52
52
  lib/sportdb/patterns.rb
53
+ lib/sportdb/pretty_printer.rb
53
54
  lib/sportdb/reader.rb
54
55
  lib/sportdb/reader_file.rb
55
56
  lib/sportdb/reader_zip.rb
@@ -81,6 +82,7 @@ test/data/at-austria/2013_14/el.txt
81
82
  test/data/at-austria/2013_14/el.yml
82
83
  test/data/at-austria/2013_14/squads/austria.txt
83
84
  test/data/at-austria/2013_14/squads/salzburg.txt
85
+ test/data/at-austria/2014_15/1-bundesliga-ii.txt
84
86
  test/data/at-austria/leagues.txt
85
87
  test/data/at-austria/teams.txt
86
88
  test/data/at-austria/teams_2.txt
@@ -128,6 +130,7 @@ test/test_date.rb
128
130
  test/test_goals.rb
129
131
  test/test_lang.rb
130
132
  test/test_load.rb
133
+ test/test_pp.rb
131
134
  test/test_reader.rb
132
135
  test/test_reader_from_string.rb
133
136
  test/test_round_auto.rb
@@ -88,6 +88,8 @@ require 'sportdb/lang'
88
88
  require 'sportdb/deleter'
89
89
  require 'sportdb/stats'
90
90
 
91
+ require 'sportdb/pretty_printer'
92
+
91
93
 
92
94
  module SportDb
93
95
 
@@ -0,0 +1,175 @@
1
+ # encoding: UTF-8
2
+
3
+ module SportDb
4
+
5
+
6
+ ###
7
+ ## reads in a text files
8
+ ## and tries to fix up/patch some parts
9
+
10
+
11
+ class Patcher
12
+
13
+ include LogUtils::Logging
14
+
15
+ def initialize( root, opts={} )
16
+ @root = root
17
+ @path = opts[:path] || opts[:paths] # pass in regex as string
18
+ @names = opts[:name] || opts[:names] # pass in regex as string
19
+
20
+ @path_regex = Regexp.new( @path ) if @path
21
+ @names_regex = Regexp.new( @names ) if @names
22
+ end
23
+
24
+
25
+ def find_files
26
+ ## note: for now always filter by .txt extension
27
+ files = Dir[ "#{@root}/**/*.txt" ]
28
+
29
+ puts "before filter:"
30
+ pp files
31
+
32
+ files = files.select do |f|
33
+
34
+ basename = File.basename( f )
35
+ dirname = File.dirname( f ) # note: add trailing slash
36
+ dirname = "#{dirname}/"
37
+
38
+ puts " basename=>#{basename}<, dirname=>#{dirname}<"
39
+
40
+ if @path_regex
41
+ match_dirname = @path_regex === dirname # note: use === (triple) for true/false regex match
42
+ else
43
+ match_dirname = true
44
+ end
45
+
46
+ if @names_regex
47
+ match_basename = @names_regex === basename
48
+ else
49
+ match_basename = true
50
+ end
51
+
52
+ match_basename && match_dirname
53
+ end
54
+
55
+ puts "after filter:"
56
+ pp files
57
+
58
+ files
59
+ end # method find_files
60
+
61
+
62
+ def patch( save=false)
63
+ files = find_files
64
+ change_logs = []
65
+
66
+ files.each do |file|
67
+ p = PrettyPrinter.from_file( file )
68
+ new_text, change_log = p.patch
69
+
70
+ next if change_log.empty? ## no changes
71
+
72
+ if save
73
+ File.open( file, 'w' ) do |f|
74
+ f.write new_text
75
+ end
76
+ end
77
+
78
+ change_logs << [file, change_log]
79
+ end
80
+
81
+ change_logs ## return change_logs or empty array
82
+ end # method patch
83
+
84
+ end ## class Patcher
85
+
86
+
87
+ class PrettyPrinter
88
+
89
+ include LogUtils::Logging
90
+
91
+ def self.from_file( path, opts={} )
92
+ ## note: assume/enfore utf-8 encoding (with or without BOM - byte order mark)
93
+ ## - see textutils/utils.rb
94
+ text = File.read_utf8( path )
95
+ self.from_string( text, opts )
96
+ end
97
+
98
+ def self.from_string( text, opts={} )
99
+ self.new( text, opts )
100
+ end
101
+
102
+
103
+ def initialize( text, opts={} )
104
+ @old_text = text
105
+ @opts = opts
106
+ end
107
+
108
+
109
+ ## change to DE_SCORES_REGEX or SCORES_DE_REGEX ??
110
+ SCORES_REGEX = /\b
111
+ (?<score1>\d{1,2})
112
+ -
113
+ (?<score2>\d{1,2})
114
+ \b
115
+ /x
116
+
117
+ def patch ## return new text (and change log??)
118
+ new_text = ''
119
+ change_log = [] ## track changes - rename - use edits? changes? etc.
120
+ line_no = 0
121
+
122
+ @old_text.each_line do |line|
123
+ line_no +=1
124
+
125
+ # comments allow:
126
+ # 1) ##### (shell/ruby style)
127
+ # 2) -- comment here (haskel/?? style)
128
+ # 3) % comment here (tex/latex style)
129
+
130
+ if line =~ /^\s*#/ || line =~ /^\s*--/ || line =~ /^\s*%/
131
+ # skip komments and do NOT copy to result (keep comments secret!)
132
+ logger.debug "[#{line_no}] add comment line >#{line}<"
133
+ new_text << line
134
+ next
135
+ end
136
+
137
+ if line =~ /^\s*$/
138
+ # kommentar oder leerzeile überspringen
139
+ logger.debug "[#{line_no}] add blank line >#{line}<"
140
+ new_text << line
141
+ next
142
+ end
143
+
144
+ ## do nothing for now
145
+ if line =~ SCORES_REGEX
146
+ ## patch scores format
147
+ logger.debug "** found scores >#{line}<"
148
+
149
+ new_line = line.dup
150
+ new_line.gsub!( SCORES_REGEX ) do |m|
151
+ logger.debug " match: >#{m}< : #{m.class.name}"
152
+
153
+ old_scores = m
154
+ ## todo: how to use named captures? possible?
155
+ new_scores = "#{$1}:#{$2}"
156
+
157
+ change_log << [line_no, "changed >#{old_scores}< to >#{new_scores}< in >#{line}<"]
158
+
159
+ new_scores
160
+ end
161
+
162
+ logger.debug "[#{line_no}] add patched line >#{new_line}<"
163
+ new_text << new_line
164
+ else
165
+ logger.debug "[#{line_no}] add >#{line}<"
166
+ new_text << line
167
+ end
168
+ end # each lines
169
+
170
+ [new_text, change_log]
171
+ end # method patch
172
+
173
+
174
+ end # class PrettyPrinter
175
+ end # module SportDb
@@ -3,7 +3,7 @@
3
3
  module SportDb
4
4
 
5
5
  MAJOR = 1 ## todo: namespace inside version or something - why? why not??
6
- MINOR = 12
6
+ MINOR = 13
7
7
  PATCH = 0
8
8
  VERSION = [MAJOR,MINOR,PATCH].join('.')
9
9
 
@@ -0,0 +1,158 @@
1
+ ###################################################
2
+ # Österreichische Bundesliga 2014/15 - Frühjahr
3
+
4
+
5
+ 20. Runde
6
+
7
+ [Sa 14.2.]
8
+ Rapid Wien 3-0 SV Ried
9
+ SV Grödig 0-2 Sturm Graz
10
+ Wolfsberger AC 1-0 Austria Wien
11
+ Wr. Neustadt 0-2 RB Salzburg
12
+ SCR Altach 2-0 Admira Wacker
13
+
14
+ 21. Runde
15
+
16
+ [Sa 21.2.]
17
+ SV Grödig 2-0 Wolfsberger AC
18
+ Austria Wien 5-2 SCR Altach
19
+ Sturm Graz 3-3 Wr. Neustadt
20
+ SV Ried 2-2 RB Salzburg
21
+ Admira Wacker 1-1 Rapid Wien
22
+
23
+ 22. Runde
24
+
25
+ [Sa 28.2.]
26
+ RB Salzburg 3-1 SV Grödig
27
+ Rapid Wien 1-0 Sturm Graz
28
+ SV Ried 2-2 Admira Wacker
29
+ Wr. Neustadt 1-0 Austria Wien
30
+ SCR Altach 1-0 Wolfsberger AC
31
+
32
+ 23. Runde
33
+
34
+ [Di 3.3.]
35
+ Rapid Wien 1-0 SCR Altach
36
+ SV Grödig 1-3 Wr. Neustadt
37
+ Sturm Graz 2-1 Austria Wien
38
+ Wolfsberger AC 1-2 SV Ried
39
+ Admira Wacker 1-4 RB Salzburg
40
+
41
+ 24. Runde
42
+
43
+ [Sa 7.3.]
44
+ RB Salzburg 0-1 SCR Altach
45
+ Austria Wien 2-1 Rapid Wien
46
+ Sturm Graz 2-0 Wolfsberger AC
47
+ SV Ried 2-1 SV Grödig
48
+ Wr. Neustadt 0-0 Admira Wacker
49
+
50
+ 25. Runde
51
+
52
+ [Sa 14.3.]
53
+ RB Salzburg 2-1 Sturm Graz
54
+ Rapid Wien 4-0 SV Grödig
55
+ Wolfsberger AC 2-0 Wr. Neustadt
56
+ Admira Wacker 1-1 Austria Wien
57
+ SCR Altach 2-1 SV Ried
58
+
59
+ 26. Runde
60
+
61
+ [Sa 21.3.]
62
+ SV Grödig 0-1 SCR Altach
63
+ Austria Wien 0-1 SV Ried
64
+ Sturm Graz 3-1 Admira Wacker
65
+ Wolfsberger AC 3-2 RB Salzburg
66
+ Wr. Neustadt 0-1 Rapid Wien
67
+
68
+ 27. Runde
69
+
70
+ [Sa 4.4.]
71
+ RB Salzburg 3-1 Austria Wien
72
+ Rapid Wien 4-1 Wolfsberger AC
73
+ SV Ried 1-2 Sturm Graz
74
+ Admira Wacker 2-3 SV Grödig
75
+ SCR Altach 3-1 Wr. Neustadt
76
+
77
+ 28. Runde
78
+
79
+ [Sa 11.4.]
80
+ Rapid Wien 3-3 RB Salzburg
81
+ SV Grödig 1-1 Austria Wien
82
+ Sturm Graz 5-0 SCR Altach
83
+ Wolfsberger AC 2-0 Admira Wacker
84
+ Wr. Neustadt 0-1 SV Ried
85
+
86
+ 29. Runde
87
+
88
+ [Sa 18.4.]
89
+ RB Salzburg 6-0 Wr. Neustadt
90
+ Austria Wien 1-1 Wolfsberger AC
91
+ Sturm Graz 2-1 SV Grödig
92
+ SV Ried 0-1 Rapid Wien
93
+ Admira Wacker 2-2 SCR Altach
94
+
95
+ 30. Runde
96
+
97
+ [Sa 25.4.]
98
+ RB Salzburg 2-1 SV Ried
99
+ Rapid Wien 1-1 Admira Wacker
100
+ Wolfsberger AC 2-1 SV Grödig
101
+ Wr. Neustadt 4-4 Sturm Graz
102
+ SCR Altach 2-0 Austria Wien
103
+
104
+ 31. Runde
105
+
106
+ [Sa 2.5.]
107
+ SV Grödig 0-3 RB Salzburg
108
+ Austria Wien 2-1 Wr. Neustadt
109
+ Sturm Graz 2-2 Rapid Wien
110
+ Wolfsberger AC 2-0 SCR Altach
111
+ Admira Wacker 1-0 SV Ried
112
+
113
+ 32. Runde
114
+
115
+ [Sa 9.5.]
116
+ RB Salzburg 4-0 Admira Wacker
117
+ Austria Wien 0-0 Sturm Graz
118
+ SV Ried 4-0 Wolfsberger AC
119
+ Wr. Neustadt 2-4 SV Grödig
120
+ SCR Altach 1-3 Rapid Wien
121
+
122
+ 33. Runde
123
+
124
+ [Sa 16.5.]
125
+ Rapid Wien 4-1 Austria Wien
126
+ SV Grödig 3-2 SV Ried
127
+ Wolfsberger AC 1-0 Sturm Graz
128
+ Admira Wacker 0-0 Wr. Neustadt
129
+ SCR Altach 2-2 RB Salzburg
130
+
131
+ 34. Runde
132
+
133
+ [Di 19.5.]
134
+ SV Grödig 0-2 Rapid Wien
135
+ Austria Wien 0-1 Admira Wacker
136
+ Sturm Graz 0-0 RB Salzburg
137
+ SV Ried 4-1 SCR Altach
138
+ Wr. Neustadt 2-0 Wolfsberger AC
139
+
140
+ 35. Runde
141
+
142
+ [So 24.5.]
143
+ RB Salzburg 3-0 Wolfsberger AC
144
+ Rapid Wien 0-0 Wr. Neustadt
145
+ SV Ried 0-2 Austria Wien
146
+ Admira Wacker 1-2 Sturm Graz
147
+ SCR Altach 2-0 SV Grödig
148
+
149
+ 36. Runde
150
+
151
+ [So 31.5.]
152
+ SV Grödig 0-1 Admira Wacker
153
+ Austria Wien 1-1 RB Salzburg
154
+ Sturm Graz 0-0 SV Ried
155
+ Wolfsberger AC 0-5 Rapid Wien
156
+ Wr. Neustadt 0-1 SCR Altach
157
+
158
+
data/test/helper.rb CHANGED
@@ -62,6 +62,13 @@ PersonReader = PersonDb::PersonReader
62
62
  ######
63
63
  # New Reader ShortCuts
64
64
 
65
+ module TestPrettyPrinter
66
+ def self.from_file( name, opts={} )
67
+ SportDb::PrettyPrinter.from_file( "#{SportDb.test_data_path}/#{name}.txt", opts )
68
+ end
69
+ end
70
+
71
+
65
72
  module TestTeamReader
66
73
  def self.from_file( name, more_attribs={} )
67
74
  TeamReader.from_file( "#{SportDb.test_data_path}/#{name}.txt", more_attribs )
data/test/test_pp.rb ADDED
@@ -0,0 +1,35 @@
1
+ # encoding: utf-8
2
+
3
+ ###
4
+ # to run use
5
+ # ruby -I ./lib -I ./test test/test_pp.rb
6
+ # or better
7
+ # rake -I ./lib test
8
+
9
+
10
+ require 'helper'
11
+
12
+ class TestPp < MiniTest::Test
13
+
14
+ def test_patch
15
+
16
+ r = TestPrettyPrinter.from_file( 'at-austria/2014_15/1-bundesliga-ii' )
17
+ new_text, change_log = r.patch
18
+
19
+ puts new_text
20
+
21
+ pp change_log
22
+
23
+
24
+ p = SportDb::Patcher.new( "#{SportDb.test_data_path}/at-austria",
25
+ path: '/\d{4}_\d{2}/$',
26
+ names: 'bundesliga|el'
27
+ )
28
+ change_logs = p.patch # note: defaults to save=false (for now)
29
+
30
+ pp change_logs
31
+
32
+ assert true ## assume ok if we get here
33
+ end # method test_patch
34
+
35
+ end # class TestPp
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sportdb-models
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.12.0
4
+ version: 1.13.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: 2015-07-22 00:00:00.000000000 Z
11
+ date: 2015-07-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: worlddb-models
@@ -128,6 +128,7 @@ files:
128
128
  - lib/sportdb/models/world/country.rb
129
129
  - lib/sportdb/models/world/state.rb
130
130
  - lib/sportdb/patterns.rb
131
+ - lib/sportdb/pretty_printer.rb
131
132
  - lib/sportdb/reader.rb
132
133
  - lib/sportdb/reader_file.rb
133
134
  - lib/sportdb/reader_zip.rb
@@ -159,6 +160,7 @@ files:
159
160
  - test/data/at-austria/2013_14/el.yml
160
161
  - test/data/at-austria/2013_14/squads/austria.txt
161
162
  - test/data/at-austria/2013_14/squads/salzburg.txt
163
+ - test/data/at-austria/2014_15/1-bundesliga-ii.txt
162
164
  - test/data/at-austria/leagues.txt
163
165
  - test/data/at-austria/teams.txt
164
166
  - test/data/at-austria/teams_2.txt
@@ -206,6 +208,7 @@ files:
206
208
  - test/test_goals.rb
207
209
  - test/test_lang.rb
208
210
  - test/test_load.rb
211
+ - test/test_pp.rb
209
212
  - test/test_reader.rb
210
213
  - test/test_reader_from_string.rb
211
214
  - test/test_round_auto.rb
@@ -257,6 +260,7 @@ test_files:
257
260
  - test/test_round_def.rb
258
261
  - test/test_utils.rb
259
262
  - test/test_reader_from_string.rb
263
+ - test/test_pp.rb
260
264
  - test/test_round_header.rb
261
265
  - test/test_round_auto.rb
262
266
  - test/test_goals.rb