sportdb-catalogs 1.2.3 → 1.2.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8b593473df2d17fc60175c907bf78b0794f3bc26a6234cc247d58e788f8850ec
4
- data.tar.gz: 0a9f535f23da1d3da21173d1c7d7588188e287b299c448f47bb8fa0cf9e33aa7
3
+ metadata.gz: ed0f3720e4ff002df8ac2d14305f3ed147656d45ce4dc2c7770a3e8057f95439
4
+ data.tar.gz: 8c1a5d9f32172cffbe7b4376d00af7c3f0d463ee8bd3e979ec6cc2d7949168d9
5
5
  SHA512:
6
- metadata.gz: 927b572cef955abbc720ce43b4fab2cff7ac3f1eaae1514069302421d4172dcb96d3b02e96d36141a900f19e12efe1a820e44881e9a43ad3eeae983c8166f060
7
- data.tar.gz: 7058a7524a1381e28b46586db1fd0b93d35ebbd807d2b75a20b2ef6071bdf738ad3db0bb3f142c83632c0b4203c42da314e6e7b6bfbcfcbf9741c7ab3f89083d
6
+ metadata.gz: 50c14e72e5f993b4d66769da4190722b125db6ba1dbd914526c7bdb01f546d13f4a498fd8fd70d251e6898aa08692e000c8e5be7dd69e1d2fc42066d8ce91e1a
7
+ data.tar.gz: d7a5f124e35a59b7daa72b0b99947ee4b6f6d0a5e15138638ce18cc883e7f3507de07a54df2d11437ceafd6acaa81749dfdc481d112738da82560262b4394121
data/CHANGELOG.md CHANGED
@@ -1,4 +1,4 @@
1
- ### 1.2.3
1
+ ### 1.2.5
2
2
  ### 0.0.1 / 2019-06-29
3
3
 
4
4
  * Everything is new. First release.
data/Manifest.txt CHANGED
@@ -10,6 +10,7 @@ lib/sportdb/catalogs/country.rb
10
10
  lib/sportdb/catalogs/event_info.rb
11
11
  lib/sportdb/catalogs/ground.rb
12
12
  lib/sportdb/catalogs/league.rb
13
+ lib/sportdb/catalogs/league_period.rb
13
14
  lib/sportdb/catalogs/national_team.rb
14
15
  lib/sportdb/catalogs/player.rb
15
16
  lib/sportdb/catalogs/version.rb
data/README.md CHANGED
@@ -11,66 +11,8 @@
11
11
 
12
12
  ## Usage
13
13
 
14
- Let's use the [/clubs datasets](https://github.com/openfootball/clubs)
15
- (3000+ football clubs from around the world)
16
- to match name "variants" e.g. `Arsenal` to canonical global unique
17
- names e.g. `Arsenal FC, London, England`:
18
14
 
19
- ``` ruby
20
- require 'sportdb/catalogs'
21
-
22
- Club = CatalogDb::Metal::Club
23
-
24
- m = Club.match_by( name: 'Arsenal' )
25
- m.size # 3 club matches found
26
- #=> 3
27
- m[0].name; m[0].city; m[0].country
28
- #=> "Arsenal FC", "London", "England"
29
- m[1].name; m[1].city; m[1].country
30
- #=> "Arsenal Tula", "Tula", "Russia"
31
- m[2].name; m[2].city; m[2].country
32
- #=> "Arsenal de Sarandí", "Sarandí", "Argentina"
33
-
34
-
35
- m = Club.match_by( name: 'Arsenal', country: 'eng' )
36
- # -or- try alternative names (and auto-generated spelling variants)
37
- m = Club.match_by( name: 'Arsenal FC', country: 'eng' )
38
- m = Club.match_by( name: 'Arsenal F.C.', country: 'eng' )
39
- m = Club.match_by( name: '...A.r.s.e.n.a.l... F.C...', country: 'eng' )
40
- m.size # 1 club match found
41
- #=> 1
42
- m[0].name; m[0].city; m[0].country
43
- #=> "Arsenal FC", "London", "England"
44
-
45
- m = Club.match_by( name: 'Arsenal', country: 'ar' )
46
- # -or- try alternative names (and auto-generated spelling variants)
47
- m = Club.match_by( name: 'Arsenal Sarandí', country: 'ar' )
48
- m = Club.match_by( name: 'Arsenal Sarandi', country: 'ar' )
49
- m.size # 1 club match found
50
- #=> 1
51
- m[0].name; m[0].city; m[0].country
52
- #=> "Arsenal de Sarandí", "Sarandí", "Argentina"
53
-
54
-
55
- # try some more
56
- m = Club.match_by( name: 'AZ' )
57
- m[0].name; m[0].city; m[0].country
58
- #=> "AZ Alkmaar", "Alkmaar", "Netherlands"
59
-
60
- m = Club.match_by( name: 'Bayern' )
61
- # -or- try alternative names (and auto-generated spelling variants)
62
- m = Club.match_by( name: 'Bayern München' )
63
- m = Club.match_by( name: 'Bayern Munchen' )
64
- m = Club.match_by( name: 'Bayern Muenchen' )
65
- m[0].name; m[0].city; m[0].country
66
- #=> "Bayern München", "München", "Germany"
67
-
68
- # and so on
69
- # ...
70
- ```
71
-
72
-
73
- That's it.
15
+ to be done
74
16
 
