leagues 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +1 -1
- data/Manifest.txt +1 -0
- data/bin/fbok +94 -0
- data/config/codes_alt.csv +1 -1
- data/config/leagues_more.csv +6 -0
- data/config/timezones_middle_east.csv +1 -2
- data/lib/leagues/league_codes.rb +3 -0
- data/lib/leagues/leagueset.rb +38 -22
- data/lib/leagues/version.rb +2 -2
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7de33794f4721fff69b19475defc328a33a8f245d259d26326a2238681cd8255
|
4
|
+
data.tar.gz: 4bd10a37c73aef136805a5377c9765ba30a6842257ee8193840cbb2c1651e25f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1dec15278cd269eb43327ef227bfb277f5865d48469e20833e6aba0e53167bb792b2761865ecaf0b3bc7889444f496cdbe4348216d6c8fab7572f58bd2dc6e22
|
7
|
+
data.tar.gz: 398b9bf89c963c0e60087be743f709c7c4f42c1417cf66b4b22980e6d42f8fc918328efcec2e782d42861324f2763aaf7375681a7c5edd342a1bfa457704ae61
|
data/CHANGELOG.md
CHANGED
data/Manifest.txt
CHANGED
data/bin/fbok
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
## tip: to test run:
|
4
|
+
## ruby -I ./lib bin/fbok
|
5
|
+
|
6
|
+
require 'leagues'
|
7
|
+
|
8
|
+
|
9
|
+
def read_raw_leagueset( path )
|
10
|
+
## no - normalize and autofill etc.
|
11
|
+
datasets = []
|
12
|
+
recs = read_csv( path )
|
13
|
+
recs.each do |rec|
|
14
|
+
key = rec['league']
|
15
|
+
seasons = SportDb::Leagueset._parse_seasons( rec['seasons'] )
|
16
|
+
|
17
|
+
datasets << [key, seasons]
|
18
|
+
end
|
19
|
+
datasets
|
20
|
+
end
|
21
|
+
|
22
|
+
args = ARGV
|
23
|
+
|
24
|
+
args = ['/sports/tmp/classic.csv' ] if args.size == 0
|
25
|
+
|
26
|
+
|
27
|
+
|
28
|
+
def check_leagueset( path )
|
29
|
+
datasets = read_raw_leagueset( path )
|
30
|
+
pp datasets
|
31
|
+
|
32
|
+
puts "==> #{path} - #{datasets.size} record(s)"
|
33
|
+
|
34
|
+
## pass 1 - league code quick check
|
35
|
+
errors = []
|
36
|
+
datasets.each do |league_query, _|
|
37
|
+
if LeagueCodes.valid?( league_query )
|
38
|
+
puts "OK #{league_query}"
|
39
|
+
else
|
40
|
+
puts "!! #{league_query}"
|
41
|
+
errors << "league code #{league_query} NOT valid"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
if errors.size > 0
|
46
|
+
puts "#{errors.size} error(s):"
|
47
|
+
pp errrors
|
48
|
+
exit 1
|
49
|
+
end
|
50
|
+
|
51
|
+
## pass 2 - league code check by season
|
52
|
+
datasets.each_with_index do |(league_query, seasons),i|
|
53
|
+
puts "-- [#{i+1}/#{datasets.size}] #{league_query}, #{seasons.size} seasons(s)"
|
54
|
+
|
55
|
+
last_league_info = nil
|
56
|
+
seasons.each_with_index do |season,j|
|
57
|
+
league_info = LeagueCodes.find_by( code: league_query, season: season )
|
58
|
+
|
59
|
+
if league_info.nil?
|
60
|
+
puts "!! #{season}"
|
61
|
+
errors << "no league info for #{league_query} #{season} found"
|
62
|
+
next
|
63
|
+
end
|
64
|
+
|
65
|
+
## only print league info (if changed from last season)
|
66
|
+
if last_league_info.nil? ||
|
67
|
+
last_league_info['code'] != league_info['code'] ||
|
68
|
+
last_league_info['name'] != league_info['name'] ||
|
69
|
+
last_league_info['tz'] != league_info['tz']
|
70
|
+
print "\n" if j != 0 ## if new league info MUST start new line
|
71
|
+
pp league_info
|
72
|
+
end
|
73
|
+
print " #{season}"
|
74
|
+
|
75
|
+
last_league_info = league_info
|
76
|
+
end
|
77
|
+
print "\n"
|
78
|
+
end
|
79
|
+
|
80
|
+
if errors.size > 0
|
81
|
+
puts "#{errors.size} error(s):"
|
82
|
+
pp errrors
|
83
|
+
else
|
84
|
+
puts
|
85
|
+
puts "OK no error(s) found"
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
path = args[0]
|
92
|
+
check_leagueset( path )
|
93
|
+
|
94
|
+
puts 'bye'
|
data/config/codes_alt.csv
CHANGED
data/config/leagues_more.csv
CHANGED
@@ -38,3 +38,9 @@ eng.efl.cup,English EFL Cup,eflcup,,
|
|
38
38
|
### fix - upstream uses world.club !!!
|
39
39
|
world.clubs,Club World Cup,clubworldcup,2000,
|
40
40
|
|
41
|
+
|
42
|
+
### quick hack
|
43
|
+
### alternate codes (duplicates); use/settle on one canonical league code!!!
|
44
|
+
br.cup,Copa do Brasil,cup,, ## br.copa
|
45
|
+
|
46
|
+
|
data/lib/leagues/league_codes.rb
CHANGED
@@ -139,6 +139,9 @@ def find_by( code:, season: )
|
|
139
139
|
|
140
140
|
if rec ## (quick hack for now) auto-add timezone
|
141
141
|
## use canoncial (league) code
|
142
|
+
## note - if timezone changes MUST auto-create a NEW record
|
143
|
+
## thus, for now always create a new copy (via dup)!!!
|
144
|
+
rec = rec.dup
|
142
145
|
rec['tz'] = find_zone!( league: rec['code'], season: season )
|
143
146
|
end
|
144
147
|
|
data/lib/leagues/leagueset.rb
CHANGED
@@ -70,35 +70,51 @@ def self.parse_args( args, autofill: nil )
|
|
70
70
|
end
|
71
71
|
|
72
72
|
|
73
|
+
# todo/fix - (maybe) move "upstream" later
|
74
|
+
# e.g. Season.parse_list or parse_lst
|
75
|
+
# or parse_line or ???
|
76
|
+
# or parse_multi(ple) - why? why not?
|
77
|
+
def self._parse_seasons( str )
|
78
|
+
## helper to parse seasons string/column
|
79
|
+
## note: ALWAYS returns an array of seaons (even if only one)
|
80
|
+
result = []
|
81
|
+
seasons = str.split( /[ ]+/ )
|
82
|
+
|
83
|
+
seasons.each do |season_str|
|
84
|
+
## note - add support for ranges e.g. 2001/02..2010/11
|
85
|
+
if season_str.index( '..' )
|
86
|
+
fst,snd = season_str.split( '..' )
|
87
|
+
# pp [fst,snd]
|
88
|
+
fst = Season.parse( fst )
|
89
|
+
snd = Season.parse( snd )
|
90
|
+
if fst < snd && fst.year? == snd.year?
|
91
|
+
result += (fst..snd).to_a
|
92
|
+
else
|
93
|
+
raise ArgumentError, "parse error - invalid season range >#{season_str}<, 1) two seasons required, 2) first < second, 3) same (year/academic) type"
|
94
|
+
end
|
95
|
+
else
|
96
|
+
season = Season.parse( season_str ) ## check season
|
97
|
+
result << season
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
result
|
102
|
+
end
|
103
|
+
|
104
|
+
|
105
|
+
|
73
106
|
def self.parse( txt, autofill: nil )
|
74
107
|
### split args in datasets with leagues and seasons
|
75
108
|
datasets = []
|
76
109
|
recs = parse_csv( txt )
|
77
110
|
recs.each do |rec|
|
78
111
|
key = rec['league'].downcase
|
79
|
-
|
80
|
-
|
112
|
+
|
81
113
|
seasons_str = rec['seasons']
|
82
|
-
seasons = seasons_str
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
if season_str.index( '..' )
|
87
|
-
fst,snd = season_str.split( '..' )
|
88
|
-
# pp [fst,snd]
|
89
|
-
fst = Season.parse( fst )
|
90
|
-
snd = Season.parse( snd )
|
91
|
-
if fst < snd && fst.year? == snd.year?
|
92
|
-
datasets[-1][1] += (fst..snd).to_a
|
93
|
-
else
|
94
|
-
raise ArgumentError, "parse error - invalid season range >#{str}<, 1) two seasons required, 2) first < second, 3) same (year/academic) type"
|
95
|
-
end
|
96
|
-
else
|
97
|
-
season = Season.parse( season_str ) ## check season
|
98
|
-
datasets[-1][1] << season
|
99
|
-
end
|
100
|
-
end
|
101
|
-
end
|
114
|
+
seasons = _parse_seasons( seasons_str )
|
115
|
+
|
116
|
+
datasets << [key, seasons]
|
117
|
+
end
|
102
118
|
|
103
119
|
new(datasets, autofill: autofill)
|
104
120
|
end
|
data/lib/leagues/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: leagues
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gerald Bauer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-04-
|
11
|
+
date: 2025-04-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: tzinfo
|
@@ -88,7 +88,8 @@ dependencies:
|
|
88
88
|
version: '4.2'
|
89
89
|
description: leagues - football leagues & timezone helpers
|
90
90
|
email: gerald.bauer@gmail.com
|
91
|
-
executables:
|
91
|
+
executables:
|
92
|
+
- fbok
|
92
93
|
extensions: []
|
93
94
|
extra_rdoc_files:
|
94
95
|
- CHANGELOG.md
|
@@ -99,6 +100,7 @@ files:
|
|
99
100
|
- Manifest.txt
|
100
101
|
- README.md
|
101
102
|
- Rakefile
|
103
|
+
- bin/fbok
|
102
104
|
- config/codes_alt.csv
|
103
105
|
- config/leagues.csv
|
104
106
|
- config/leagues_more.csv
|