sportdb-writers 0.1.1 → 0.1.2

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
  SHA256:
3
- metadata.gz: f4c4a35292a78b32475f88dc7d43246c1782dcd82c15afed36aec0b6e1143e94
4
- data.tar.gz: 6ec7868264b09d86494f86b2a30c7577212e7e262901df415b36d2bd3c4d4d06
3
+ metadata.gz: 7e6c426324cdb4d759fd741cc287435dc10a16f7aabbaf699295132c0f38a6e1
4
+ data.tar.gz: 70b7dc48369a7b822cd2b800dcb9dc05f1188cf18559bb43a5654d3fd63dc304
5
5
  SHA512:
6
- metadata.gz: 6ca5e6e0ec314d83328900e159d6f561869ba4f93d160628b012c1f16b571df3b2d7c92fb418b74fcf474bf3fd8451c03590e629318309b4cb93ee2eaee7c491
7
- data.tar.gz: 4ed5b4c8538c9438532fb80432a7c7087f3b84c991a38d4026a4e74981759093fed3d475d9191b2f28d6c3ae776de87c3826e1f80f7531e00da28f6d4a009a3d
6
+ metadata.gz: 9f78877c0169b086b0e3b8d0e5357b0b24a729a12f294a5344d7797ffe6f7be29eb0d4ed7557181429c07b959c4ddce7528bbdeb272e7e8da4396a5d037c17f0
7
+ data.tar.gz: 24502014e49eb97679ab177b893f44a375f796185155da9ee4a5e7d705d5d3e43e171b14a6c494ef3cb3087961f769fc09aa646e4e48a50cc6b426d961839789
data/CHANGELOG.md CHANGED
@@ -1,4 +1,4 @@
1
- ### 0.1.1
1
+ ### 0.1.2
2
2
 
3
3
  ### 0.0.1 / 2020-11-15
4
4
 
data/Manifest.txt CHANGED
@@ -4,18 +4,15 @@ README.md
4
4
  Rakefile
5
5
  bin/fbgen
6
6
  bin/fbtxt
7
- lib/sportdb/leagues/leagues_at.rb
8
- lib/sportdb/leagues/leagues_de.rb
9
- lib/sportdb/leagues/leagues_eng.rb
10
- lib/sportdb/leagues/leagues_es.rb
11
- lib/sportdb/leagues/leagues_europe.rb
12
- lib/sportdb/leagues/leagues_it.rb
13
- lib/sportdb/leagues/leagues_mx.rb
14
- lib/sportdb/leagues/leagues_south_america.rb
15
- lib/sportdb/leagues/leagues_world.rb
7
+ config/leagues_america.csv
8
+ config/leagues_europe.csv
9
+ config/leagues_world.csv
10
+ config/openfootball.csv
16
11
  lib/sportdb/writers.rb
17
12
  lib/sportdb/writers/github.rb
13
+ lib/sportdb/writers/github_config.rb
18
14
  lib/sportdb/writers/goals.rb
15
+ lib/sportdb/writers/league_config.rb
19
16
  lib/sportdb/writers/txt_writer.rb
20
17
  lib/sportdb/writers/version.rb
21
18
  lib/sportdb/writers/write.rb
data/bin/fbgen CHANGED
@@ -14,13 +14,42 @@ args=ARGV
14
14
 
15
15
 
16
16
  opts = {
17
+ source_path: [],
18
+ push: false,
19
+ dry: false, ## dry run (no write)
20
+ debug: true,
17
21
  }
18
22
 
23
+
24
+
19
25
  parser = OptionParser.new do |parser|
20
- parser.banner = "Usage: #{$PROGRAM_NAME} [options]"
26
+ parser.banner = "Usage: #{$PROGRAM_NAME} [options] [args]"
27
+
28
+ parser.on( "-p", "--push",
29
+ "fast forward sync and commit & push changes to git repo - default is (#{opts[:push]})" ) do |push|
30
+ opts[:push] = push
31
+ end
32
+ parser.on( "--dry",
33
+ "dry run; do NOT write - default is (#{opts[:dry]})" ) do |dry|
34
+ opts[:dry] = dry
35
+ end
36
+ parser.on( "-q", "--quiet",
37
+ "less debug output/messages - default is (#{!opts[:debug]})" ) do |debug|
38
+ opts[:debug] = !debug
39
+ end
21
40
  end
22
41
  parser.parse!( args )
23
42
 
43
+
44
+
45
+ if opts[:source_path].empty? &&
46
+ File.exist?( '/sports/cache.api.fbdat') &&
47
+ File.exist?( '/sports/cache.wfb' )
48
+ opts[:source_path] << '/sports/cache.api.fbdat'
49
+ opts[:source_path] << '/sports/cache.wfb'
50
+ end
51
+
52
+
24
53
  puts "OPTS:"
25
54
  p opts
26
55
  puts "ARGV:"
@@ -56,6 +85,47 @@ end
56
85
  pp datasets
57
86
 
58
87
 
88
+
89
+ def find_file( filename, path: )
90
+ path.each do |src_dir|
91
+ path = "#{src_dir}/#{filename}"
92
+ return path if File.exist?( path )
93
+ end
94
+
95
+ ## fix - raise file not found error!!!
96
+ nil ## not found - raise filenot found error - why? why not?
97
+ end
98
+
99
+
100
+ source_path = opts[:source_path]
101
+ source_path = ['.'] if source_path.empty? ## use ./ as default
102
+
103
+
104
+ root_dir = if opts[:push]
105
+ SportDb::GitHubSync.root # e.g. "/sports"
106
+ else
107
+ './o'
108
+ end
109
+
110
+
111
+ puts " (output) root_dir: >#{root_dir}<"
112
+
113
+
114
+ sync = if opts[:push]
115
+ repos = SportDb::GitHubSync.find_repos( datasets )
116
+ puts " #{repos.size} repo(s):"
117
+ pp repos
118
+ SportDb::GitHubSync.new( repos )
119
+ else
120
+ nil
121
+ end
122
+ puts " sync:"
123
+ pp sync
124
+
125
+ sync.git_fast_forward_if_clean if sync
126
+
127
+
128
+
59
129
  datasets.each do |league_key, seasons|