75
17
 
76
18
 
@@ -50,7 +50,7 @@ SQL
50
50
  ### todo/fix: allow special normalize formula for
51
51
  ## code - why? why not?
52
52
  ## e.g. allow ö1 or ö or such - why? why not?
53
- code = normalize( unaccent(code) )
53
+ code = normalize( code )
54
54
 
55
55
  rows = nil
56
56
  if country.nil?
@@ -120,7 +120,7 @@ SQL
120
120
  def self.match_by_name_or_code( q,
121
121
  country: nil )
122
122
  name = normalize( unaccent(q) )
123
- code = normalize( unaccent(q) )
123
+ code = normalize( q )
124
124
 
125
125
  rows = nil
126
126
  if country.nil?
@@ -0,0 +1,151 @@
1
+ module CatalogDb
2
+ module Metal
3
+
4
+ class LeaguePeriod < Record
5
+ self.tablename = 'league_periods'
6
+
7
+ self.columns = ['id',
8
+ 'key', ## league foreign refkey!!!
9
+ 'tier_key', ## change to code - why? why not?
10
+ 'name',
11
+ 'qname',
12
+ 'slug',
13
+ 'start_season',
14
+ 'end_season']
15
+
16
+
17
+ def self.cache() @cache ||= Hash.new; end
18
+
19
+
20
+ def self._record( id ) ## use _record! as name - why? why not?
21
+ if (rec = cache[ id ])
22
+ rec ## return cached
23
+ else ## query and cache and return
24
+ rows = execute( <<-SQL )
25
+ SELECT #{self.columns.join(', ')}
26
+ FROM league_periods
27
+ WHERE leagues_periods.id = #{id}
28
+ SQL
29
+
30
+ ## todo/fix: also assert for rows == 1 AND NOT MULTIPLE records - why? why not?
31
+ if rows.empty?
32
+ raise ArgumentError, "league period record with id #{id} not found"
33
+ else
34
+ _build_league_period( rows[0] )
35
+ end
36
+ end
37
+ end
38
+
39
+
40
+ def self._build_league_period( row )
41
+ ## get league record by ky
42
+ ## league = League._record( row[1] )
43
+
44
+ ## note: cache structs by key (do NOT rebuild duplicates; reuse)
45
+ cache[ row[0] ] ||= Sports::LeaguePeriod.new(
46
+ key: row[2], ## tier key
47
+ name: row[3],
48
+ qname: row[4],
49
+ slug: row[5],
50
+ start_season: row[6] ? Season.parse( row[6]) : nil,
51
+ end_season: row[7] ? Season.parse( row[7]) : nil
52
+ )
53
+ end
54
+
55
+
56
+ def self._calc_yyyymm( season )
57
+ start_yyyymm = if season.calendar?
58
+ "#{season.start_year}01".to_i
59
+ else
60
+ "#{season.start_year}07".to_i
61
+ end
62
+
63
+ end_yyyymm = if season.calendar?
64
+ "#{season.end_year}12".to_i
65
+ else
66
+ "#{season.end_year}06".to_i
67
+ end
68
+
69
+ [start_yyyymm, end_yyyymm]
70
+ end
71
+
72
+
73
+ def self.match_by_code( code, season: )
74
+ code = normalize( code )
75
+
76
+ season = Season( season )
77
+ start_yyyymm, end_yyyymm = _calc_yyyymm( season )
78
+
79
+ rows = nil
80
+ ## note: returns empty array if no match and NOT nil
81
+ rows = execute( <<-SQL )
82
+ SELECT #{self.columns.join(', ')}
83
+ FROM league_periods
84
+ INNER JOIN league_period_codes ON league_periods.id = league_period_codes.league_period_id
85
+ WHERE league_period_codes.code = '#{code}' AND
86
+ league_period_codes.start_yyyymm <= #{start_yyyymm} AND
87
+ league_period_codes.end_yyyymm >= #{end_yyyymm}
88
+ SQL
89
+
90
+ ## wrap results array into struct records
91
+ rows.map {|row| _build_league_period( row )}
92
+ end
93
+
94
+
95
+ def self.match_by_name( name, season: )
96
+ ## note: match must for now always include name
97
+ name = normalize( unaccent(name) )
98
+
99
+ season = Season( season )
100
+ start_yyyymm, end_yyyymm = _calc_yyyymm( season )
101
+
102
+ rows = nil
103
+ ## note: returns empty array if no match and NOT nil
104
+ rows = execute( <<-SQL )
105
+ SELECT #{self.columns.join(', ')}
106
+ FROM league_periods
107
+ INNER JOIN league_period_names ON league_periods.id = league_period_names.league_period_id
108
+ WHERE league_period_names.name = '#{name}' AND
109
+ league_period_names.start_yyyymm <= #{start_yyyymm} AND
110
+ league_period_names.end_yyyymm >= #{end_yyyymm}
111
+ SQL
112
+
113
+ ## wrap results array into struct records
114
+ rows.map {|row| _build_league_period( row )}
115
+ end
116
+
117
+
118
+ def self.match_by_name_or_code( q, season: )
119
+ name = normalize( unaccent(q) )
120
+ code = normalize( q )
121
+
122
+ season = Season( season )
123
+ start_yyyymm, end_yyyymm = _calc_yyyymm( season )
124
+
125
+ rows = nil
126
+ ## note: returns empty array if no match and NOT nil
127
+ rows = execute( <<-SQL )
128
+ SELECT #{self.columns.join(', ')}
129
+ FROM league_periods
130
+ INNER JOIN league_period_names ON league_periods.id = league_period_names.league_period_id
131
+ WHERE league_period_names.name = '#{name}' AND
132
+ league_period_names.start_yyyymm <= #{start_yyyymm} AND
133
+ league_period_names.end_yyyymm >= #{end_yyyymm}
134
+ UNION
135
+ SELECT #{self.columns.join(', ')}
136
+ FROM league_periods
137
+ INNER JOIN league_period_codes ON league_periods.id = league_period_codes.league_period_id
138
+ WHERE league_period_codes.code = '#{code}' AND
139
+ league_period_codes.start_yyyymm <= #{start_yyyymm} AND
140
+ league_period_codes.end_yyyymm >= #{end_yyyymm}
141
+ SQL
142
+
143
+ ## wrap results array into struct records
144
+ rows.map {|row| _build_league_period( row )}
145
+ end
146
+
147
+ end # class LeaguePeriod
148
+ end # module Metal
149
+ end # module CatalogDb
150
+
151
+
@@ -5,7 +5,7 @@ module Catalogs
5
5
 
