sportdb-readers 2.0.1 → 2.1.0

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: dbb28e300a9554870b241ebd71e204914caae0dcdfd299ad4fb9ce8c29b8a48e
4
- data.tar.gz: cfd60853ca4a88aad6a652a7d1f26a8d131d9f540f16d89411a851b275b2f997
3
+ metadata.gz: f272d4ffee7d8d56aa09bc05ec0280ab252ef793cc26090206e4dad41824cd43
4
+ data.tar.gz: 3343b9b089991220fa61584f166a229ce1bd35aad695a0aef76ac692fc62825e
5
5
  SHA512:
6
- metadata.gz: 7bd415167e8969b605682f74d3b420f3aae0dc6db8925f0db872a6753fdd79e593eb5dc479b3cd9a9c5d040eea81da6f274ad2739cd2116fad445cb3452ad8a8
7
- data.tar.gz: 860bc2949679d7b5654ced5ff3c20d59e1c77ac41253d5924612669dab800560a58886b1de8b1079d591a35a55176cd0200edf72e25449b23147b58f694e3e67
6
+ metadata.gz: 665bd28de289348d82f8bb3157e08601f20ebe35794c3e1694802fb77df34151bb15589a784c615c3c83fb3c1ad30a0e66f51a0c4a34a366dd666be3b1249d41
7
+ data.tar.gz: d330593cd5ae11a2a887ef365e69c3cd02486623e9a0fbca132466eef7408b65a455ab9ee1cad6f55f6f1d706c7f901f816f23bb01060fd28457ca6df5879092
data/CHANGELOG.md CHANGED
@@ -1,4 +1,4 @@
1
- ### 2.0.1
1
+ ### 2.1.0
2
2
 
3
3
  ### 0.0.1 / 2019-10-29
4
4
 
data/Manifest.txt CHANGED
@@ -4,7 +4,6 @@ NOTES.md
4
4
  README.md
5
5
  Rakefile
6
6
  lib/sportdb/readers.rb
7
- lib/sportdb/readers/conf_reader.rb
8
7
  lib/sportdb/readers/match_reader.rb
9
8
  lib/sportdb/readers/package.rb
10
9
  lib/sportdb/readers/sync/club.rb
@@ -1,3 +1,9 @@
1
+ ###
2
+ # todo/fix:
3
+ # add optional stage to
4
+ # group, round to make uniquie
5
+ # same group or round name is different (record) if differant stage !!!!
6
+
1
7
 
2
8
  module SportDb
3
9
  class MatchReader ## todo/check: rename to MatchReaderV2 (use plural?) why? why not?
@@ -29,17 +35,43 @@ class MatchReader ## todo/check: rename to MatchReaderV2 (use plural?) why? w
29
35
  @txt = txt
30
36
  end
31
37
 
38
+
39
+
32
40
  def parse( season: nil )
33
- secs = LeagueOutlineReader.parse( @txt, season: season )
34
- pp secs
41
+ secs = QuickLeagueOutlineReader.parse( @txt )
42
+ ## pp secs
43
+
44
+ ########
45
+ # step 1 - prepare secs
46
+ # -- filter seasons if filter present
47
+ secs = filter_secs( sec, season: season ) if season
48
+
49
+ ## -- check & map; replace inline (string with data struct record)
50
+ secs.each do |sec|
51
+ sec[:season] = Season.parse( sec[:season ] )
52
+ sec[:league] = Import::League.find!( sec[:league] )
53
+
54
+ ##
55
+ ## quick hack - assume "Regular" or "Regular Season"
56
+ ## as default stage (thus, no stage)
57
+ if sec[:stage]
58
+ sec[:stage] = nil if ['Regular',
59
+ 'Regular Season',
60
+ 'Regular Stage',
61
+ ].include?( sec[:stage] )
62
+ end
63
+ end
35
64
 
65
+
66
+ ###
67
+ # step 2 - handle secs
36
68
  secs.each do |sec| ## sec(tion)s
37
69
  season = sec[:season]
38
70
  league = sec[:league]
39
71
  stage = sec[:stage]
40
72
  lines = sec[:lines]
41
73
 
42
- ### check if event info availabe - use start_date;
74
+ ### check if event info available - use start_date;
43
75
  ## otherwise we have to guess (use a "synthetic" start_date)
44
76
  event_info = catalog.events.find_by( season: season,
45
77
  league: league )
@@ -74,51 +106,18 @@ class MatchReader ## todo/check: rename to MatchReaderV2 (use plural?) why? w
74
106
  pp groups
75
107
 
76
108
 
77
-
109
+ ##################################
78
110
  ## step 1: map/find teams
79
111
 