60
130
  seasons = [ Season('2024/25') ] if seasons.empty?
61
131
 
@@ -66,15 +136,22 @@ datasets.each do |league_key, seasons|
66
136
 
67
137
  seasons.each do |season|
68
138
  ### get matches
69
- src_dir = "/sports/cache.wfb"
70
- path = "#{src_dir}/#{season.to_path}/#{league_key}.csv"
139
+
140
+ filename = "#{season.to_path}/#{league_key}.csv"
141
+ path = find_file( filename, path: source_path )
142
+
143
+ if path.nil?
144
+ puts "!! no source found for #{filename}; sorry"
145
+ exit 1
146
+ end
147
+
71
148
  puts " ---> reading matches in #{path} ..."
72
149
  matches = SportDb::CsvMatchParser.read( path )
73
150
  puts " #{matches.size} matches"
74
151
 
75
152
  ## build
76
153
  txt = SportDb::TxtMatchWriter.build( matches )
77
- puts txt
154
+ puts txt if opts[:debug]
78
155
 
79
156
  league_name = league_info[ :name ] # e.g. Brasileiro Série A
80
157
  basename = league_info[ :basename] #.e.g 1-seriea
@@ -86,14 +163,21 @@ datasets.each do |league_key, seasons|
86
163
  buf << "= #{league_name} #{season}\n\n"
87
164
  buf << txt
88
165
 
89
- ## note - repo_path moved!!!
90
- ## repo_path = league_info[ :path ] # e.g. brazil or world/europe/portugal etc.
91
- repo_path = SportDb::GitHubSync::REPOS[ league_key ]
166
+ repo = SportDb::GitHubSync::REPOS[ league_key ]
167
+ repo_path = "#{repo['owner']}/#{repo['name']}"
168
+ repo_path << "/#{repo['path']}" if repo['path'] ## note: do NOT forget to add optional extra path!!!
92
169
 
93
- outpath = "./o/#{repo_path}/#{season.to_path}/#{basename}.txt"
94
- write_text( outpath, buf )
170
+ outpath = "#{root_dir}/#{repo_path}/#{season.to_path}/#{basename}.txt"
171
+ if opts[:dry]
172
+ puts " (dry) writing to >#{outpath}<..."
173
+ else
174
+ write_text( outpath, buf )
175
+ end
95
176
  end
96
177
  end
97
178
 
98
179
 
180
+ sync.git_push_if_changes if sync
181
+
182
+
99
183
  puts "bye"
@@ -0,0 +1,6 @@
1
+ key, name, basename, start_season, end_season, comments
2
+
3
+ ar.1, Argentina Primera Division, 1-primeradivision,,,
4
+ br.1, Brasileiro Série A, 1-seriea,,,
5
+
6
+ mx.1, Liga MX, 1-ligamx,,, ## note: basename gets overwritten by stages e.g. 1-apertura or 1-clausura
@@ -0,0 +1,85 @@
1
+ key, name, basename, start_season, end_season, comments
2
+
3
+ at.1, Österr. Bundesliga, 1-bundesliga,,,
4
+ at.2, Österr. 2. Liga, 2-liga2, 2018/19,,
5
+ at.2, Österr. Erste Liga, 2-liga1, , 2017/18,
6
+ at.3.o, Österr. Regionalliga Ost, 3-regionalliga-ost,,,
7
+ at.cup, ÖFB Cup, cup,,,
8
+
9
+
10
+ de.1, Deutsche Bundesliga, 1-bundesliga,,,
11
+ de.2, Deutsche 2. Bundesliga, 2-bundesliga2,,,
12
+ de.3, Deutsche 3. Liga, 3-liga3,,,
13
+ de.cup, DFB Pokal, cup,,,
14
+
15
+ it.1, Italian Serie A, 1-seriea,,,
16
+ it.2, Italian Serie B, 2-serieb,,,
17
+
18
+ es.1, Primera División de España, 1-liga,,,
19
+ es.2, Segunda División de España, 2-liga2,,,
20
+
21
+ fr.1, French Ligue 1, 1-ligue1,,,
22
+ fr.2, French Ligue 2, 2-ligue2,,,
23
+
24
+
25
+ eng.1, English Premier League, 1-premierleague, 1992/93,,
26
+ eng.1, English Division One, 1-division1, 1892/93, 1991/92, ## start of division 1 & 2
27
+ eng.1, English Football League, 1-footballleague, 1888/89, 1891/92, ## single league (no divisions)
28
+
29
+ eng.2, English Championship, 2-championship, 2004/05,, ## rebranding divsion 1 => championship
30
+ eng.2, English Division One, 2-division1, 1992/93, 2003/04, ## start of premier league
31
+ eng.2, English Division Two, 2-division2, 1892/93, 1991/92, ## or use English Football League Second Division ???
32
+
33
+ eng.3, English League One, 3-league1,,,
34
+ eng.4, English League Two, 4-league2,,,
35
+ eng.5, English National League, 5-nationalleague,,,
36
+ eng.cup, English FA Cup, facup,,,
37
+
38
+
39
+ hu.1, Hungarian NB I, 1-nbi,,,
40
+
41
+ gr.1, Super League Greece, 1-superleague,,,
42
+
43
+ pt.1, Portuguese Primeira Liga, 1-primeiraliga,,,
44
+ pt.2, Portuguese Segunda Liga, 2-segundaliga,,,
45
+
46
+ ch.1, Swiss Super League, 1-superleague,,,
47
+ ch.2, Swiss Challenge League, 2-challengeleague,,,
48
+
49
+ tr.1, Turkish Süper Lig, 1-superlig,,,
50
+ tr.2, Turkish 1. Lig, 2-lig1,,,
51
+
52
+ is.1, Iceland Urvalsdeild, 1-urvalsdeild,,,
53
+
54
+ sco.1, Scottish Premiership, 1-premiership,,,
55
+
56
+ ie.1, Irish Premier Division, 1-premierdivision,,,
57
+
58
+ fi.1, Finland Veikkausliiga, 1-veikkausliiga,,,
59
+
60
+ se.1, Sweden Allsvenskan, 1-allsvenskan,,,
61
+ se.2, Sweden Superettan, 2-superettan,,,
62
+
63
+ no.1, Norwegian Eliteserien, 1-eliteserien,,,
64
+ dk.1, Denmark Superligaen, 1-superligaen,,,
65
+
66
+ lu.1, Luxembourger First Division, 1-nationaldivision,,,
67
+
68
+ be.1, Belgian First Division A, 1-firstdivisiona,,,
69
+
70
+ nl.1, Dutch Eredivisie, 1-eredivisie,,,
71
+
72
+ cz.1, Czech First League, 1-firstleague,,,
73
+ sk.1, Slovakia First League, 1-superliga,,,
74
+ hr.1, Croatia 1. HNL, 1-hnl,,,
75
+
76
+ pl.1, Poland Ekstraklasa, 1-ekstraklasa,,,
77
+
78
+ ro.1, Romanian Liga 1, 1-liga1,,,
79
+
80
+ ua.1, Ukraine Premier League, 1-premierleague,,,
81
+
82
+ ru.1, Russian Premier League, 1-premierliga,,,
83
+ ru.2, Russian 1. Division, 2-division1,,,
84
+
85
+
@@ -0,0 +1,4 @@
1
+ key, name, basename, start_season, end_season, comments
2
+
3
+ cn.1, Chinese Super League, 1-superleague,,,
4
+ jp.1, Japan J1 League, 1-j1league,,,
@@ -0,0 +1,52 @@
1
+ key, path
2
+
3
+ at, austria
4
+
5
+ de, deutschland
6
+ eng, england
7
+ es, espana
8
+ it, italy
9
+
10
+ fr, europe/france
11
+
12
+ hu, europe/hungary
13
+ gr, europe/greece
14
+ pt, europe/portugal
15
+
16
+ ch, europe/switzerland
17
+
18
+ tr, europe/turkey
19
+
20
+ is, europe/iceland
21
+ sco, europe/scotland
22
+ ie, europe/ireland
23
+
24
+ fi, europe/finland
25
+ se, europe/sweden
26
+ no, europe/norway
27
+ dk, europe/denmark
28
+
29
+ lu, europe/luxembourg
30
+ be, europe/belgium
31
+ nl, europe/netherlands
32
+ cz, europe/czech-republic
33
+
34
+ sk, europe/slovakia
35
+ hr, europe/croatia
36
+ pl, europe/poland
37
+
38
+ ro, europe/romania
39
+
40
+ ua, europe/ukraine
41
+
42
+ ru, europe/russia
43
+
44
+
45
+ mx, mexico
46
+
47
+ ar, south-america/argentina
48
+ br, south-america/brazil
49
+
50
+ cn, world/asia/china
51
+ jp, world/asia/japan
52
+
@@ -6,118 +6,47 @@ module SportDb
6
6
  ## add -i/--interactive flag
