sportdb-catalogs 1.0.0 → 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,20 +1,182 @@
1
- # encoding: utf-8
2
-
3
1
  ### our own sportdb libs / gems
2
+ ### try min. dependencies - change to structs only (NOT formats) - why? why not?
3
+ ## require 'sportdb/structs'
4
4
  require 'sportdb/formats'
5
5
 
6
- ### "built-in" default dataset libs / gems
7
- require 'fifa' ## get a list of all fifa countries with (three letter) codes
8
- require 'footballdb/leagues'
9
- require 'footballdb/clubs'
6
+ require 'sqlite3'
7
+
10
8
 
11
9
 
12
10
  ###
13
11
  # our own code
14
- require 'sportdb/catalogs/version' # let version always go first
15
- require 'sportdb/catalogs/wiki_index'
16
- require 'sportdb/catalogs/catalog'
17
- require 'sportdb/catalogs/config'
12
+ require_relative 'catalogs/version' # let version always go first
13
+
14
+ require_relative 'catalogs/base' ## base record
15
+ require_relative 'catalogs/country'
16
+ require_relative 'catalogs/city'
17
+
18
+ require_relative 'catalogs/club'
19
+ require_relative 'catalogs/national_team'
20
+ require_relative 'catalogs/league'
21
+ require_relative 'catalogs/event_info'
22
+ require_relative 'catalogs/ground'
23
+
24
+ ## more
25
+ require_relative 'catalogs/player'
26
+
27
+
28
+
29
+ module SportDb
30
+ module Import
31
+
32
+ class Configuration
33
+ ## note: add more configs (open class), see sportdb-structs for original config!!!
34
+
35
+ ###
36
+ # find a better name for setting - why? why not?
37
+ # how about catalogdb or ???
38
+ attr_reader :catalog_path
39
+ def catalog_path=(path)
40
+ @catalog_path = path
41
+ ########
42
+ # reset database here to new path
43
+ CatalogDb::Metal::Record.database = path
44
+
45
+ ## plus automagically set world search too (to use CatalogDb)
46
+ self.world = WorldSearch.new(
47
+ countries: CatalogDb::Metal::Country,
48
+ cities: CatalogDb::Metal::City,
49
+ )
50
+
51
+ @catalog_path
52
+ end
53
+
54
+ def catalog
55
+ @catalog ||= SportSearch.new(
56
+ leagues: CatalogDb::Metal::League,
57
+ national_teams: CatalogDb::Metal::NationalTeam,
58
+ clubs: CatalogDb::Metal::Club,
59
+ grounds: CatalogDb::Metal::Ground,
60
+ events: CatalogDb::Metal::EventInfo,
61
+ players: CatalogDb::Metal::Player, # note - via players.db !!!
62
+ )
63
+ end
64
+
65
+ ###
66
+ # find a better name for setting - why? why not?
67
+ # how about playersdb or ???
68
+ attr_reader :players_path
69
+ def players_path=(path)
70
+ @players_path = path
71
+ ########
72
+ # reset database here to new path
73
+ CatalogDb::Metal::PlayerRecord.database = path
74
+
75
+ @players_path
76
+ end
77
+ end # class Configuration
78
+
79
+
80
+ ## e.g. use config.catalog -- keep Import.catalog as a shortcut (for "read-only" access)
81
+ def self.catalog() config.catalog; end
82
+ end # module Import
83
+ end # module SportDb
84
+
85
+
86
+
87
+
88
+
89
+ ###
90
+ # add status
91
+ module CatalogDb
92
+ module Metal
93
+
94
+ def self.tables
95
+
96
+ puts "==> table stats"
97
+ catalog_path = SportDb::Import.config.catalog_path
98
+ if catalog_path
99
+ puts " #{File.basename(catalog_path)} in (#{File.dirname(catalog_path)})"
100
+ puts " #{Country.count} countries / #{City.count} cities"
101
+ puts " #{NationalTeam.count} national teams"
102
+ puts " #{League.count} leagues"
103
+ puts " #{Club.count} clubs"
104
+ puts " #{Ground.count} grounds"
105
+ ## add more
106
+
107
+ else
108
+ puts " - no catalog.db set - "
109
+ end
110
+
111
+ ## todo/fix:
112
+ ## check if players_path configured???
113
+ players_path = SportDb::Import.config.players_path
114
+ if players_path
115
+ puts " #{File.basename(players_path)} in (#{File.dirname(players_path)})"
116
+ puts " #{Player.count} players"
117
+ else
118
+ puts " - no players.db set -"
119
+ end
120
+ end
121
+
122
+ end # module Metal
123
+ end # module CatalogDb
124
+
125
+
126
+
127
+ ###
128
+ # global helpers
129
+ # find a better name/place in module(s) or such
130
+ ##
131
+ ## what name to use?
132
+ ## find_countries_for_league_clubs or such
133
+ ## find_countries_for_league - why? why not?
134
+ ## note - returns array of countries OR single country
135
+
136
+ def find_countries_for_league( league )
137
+ ## todo/fix: assert league is a League with country record/struct !!!!!
138
+
139
+ countries = []
140
+ countries << league.country ### assume league.country is already db record/struct - why? why not?
141
+ ## check for 2nd countries for known leagues
142
+ ## (re)try with second country - quick hacks for known leagues
143
+ ## e.g. Swanse, cardiff in premier league
144
+ ## san mariono in serie a (italy)
145
+ ## monaco in ligue 1 (france)
146
+ ## etc.
147
+ ## add andorra to spanish la liga (e.g. andorra fc???)
148
+
149
+ case league.country.key
150
+ when 'eng' then countries << CatalogDb::Metal::Country._record('wal')
151
+ when 'sco' then countries << CatalogDb::Metal::Country._record('eng')
152
+ when 'ie' then countries << CatalogDb::Metal::Country._record('nir')
153
+ when 'fr' then countries << CatalogDb::Metal::Country._record('mc')
154
+ when 'es' then countries << CatalogDb::Metal::Country._record('ad')
155
+ when 'it' then countries << CatalogDb::Metal::Country._record('sm')
156
+ when 'ch' then countries << CatalogDb::Metal::Country._record('li')
157
+ when 'us' then countries << CatalogDb::Metal::Country._record('ca')
158
+ when 'au' then countries << CatalogDb::Metal::Country._record('nz')
159
+ end
160
+
161
+ ## use single ("unwrapped") item for one country
162
+ ## otherwise use array
163
+ country = countries.size == 1 ? countries[0] : countries
164
+ country
165
+ end
166
+
167
+
168
+
169
+
170
+
171
+
172
+ require 'footballdb/data' ## pull in catalog.db (built-in/default data/db)
173
+
174
+ ###
175
+ ## add default/built-in catalog here - why? why not?
176
+ ## todo/fix - set catalog_path on demand
177
+ ## note: for now required for world search setup etc.
178
+ SportDb::Import.config.catalog_path = "#{FootballDb::Data.data_dir}/catalog.db"
179
+
18
180
 