80
112
  ## note: loop over keys (holding the names); values hold the usage counter!! e.g. 'Arsenal' => 2, etc.
81
- mods = nil
82
- if league.clubs? && league.intl? ## todo/fix: add intl? to ActiveRecord league!!!
83
-
84
- ## quick hack - use "dynamic" keys for keys
85
- uefa_el_q = Import::League.match_by( code: 'uefa.el.quali' )[0]
86
- uefa_cl_q = Import::League.match_by( code: 'uefa.cl.quali' )[0]
87
- uefa_cl = Import::League.match_by( code: 'uefa.cl' )[0]
88
- uefa_el = Import::League.match_by( code: 'uefa.el' )[0]
89
-
90
- pp [uefa_el_q, uefa_cl_q, uefa_cl, uefa_el]
91
-
92
- ### quick hack mods for popular/known ambigious club names
93
- ## todo/fix: make more generic / reuseable!!!!
94
- mods = {}
95
- ## europa league uses same mods as champions league
96
- mods[ uefa_el_q.key ] =
97
- mods[ uefa_cl_q.key ] =
98
- mods[ uefa_el.key ] =
99
- mods[ uefa_cl.key ] = catalog.clubs.build_mods(
100
- { 'Liverpool | Liverpool FC' => 'Liverpool FC, ENG',
101
- 'Arsenal | Arsenal FC' => 'Arsenal FC, ENG',
102
- 'Barcelona' => 'FC Barcelona, ESP',
103
- 'Valencia' => 'Valencia CF, ESP',
104
- 'Rangers FC' => 'Rangers FC, SCO',
105
- })
106
- end
107
-
108
113
  # puts " [debug] auto_conf_teams:"
109
114
  # pp auto_conf_teams
110
115
 
111
-
112
- ## todo/fix
113
- ## ** !!! ERROR - too many matches (2) for club >Barcelona<:
114
- ## [<Club: FC Barcelona (ESP)>, <Club: Barcelona Guayaquil (ECU)>]
115
-
116
116
  puts "league:"
117
117
  pp league
118
118
 
119
119
  teams = catalog.teams.find_by!( name: auto_conf_teams,
120
- league: league,
121
- mods: mods )
120
+ league: league )
122
121
 
123
122
  puts " [debug] teams:"
124
123
  pp teams
@@ -223,5 +222,34 @@ class MatchReader ## todo/check: rename to MatchReaderV2 (use plural?) why? w
223
222
  end # method parse
224
223
 
225
224
 
225
+
226
+
227
+
228
+ #####
229
+ # filter by season helpers
230
+ def filter_secs( secs, season: )
231
+ filtered_secs = []
232
+ filter = norm_seasons( season )
233
+ secs.each do |sec|
234
+ if filter.include?( Season.parse( sec[:season] ).key )
235
+ filtered_secs << sec
236
+ else
237
+ puts " skipping season >#{sec[:season]}< NOT matched by filter"
238
+ end
239
+ end
240
+ filtered_secs
241
+ end
242
+
243
+ def norm_seasons( season_or_seasons ) ## todo/check: add alias norm_seasons - why? why not?
244
+ seasons = if season_or_seasons.is_a?( Array ) # is it an array already
245
+ season_or_seasons
246
+ elsif season_or_seasons.is_a?( Range ) # e.g. Season(1999)..Season(2001) or such
247
+ season_or_seasons.to_a
248
+ else ## assume - single entry - wrap in array
249
+ [season_or_seasons]
250
+ end
251
+
252
+ seasons.map { |season| Season( season ).key }
253
+ end
226
254
  end # class MatchReader
227
255
  end # module SportDb
@@ -3,33 +3,6 @@ module SportDb
3
3
  class Package
4
4
 
5
5
  ## note: add readers here; for full class def see the sourcein sportdb-formats!!!
6
-
7
- def read_leagues
8
- each_leagues { |entry| SportDb.parse_leagues( entry.read ) }
9
- end
10
-
11
- def read_clubs
12
- each_clubs { |entry| SportDb.parse_clubs( entry.read ) }
13
- end
14
-
15
- def read_club_props
16
- each_club_props { |entry| SportDb.parse_club_props( entry.read ) }
17
- end
18
-
19
-
20
- def read_conf( *names, season: nil )
21
- if names.empty? ## no (entry) names passed in; read in all
22
- each_conf do |entry|
23
- SportDb.parse_conf( entry.read, season: season )
24
- end
25
- else
26
- names.each do |name|
27
- entry = @pack.find( name )
28
- SportDb.parse_conf( entry.read, season: season )
29
- end
30
- end
31
- end
32
-
33
6
  def read_match( *names, season: nil )