7
7
  ## will prompt yes/no before git operations (with consequences)!!!
8
8
 
9
+
10
+
9
11
  class GitHubSync
10
12
 
11
- ## map leagues to repo+path
12
- ## e.g. fr.1 => europe/france
13
- ## eng..1 => england
14
- REPOS = {
15
- 'at.1' => 'austria',
16
- 'at.2' => 'austria',
17
- 'at.3.o' => 'austria',
18
- 'at.cup' => 'austria',
19
-
20
- 'de.1' => 'deutschland',
21
- 'de.2' => 'deutschland',
22
- 'de.3' => 'deutschland',
23
- 'de.cup' => 'deutschland',
24
-
25
- 'eng.1' => 'england',
26
- 'eng.2' => 'england',
27
- 'eng.3' => 'england',
28
- 'eng.4' => 'england',
29
- 'eng.5' => 'england',
30
- 'eng.cup' => 'england', # English FA Cup
31
-
32
- 'es.1' => 'espana',
33
- 'es.2' => 'espana',
34
-
35
- 'fr.1' => 'europe/france',
36
- 'fr.2' => 'europe/france',
37
-
38
- 'hu.1' => 'europe/hungary',
39
- 'gr.1' => 'europe/greece',
40
- 'pt.1' => 'europe/portugal',
41
- 'pt.2' => 'europe/portugal',
42
-
43
- 'ch.1' => 'europe/switzerland',
44
- 'ch.2' => 'europe/switzerland',
45
-
46
- 'tr.1' => 'europe/turkey',
47
- 'tr.2' => 'europe/turkey',
48
-
49
- 'is.1' => 'europe/iceland',
50
- 'sco.1' => 'europe/scotland',
51
- 'ie.1' => 'europe/ireland',
52
-
53
- 'fi.1' => 'europe/finland',
54
- 'se.1' => 'europe/sweden',
55
- 'se.2' => 'europe/sweden',
56
- 'no.1' => 'europe/norway',
57
- 'dk.1' => 'europe/denmark',
58
-
59
- 'lu.1' => 'europe/luxembourg',
60
- 'be.1' => 'europe/belgium',
61
- 'nl.1' => 'europe/netherlands',
62
- 'cz.1' => 'europe/czech-republic',
63
-
64
- 'sk.1' => 'europe/slovakia',
65
- 'hr.1' => 'europe/croatia',
66
- 'pl.1' => 'europe/poland',
67
-
68
- 'ro.1' => 'europe/romania',
69
-
70
- 'ua.1' => 'europe/ukraine',
71
-
72
- 'ru.1' => 'europe/russia',
73
- 'ru.2' => 'europe/russia',
74
-
75
- 'it.1' => 'italy',
76
- 'it.2' => 'italy',
77
-
78
- 'mx.1' => 'mexico',
79
-
80
- 'ar.1' => 'south-america/argentina',
81
- 'br.1' => 'south-america/brazil',
82
-
83
- 'cn.1' => 'world/asia/china',
84
- 'jp.1' => 'world/asia/japan',
85
- }
86
-
87
-
88
-
89
- ########
13
+ ########
90
14
  ## (auto)default to Writer.config.out_dir - why? why not?