19
181
 
20
182
  puts SportDb::Module::Catalogs.banner # say hello
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.0.0
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gerald Bauer
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-08-01 00:00:00.000000000 Z
11
+ date: 2024-08-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sportdb-formats
@@ -16,117 +16,106 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 1.1.3
19
+ version: 2.0.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 1.1.3
26
+ version: 2.0.0
27
27
  - !ruby/object:Gem::Dependency
28
- name: fifa
28
+ name: sqlite3
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 2020.5.18
33
+ version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: 2020.5.18
40
+ version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: footballdb-leagues
42
+ name: footballdb-data
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: 2020.7.7
47
+ version: '0'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: 2020.7.7
55
- - !ruby/object:Gem::Dependency
56
- name: footballdb-clubs
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- version: 2020.7.7
62
- type: :runtime
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: 2020.7.7
54
+ version: '0'
69
55
  - !ruby/object:Gem::Dependency
70
56
  name: rdoc
71
57
  requirement: !ruby/object:Gem::Requirement
72
58
  requirements:
73
- - - "~>"
59
+ - - ">="
74
60
  - !ruby/object:Gem::Version
75
61
  version: '4.0'
62
+ - - "<"
63
+ - !ruby/object:Gem::Version
64
+ version: '7'
76
65
  type: :development