6
6
  MAJOR = 1 ## todo: namespace inside version or something - why? why not??
7
7
  MINOR = 2
8
- PATCH = 3
8
+ PATCH = 5
9
9
  VERSION = [MAJOR,MINOR,PATCH].join('.')
10
10
 
11
11
  def self.version
@@ -15,6 +15,7 @@ require_relative 'catalogs/city'
15
15
  require_relative 'catalogs/club'
16
16
  require_relative 'catalogs/national_team'
17
17
  require_relative 'catalogs/league'
18
+ require_relative 'catalogs/league_period'
18
19
  require_relative 'catalogs/event_info'
19
20
  require_relative 'catalogs/ground'
20
21
 
@@ -44,7 +45,7 @@ def self.tables
44
45
  ## puts
45
46
  puts " #{Country.count} countries / #{City.count} cities"
46
47
  puts " #{NationalTeam.count} national teams"
47
- puts " #{League.count} leagues"
48
+ puts " #{League.count} leagues / #{LeaguePeriod.count} periods"
48
49
  puts " #{Club.count} clubs"
49
50
  puts " #{Ground.count} grounds"
50
51
  ## add more
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sportdb-catalogs
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.3
4
+ version: 1.2.5
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-08-24 00:00:00.000000000 Z
11
+ date: 2024-10-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sportdb-structs
@@ -108,6 +108,7 @@ files:
108
108
  - lib/sportdb/catalogs/event_info.rb
109
109
  - lib/sportdb/catalogs/ground.rb
110
110
  - lib/sportdb/catalogs/league.rb
111
+ - lib/sportdb/catalogs/league_period.rb
111
112
  - lib/sportdb/catalogs/national_team.rb
112
113
  - lib/sportdb/catalogs/player.rb
113
114
  - lib/sportdb/catalogs/version.rb