91
15
  ##
92
- ## note - is root for org (NOT monotree for now - why?`why not?)
93
- def self.root() @root || "/sports/openfootball"; end
94
- def self.root=( dir ) @root = dir; end
16
+ ## note - is monotree (that is, requires openfootball/england etc.
17
+ ## for repo pathspecs)
18
+ def self.root() @root || "/sports"; end
19
+ def self.root=( dir ) @root = dir; end
95
20
  ## use root_dir (alias) - why? why not?
96
21
 
97
22
 
98
- def initialize( datasets )
99
- @repos = _find_repos( datasets )
23
+ def initialize( repos )
24
+ @repos = repos
100
25
  end
101
26
 
102
27
 
103
- def git_push_if_changes
104
- _git_push_if_changes( @repos )
105
- end
106
-
28
+ def git_push_if_changes
29
+ message = "auto-update week #{Date.today.cweek}" ## add /#{Date.today.cday - why? why not?
30
+ puts message
31
+
32
+ @repos.each do |pathspec|
33
+ _git_push_if_changes( pathspec, message: message )
34
+ end
35
+ end
36
+
107
37
  def git_fast_forward_if_clean
108
- _git_fast_forward_if_clean( @repos )
38
+ @repos.each do |pathspec|
39
+ _git_fast_forward_if_clean( pathspec )
40
+ end
109
41
  end
110
42
 
111
43
 
44
+
112
45
  ## todo/fix: rename to something like
113
46
  ## git_(auto_)commit_and_push_if_changes/if_dirty()
114
47
 
115
- def _git_push_if_changes( names ) ## optenfootball repo names e.g. world, england, etc.
116
- message = "auto-update week #{Date.today.cweek}" ## add /#{Date.today.cday - why? why not?
117
- puts message
118
-
119
- names.each do |name|
120
- path = "#{self.class.root}/#{name}"
48
+ def _git_push_if_changes( pathspec, message: )
49
+ path = "#{self.class.root}/#{pathspec}"
121
50
 
122
51
  Gitti::GitProject.open( path ) do |proj|
123
52
  puts ''
@@ -133,13 +62,11 @@ def _git_push_if_changes( names ) ## optenfootball repo names e.g. world, engl
133
62
  proj.push
134
63
  end
135
64
  end
136
- end
137
65
  end
138
66
 
139
67
 
140
- def _git_fast_forward_if_clean( names )
141
- names.each do |name|
142
- path = "#{self.class.root}/#{name}"
68
+ def _git_fast_forward_if_clean( pathspec )
69
+ path = "#{self.class.root}/#{pathspec}"
143
70
 
144
71
  Gitti::GitProject.open( path ) do |proj|
145
72
  output = proj.changes
@@ -151,45 +78,6 @@ def _git_fast_forward_if_clean( names )
151
78
 
152
79
  proj.fast_forward
153
80
  end
154
- end
155
81
  end
156
-
157
-
158
- ## todo/check: find a better name for helper?
159
- ## note: datasets of format
160
- ##
161
- ## DATASETS = [
162
- ## ['it.1', %w[2020/21 2019/20]],
163
- ## ['it.2', %w[2019/20]],
164
- ## ['es.1', %w[2019/20]],
165
- ## ['es.2', %w[2019/20]],
166
- ## ]
167
-
168
-
169
- def _find_repos( datasets )
170
- repos = []
171
- datasets.each do |dataset|
172
- league_key = dataset[0]
173
- path = REPOS[ league_key ]
174
- ## pp path
175
- if path.nil?
176
- puts "!! ERROR - no repo path found for league >#{league_key}<; sorry"
177
- exit 1
178
- end
179
-
180
- ## auto-add
181
- ## openfootball/ org here
182
- ## and keep root "generic" to monoroot - why? why not?
183
-
184
- ## use only first part e.g. europe/belgium => europe
185
- repos << path.split( '/' )[0]
186
- end
187
- pp repos
188
- repos.uniq ## note: remove duplicates (e.g. europe or world or such)
189
- end
190
-
191
-
192
-
193
-
194
82
  end # class GitHub
195
83
  end # module SportDb