34
7
  if names.empty? ## no (entry) names passed in; read in all
35
8
  each_match do |entry|
@@ -43,29 +16,8 @@ module SportDb
43
16
  end
44
17
  end
45
18
 
46
-
47
- def read( *names, season: nil )
48
- if names.empty? ## read all datafiles
49
- read_leagues()
50
- read_clubs()
51
- read_club_props()
52
- ## note: skip conf(iguration)s for now!!!!!!!
53
- ## read_conf( season: season )
54
- read_match( season: season )
55
- else
56
- names.each do |name|
57
- entry = @pack.find( name )
58
- ## fix/todo: add read_leagues, read_clubs too!!!
59
- if match_conf?( name ) ## check if datafile matches conf(iguration) naming (e.g. .conf.txt)
60
- SportDb.parse_conf( entry.read, season: season )
61
- elsif match_club_props?( name )
62
- SportDb.parse_club_props( entry.read )
63
- else ## assume "regular" match datafile or check pattern and report error on fail - why? why not?
64
- SportDb.parse_match( entry.read, season: season )
65
- end
66
- end
67
- end
68
- end
19
+ ## note: read is same as read_match for now!!!
20
+ ## in the future add (again) more formats (see attic for history)
21
+ alias_method :read, :read_match
69
22
  end # class Package
70
-
71
23
  end # module SportDb
@@ -20,6 +20,8 @@ module Sync
20
20
  ## and lookup by name AND stage??
21
21
 
22
22
 
23
+
24
+
23
25
  round_rec = if match.round
24
26
  ## query for round - allow string or round rec
25
27
  round_name = match.round.is_a?( String ) ? match.round : match.round.name
@@ -57,8 +59,8 @@ module Sync
57
59
  end
58
60
 
59
61
  ### todo/check: what happens if there's more than one match? exception raised??
60
- rec = if ['N. N.'].include?( team1_name ) && ## some special cases - always assume new record for now (to avoid ambigious update conflict)
61
- ['N. N.'].include?( team2_name )
62
+ rec = if ['N. N.', 'N.N.'].include?( team1_name ) && ## some special cases - always assume new record for now (to avoid ambigious update conflict)
63
+ ['N. N.', 'N.N.'].include?( team2_name )
62
64
  ## always assume new record for now
63
65
  ## check for date or such - why? why not?
64
66
  nil
@@ -137,6 +139,10 @@ module Sync
137
139
  else
138
140
  # update - todo
139
141
  puts "!! ERROR - match updates not yet supported (only inserts); sorry"
142
+ pp match
143
+ puts "---"
144
+ puts "found match record:"
145
+ pp rec
140
146
  exit 1
141
147
  end
142
148
  rec
@@ -3,10 +3,9 @@
3
3
  module SportDb
4
4
  module Module
5
5
  module Readers
6
-
7
6
  MAJOR = 2 ## todo: namespace inside version or something - why? why not??
8
- MINOR = 0
9
- PATCH = 1
7
+ MINOR = 1
8
+ PATCH = 0
10
9
  VERSION = [MAJOR,MINOR,PATCH].join('.')
11
10
 
12
11
  def self.version
@@ -16,7 +16,6 @@ require_relative 'readers/sync/more'
16
16
  require_relative 'readers/sync/match' ## note - let match sync go last
17
17
 
18
18
  ## add readers & friends
19
- require_relative 'readers/conf_reader'
20
19
  require_relative 'readers/match_reader'
21
20
  require_relative 'readers/package'
22
21
 
@@ -26,20 +25,10 @@ require_relative 'readers/package'
26
25
  ##
27
26
  ## add convenience shortcut helpers
28
27
  module SportDb
29
- def self.read_conf( path, season: nil ) ConfReader.read( path, season: season ); end
30
- def self.parse_conf( txt, season: nil ) ConfReader.parse( txt, season: season ); end
31
-
32
28
  ### todo/check: add alias read_matches - why? why not?
33
29
  def self.read_match( path, season: nil ) MatchReader.read( path, season: season ); end
34
30
  def self.parse_match( txt, season: nil ) MatchReader.parse( txt, season: season ); end
35
31
 
36
- def self.read_club_props( path ) Import::ClubPropsReader.read( path ); end
37
- def self.parse_club_props( txt ) Import::ClubPropsReader.parse( txt ); end
38
-
39
- def self.parse_leagues( txt ) recs = Import::LeagueReader.parse( txt ); Import.catalog.leagues.add( recs ); end
40
- def self.parse_clubs( txt ) recs = Import::ClubReader.parse( txt ); Import.catalog.clubs.add( recs ); end
41
-
42
-
43
32
  def self.read( path, season: nil )
