fbtok 0.0.1 → 0.1.1
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 +4 -4
- data/CHANGELOG.md +1 -0
- data/Manifest.txt +3 -1
- data/README.md +14 -0
- data/Rakefile +5 -2
- data/bin/fbchk +177 -0
- data/bin/fbt +167 -0
- data/bin/fbtok +133 -1
- data/bin/fbx +149 -0
- data/lib/fbtok.rb +6 -2
- metadata +10 -5
- data/lib/fbtok/fbtok.rb +0 -141
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b4ab88883b8f80ee4824cab352297f037e2afcb72351bf6956a8e48bddd5a164
|
4
|
+
data.tar.gz: 6bd75bea2015124e34b01f506757a54a5537ca0544559a0377b6f0a6a0533c0b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 94b3582db70136fdeadeebe003fefdff304ca923bd76edcc0a40d28731c64e73f372b7c0ecf74e58623358102c32ad51e0a233becee4555d5ccd322552d53d80
|
7
|
+
data.tar.gz: dca47c3d3e134ed9c103ba873e76e0c4793d690bbaf6ced8a34693e4c2fea3fc1ff43af0d45ebc62738022f02bb02a0e0bcc04c153dd752a49c7a50d62ba6bba
|
data/CHANGELOG.md
CHANGED
data/Manifest.txt
CHANGED
data/README.md
CHANGED
@@ -19,6 +19,20 @@ $ gem install fbtok
|
|
19
19
|
|
20
20
|
## Usage
|
21
21
|
|
22
|
+
|
23
|
+
### fbtok - use tokenizer/parser
|
24
|
+
|
25
|
+
- depends on sportdb-parser
|
26
|
+
|
27
|
+
### fbt - use quick match reader & fbx - dump match schedule - uses quick league & match readers
|
28
|
+
|
29
|
+
- depends on sportdb-quick
|
30
|
+
|
31
|
+
### fbchk - use quick match linter; check league and team names via search & more
|
32
|
+
|
33
|
+
- depends on sportdb-formats (incl. sportdb-search & sportdb-catalogs)
|
34
|
+
|
35
|
+
|
22
36
|
...
|
23
37
|
|
24
38
|
|
data/Rakefile
CHANGED
@@ -2,7 +2,7 @@ require 'hoe'
|
|
2
2
|
|
3
3
|
|
4
4
|
Hoe.spec 'fbtok' do
|
5
|
-
self.version = '0.
|
5
|
+
self.version = '0.1.1'
|
6
6
|
|
7
7
|
self.summary = "fbtok - football.txt lint tools incl. tokenizer, parser & more"
|
8
8
|
self.description = summary
|
@@ -19,7 +19,10 @@ Hoe.spec 'fbtok' do
|
|
19
19
|
self.licenses = ['Public Domain']
|
20
20
|
|
21
21
|
self.extra_deps = [
|
22
|
-
|
22
|
+
# ['sportdb-parser', '>= 0.2.2'],
|
23
|
+
# ['sportdb-structs', '>= 0.5.0'],
|
24
|
+
# ['logutils', '>= 0.6.1'],
|
25
|
+
['sportdb-formats', '>= 2.1.2'],
|
23
26
|
]
|
24
27
|
|
25
28
|
self.spec_extras = {
|
data/bin/fbchk
ADDED
@@ -0,0 +1,177 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
## tip: to test run:
|
4
|
+
## ruby -I ./lib bin/fbchk
|
5
|
+
|
6
|
+
|
7
|
+
## local hack for debugging
|
8
|
+
## use local versions if present
|
9
|
+
$LOAD_PATH.unshift( File.expand_path( '/sports/sportdb/sport.db/sportdb-structs/lib' ))
|
10
|
+
$LOAD_PATH.unshift( File.expand_path( '/sports/sportdb/sport.db/sportdb-catalogs/lib' ))
|
11
|
+
$LOAD_PATH.unshift( File.expand_path( '/sports/sportdb/sport.db/sportdb-search/lib' ))
|
12
|
+
|
13
|
+
|
14
|
+
## our own code
|
15
|
+
require 'fbtok'
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
## local hack
|
20
|
+
## if exists up-to-date catalog db (use local version NOT built-in)
|
21
|
+
catalog_path = '/sports/sportdb/sport.db/catalog/catalog.db'
|
22
|
+
if File.exist?( catalog_path )
|
23
|
+
SportDb::Import.config.catalog_path = catalog_path
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
args = ARGV
|
28
|
+
opts = { debug: false,
|
29
|
+
file: nil,
|
30
|
+
teams: true, ## check/lint teams (name errros etc.)
|
31
|
+
}
|
32
|
+
|
33
|
+
parser = OptionParser.new do |parser|
|
34
|
+
parser.banner = "Usage: #{$PROGRAM_NAME} [options]"
|
35
|
+
|
36
|
+
##
|
37
|
+
## check if git has a offline option?? (use same)
|
38
|
+
## check for other tools - why? why not?
|
39
|
+
# parser.on( "-q", "--quiet",
|
40
|
+
# "less debug output/messages - default is (#{!opts[:debug]})" ) do |debug|
|
41
|
+
# opts[:debug] = false
|
42
|
+
# end
|
43
|
+
parser.on( "--verbose", "--debug",
|
44
|
+
"turn on verbose / debug output (default: #{opts[:debug]})" ) do |debug|
|
45
|
+
opts[:debug] = true
|
46
|
+
end
|
47
|
+
|
48
|
+
parser.on( "-f FILE", "--file FILE",
|
49
|
+
"read datafiles (pathspecs) via .csv file") do |file|
|
50
|
+
opts[:file] = file
|
51
|
+
end
|
52
|
+
|
53
|
+
parser.on( "--[no-]teams",
|
54
|
+
"turn on/off team name checks (default: #{opts[:teams]})") do |teams|
|
55
|
+
opts[:teams] = teams
|
56
|
+
end
|
57
|
+
end
|
58
|
+
parser.parse!( args )
|
59
|
+
|
60
|
+
|
61
|
+
puts "OPTS:"
|
62
|
+
p opts
|
63
|
+
puts "ARGV:"
|
64
|
+
p args
|
65
|
+
|
66
|
+
|
67
|
+
## todo/check - use packs or projects or such
|
68
|
+
## instead of specs - why? why not?
|
69
|
+
specs = []
|
70
|
+
if opts[:file]
|
71
|
+
recs = read_csv( opts[:file] )
|
72
|
+
pp recs
|
73
|
+
## note - make pathspecs relative to passed in file arg!!!
|
74
|
+
basedir = File.dirname( opts[:file] )
|
75
|
+
recs.each do |rec|
|
76
|
+
paths = SportDb::Parser::Opts.find( rec['path'], dir: basedir )
|
77
|
+
specs << [paths, rec]
|
78
|
+
end
|
79
|
+
else
|
80
|
+
paths = if args.empty?
|
81
|
+
[]
|
82
|
+
else
|
83
|
+
## check for directories
|
84
|
+
## and auto-expand
|
85
|
+
SportDb::Parser::Opts.expand_args( args )
|
86
|
+
end
|
87
|
+
specs << [paths, {}]
|
88
|
+
end
|
89
|
+
|
90
|
+
|
91
|
+
if opts[:debug]
|
92
|
+
SportDb::QuickMatchLinter.debug = true
|
93
|
+
SportDb::QuickMatchReader.debug = true
|
94
|
+
SportDb::MatchParser.debug = true
|
95
|
+
else
|
96
|
+
SportDb::QuickMatchLinter.debug = false
|
97
|
+
SportDb::QuickMatchReader.debug = false
|
98
|
+
SportDb::MatchParser.debug = false
|
99
|
+
LogUtils::Logger.root.level = :info
|
100
|
+
end
|
101
|
+
|
102
|
+
|
103
|
+
specs.each_with_index do |(paths, rec),i|
|
104
|
+
errors = []
|
105
|
+
paths.each_with_index do |path,j|
|
106
|
+
puts "==> [#{j+1}/#{paths.size}] reading >#{path}<..."
|
107
|
+
quick = SportDb::QuickMatchLinter.new( read_text( path ),
|
108
|
+
check_teams: opts[:teams] )
|
109
|
+
matches = quick.parse
|
110
|
+
|
111
|
+
|
112
|
+
if quick.errors?
|
113
|
+
puts "!! #{quick.errors.size} error(s):"
|
114
|
+
pp quick.errors
|
115
|
+
|
116
|
+
quick.errors.each do |err|
|
117
|
+
errors << [ path, *err ] # note: use splat (*) to add extra values (starting with msg)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
puts " #{matches.size} match(es)"
|
121
|
+
end
|
122
|
+
|
123
|
+
if errors.size > 0
|
124
|
+
puts
|
125
|
+
puts "!! #{errors.size} PARSE ERRORS in #{paths.size} datafile(s)"
|
126
|
+
pp errors
|
127
|
+
else
|
128
|
+
puts
|
129
|
+
puts " OK - no parse errors in #{paths.size} datafile(s)"
|
130
|
+
end
|
131
|
+
|
132
|
+
## add errors to rec via rec['errors'] to allow
|
133
|
+
## for further processing/reporting
|
134
|
+
rec['errors'] = errors
|
135
|
+
end
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
###
|
140
|
+
## generate a report if --file option used
|
141
|
+
if opts[:file]
|
142
|
+
|
143
|
+
buf = String.new
|
144
|
+
|
145
|
+
buf << "# fbchk summary report - #{specs.size} dataset(s)\n\n"
|
146
|
+
|
147
|
+
specs.each_with_index do |(paths, rec),i|
|
148
|
+
errors = rec['errors']
|
149
|
+
|
150
|
+
if errors.size > 0
|
151
|
+
buf << "!! #{errors.size} ERROR(S) "
|
152
|
+
else
|
153
|
+
buf << " OK "
|
154
|
+
end
|
155
|
+
buf << "%-20s" % rec['path']
|
156
|
+
buf << " - #{paths.size} datafile(s)"
|
157
|
+
buf << "\n"
|
158
|
+
|
159
|
+
if errors.size > 0
|
160
|
+
buf << errors.pretty_inspect
|
161
|
+
buf << "\n"
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
puts
|
166
|
+
puts "SUMMARY:"
|
167
|
+
puts buf
|
168
|
+
|
169
|
+
basedir = File.dirname( opts[:file] )
|
170
|
+
basename = File.basename( opts[:file], File.extname( opts[:file] ))
|
171
|
+
outpath = "#{basedir}/fbcheck.#{basename}.txt"
|
172
|
+
write_text( outpath, buf )
|
173
|
+
end
|
174
|
+
|
175
|
+
|
176
|
+
puts "bye"
|
177
|
+
|
data/bin/fbt
ADDED
@@ -0,0 +1,167 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
## tip: to test run:
|
4
|
+
## ruby -I ./lib bin/fbt
|
5
|
+
## -or-
|
6
|
+
## ruby -I ../parser/lib -I ./lib bin/fbt
|
7
|
+
## -or-
|
8
|
+
## ruby -I ../parser/lib -I ../sportdb-structs/lib -I ./lib bin/fbt
|
9
|
+
|
10
|
+
|
11
|
+
## our own code
|
12
|
+
require 'fbtok'
|
13
|
+
|
14
|
+
|
15
|
+
##
|
16
|
+
## read textfile
|
17
|
+
## and dump tokens
|
18
|
+
##
|
19
|
+
## fbt ../openfootball/.../euro.txt
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
|
24
|
+
args = ARGV
|
25
|
+
opts = { debug: false,
|
26
|
+
file: nil,
|
27
|
+
}
|
28
|
+
|
29
|
+
parser = OptionParser.new do |parser|
|
30
|
+
parser.banner = "Usage: #{$PROGRAM_NAME} [options]"
|
31
|
+
|
32
|
+
##
|
33
|
+
## check if git has a offline option?? (use same)
|
34
|
+
## check for other tools - why? why not?
|
35
|
+
# parser.on( "-q", "--quiet",
|
36
|
+
# "less debug output/messages - default is (#{!opts[:debug]})" ) do |debug|
|
37
|
+
# opts[:debug] = false
|
38
|
+
# end
|
39
|
+
parser.on( "--verbose", "--debug",
|
40
|
+
"turn on verbose / debug output (default: #{opts[:debug]})" ) do |debug|
|
41
|
+
opts[:debug] = true
|
42
|
+
end
|
43
|
+
|
44
|
+
parser.on( "-f FILE", "--file FILE",
|
45
|
+
"read datafiles (pathspecs) via .csv file") do |file|
|
46
|
+
opts[:file] = file
|
47
|
+
end
|
48
|
+
|
49
|
+
|
50
|
+
end
|
51
|
+
parser.parse!( args )
|
52
|
+
|
53
|
+
puts "OPTS:"
|
54
|
+
p opts
|
55
|
+
puts "ARGV:"
|
56
|
+
p args
|
57
|
+
|
58
|
+
|
59
|
+
## todo/check - use packs or projects or such
|
60
|
+
## instead of specs - why? why not?
|
61
|
+
specs = []
|
62
|
+
if opts[:file]
|
63
|
+
recs = read_csv( opts[:file] )
|
64
|
+
pp recs
|
65
|
+
## note - make pathspecs relative to passed in file arg!!!
|
66
|
+
basedir = File.dirname( opts[:file] )
|
67
|
+
recs.each do |rec|
|
68
|
+
paths = SportDb::Parser::Opts.find( rec['path'], dir: basedir )
|
69
|
+
specs << [paths, rec]
|
70
|
+
end
|
71
|
+
else
|
72
|
+
paths = if args.empty?
|
73
|
+
[
|
74
|
+
'../../../openfootball/euro/2021--europe/euro.txt',
|
75
|
+
'../../../openfootball/euro/2024--germany/euro.txt',
|
76
|
+
]
|
77
|
+
else
|
78
|
+
## check for directories
|
79
|
+
## and auto-expand
|
80
|
+
SportDb::Parser::Opts.expand_args( args )
|
81
|
+
end
|
82
|
+
specs << [paths, {}]
|
83
|
+
end
|
84
|
+
|
85
|
+
|
86
|
+
if opts[:debug]
|
87
|
+
SportDb::QuickMatchReader.debug = true
|
88
|
+
SportDb::MatchParser.debug = true
|
89
|
+
else
|
90
|
+
SportDb::QuickMatchReader.debug = false
|
91
|
+
SportDb::MatchParser.debug = false
|
92
|
+
LogUtils::Logger.root.level = :info
|
93
|
+
end
|
94
|
+
|
95
|
+
|
96
|
+
specs.each_with_index do |(paths, rec),i|
|
97
|
+
errors = []
|
98
|
+
paths.each_with_index do |path,j|
|
99
|
+
puts "==> [#{j+1}/#{paths.size}] reading >#{path}<..."
|
100
|
+
quick = SportDb::QuickMatchReader.new( read_text( path ) )
|
101
|
+
matches = quick.parse
|
102
|
+
|
103
|
+
if quick.errors?
|
104
|
+
puts "!! #{quick.errors.size} error(s):"
|
105
|
+
pp quick.errors
|
106
|
+
|
107
|
+
quick.errors.each do |err|
|
108
|
+
errors << [ path, *err ] # note: use splat (*) to add extra values (starting with msg)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
puts " #{matches.size} match(es)"
|
112
|
+
end
|
113
|
+
|
114
|
+
if errors.size > 0
|
115
|
+
puts
|
116
|
+
puts "!! #{errors.size} PARSE ERRORS in #{paths.size} datafile(s)"
|
117
|
+
pp errors
|
118
|
+
else
|
119
|
+
puts
|
120
|
+
puts " OK - no parse errors in #{paths.size} datafile(s)"
|
121
|
+
end
|
122
|
+
|
123
|
+
## add errors to rec via rec['errors'] to allow
|
124
|
+
## for further processing/reporting
|
125
|
+
rec['errors'] = errors
|
126
|
+
end
|
127
|
+
|
128
|
+
|
129
|
+
|
130
|
+
###
|
131
|
+
## generate a report if --file option used
|
132
|
+
if opts[:file]
|
133
|
+
|
134
|
+
buf = String.new
|
135
|
+
|
136
|
+
buf << "# fbt summary report - #{specs.size} dataset(s)\n\n"
|
137
|
+
|
138
|
+
specs.each_with_index do |(paths, rec),i|
|
139
|
+
errors = rec['errors']
|
140
|
+
|
141
|
+
if errors.size > 0
|
142
|
+
buf << "!! #{errors.size} ERROR(S) "
|
143
|
+
else
|
144
|
+
buf << " OK "
|
145
|
+
end
|
146
|
+
buf << "%-20s" % rec['path']
|
147
|
+
buf << " - #{paths.size} datafile(s)"
|
148
|
+
buf << "\n"
|
149
|
+
|
150
|
+
if errors.size > 0
|
151
|
+
buf << errors.pretty_inspect
|
152
|
+
buf << "\n"
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
puts
|
157
|
+
puts "SUMMARY:"
|
158
|
+
puts buf
|
159
|
+
|
160
|
+
# maybe write out in the future?
|
161
|
+
# basedir = File.dirname( opts[:file] )
|
162
|
+
# basename = File.basename( opts[:file], File.extname( opts[:file] ))
|
163
|
+
end
|
164
|
+
|
165
|
+
|
166
|
+
puts "bye"
|
167
|
+
|
data/bin/fbtok
CHANGED
@@ -5,9 +5,141 @@
|
|
5
5
|
|
6
6
|
require 'fbtok'
|
7
7
|
|
8
|
+
args = ARGV
|
9
|
+
|
8
10
|
|
9
|
-
|
11
|
+
opts = {
|
12
|
+
debug: true,
|
13
|
+
metal: false,
|
14
|
+
file: nil,
|
15
|
+
}
|
10
16
|
|
17
|
+
parser = OptionParser.new do |parser|
|
18
|
+
parser.banner = "Usage: #{$PROGRAM_NAME} [options] PATH"
|
19
|
+
|
20
|
+
|
21
|
+
parser.on( "-q", "--quiet",
|
22
|
+
"less debug output/messages - default is (#{!opts[:debug]})" ) do |debug|
|
23
|
+
opts[:debug] = false
|
24
|
+
end
|
25
|
+
parser.on( "--verbose", "--debug",
|
26
|
+
"turn on verbose / debug output (default: #{opts[:debug]})" ) do |debug|
|
27
|
+
opts[:debug] = true
|
28
|
+
end
|
29
|
+
|
30
|
+
parser.on( "--metal",
|
31
|
+
"turn off typed parse tree; show to the metal tokens"+
|
32
|
+
" (default: #{opts[:metal]})" ) do |metal|
|
33
|
+
opts[:metal] = true
|
34
|
+
end
|
35
|
+
|
36
|
+
parser.on( "-f FILE", "--file FILE",
|
37
|
+
"read datafiles (pathspecs) via .csv file") do |file|
|
38
|
+
opts[:file] = file
|
39
|
+
## note: for batch (massive) processing auto-set debug (verbose output) to false (as default)
|
40
|
+
opts[:debug] = false
|
41
|
+
end
|
42
|
+
end
|
43
|
+
parser.parse!( args )
|
44
|
+
|
45
|
+
puts "OPTS:"
|
46
|
+
p opts
|
47
|
+
puts "ARGV:"
|
48
|
+
p args
|
49
|
+
|
50
|
+
|
51
|
+
## todo/check - use packs or projects or such
|
52
|
+
## instead of specs - why? why not?
|
53
|
+
specs = []
|
54
|
+
if opts[:file]
|
55
|
+
recs = read_csv( opts[:file] )
|
56
|
+
pp recs
|
57
|
+
## note - make pathspecs relative to passed in file arg!!!
|
58
|
+
basedir = File.dirname( opts[:file] )
|
59
|
+
recs.each do |rec|
|
60
|
+
paths = SportDb::Parser::Opts.find( rec['path'], dir: basedir )
|
61
|
+
specs << [paths, rec]
|
62
|
+
end
|
63
|
+
else
|
64
|
+
paths = if args.empty?
|
65
|
+
[
|
66
|
+
'../../../openfootball/euro/2021--europe/euro.txt',
|
67
|
+
'../../../openfootball/euro/2024--germany/euro.txt',
|
68
|
+
]
|
69
|
+
else
|
70
|
+
## check for directories
|
71
|
+
## and auto-expand
|
72
|
+
SportDb::Parser::Opts.expand_args( args )
|
73
|
+
end
|
74
|
+
specs << [paths, {}]
|
75
|
+
end
|
76
|
+
|
77
|
+
|
78
|
+
SportDb::Parser::Linter.debug = true if opts[:debug]
|
79
|
+
|
80
|
+
linter = SportDb::Parser::Linter.new
|
81
|
+
|
82
|
+
|
83
|
+
specs.each_with_index do |(paths, rec),i|
|
84
|
+
errors = []
|
85
|
+
|
86
|
+
paths.each_with_index do |path,j|
|
87
|
+
puts "==> [#{j+1}/#{paths.size}] reading >#{path}<..."
|
88
|
+
linter.read( path, parse: !opts[:metal] )
|
89
|
+
|
90
|
+
errors += linter.errors if linter.errors?
|
91
|
+
end
|
92
|
+
|
93
|
+
if errors.size > 0
|
94
|
+
puts
|
95
|
+
pp errors
|
96
|
+
puts
|
97
|
+
puts "!! #{errors.size} parse error(s) in #{paths.size} datafiles(s)"
|
98
|
+
else
|
99
|
+
puts
|
100
|
+
puts "OK no parse errors found in #{paths.size} datafile(s)"
|
101
|
+
end
|
102
|
+
|
103
|
+
## add errors to rec via rec['errors'] to allow
|
104
|
+
## for further processing/reporting
|
105
|
+
rec['errors'] = errors
|
106
|
+
end
|
107
|
+
|
108
|
+
|
109
|
+
###
|
110
|
+
## generate a report if --file option used
|
111
|
+
if opts[:file]
|
112
|
+
|
113
|
+
buf = String.new
|
114
|
+
|
115
|
+
buf << "# fbtok summary report - #{specs.size} dataset(s)\n\n"
|
116
|
+
|
117
|
+
specs.each_with_index do |(paths, rec),i|
|
118
|
+
errors = rec['errors']
|
119
|
+
|
120
|
+
if errors.size > 0
|
121
|
+
buf << "!! #{errors.size} ERROR(S) "
|
122
|
+
else
|
123
|
+
buf << " OK "
|
124
|
+
end
|
125
|
+
buf << "%-20s" % rec['path']
|
126
|
+
buf << " - #{paths.size} datafile(s)"
|
127
|
+
buf << "\n"
|
128
|
+
|
129
|
+
if errors.size > 0
|
130
|
+
buf << errors.pretty_inspect
|
131
|
+
buf << "\n"
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
puts
|
136
|
+
puts "SUMMARY:"
|
137
|
+
puts buf
|
138
|
+
|
139
|
+
# maybe write out in the future?
|
140
|
+
# basedir = File.dirname( opts[:file] )
|
141
|
+
# basename = File.basename( opts[:file], File.extname( opts[:file] ))
|
142
|
+
end
|
11
143
|
|
12
144
|
puts "bye"
|
13
145
|
|
data/bin/fbx
ADDED
@@ -0,0 +1,149 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
## tip: to test run:
|
4
|
+
## ruby -I ./lib -I ../parser/lib bin/fbx
|
5
|
+
|
6
|
+
##
|
7
|
+
## todo/fix - use for testing
|
8
|
+
# reads textfile and dumps results in json
|
9
|
+
#
|
10
|
+
# check - keep fbx name or find a differnt name - why? why not?
|
11
|
+
|
12
|
+
|
13
|
+
## our own code
|
14
|
+
require 'fbtok'
|
15
|
+
|
16
|
+
|
17
|
+
##
|
18
|
+
## read textfile
|
19
|
+
## and dump match parse results
|
20
|
+
##
|
21
|
+
## fbt ../openfootball/.../euro.txt
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
|
26
|
+
args = ARGV
|
27
|
+
opts = { debug: false,
|
28
|
+
outline: false }
|
29
|
+
|
30
|
+
parser = OptionParser.new do |parser|
|
31
|
+
parser.banner = "Usage: #{$PROGRAM_NAME} [options]"
|
32
|
+
|
33
|
+
##
|
34
|
+
## check if git has a offline option?? (use same)
|
35
|
+
## check for other tools - why? why not?
|
36
|
+
|
37
|
+
|
38
|
+
parser.on( "--verbose", "--debug",
|
39
|
+
"turn on verbose / debug output (default: #{opts[:debug]})" ) do |debug|
|
40
|
+
opts[:debug] = debug
|
41
|
+
end
|
42
|
+
|
43
|
+
parser.on( "--outline",
|
44
|
+
"turn on outline (only) output (default: #{opts[:outline]})" ) do |outline|
|
45
|
+
opts[:outline] = outline
|
46
|
+
end
|
47
|
+
end
|
48
|
+
parser.parse!( args )
|
49
|
+
|
50
|
+
puts "OPTS:"
|
51
|
+
p opts
|
52
|
+
puts "ARGV:"
|
53
|
+
p args
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
paths = if args.empty?
|
60
|
+
[
|
61
|
+
'../../../openfootball/euro/2021--europe/euro.txt',
|
62
|
+
'../../../openfootball/euro/2024--germany/euro.txt',
|
63
|
+
]
|
64
|
+
else
|
65
|
+
## check for directories
|
66
|
+
## and auto-expand
|
67
|
+
|
68
|
+
SportDb::Parser::Opts.expand_args( args )
|
69
|
+
end
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
SportDb::MatchParser.debug = true if opts[:debug]
|
78
|
+
|
79
|
+
|
80
|
+
## errors = []
|
81
|
+
|
82
|
+
|
83
|
+
paths.each_with_index do |path,i|
|
84
|
+
puts "==> [#{i+1}/#{paths.size}] reading >#{path}<..."
|
85
|
+
|
86
|
+
txt = read_text( path )
|
87
|
+
secs = SportDb::QuickLeagueOutlineReader.parse( txt )
|
88
|
+
## pp secs
|
89
|
+
|
90
|
+
secs.each_with_index do |sec,j| ## sec(tion)s
|
91
|
+
season = sec[:season]
|
92
|
+
league = sec[:league]
|
93
|
+
stage = sec[:stage]
|
94
|
+
lines = sec[:lines]
|
95
|
+
|
96
|
+
puts " section #{j+1}/#{secs.size} - #{league.name} #{season}, #{stage} - #{lines.size} line(s)"
|
97
|
+
|
98
|
+
next if opts[:outline]
|
99
|
+
|
100
|
+
=begin
|
101
|
+
### check if event info availabe - use start_date;
|
102
|
+
## otherwise we have to guess (use a "synthetic" start_date)
|
103
|
+
event_info = catalog.events.find_by( season: season,
|
104
|
+
league: league )
|
105
|
+
|
106
|
+
start = if event_info && event_info.start_date
|
107
|
+
puts "event info found:"
|
108
|
+
puts " using start date from event: "
|
109
|
+
pp event_info
|
110
|
+
pp event_info.start_date
|
111
|
+
event_info.start_date
|
112
|
+
else
|
113
|
+
=end
|
114
|
+
start = if season.year?
|
115
|
+
Date.new( season.start_year, 1, 1 )
|
116
|
+
else
|
117
|
+
Date.new( season.start_year, 7, 1 )
|
118
|
+
end
|
119
|
+
|
120
|
+
parser = SportDb::MatchParser.new( lines,
|
121
|
+
start ) ## note: keep season start_at date for now (no need for more specific stage date need for now)
|
122
|
+
|
123
|
+
auto_conf_teams, matches, rounds, groups = parser.parse
|
124
|
+
|
125
|
+
puts ">>> #{auto_conf_teams.size} teams:"
|
126
|
+
pp auto_conf_teams
|
127
|
+
puts ">>> #{matches.size} matches:"
|
128
|
+
## pp matches
|
129
|
+
puts ">>> #{rounds.size} rounds:"
|
130
|
+
pp rounds
|
131
|
+
puts ">>> #{groups.size} groups:"
|
132
|
+
pp groups
|
133
|
+
end # each secs
|
134
|
+
end # each paths
|
135
|
+
|
136
|
+
=begin
|
137
|
+
if errors.size > 0
|
138
|
+
puts
|
139
|
+
pp errors
|
140
|
+
puts
|
141
|
+
puts "!! #{errors.size} parse error(s) in #{paths.size} datafiles(s)"
|
142
|
+
else
|
143
|
+
puts
|
144
|
+
puts "OK no parse errors found in #{paths.size} datafile(s)"
|
145
|
+
end
|
146
|
+
=end
|
147
|
+
|
148
|
+
puts "bye"
|
149
|
+
|
data/lib/fbtok.rb
CHANGED
@@ -1,9 +1,13 @@
|
|
1
1
|
|
2
|
-
require 'sportdb/
|
2
|
+
require 'sportdb/formats'
|
3
|
+
|
4
|
+
|
5
|
+
## more stdlibs
|
6
|
+
require 'optparse' ## check - already auto-required in cocos? keep? why? why not?
|
3
7
|
|
4
8
|
|
5
9
|
## our own code
|
6
10
|
require_relative 'fbtok/opts'
|
7
|
-
require_relative 'fbtok/
|
11
|
+
require_relative 'fbtok/linter'
|
8
12
|
|
9
13
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fbtok
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gerald Bauer
|
@@ -11,19 +11,19 @@ cert_chain: []
|
|
11
11
|
date: 2025-01-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name: sportdb-
|
14
|
+
name: sportdb-formats
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 2.1.2
|
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:
|
26
|
+
version: 2.1.2
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rdoc
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -61,7 +61,10 @@ dependencies:
|
|
61
61
|
description: fbtok - football.txt lint tools incl. tokenizer, parser & more
|
62
62
|
email: gerald.bauer@gmail.com
|
63
63
|
executables:
|
64
|
+
- fbchk
|
65
|
+
- fbt
|
64
66
|
- fbtok
|
67
|
+
- fbx
|
65
68
|
extensions: []
|
66
69
|
extra_rdoc_files:
|
67
70
|
- CHANGELOG.md
|
@@ -72,9 +75,11 @@ files:
|
|
72
75
|
- Manifest.txt
|
73
76
|
- README.md
|
74
77
|
- Rakefile
|
78
|
+
- bin/fbchk
|
79
|
+
- bin/fbt
|
75
80
|
- bin/fbtok
|
81
|
+
- bin/fbx
|
76
82
|
- lib/fbtok.rb
|
77
|
-
- lib/fbtok/fbtok.rb
|
78
83
|
- lib/fbtok/linter.rb
|
79
84
|
- lib/fbtok/opts.rb
|
80
85
|
homepage: https://github.com/sportdb/footty
|
data/lib/fbtok/fbtok.rb
DELETED
@@ -1,141 +0,0 @@
|
|
1
|
-
|
2
|
-
module Fbtok
|
3
|
-
def self.main( args=ARGV )
|
4
|
-
|
5
|
-
opts = {
|
6
|
-
debug: true,
|
7
|
-
metal: false,
|
8
|
-
file: nil,
|
9
|
-
}
|
10
|
-
|
11
|
-
parser = OptionParser.new do |parser|
|
12
|
-
parser.banner = "Usage: #{$PROGRAM_NAME} [options] PATH"
|
13
|
-
|
14
|
-
|
15
|
-
parser.on( "-q", "--quiet",
|
16
|
-
"less debug output/messages - default is (#{!opts[:debug]})" ) do |debug|
|
17
|
-
opts[:debug] = false
|
18
|
-
end
|
19
|
-
parser.on( "--verbose", "--debug",
|
20
|
-
"turn on verbose / debug output (default: #{opts[:debug]})" ) do |debug|
|
21
|
-
opts[:debug] = true
|
22
|
-
end
|
23
|
-
|
24
|
-
parser.on( "--metal",
|
25
|
-
"turn off typed parse tree; show to the metal tokens"+
|
26
|
-
" (default: #{opts[:metal]})" ) do |metal|
|
27
|
-
opts[:metal] = true
|
28
|
-
end
|
29
|
-
|
30
|
-
parser.on( "-f FILE", "--file FILE",
|
31
|
-
"read datafiles (pathspecs) via .csv file") do |file|
|
32
|
-
opts[:file] = file
|
33
|
-
## note: for batch (massive) processing auto-set debug (verbose output) to false (as default)
|
34
|
-
opts[:debug] = false
|
35
|
-
end
|
36
|
-
end
|
37
|
-
parser.parse!( args )
|
38
|
-
|
39
|
-
puts "OPTS:"
|
40
|
-
p opts
|
41
|
-
puts "ARGV:"
|
42
|
-
p args
|
43
|
-
|
44
|
-
|
45
|
-
## todo/check - use packs or projects or such
|
46
|
-
## instead of specs - why? why not?
|
47
|
-
specs = []
|
48
|
-
if opts[:file]
|
49
|
-
recs = read_csv( opts[:file] )
|
50
|
-
pp recs
|
51
|
-
## note - make pathspecs relative to passed in file arg!!!
|
52
|
-
basedir = File.dirname( opts[:file] )
|
53
|
-
recs.each do |rec|
|
54
|
-
paths = SportDb::Parser::Opts.find( rec['path'], dir: basedir )
|
55
|
-
specs << [paths, rec]
|
56
|
-
end
|
57
|
-
else
|
58
|
-
paths = if args.empty?
|
59
|
-
[
|
60
|
-
'../../../openfootball/euro/2021--europe/euro.txt',
|
61
|
-
'../../../openfootball/euro/2024--germany/euro.txt',
|
62
|
-
]
|
63
|
-
else
|
64
|
-
## check for directories
|
65
|
-
## and auto-expand
|
66
|
-
SportDb::Parser::Opts.expand_args( args )
|
67
|
-
end
|
68
|
-
specs << [paths, {}]
|
69
|
-
end
|
70
|
-
|
71
|
-
|
72
|
-
SportDb::Parser::Linter.debug = true if opts[:debug]
|
73
|
-
|
74
|
-
linter = SportDb::Parser::Linter.new
|
75
|
-
|
76
|
-
|
77
|
-
specs.each_with_index do |(paths, rec),i|
|
78
|
-
errors = []
|
79
|
-
|
80
|
-
paths.each_with_index do |path,j|
|
81
|
-
puts "==> [#{j+1}/#{paths.size}] reading >#{path}<..."
|
82
|
-
linter.read( path, parse: !opts[:metal] )
|
83
|
-
|
84
|
-
errors += linter.errors if linter.errors?
|
85
|
-
end
|
86
|
-
|
87
|
-
if errors.size > 0
|
88
|
-
puts
|
89
|
-
pp errors
|
90
|
-
puts
|
91
|
-
puts "!! #{errors.size} parse error(s) in #{paths.size} datafiles(s)"
|
92
|
-
else
|
93
|
-
puts
|
94
|
-
puts "OK no parse errors found in #{paths.size} datafile(s)"
|
95
|
-
end
|
96
|
-
|
97
|
-
## add errors to rec via rec['errors'] to allow
|
98
|
-
## for further processing/reporting
|
99
|
-
rec['errors'] = errors
|
100
|
-
end
|
101
|
-
|
102
|
-
|
103
|
-
###
|
104
|
-
## generate a report if --file option used
|
105
|
-
if opts[:file]
|
106
|
-
|
107
|
-
buf = String.new
|
108
|
-
|
109
|
-
buf << "# fbtok summary report - #{specs.size} dataset(s)\n\n"
|
110
|
-
|
111
|
-
specs.each_with_index do |(paths, rec),i|
|
112
|
-
errors = rec['errors']
|
113
|
-
|
114
|
-
if errors.size > 0
|
115
|
-
buf << "!! #{errors.size} ERROR(S) "
|
116
|
-
else
|
117
|
-
buf << " OK "
|
118
|
-
end
|
119
|
-
buf << "%-20s" % rec['path']
|
120
|
-
buf << " - #{paths.size} datafile(s)"
|
121
|
-
buf << "\n"
|
122
|
-
|
123
|
-
if errors.size > 0
|
124
|
-
buf << errors.pretty_inspect
|
125
|
-
buf << "\n"
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
|
-
puts
|
130
|
-
puts "SUMMARY:"
|
131
|
-
puts buf
|
132
|
-
|
133
|
-
# maybe write out in the future?
|
134
|
-
# basedir = File.dirname( opts[:file] )
|
135
|
-
# basename = File.basename( opts[:file], File.extname( opts[:file] ))
|
136
|
-
end
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
end # method self.main
|
141
|
-
end # module Fbtok
|