fbtok 0.3.4 → 0.4.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.
@@ -1,33 +1,15 @@
1
- #!/usr/bin/env ruby
2
1
 
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
2
+ module Fbquick
9
3
 
10
4
 
11
- ## our own code
12
- require 'fbtok'
5
+ def self.main( args=ARGV )
13
6
 
14
-
15
- ##
16
- ## read textfile
17
- ## and dump tokens
18
- ##
19
- ## fbt ../openfootball/.../euro.txt
20
-
21
-
22
-
23
-
24
- args = ARGV
25
7
  opts = { debug: false,
26
8
  file: nil,
27
9
  }
28
10
 
29
11
  parser = OptionParser.new do |parser|
30
- parser.banner = "Usage: #{$PROGRAM_NAME} [options]"
12
+ parser.banner = "Usage: #{$PROGRAM_NAME} [options] DATAFILE or DIR"
31
13
 
32
14
  ##
33
15
  ## check if git has a offline option?? (use same)
@@ -57,7 +39,7 @@ if opts[:debug]
57
39
  p opts
58
40
  puts "ARGV:"
59
41
  p args
60
-
42
+
61
43
  SportDb::QuickMatchReader.debug = true
62
44
  SportDb::MatchParser.debug = true
63
45
  else
@@ -70,30 +52,26 @@ end
70
52
  ## todo/check - use packs or projects or such
71
53
  ## instead of specs - why? why not?
72
54
  specs = if opts[:file]
73
- SportDb::Parser::Opts.read_pathspecs( opts[:file] )
55
+ read_pathspecs( opts[:file] )
74
56
  else
75
- paths = if args.empty?
76
- ['/sports/openfootball/euro/2021--europe/euro.txt',
77
- '/sports/openfootball/euro/2024--germany/euro.txt']
78
- else
79
- ## check for directories
80
- ## and auto-expand
81
- SportDb::Parser::Opts.expand_args( args )
82
- end
83
- ## always return array of specs
84
- [SportDb::Parser::Opts.build_pathspec( paths: paths)]
57
+ args = ['/sports/openfootball/euro/2021--europe/euro.txt',
58
+ '/sports/openfootball/euro/2024--germany/euro.txt'] if args.empty?
59
+
60
+ build_pathspecs( args )
85
61
  end
86
62
 
63
+ pp specs
64
+
87
65
 
88
66
 
89
- specs.each_with_index do |spec,i|
90
- paths = spec.paths
91
- rec = spec.rec
67
+ specs.each_with_index do |rec,i|
68
+ datafiles = rec['datafiles']
92
69
  errors = []
93
70
 
94
- paths.each_with_index do |path,j|
95
- puts "==> [#{j+1}/#{paths.size}] reading >#{path}<..."
96
- quick = SportDb::QuickMatchReader.new( read_text( path ) )
71
+ datafiles.each_with_index do |path,j|
72
+ puts "==> [#{i+1}/#{specs.size}, #{j+1}/#{datafiles.size}] reading >#{path}<..."
73
+ txt = read_text( path )
74
+ quick = SportDb::QuickMatchReader.new( txt )
97
75
  matches = quick.parse
98
76
 
99
77
  if quick.errors?
@@ -109,11 +87,11 @@ specs = if opts[:file]
109
87
 
110
88
  if errors.size > 0
111
89
  puts
112
- puts "!! #{errors.size} PARSE ERRORS in #{paths.size} datafile(s)"
90
+ puts "!! #{errors.size} PARSE ERRORS in #{datafiles.size} datafile(s)"
113
91
  pp errors
114
92
  else
115
93
  puts
116
- puts " OK - no parse errors in #{paths.size} datafile(s)"
94
+ puts " OK - no parse errors in #{datafiles.size} datafile(s)"
117
95
  end
118
96
 
119
97
  ## add errors to rec via rec['errors'] to allow
@@ -126,9 +104,9 @@ specs = if opts[:file]
126
104
  ###
127
105
  ## generate a report if --file option used
128
106
  if opts[:file]
129
- buf = SportDb::Parser::BatchReport.new(
130
- specs,
131
- title: 'fbt summary report' ).build
107
+ buf = SportDb::PathspecReport.new(
108
+ specs,
109
+ title: 'fbquick summary report' ).build
132
110
 