@@ -0,0 +1,97 @@
1
+
2
+ module SportDb
3
+ class GitHubConfig
4
+
5
+ ## map leagues to repo+path
6
+ ## e.g. fr.1 => europe/france
7
+ ## eng..1 => england
8
+ ##
9
+ ## for other than openfootball (default)
10
+ ## use @
11
+ ## e.g. myorg@austria
12
+ ## austria@myorg ??
13
+ ##
14
+ ## myorg@europe/france
15
+ ## europe/france@myorg
16
+
17
+
18
+ def self.read( path )
19
+ recs = read_csv( path )
20
+ new( recs )
21
+ end
22
+
23
+ def initialize( recs=nil )
24
+ @table = {}
25
+ add( recs ) if recs
26
+ end
27
+
28
+
29
+ def add( recs )
30
+ recs.each do |rec|
31
+ path = rec['path'] ## use pathspec - why? why not?
32
+ ## or repospec or such
33
+
34
+ ## auto-expand to openfootball as default org if no @ specified
35
+ owner, path = if path.index( '@')
36
+ path.split( '@', 2 )
37
+ else
38
+ ['openfootball', path ]
39
+ end
40
+ name, path = path.split( '/', 2 )
41
+
42
+
43
+ ## openfootball@europe/france
44
+ ## =>
45
+ ## owner: openfootball
46
+ ## name: europe
47
+ ## path: france
48
+ ##
49
+ ## openfootball@austria
50
+ ## =>
51
+ ## owner: openfootball
52
+ ## name: austria
53
+ ## path: nil
54
+ @table[ rec['key'] ] = { 'owner' => owner, ## (required)
55
+ 'name' => name, ## (required)
56
+ 'path' => path ## extra/inner/inside/local path (optional)
57
+ }
58
+ end
59
+ end
60
+
61
+
62
+ ##
63
+ ## todo/fix:
64
+ ## make key lookup more flexible
65
+ ## auto-add more variants!!!
66
+ ## e.g. at.1 AT1, AT or such
67
+ ##
68
+
69
+ ## find (full) record by key
70
+ def find( key )
71
+ key = key.to_s.downcase
72
+
73
+ ## first check for 1:1 match
74
+ rec = @table[key]
75
+ if rec.nil?
76
+ ## try match by (country / first) code
77
+ ## split by .
78
+ key, _ = key.split( '.' )
79
+ rec = @table[key]
80
+ end
81
+
82
+ rec
83
+ end
84
+ alias_method :[], :find ## keep alias - why? why not?
85
+
86
+
87
+ def find_repo( key )
88
+ rec = _find( key )
89
+
90
+ rec ? "#{rec['owner']}/#{rec['name']}" : nil
91
+ end
92
+
93
+ end # class GitHubConfig
94
+ end # module SportDb
95
+
96
+
97
+
@@ -0,0 +1,83 @@
1
+
2
+ module SportDb
3
+ class LeagueConfig
4
+
5
+ def self.read( path )
6
+ recs = read_csv( path )
7
+ new( recs )
8
+ end
9
+
10
+ def initialize( recs=nil )
11
+ @table = {}
12
+ add( recs ) if recs
13
+ end
14
+
15
+
16
+ class LeagueItem
17
+ def initialize
18
+ @recs = []
19
+ end
20
+ def add( rec ) @recs << rec; end
21
+ alias_method :<<, :add
22
+
23
+ def find_by_season( season )
24
+ @recs.each do |rec|
25
+ start_season = rec['start_season']
26
+ end_season = rec['end_season']
27
+ return rec if (start_season.nil? || start_season <= season) &&
28
+ (end_season.nil? || end_season >= season)
29
+ end
30
+ nil
31
+ end
32
+
33
+
34
+ def name_by_season( season )
35
+ rec = find_by_season( season )
36
+ rec ? rec['name'] : nil
37
+ end
38
+
39
+ def basename_by_season( season )
40
+ rec = find_by_season( season )
41
+ rec ? rec['basename'] : nil
42
+ end
43
+
44
+
45
+ def [](key)
46
+ ## short cut - if only one or zero rec
47
+ ## return directly
48
+ if @recs.empty?
49
+ nil
50
+ elsif @recs.size == 1 &&
51
+ @recs[0]['start_season'].nil? &&
52
+ @recs[0]['end_season'].nil?
53
+ @recs[0][key.to_s]
54
+ else ### return proc that requires season arg
55
+ case key.to_sym
56
+ when :name then method(:name_by_season).to_proc
57
+ when :basename then method(:basename_by_season).to_proc
58
+ else
59
+ nil ## return nil - why? why not?
60
+ ## raise ArgumentError, "invalid key #{key}; use :name or :basename"
61
+ end
62
+ end
63
+ end
64
+ end
65
+
66
+ def add( recs )
67
+ recs.each do |rec|
68
+ @table[ rec['key'] ] ||= LeagueItem.new
69
+
70
+ ## note: auto-change seasons to season object or nil
71
+ @table[ rec['key'] ] << { 'name' => rec['name'],
72
+ 'basename' => rec['basename'],
73
+ 'start_season' => rec['start_season'].empty? ? nil : Season.parse( rec['start_season'] ),
74
+ 'end_season' => rec['end_season'].empty? ? nil : Season.parse( rec['end_season'] ),
75
+ }
76
+ end
77
+ end
78
+
79
+
80
+ def [](key) @table[ key.to_s.downcase ]; end
81
+
82
+ end # class LeagueConfig
83
+ end # module SportDb
@@ -4,7 +4,7 @@ module Module
4
4
  module Writers
5
5
  MAJOR = 0 ## todo: namespace inside version or something - why? why not??
6
6
  MINOR = 1
7
- PATCH = 1
7
+ PATCH = 2
8
8
  VERSION = [MAJOR,MINOR,PATCH].join('.')
9
9
 
10
10
  def self.version
@@ -53,7 +53,7 @@ def self.write( league:, season:,
53
53
  source:,
54
54
  extra: nil,
55
55
  split: false,
56
- normalize: false,
56
+ normalize: false,
57
57
  rounds: true )
58
58
  season = Season( season ) ## normalize season
59
59
 