44
33
  pack = if File.directory?( path ) ## if directory assume "unzipped" package
45
34
  DirPackage.new( path )
@@ -52,17 +41,9 @@ module SportDb
52
41
  if pack
53
42
  pack.read( season: season )
54
43
  else
55
- if Package.conf?( path ) ## check if datafile matches conf(iguration) naming (e.g. .conf.txt)
56
- read_conf( path, season: season )
57
- elsif Package.club_props?( path )
58
- read_club_props( path )
59
- else ## assume "regular" match datafile
60
- read_match( path, season: season )
61
- end
44
+ read_match( path, season: season )
62
45
  end
63
46
  end # method read
64
-
65
-
66
47
  end # module SportDb
67
48
 
68
49
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sportdb-readers
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.1.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: 2024-08-23 00:00:00.000000000 Z
11
+ date: 2024-09-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sportdb-formats
@@ -89,7 +89,6 @@ files:
89
89
  - README.md
90
90
  - Rakefile
91
91
  - lib/sportdb/readers.rb
92
- - lib/sportdb/readers/conf_reader.rb
93
92
  - lib/sportdb/readers/match_reader.rb
94
93
  - lib/sportdb/readers/package.rb
95
94
  - lib/sportdb/readers/sync/club.rb
@@ -1,99 +0,0 @@
1
-
2
- module SportDb
3
-
4
-
5
- class ConfReader ## todo/check: rename to EventsReaderV2 (use plural?) why? why not?
6
-
7
- def self.read( path, season: nil ) ## use - rename to read_file or from_file etc. - why? why not?
8
- txt = File.open( path, 'r:utf-8' ) {|f| f.read }
9
- parse( txt, season: season )
10
- end
11
-
12
- def self.parse( txt, season: nil )
13
- new( txt ).parse( season: season )
14
- end
15
-
16
-
17
- include Logging
18
-
19
- def initialize( txt )
20
- @txt = txt
21
- end
22
-
23
- def parse( season: nil )
24
- secs = LeagueOutlineReader.parse( @txt, season: season )
25
- pp secs
26
-
27
- ## pass 1 - check & map; replace inline (string with record)
28
- secs.each do |sec| # sec(tion)s
29
-
30
- conf = ConfParser.parse( sec[:lines] )
31
-
32
- league = sec[:league]
33
- teams = [] ## convert lines to teams
34
-
35
- if league.clubs?
36
- if league.intl?
37
- conf.each do |name, rec|
38
- country_key = rec[:country]
39
- teams << catalog.clubs.find_by!( name: name,
40
- country: country_key )
41
- end
42
- else
43
- conf.each do |name, _|
44
- ## note: rank and standing gets ignored (not used) for now
45
- teams << catalog.clubs.find_by!( name: name,
46
- league: league )
47
- end
48
- end
49
- else ### assume national teams
50
- conf.each do |name, _|
51
- ## note: rank and standing gets ignored (not used) for now
52
- teams << catalog.national_teams.find!( name )
53
- end
54
- end
55
-
56
-
57
- sec[:teams] = teams
58
-
59
- sec.delete( :lines ) ## remove lines entry
60
- end
61
-
62
-
63
- ## pass 2 - import (insert/update) into db
64
- secs.each do |sec| # sec(tion)s
65
- ## todo/fix: always return Season struct record in LeagueReader - why? why not?
66
- event_rec = Sync::Event.find_or_create_by( league: sec[:league],
67
- season: sec[:season] )
68
-
69
- stage_rec = if sec[:stage]
70
- Sync::Stage.find_or_create( sec[:stage], event: event_rec )
71
- else
72
- nil
73
- end
74
-
75
- ## todo/fix: check if all teams are unique
76
- ## check if uniq works for club/national_team record (struct) - yes,no ??
77
- teams = sec[:teams]
78
- teams = teams.uniq
79
-
80
- ## add to database
81
- team_recs = stage_rec ? stage_rec.teams : event_rec.teams
82
- team_ids = stage_rec ? stage_rec.team_ids : event_rec.team_ids
83
-
84
- new_team_recs = Sync::Team.find_or_create( teams )
85
- new_team_recs.each do |team_rec|
86
- ## add teams to event
87
- ## for now check if team is alreay included
88
- ## todo/fix: clear/destroy_all first - why? why not!!!
89
- team_recs << team_rec unless team_ids.include?( team_rec.id )
90
- end
91
- end
92
-
93
- true ## todo/fix: return true/false or something
94
- end # method read
95
-
96
- def catalog() Import.catalog; end ## shortcut convenience helper
97
-
98
- end # class ConfReader
99
- end # module SportDb