77
66
  prerelease: false
78
67
  version_requirements: !ruby/object:Gem::Requirement
79
68
  requirements:
80
- - - "~>"
69
+ - - ">="
81
70
  - !ruby/object:Gem::Version
82
71
  version: '4.0'
72
+ - - "<"
73
+ - !ruby/object:Gem::Version
74
+ version: '7'
83
75
  - !ruby/object:Gem::Dependency
84
76
  name: hoe
85
77
  requirement: !ruby/object:Gem::Requirement
86
78
  requirements:
87
79
  - - "~>"
88
80
  - !ruby/object:Gem::Version
89
- version: '3.16'
81
+ version: '4.1'
90
82
  type: :development
91
83
  prerelease: false
92
84
  version_requirements: !ruby/object:Gem::Requirement
93
85
  requirements:
94
86
  - - "~>"
95
87
  - !ruby/object:Gem::Version
96
- version: '3.16'
88
+ version: '4.1'
97
89
  description: sportdb-catalogs - sport.db (search 'n' find) catalogs for countries,
98
90
  leagues, clubs, national teams, and more
99
- email: opensport@googlegroups.com
91
+ email: gerald.bauer@gmail.com
100
92
  executables: []
101
93
  extensions: []
102
94
  extra_rdoc_files:
103
95
  - CHANGELOG.md
104
96
  - Manifest.txt
105
- - NOTES.md
106
97
  - README.md
107
98
  files:
108
99
  - CHANGELOG.md
109
100
  - Manifest.txt
110
- - NOTES.md
111
101
  - README.md
112
102
  - Rakefile
113
103
  - lib/sportdb/catalogs.rb
114
- - lib/sportdb/catalogs/catalog.rb
115
- - lib/sportdb/catalogs/config.rb
104
+ - lib/sportdb/catalogs/base.rb
105
+ - lib/sportdb/catalogs/city.rb
106
+ - lib/sportdb/catalogs/club.rb
107
+ - lib/sportdb/catalogs/country.rb
108
+ - lib/sportdb/catalogs/event_info.rb
109
+ - lib/sportdb/catalogs/ground.rb
110
+ - lib/sportdb/catalogs/league.rb
111
+ - lib/sportdb/catalogs/national_team.rb
112
+ - lib/sportdb/catalogs/player.rb
116
113
  - lib/sportdb/catalogs/version.rb
117
- - lib/sportdb/catalogs/wiki_index.rb
118
- - test/helper.rb
119
- - test/test_clubs.rb
120
- - test/test_clubs_history.rb
121
- - test/test_countries.rb
122
- - test/test_leagues.rb
123
- - test/test_national_teams.rb
124
- - test/test_wiki_index.rb
125
114
  homepage: https://github.com/sportdb/sport.db
126
115
  licenses:
127
116
  - Public Domain
128
117
  metadata: {}
129
- post_install_message:
118
+ post_install_message:
130
119
  rdoc_options:
131
120
  - "--main"
132
121
  - README.md
@@ -136,16 +125,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
136
125
  requirements:
137
126
  - - ">="
138
127
  - !ruby/object:Gem::Version
139
- version: 2.2.2
128
+ version: 3.1.0
140
129
  required_rubygems_version: !ruby/object:Gem::Requirement
141
130
  requirements:
142
131
  - - ">="
143
132
  - !ruby/object:Gem::Version
144
133
  version: '0'
145
134
  requirements: []
146
- rubyforge_project:
147
- rubygems_version: 2.5.2
148
- signing_key:
135
+ rubygems_version: 3.4.10
136
+ signing_key:
149
137
  specification_version: 4
150
138
  summary: sportdb-catalogs - sport.db (search 'n' find) catalogs for countries, leagues,
151
139
  clubs, national teams, and more