@@ -71,7 +71,7 @@ def self.write( league:, season:,
71
71
  exit 1
72
72
  end
73
73
  source_info = { path: source } ## wrap in "plain" source dir in source info
74
-
74
+
75
75
  source_path = source_info[:path]
76
76
 
77
77
  ## format lets you specify directory layout
@@ -106,14 +106,14 @@ def self.write( league:, season:,
106
106
  if normalize.is_a?(Proc)
107
107
  matches = normalize.call( matches, league: league,
108
108
  season: season )
109
- else
109
+ else
110
110
  puts "!! ERROR - normalize; expected proc got #{normalize.inspect}"
111
111
  exit 1
112
- end
112
+ end
113
113
  end
114
-
115
114
 
116
-
115
+
116
+
117
117
  league_name = league_info[ :name ] # e.g. Brasileiro Série A
118
118
  basename = league_info[ :basename] #.e.g 1-seriea
119
119
 
@@ -122,7 +122,10 @@ def self.write( league:, season:,
122
122
 
123
123
  ## note - repo_path moved!!!
124
124
  ## repo_path = league_info[ :path ] # e.g. brazil or world/europe/portugal etc.
125
- repo_path = SportDb::GitHubSync::REPOS[ league ]
125
+ repo = SportDb::GitHubSync::REPOS[ league ]
126
+ repo_path = "#{repo['owner']}/#{repo['name']}"
127
+ repo_path << "/#{repo['path']}" if repo['path'] ## note: do NOT forget to add optional extra path!!!
128
+
126
129
 
127
130
 
128
131
  season_path = String.new ## note: allow extra path for output!!!! e.g. archive/2000s etc.
@@ -175,7 +178,7 @@ def self.write( league:, season:,
175
178
  )
176
179
 
177
180
  ## note: might be empty!!! if no matches skip (do NOT write)
178
- write_text( "#{config.out_dir}/#{repo_path}/#{season_path}/#{stage_basename}.txt",
181
+ write_text( "#{config.out_dir}/#{repo_path}/#{season_path}/#{stage_basename}.txt",
179
182
  buf ) unless buf.empty?
180
183
  end
181
184
  else ## no stages - assume "regular" plain vanilla season
@@ -29,29 +29,67 @@ require_relative 'writers/goals'
29
29
  require_relative 'writers/write'
30
30
 
31
31
 
32
+ ## setup leagues (info) table
33
+ require_relative 'writers/league_config'
34
+
35
+ module Writer
36
+ LEAGUES = SportDb::LeagueConfig.new
37
+
38
+ ['leagues_europe',
39
+ 'leagues_america',
40
+ 'leagues_world'
41
+ ].each do |name|
42
+ recs = read_csv( "#{SportDb::Module::Writers.root}/config/#{name}.csv" )
43
+ LEAGUES.add( recs )
44
+ end
45
+ end # module Writer
46
+
47
+
32
48
 
33
49
  ########################
34
50
  # push & pull github scripts
35
51
  require 'gitti' ## note - requires git machinery
36
52
 
53
+ require_relative 'writers/github_config'
37
54
  require_relative 'writers/github' ## github helpers/update machinery
38
55
 
39
56
 
57
+ module SportDb
58
+ class GitHubSync
59
+ REPOS = GitHubConfig.new
60
+ recs = read_csv( "#{SportDb::Module::Writers.root}/config/openfootball.csv" )
61
+ REPOS.add( recs )
40
62
 
41
- ## setup empty leagues (info) hash
42
- module Writer
43
- LEAGUES = {}
63
+ ## todo/check: find a better name for helper?
64
+ ## note: datasets of format
65
+ ##
66
+ ## DATASETS = [
67
+ ## ['it.1', %w[2020/21 2019/20]],
68
+ ## ['it.2', %w[2019/20]],
69
+ ## ['es.1', %w[2019/20]],
70
+ ## ['es.2', %w[2019/20]],
71
+ ## ]
72
+
73
+ def self.find_repos( datasets )
74
+ repos = []
75
+ datasets.each do |dataset|
76
+ league_key = dataset[0]
77
+ repo = REPOS[ league_key ]
78
+ ## pp repo
79
+ if repo.nil?
80
+ puts "!! ERROR - no repo config/path found for league >#{league_key}<; sorry"
81
+ exit 1
82
+ end
83
+
84
+ repos << "#{repo['owner']}/#{repo['name']}"
85
+ end
86
+
87
+ pp repos
88
+ repos.uniq ## note: remove duplicates (e.g. europe or world or such)
44
89
  end
90
+ end # class GitHubSync
91
+ end # module SportDb
45
92
 
46
- require_relative 'leagues/leagues_at'
47
- require_relative 'leagues/leagues_de'
48
- require_relative 'leagues/leagues_eng'
49
- require_relative 'leagues/leagues_es'
50
- require_relative 'leagues/leagues_europe'
51
- require_relative 'leagues/leagues_it'
52
- require_relative 'leagues/leagues_mx'
53
- require_relative 'leagues/leagues_south_america'
54
- require_relative 'leagues/leagues_world'
55
93
 
56
94
 
57
95
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sportdb-writers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.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: 2024-09-04 00:00:00.000000000 Z
11
+ date: 2024-09-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sportdb-quick
@@ -90,18 +90,15 @@ files:
90
90
  - Rakefile
91
91
  - bin/fbgen
92
92
  - bin/fbtxt
93
- - lib/sportdb/leagues/leagues_at.rb
94
- - lib/sportdb/leagues/leagues_de.rb
95
- - lib/sportdb/leagues/leagues_eng.rb
96
- - lib/sportdb/leagues/leagues_es.rb
97
- - lib/sportdb/leagues/leagues_europe.rb
98
- - lib/sportdb/leagues/leagues_it.rb
99
- - lib/sportdb/leagues/leagues_mx.rb
100
- - lib/sportdb/leagues/leagues_south_america.rb
101
- - lib/sportdb/leagues/leagues_world.rb
93
+ - config/leagues_america.csv
94
+ - config/leagues_europe.csv
95
+ - config/leagues_world.csv
96
+ - config/openfootball.csv
102
97
  - lib/sportdb/writers.rb
103
98
  - lib/sportdb/writers/github.rb
99
+ - lib/sportdb/writers/github_config.rb
104
100
  - lib/sportdb/writers/goals.rb
101
+ - lib/sportdb/writers/league_config.rb
105
102
  - lib/sportdb/writers/txt_writer.rb
106
103
  - lib/sportdb/writers/version.rb
107
104
  - lib/sportdb/writers/write.rb
@@ -1,35 +0,0 @@
1
- module Writer
2
-
3
- ########################
4
- # Austria
5
-
6
- LEAGUES.merge!(
7
- 'at.1' => { name: 'Österr. Bundesliga',
8
- basename: '1-bundesliga',
9
- stages: ->(season) {
10
- if season.start_year >= 2018
11
- [['Grunddurchgang'],
12
- ['Finaldurchgang - Meister',
13
- 'Finaldurchgang - Qualifikation',
14
- 'Europa League Play-off']]
15
- else
16
- nil
17
- end
18
- },
19
- },
20
- 'at.2' => { name: ->(season) { season.start_year >= 2018 ?
21
- 'Österr. 2. Liga' :
22
- 'Österr. Erste Liga' },
23
- basename: ->(season) { season.start_year >= 2018 ?
24
- '2-liga2' :
25
- '2-liga1' },
26
- },
27
- 'at.3.o' => { name: 'Österr. Regionalliga Ost',
28
- basename: '3-regionalliga-ost',
29
- },
30
- 'at.cup' => { name: 'ÖFB Cup',
31
- basename: 'cup',
32
- }
33
- )
34
-
35
- end # module Writer
@@ -1,21 +0,0 @@
1
- module Writer
2
-
3
- ############################
4
- # Germany / Deutschland
5
-
6
- LEAGUES.merge!(
7
- 'de.1' => { name: 'Deutsche Bundesliga',
8
- basename: '1-bundesliga',
9
- },
10
- 'de.2' => { name: 'Deutsche 2. Bundesliga',
11
- basename: '2-bundesliga2',
12
- },
13
- 'de.3' => { name: 'Deutsche 3. Liga',
14
- basename: '3-liga3',
15
- },
16
- 'de.cup' => { name: 'DFB Pokal',
17
- basename: 'cup',
18
- }
19
- )
20
-
21
- end # module Writer
@@ -1,58 +0,0 @@
1
- module Writer
2
-
3
- ####################
4
- # England
5
-
6
-
7
- def self.eng1( season )
8
- case season ## todo/fix: - use cast e.g. Season(season) - make sure it's a season obj
9
- when Season('1888/89')..Season('1891/92') ## single league (no divisions)
10
- {name: 'English Football League',
11
- basename: '1-footballleague'}
12
- when Season('1892/93')..Season('1991/92') ## start of division 1 & 2
13
- {name: 'English Division One',
14
- basename: '1-division1'}
15
- else ## starts in season 1992/93
16
- {name: 'English Premier League',
17
- basename: '1-premierleague'}
18
- end
19
- end
20
-
21
- def self.eng2( season )
22
- case season
23
- when Season('1892/93')..Season('1991/92')
24
- {name: 'English Division Two', ## or use English Football League Second Division ???
25
- basename: '2-division2'}
26
- when Season('1992/93')..Season('2003/04') ## start of premier league
27
- {name: 'English Division One',
28
- basename: '2-division1'}
29
- else # starts in 2004/05
30
- {name: 'English Championship', ## rebranding divsion 1 => championship
31
- basename: '2-championship'}
32
- end
33
- end
34
-
35
-
36
- LEAGUES.merge!(
37
- 'eng.1' => { name: ->(season) { eng1( season )[ :name ] },
38
- basename: ->(season) { eng1( season )[ :basename ] },
39
- },
40
- 'eng.2' => { name: ->(season) { eng2( season )[ :name ] },
41
- basename: ->(season) { eng2( season )[ :basename ] },
42
- },
43
- 'eng.3' => { name: 'English League One',
44
- basename: '3-league1',
45
- },
46
- 'eng.4' => { name: 'English League Two',
47
- basename: '4-league2',
48
- },
49
- 'eng.5' => { name: 'English National League',
50
- basename: '5-nationalleague',
51
- },
52
- 'eng.cup' => { name: 'English FA Cup',
53
- basename: 'facup',
54
- }
55
- )
56
-
57
- end # module Writer
58
-
@@ -1,15 +0,0 @@
1
- module Writer
2
-
3
- LEAGUES.merge!(
4
- ###################
5
- # Spain / Espana
6
- 'es.1' => { name: 'Primera División de España',
7
- basename: '1-liga',
8
- },
9
- 'es.2' => { name: 'Segunda División de España',
10
- basename: '2-liga2',
11
- },
12
- )
13
-
14
- end # module Writer
15
-
@@ -1,185 +0,0 @@
1
- module Writer
2
-
3
- LEAGUES.merge!(
4
-
5
- ###
6
- # Uefa
7
- ## quick and dirty add for champions league
8
- 'uefa.cl' => { name: 'UEFA Champions League',
9
- basename: 'cl',
10
- },
11
-
12
- ########################
13
- # France
14
- 'fr.1' => { name: 'French Ligue 1',
15
- basename: '1-ligue1',
16
- },
17
- 'fr.2' => { name: 'French Ligue 2',
18
- basename: '2-ligue2',
19
- },
20
-
21
- 'hu.1' => { name: 'Hungarian NB I',
22
- basename: '1-nbi',
23
- },
24
- 'gr.1' => { name: 'Super League Greece',
25
- basename: '1-superleague',
26
- stages: ->(season) {
27
- if season.start_year >= 2019 # new league system starting with 2015/16 season
28
- [['Regular Season'],
29
- ['Playoffs - Championship',
30
- 'Playoffs - Relegation']]
31
- elsif [2017,2018].include?( season.start_year ) ## 2017/18, 2018/19
32
- nil
33
- elsif [2013,2014,2015,2016].include?( season.start_year )
34
- [['Regular Season'],
35
- ['Playoffs']]
36
- elsif season.start_year == 2012
37
- [['Regular Season'],
38
- ['Playoffs',
39
- 'Match 6th Place']]
40
- elsif [2010,2011].include?( season.start_year )
41
- [['Regular Season'],
42
- ['Playoffs']]
43
- else
44
- nil
45
- end
46
- },
47
- },
48
-
49
- 'pt.1' => { name: 'Portuguese Primeira Liga',
50
- basename: '1-primeiraliga',
51
- },
52
- 'pt.2' => { name: 'Portuguese Segunda Liga',
53
- basename: '2-segundaliga',
54
- },
55
-
56
- 'ch.1' => { name: 'Swiss Super League',
57
- basename: '1-superleague',
58
- },
59
- 'ch.2' => { name: 'Swiss Challenge League',
60
- basename: '2-challengeleague',
61
- },
62
- 'tr.1' => { name: 'Turkish Süper Lig',
63
- basename: '1-superlig',
64
- },
65
- 'tr.2' => { name: 'Turkish 1. Lig',
66
- basename: '2-lig1',
67
- },
68
-
69
-
70
- 'is.1' => { name: 'Iceland Urvalsdeild',
71
- basename: '1-urvalsdeild',
72
- },
73
- 'sco.1' => { name: 'Scottish Premiership',
74
- basename: '1-premiership',
75
- stages: [['Regular Season'],
76
- ['Playoffs - Championship',
77
- 'Playoffs - Relegation' ]]
78
- },
79
- 'ie.1' => { name: 'Irish Premier Division',
80
- basename: '1-premierdivision',
81
- },
82
-
83
- 'fi.1' => { name: 'Finland Veikkausliiga', ## note: make optional!!! override here (otherwise (re)use "regular" lookup "canonical" name from league!!!)
84
- basename: '1-veikkausliiga',
85
- stages: [['Regular Season'],
86
- ['Playoffs - Championship',
87
- 'Playoffs - Challenger',
88
- 'Europa League Finals' ]]
89
- },
90
- 'se.1' => { name: 'Sweden Allsvenskan',
91
- basename: '1-allsvenskan',
92
- },
93
- 'se.2' => { name: 'Sweden Superettan',
94
- basename: '2-superettan',
95
- },
96
- 'no.1' => { name: 'Norwegian Eliteserien',
97
- basename: '1-eliteserien',
98
- },
99
- 'dk.1' => { name: 'Denmark Superligaen',
100
- basename: '1-superligaen',
101
- stages: [['Regular Season'],
102
- ['Playoffs - Championship',
103
- 'Playoffs - Relegation',
104
- 'Europa League Finals']]
105
- },
106
-
107
- 'lu.1' => { name: 'Luxembourger First Division',
108
- basename: '1-nationaldivision',
109
- },
110
- 'be.1' => { name: 'Belgian First Division A',
111
- basename: '1-firstdivisiona',
112
- stages: [['Regular Season'],
113
- ['Playoffs - Championship',
114
- 'Playoffs - Europa League',
115
- 'Playoffs - Europa League - Finals']]
116
- },
117
- 'nl.1' => { name: 'Dutch Eredivisie',
118
- basename: '1-eredivisie',
119
- },
120
- 'cz.1' => { name: 'Czech First League',
121
- basename: '1-firstleague',
122
- stages: [['Regular Season'],
123
- ['Playoffs - Championship',
124
- 'Europa League Play-off',
125
- 'Playoffs - Relegation'
126
- ]]
127
- },
128
- 'sk.1' => { name: 'Slovakia First League',
129
- basename: '1-superliga',
130
- stages: [['Regular Season'],
131
- ['Playoffs - Championship',
132
- 'Playoffs - Relegation',
133
- 'Europa League Finals']]
134
- },
135
- 'hr.1' => { name: 'Croatia 1. HNL',
136
- basename: '1-hnl',
137
- },
138
- 'pl.1' => { name: 'Poland Ekstraklasa',
139
- basename: '1-ekstraklasa',
140
- stages: [['Regular Season'],
141
- ['Playoffs - Championship',
142
- 'Playoffs - Relegation']]
143
- },
144
-
145
- 'ro.1' => { name: 'Romanian Liga 1',
146
- basename: '1-liga1',
147
- stages: ->(season) {
148
- if season.start_year >= 2015 # new league system starting with 2015/16 season
149
- [['Regular Season'],
150
- ['Playoffs - Championship',
151
- 'Playoffs - Relegation']]
152
- else
153
- nil
154
- end
155
- },
156
- },
157
-
158
- 'ua.1' => { name: 'Ukraine Premier League',
159
- basename: '1-premierleague',
160
- stages: [['Regular Season'],
161
- ['Playoffs - Championship',
162
- 'Playoffs - Relegation',
163
- 'Europa League Finals']]
164
- },
165
-
166
-
167
- 'ru.1' => { name: 'Russian Premier League',
168
- basename: '1-premierliga',
169
- stages: ->(season) {
170
- if season.start_year == 2011 # 2011/12 - new (transition) league system during season switch from calendar year to academic
171
- [['Regular Season'],
172
- ['Playoffs - Championship',
173
- 'Playoffs - Relegation']]
174
- else
175
- nil
176
- end
177
- },
178
- },
179
- 'ru.2' => { name: 'Russian 1. Division',
180
- basename: '2-division1',
181
- },
182
- )
183
-
184
-
185
- end # module Writer
@@ -1,16 +0,0 @@
1
- module Writer
2
-
3
- LEAGUES.merge!(
4
-
5
- ########################
6
- # Italy
7
- 'it.1' => { name: 'Italian Serie A',
8
- basename: '1-seriea',
9
- },
10
- 'it.2' => { name: 'Italian Serie B',
11
- basename: '2-serieb',
12
- },
13
-
14
- )
15
-
16
- end # module Writer
@@ -1,23 +0,0 @@
1
- module Writer
2
-
3
- LEAGUES.merge!(
4
-
5
- ##############################
6
- # Mexico
7
- #
8
- # - Viertelfinale
9
- # - Halbfinale
10
- # - Finale
11
-
12
- 'mx.1' => { name: 'Liga MX',
13
- basename: '1-ligamx', ## note: gets "overwritten" by stages (see below)
14
- stages: [{basename: '1-apertura', names: ['Apertura']},
15
- {basename: '1-apertura_liguilla', names: ['Apertura - Liguilla']},
16
- {basename: '1-clausura', names: ['Clausura']},
17
- {basename: '1-clausura_liguilla', names: ['Clausura - Liguilla']},
18
- ],
19
- },
20
- )
21
-
22
-
23
- end # module Writer
@@ -1,17 +0,0 @@
1
- module Writer
2
-
3
-
4
- LEAGUES.merge!(
5
- 'ar.1' => { name: 'Argentina Primera Division',
6
- basename: '1-primeradivision',
7
- },
8
-
9
- ############################
10
- # Brazil
11
- 'br.1' => { name: 'Brasileiro Série A', ## league name
12
- basename: '1-seriea',
13
- },
14
- )
15
-
16
-
17
- end # module Writer
@@ -1,14 +0,0 @@
1
-
2
- module Writer
3
-
4
- LEAGUES.merge!(
5
- 'cn.1' => { name: 'Chinese Super League',
6
- basename: '1-superleague',
7
- },
8
- 'jp.1' => { name: 'Japan J1 League',
9
- basename: '1-j1league',
10
- },
11
- )
12
-
13
- end # module Writer
14
-