133
111
  puts
134
112
  puts "SUMMARY:"
@@ -139,7 +117,7 @@ if opts[:file]
139
117
  # basename = File.basename( opts[:file], File.extname( opts[:file] ))
140
118
  end
141
119
 
142
-
143
-
144
120
  puts "bye"
121
+ end
145
122
 
123
+ end # module Fbquick
@@ -0,0 +1,127 @@
1
+
2
+ module Fbtok
3
+
4
+
5
+ def self.main( args=ARGV )
6
+
7
+ opts = {
8
+ debug: true,
9
+ warn: false,
10
+ file: nil,
11
+ }
12
+
13
+
14
+ parser = OptionParser.new do |parser|
15
+ parser.banner = "Usage: #{$PROGRAM_NAME} [options] DATAFILE or DIR"
16
+
17
+
18
+ parser.on( "-q", "--quiet",
19
+ "less debug output/messages (default: #{!opts[:debug]})" ) do |debug|
20
+ opts[:debug] = false
21
+ end
22
+ parser.on( "--verbose", "--debug",
23
+ "turn on verbose / debug output (default: #{opts[:debug]})" ) do |debug|
24
+ opts[:debug] = true
25
+ end
26
+ parser.on( "-w", "--warn",
27
+ "turn warnings into errors (default: #{opts[:warn]})" ) do |warn|
28
+ opts[:warn] = true
29
+ end
30
+
31
+
32
+ parser.on( "-f FILE", "--file FILE",
33
+ "read datafiles (pathspecs) via .csv file") do |file|
34
+ opts[:file] = file
35
+ ## note: for batch (massive) processing auto-set debug (verbose output) to false (as default)
36
+ opts[:debug] = false
37
+ end
38
+ end
39
+ parser.parse!( args )
40
+
41
+
42
+
43
+ if opts[:debug]
44
+ puts "OPTS:"
45
+ p opts
46
+ puts "ARGV:"
47
+ p args
48
+ end
49
+
50
+
51
+ # SportDb::Parser::Linter.debug = opts[:debug]
52
+ # SportDb::Parser::Linter.warn = opts[:warn]
53
+
54
+
55
+
56
+ ## todo/check - use packs or projects or such
57
+ ## instead of specs - why? why not?
58
+ specs = if opts[:file]
59
+ read_pathspecs( opts[:file] )
60
+ else
61
+ args = ['/sports/openfootball/euro/2021--europe/euro.txt',
62
+ '/sports/openfootball/euro/2024--germany/euro.txt'] if args.empty?
63
+
64
+ build_pathspecs( args )
65
+ end
66
+
67
+
68
+ pp specs
69
+
70
+
71
+
72
+ specs.each_with_index do |rec,i|
73
+ datafiles = rec['datafiles']
74
+
75
+ errors = []
76
+
77
+ datafiles.each_with_index do |path,j|
78
+ puts "==> [#{i+1}/#{specs.size}, #{j+1}/#{datafiles.size}] reading >#{path}<..."
79
+
80
+ txt = read_text( path )
81
+ lexer = SportDb::Lexer.new( txt, debug: opts[:debug] )
82
+ tokens, more_errors = lexer.tokenize_with_errors
83
+
84
+ ####
85
+ ## todo - report error on empty file (no tokens!!!)
86
+
87
+ puts " #{tokens.size} token(s)"
88
+
89
+ errors += more_errors if more_errors.size > 0
90
+ end
91
+
92
+ if errors.size > 0
93
+ puts
94
+ pp errors
95
+ puts
96
+ puts "!! #{errors.size} tokenize error(s) in #{datafiles.size} datafiles(s)"
97
+ else
98
+ puts
99
+ puts "OK no tokenize errors found in #{datafiles.size} datafile(s)"
100
+ end
101
+
102
+ ## add errors to rec via rec['errors'] to allow
103
+ ## for further processing/reporting
104
+ rec['errors'] = errors
105
+ end
106
+
107
+
108
+ ###
109
+ ## generate a report if --file option used
110
+ if opts[:file]
111
+ buf = SportDb::PathspecReport.new(
112
+ specs,
113
+ title: 'fbtok summary report' ).build
114
+
115
+ puts
116
+ puts "SUMMARY:"
117
+ puts buf
118
+
119
+ # maybe write out in the future?
120
+ # basedir = File.dirname( opts[:file] )
121
+ # basename = File.basename( opts[:file], File.extname( opts[:file] ))
122
+ end
123
+
124
+ puts "bye"
125
+
126
+ end # self.main
127
+ end # module Fbtok
@@ -0,0 +1,141 @@
1
+
2
+ module Fbtree
3
+
4
+ def self.main( args=ARGV )
5
+
6
+
7
+ opts = {
8
+ debug: true,
9
+ warn: false,
10
+ file: nil,
11
+ }
12
+
13
+ parser = OptionParser.new do |parser|
14
+ parser.banner = "Usage: #{$PROGRAM_NAME} [options] DATAFILE or DIR"
15
+
16
+
17
+ parser.on( "-q", "--quiet",
18
+ "less debug output/messages (default: #{!opts[:debug]})" ) do |debug|
19
+ opts[:debug] = false
20
+ end
21
+ parser.on( "--verbose", "--debug",
22
+ "turn on verbose / debug output (default: #{opts[:debug]})" ) do |debug|
23
+ opts[:debug] = true
24
+ end
25
+ parser.on( "-w", "--warn",
26
+ "turn warnings into errors (default: #{opts[:warn]})" ) do |warn|
27
+ opts[:warn] = true
28
+ end
29
+
30
+
31
+ parser.on( "-f FILE", "--file FILE",
32
+ "read datafiles (pathspecs) via .csv file") do |file|
33
+ opts[:file] = file
34
+ ## note: for batch (massive) processing auto-set debug (verbose output) to false (as default)
35
+ opts[:debug] = false
36
+ end
37
+
38
+ end
39
+ parser.parse!( args )
40
+
41
+
42
+ if opts[:debug]
43
+ puts "OPTS:"
44
+ p opts
45
+ puts "ARGV:"
46
+ p args
47
+ end
48
+
49
+
50
+ # SportDb::Parser::Linter.debug = opts[:debug]
51
+ # SportDb::Parser::Linter.warn = opts[:warn]
52
+
53
+
54
+
55
+
56
+ ## todo/check - use packs or projects or such
57
+ ## instead of specs - why? why not?
58
+ specs = if opts[:file]
59
+ read_pathspecs( opts[:file] )
60
+ else
61
+ args = ['/sports/openfootball/euro/2021--europe/euro.txt',
62
+ '/sports/openfootball/euro/2024--germany/euro.txt'] if args.empty?
63
+
64
+ build_pathspecs( args )
65
+ end
66
+
67
+
68
+
69
+
70
+ specs.each_with_index do |rec,i|
71
+ datafiles = rec['datafiles']
72
+
73
+ errors = []
74
+
75
+ datafiles.each_with_index do |path,j|
76
+ puts "==> [#{i+1}/#{specs.size}, #{j+1}/#{datafiles.size}] reading >#{path}<..."
77
+
78
+ txt = read_text( path )
79
+ parser = RaccMatchParser.new( txt, debug: opts[:debug] )
80
+ tree = parser.parse
81
+
82
+ dump_tree_stats( tree )
83
+
84
+ errors += parser.errors if parser.errors?
85
+ end
86
+
87
+
88
+ if errors.size > 0
89
+ puts
90
+ pp errors
91
+ puts
92
+ puts "!! #{errors.size} parse error(s) in #{datafiles.size} datafiles(s)"
93
+ else
94
+ puts
95
+ puts "OK no parse errors found in #{datafiles.size} datafile(s)"
96
+ end
97
+
98
+ ## add errors to rec via rec['errors'] to allow
99
+ ## for further processing/reporting
100
+ rec['errors'] = errors
101
+ end
102
+
103
+
104
+ ###
105
+ ## generate a report if --file option used
106
+ if opts[:file]
107
+
108
+ buf = SportDb::PathspecReport.new(
109
+ specs,
110
+ title: 'fbtree summary report' ).build
111
+
112
+ puts
113
+ puts "SUMMARY:"
114
+ puts buf
115
+
116
+ # maybe write out in the future?
117
+ # basedir = File.dirname( opts[:file] )
118
+ # basename = File.basename( opts[:file], File.extname( opts[:file] ))
119
+ end
120
+
121
+ puts "bye"
122
+ end
123
+
124
+
125
+ def self.dump_tree_stats( tree )
126
+ stats = Hash.new(0) ## track counts only for now
127
+ tree.each do |node|
128
+ stats[ node.class ] += 1
129
+ end
130
+
131
+ match_count = stats[ RaccMatchParser::MatchLine ]
132
+ goal_count = stats[ RaccMatchParser::GoalLine ]
133
+ lineup_count = stats[ RaccMatchParser::LineupLine ]
134
+
135
+ puts " #{match_count} MatchLine(s)" if match_count > 0
136
+ puts " #{goal_count} GoalLine(s)" if goal_count > 0
137
+ puts " #{lineup_count} LineupLine(s)" if lineup_count > 0
138
+ end
139
+
140
+
141
+ end # module Fbtree
data/lib/fbtok/fbx.rb ADDED
@@ -0,0 +1,107 @@
1
+ ##
2
+ ## todo/fix - use for testing
3
+ # reads textfile and dumps results in json
4
+ #
5
+ # check - keep fbx name or find a differnt name - why? why not?
6
+
7
+ ##
8
+ ## read textfile
9
+ ## and dump match parse results
10
+ ##
11
+ ## fbt ../openfootball/.../euro.txt
12
+
13
+
14
+
15
+ module Fbx
16
+
17
+ def self.main( args=ARGV )
18
+
19
+ opts = { debug: false,
20
+ outline: false }
21
+
22
+ parser = OptionParser.new do |parser|
23
+ parser.banner = "Usage: #{$PROGRAM_NAME} [options] DATAFILE"
24
+
25
+ ##
26
+ ## check if git has a offline option?? (use same)
27
+ ## check for other tools - why? why not?
28
+
29
+
30
+ parser.on( "--verbose", "--debug",
31
+ "turn on verbose / debug output (default: #{opts[:debug]})" ) do |debug|
32
+ opts[:debug] = debug
33
+ end
34
+
35
+ # parser.on( "--outline",
36
+ # "turn on outline (only) output (default: #{opts[:outline]})" ) do |outline|
37
+ # opts[:outline] = outline
38
+ # end
39
+ end
40
+ parser.parse!( args )
41
+
42
+
43
+ if opts[:debug]
44
+ puts "OPTS:"
45
+ p opts
46
+ puts "ARGV:"
47
+ p args
48
+
49
+ SportDb::MatchParser.debug = true
50
+ else
51
+ SportDb::MatchParser.debug = false
52
+ LogUtils::Logger.root.level = :info
53
+ end
54
+
55
+
56
+ args = [
57
+ '../../../openfootball/euro/2021--europe/euro.txt',
58
+ '../../../openfootball/euro/2024--germany/euro.txt',
59
+ ] if args.empty?
60
+
61
+ pp args
62
+
63
+
64
+
65
+ ## errors = []
66
+
67
+
68
+ paths = args
69
+
70
+ paths.each_with_index do |path,i|
71
+ puts "==> [#{i+1}/#{paths.size}] reading >#{path}<..."
72
+
73
+ txt = read_text( path )
74
+
75
+ ##
76
+ ## note - use start: nil => requires that first date incl. a year!!!
77
+ parser = SportDb::MatchParser.new( txt, start: nil )
78
+
79
+ auto_conf_teams, matches, rounds, groups = parser.parse
80
+
81
+ puts ">>> #{auto_conf_teams.size} teams:"
82
+ pp auto_conf_teams
83
+ puts ">>> #{matches.size} matches:"
84
+ pp matches[0,2] ## print first two matches
85
+ puts "..."
86
+ puts ">>> #{rounds.size} rounds:"
87
+ pp rounds
88
+ puts ">>> #{groups.size} groups:"
89
+ pp groups
90
+ end # each paths
91
+
92
+ =begin
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
+ =end
103
+
104
+ puts "bye"
105
+
106
+ end # self.main
107
+ end # module Fbx