data/NOTES.md DELETED
@@ -1,5 +0,0 @@
1
- # Notes
2
-
3
- ## Todos
4
-
5
-
@@ -1,105 +0,0 @@
1
-
2
- module SportDb
3
- module Import
4
-
5
-
6
- class Catalog
7
- def config() Import.config; end
8
-
9
-
10
- ## todo/check: rename to country_mappings/index - why? why not?
11
- ## or countries_by_code or countries_by_key
12
- def countries() @countries ||= build_country_index; end
13
- def national_teams() @national_teams ||= build_national_team_index; end
14
- def clubs() @clubs ||= build_club_index; end
15
- def clubs_history() @clubs_history ||= build_club_history_index; end ## note: used for now (only) lookups by season for now
16
- def teams() @teams ||= build_team_index; end
17
- def leagues() @leagues ||= build_league_index; end
18
-
19
- def events() @events ||= build_event_index; end
20
- def seasons() @seasons ||= build_season_index; end
21
-
22
-
23
-
24
- def build_team_index() TeamIndex.new; end
25
-
26
- def build_country_index ## todo/check: rename to setup_country_index or read_country_index - why? why not?
27
- CountryIndex.new( Fifa.countries )
28
- end
29
-
30
- def build_national_team_index
31
- ## auto-build national teams from Fifa.countries for now
32
- teams = []
33
- Fifa.countries.each do |country|
34
- team = NationalTeam.new( key: country.code.downcase, ## note: use country code (fifa)
35
- name: country.name,
36
- code: country.code, ## note: use country code (fifa)
37
- alt_names: country.alt_names )
38
- team.country = country
39
-
40
- teams << team
41
- end
42
-
43
- NationalTeamIndex.new( teams )
44
- end
45
-
46
- def build_club_index
47
- ## unify team names; team (builtin/known/shared) name mappings
48
- ## cleanup team names - use local ("native") name with umlaut etc.
49
- ## todo/fix: add to teamreader
50
- ## check that name and alt_names for a club are all unique (not duplicates)
51
-
52
- clubs = if config.clubs_dir ## check if clubs_dir is defined / set (otherwise it's nil)
53
- ClubIndex.build( config.clubs_dir )
54
- else ## no clubs_dir set - try using builtin from footballdb-clubs
55
- FootballDb::Import::build_club_index
56
- end
57
-
58
- if clubs.errors?
59
- puts ""
60
- puts "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
61
- puts " #{clubs.errors.size} errors:"
62
- pp clubs.errors
63
- ## exit 1
64
- end
65
-
66
- clubs
67
- end # method build_club_index
68
-
69
- def build_club_history_index
70
- if config.clubs_dir ## (re)use clubs dir for now - why? why not?
71
- ClubHistoryIndex.build( config.clubs_dir )
72
- else
73
- puts "!! WARN - no clubs_dir set; for now NO built-in club histories in catalog; sorry - fix!!!!"
74
- ClubHistoryIndex.new ## return empty history index
75
- end
76
- end
77
-
78
-
79
- def build_league_index
80
- leagues = if config.leagues_dir ## check if clubs_dir is defined / set (otherwise it's nil)
81
- LeagueIndex.build( config.leagues_dir )
82
- else ## no leagues_dir set - try using builtin from footballdb-leagues
83
- FootballDb::Import.build_league_index
84
- end
85
- end
86
-
87
-
88
- def build_event_index
89
- if config.leagues_dir ## (re)use leagues dir for now - add separate seasons_dir - why? why not?
90
- EventIndex.build( config.leagues_dir )
91
- else
92
- puts "!! WARN - no leagues_dir set; for now NO built-in events in catalog; sorry - fix!!!!"
93
- EventIndex.new ## return empty event index
94
- end
95
- end
96
-
97
- def build_season_index
98
- # note: for now always (re)use the events from the event (info) index
99
- SeasonIndex.new( events )
100
- end
101
-
102
- end # class Catalog
103
-
104
- end # module Import
105
- end # module SportDb
@@ -1,25 +0,0 @@
1
- # encoding: utf-8
2
-
3
- module SportDb
4
- module Import
5
-
6
- class Configuration
7
- ## note: add more configs (open class), see sportdb-formats for original config!!!
8
-
9
- ##
10
- ## todo: allow configure of countries_dir like clubs_dir
11
- ## "fallback" and use a default built-in world/countries.txt
12
-
13
- ####
14
- # todo/check: find a better way to configure club / team datasets - why? why not?
15
- attr_accessor :clubs_dir
16
- ## def clubs_dir() @clubs_dir; end ### note: return nil if NOT set on purpose for now - why? why not?
17
-
18
- attr_accessor :leagues_dir
19
- ## def leagues_dir() @leagues_dir; end
20
-
21
- def catalog() @catalog ||= Catalog.new; end
22
- end # class Configuration
23
-
24
- end # module Import
25
- end # module SportDb
@@ -1,81 +0,0 @@
1
- # encoding: utf-8
2
-
3
- module SportDb
4
- module Import
5
-
6
-
7
- class WikiIndex
8
-
9
- def self.build( path )
10
- pack = Package.new( path )
11
- recs = []
12
- pack.each_clubs_wiki do |entry|
13
- recs += WikiReader.parse( entry.read )
14
- end
15
- recs
16
-
17
- new( recs )
18
- end
19
-
20
-
21
- include NameHelper
22
- ## e.g. strip_lang, strip_year, normalize
23
-
24
- ## fix/todo:
25
- ## also used / duplicated in ClubIndex#add_wiki !!!
26
- def strip_wiki( name ) # todo/check: rename to strip_wikipedia_en - why? why not?
27
- ## note: strip disambiguationn qualifier from wikipedia page name if present
28
- ## note: only remove year and foot... for now
29
- ## e.g. FC Wacker Innsbruck (2002) => FC Wacker Innsbruck
30
- ## Willem II (football club) => Willem II
31
- ##
32
- ## e.g. do NOT strip others !! e.g.
33
- ## América Futebol Clube (MG)
34
- ## only add more "special" cases on demand (that, is) if we find more
35
- name = name.gsub( /\([12][^\)]+?\)/, '' ).strip ## starting with a digit 1 or 2 (assuming year)
36
- name = name.gsub( /\(foot[^\)]+?\)/, '' ).strip ## starting with foot (assuming football ...)
37
- name
38
- end
39
-
40
-
41
- def initialize( recs )
42
- @pages_by_country = {}
43
-
44
- ## todo/fix:
45
- ## check for duplicate recs - report and exit on dupliate!!!!!!
46
- recs.each do |rec|
47
- h = @pages_by_country[ rec.country.key ] ||= {}
48
- h[ normalize( strip_wiki( rec.name )) ] = rec
49
- end
50
- end
51
-
52
-
53
- def find_by( club: ) ## todo/check: use find_by_club - why? why not?
54
- find_by_club( club )
55
- end
56
-
57
- def find_by_club( club )
58
- rec = nil
59
-
60
- ## get query params from club
61
- names = [club.name]+club.alt_names
62
- country_key = club.country.key
63
-
64
- h = @pages_by_country[ country_key ]
65
- if h
66
- ## todo/check: sort names ?
67
- ## sort by longest first (for best match)
68
- names.each do |name|
69
- ## note: normalize AND sanitize (e.g. remove/string year and lang e.g. (1946-2001), [en] too)
70
- rec = h[ normalize( strip_year( strip_lang( name ))) ]
71
- break if rec ## bingo!! found - break on first match
72
- end
73
- end
74
-
75
- rec ## note: return nil if nothing found
76
- end
77
- end # class WikiIndex
78
-
79
-
80
- end # module Import
81
- end # module SportDb
data/test/helper.rb DELETED
@@ -1,13 +0,0 @@
1
- ## note: use the local version of sportdb gems
2
- $LOAD_PATH.unshift( File.expand_path( '../sportdb-formats/lib' ))
3
-
4
- ## minitest setup
5
- require 'minitest/autorun'
6
-
7
-
8
- ## our own code
9
- require 'sportdb/catalogs'
10
-
11
-
12
- SportDb::Import.config.clubs_dir = '../../../openfootball/clubs'
13
- SportDb::Import.config.leagues_dir = '../../../openfootball/leagues'