sportdb-writers 0.1.0 → 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.
@@ -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
@@ -46,7 +46,14 @@ def self.build( matches, rounds: true )
46
46
  buf << "#{round} #{match.round}"
47
47
  else ## use as is from match
48
48
  ## note: for now assume english names
49
- buf << round_translations[match.round] || match.round
49
+ if match.round.nil?
50
+ ## warn
51
+ puts "!! ERROR - match with round nil?"
52
+ pp match
53
+ exit 1
54
+ end
55
+
56
+ buf << (round_translations[match.round] || match.round)
50
57
  end
51
58
  buf << "\n"
52
59
  end
@@ -1,11 +1,10 @@
1
1
 
2
2
  module SportDb
3
- module Module
3
+ module Module
4
4
  module Writers
5
-
6
5
  MAJOR = 0 ## todo: namespace inside version or something - why? why not??
7
6
  MINOR = 1
8
- PATCH = 0
7
+ PATCH = 2
9
8
  VERSION = [MAJOR,MINOR,PATCH].join('.')
10
9
 
11
10
  def self.version
@@ -21,5 +20,5 @@ module SportDb
21
20
  end
22
21
 
23
22
  end # module Writers
24
- end # module Module
25
- end # module SportDb
23
+ end # module Module
24
+ end # module SportDb
@@ -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
@@ -1,14 +1,6 @@
1
- ## just use sportdb/catalogs ?! - why? why not?
2
- # require 'sportdb/importers' # -- requires db support
3
- # require 'sportdb/readers' # -- requires db support
4
- #
5
- # note - for now only requires sportdb/formats !!!
6
- # normalize moved out as a proc!!!
7
- require 'sportdb/formats'
8
1
 
2
+ require 'sportdb/quick'
9
3
 
10
- ## todo/fix - make sure upstream cocos is included/required
11
- require 'cocos'
12
4
 
13
5
 
14
6
  module Writer
@@ -37,29 +29,67 @@ require_relative 'writers/goals'
37
29
  require_relative 'writers/write'
38
30
 
39
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
+
40
48
 
41
49
  ########################
42
50
  # push & pull github scripts
43
51
  require 'gitti' ## note - requires git machinery
44
52
 
53
+ require_relative 'writers/github_config'
45
54
  require_relative 'writers/github' ## github helpers/update machinery
46
55
 
47
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 )
48
62
 
49
- ## setup empty leagues (info) hash
50
- module Writer
51
- 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)
52
89
  end
90
+ end # class GitHubSync
91
+ end # module SportDb
53
92
 
54
- require_relative 'leagues/leagues_at'
55
- require_relative 'leagues/leagues_de'
56
- require_relative 'leagues/leagues_eng'
57
- require_relative 'leagues/leagues_es'
58
- require_relative 'leagues/leagues_europe'
59
- require_relative 'leagues/leagues_it'
60
- require_relative 'leagues/leagues_mx'
61
- require_relative 'leagues/leagues_south_america'
62
- require_relative 'leagues/leagues_world'
63
93
 
64
94
 
65
95
 
metadata CHANGED
@@ -1,17 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sportdb-writers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
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-07-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
- name: sportdb-formats
14
+ name: sportdb-quick
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
@@ -38,20 +38,6 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
- - !ruby/object:Gem::Dependency
42
- name: cocos
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :runtime
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: '0'
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: rdoc
57
43
  requirement: !ruby/object:Gem::Requirement
@@ -89,7 +75,9 @@ dependencies:
89
75
  description: sportdb-writers - sport.db writers for match schedules and results, and
90
76
  more
91
77
  email: gerald.bauer@gmail.com
92
- executables: []
78
+ executables:
79
+ - fbgen
80
+ - fbtxt
93
81
  extensions: []
94
82
  extra_rdoc_files:
95
83
  - CHANGELOG.md
@@ -100,18 +88,17 @@ files:
100
88
  - Manifest.txt
101
89
  - README.md
102
90
  - Rakefile
103
- - lib/sportdb/leagues/leagues_at.rb
104
- - lib/sportdb/leagues/leagues_de.rb
105
- - lib/sportdb/leagues/leagues_eng.rb
106
- - lib/sportdb/leagues/leagues_es.rb
107
- - lib/sportdb/leagues/leagues_europe.rb
108
- - lib/sportdb/leagues/leagues_it.rb
109
- - lib/sportdb/leagues/leagues_mx.rb
110
- - lib/sportdb/leagues/leagues_south_america.rb
111
- - lib/sportdb/leagues/leagues_world.rb
91
+ - bin/fbgen
92
+ - bin/fbtxt
93
+ - config/leagues_america.csv
94
+ - config/leagues_europe.csv
95
+ - config/leagues_world.csv
96
+ - config/openfootball.csv
112
97
  - lib/sportdb/writers.rb
113
98
  - lib/sportdb/writers/github.rb
99
+ - lib/sportdb/writers/github_config.rb
114
100
  - lib/sportdb/writers/goals.rb
101
+ - lib/sportdb/writers/league_config.rb
115
102
  - lib/sportdb/writers/txt_writer.rb
116
103
  - lib/sportdb/writers/version.rb
117
104
  - lib/sportdb/writers/write.rb
@@ -129,7 +116,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
129
116
  requirements:
130
117
  - - ">="
131
118
  - !ruby/object:Gem::Version
132
- version: 2.2.2
119
+ version: 3.1.0
133
120
  required_rubygems_version: !ruby/object:Gem::Requirement
134
121
  requirements:
135
122
  - - ">="
@@ -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
-