sportdb-formats 1.0.6 → 1.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/Manifest.txt +6 -33
  3. data/Rakefile +2 -5
  4. data/lib/sportdb/formats.rb +54 -70
  5. data/lib/sportdb/formats/country/country_index.rb +2 -2
  6. data/lib/sportdb/formats/event/event_index.rb +141 -0
  7. data/lib/sportdb/formats/event/event_reader.rb +183 -0
  8. data/lib/sportdb/formats/league/league_index.rb +22 -18
  9. data/lib/sportdb/formats/league/league_outline_reader.rb +45 -13
  10. data/lib/sportdb/formats/league/league_reader.rb +7 -1
  11. data/lib/sportdb/formats/match/match_parser.rb +101 -111
  12. data/lib/sportdb/formats/package.rb +59 -11
  13. data/lib/sportdb/formats/parser_helper.rb +11 -2
  14. data/lib/sportdb/formats/team/club_index.rb +13 -11
  15. data/lib/sportdb/formats/team/club_index_history.rb +134 -0
  16. data/lib/sportdb/formats/team/club_reader_history.rb +203 -0
  17. data/lib/sportdb/formats/team/club_reader_props.rb +20 -5
  18. data/lib/sportdb/formats/version.rb +2 -2
  19. data/test/helper.rb +51 -81
  20. data/test/test_club_index_history.rb +107 -0
  21. data/test/test_club_reader_history.rb +212 -0
  22. data/test/test_datafile_package.rb +1 -1
  23. data/test/test_regex.rb +25 -7
  24. metadata +9 -78
  25. data/lib/sportdb/formats/config.rb +0 -40
  26. data/lib/sportdb/formats/match/match_parser_csv.rb +0 -314
  27. data/lib/sportdb/formats/name_helper.rb +0 -84
  28. data/lib/sportdb/formats/score/score_formats.rb +0 -220
  29. data/lib/sportdb/formats/score/score_parser.rb +0 -202
  30. data/lib/sportdb/formats/season_utils.rb +0 -27
  31. data/lib/sportdb/formats/structs/country.rb +0 -31
  32. data/lib/sportdb/formats/structs/group.rb +0 -18
  33. data/lib/sportdb/formats/structs/league.rb +0 -37
  34. data/lib/sportdb/formats/structs/match.rb +0 -151
  35. data/lib/sportdb/formats/structs/matchlist.rb +0 -220
  36. data/lib/sportdb/formats/structs/round.rb +0 -25
  37. data/lib/sportdb/formats/structs/season.rb +0 -123
  38. data/lib/sportdb/formats/structs/standings.rb +0 -247
  39. data/lib/sportdb/formats/structs/team.rb +0 -150
  40. data/lib/sportdb/formats/structs/team_usage.rb +0 -88
  41. data/test/test_clubs.rb +0 -40
  42. data/test/test_conf.rb +0 -65
  43. data/test/test_csv_match_parser.rb +0 -114
  44. data/test/test_csv_match_parser_utils.rb +0 -20
  45. data/test/test_csv_reader.rb +0 -31
  46. data/test/test_match.rb +0 -30
  47. data/test/test_match_auto.rb +0 -72
  48. data/test/test_match_auto_champs.rb +0 -45
  49. data/test/test_match_auto_euro.rb +0 -37
  50. data/test/test_match_auto_worldcup.rb +0 -61
  51. data/test/test_match_champs.rb +0 -27
  52. data/test/test_match_eng.rb +0 -26
  53. data/test/test_match_euro.rb +0 -27
  54. data/test/test_match_worldcup.rb +0 -27
  55. data/test/test_name_helper.rb +0 -67
  56. data/test/test_scores.rb +0 -122
  57. data/test/test_season.rb +0 -62
@@ -36,17 +36,16 @@ class ClubPropsReader
36
36
 
37
37
  ## find / match club by (canocial) name
38
38
  m = catalog.clubs.match( name )
39
- if m && m.size > 1
39
+ if m.size > 1
40
40
  puts "** !!! WARN !!! ambigious (multiple) club matches (#{m.size}) for name >#{name}< in props row:"
41
41
  pp rec
42
42
  pp m
43
43
 
44
44
  ## todo/fix: try filter by canonical name if more than one match
45
45
  m = m.select { |club| club.name == name }
46
- m = nil if m.empty? ## note: reset to nil if no more matches
47
46
  end
48
47
 
49
- if m.nil?
48
+ if m.empty?
50
49
  puts "** !!! ERROR !!! no club match for (canonical) name >#{name}< in props row:"
51
50
  pp rec
52
51
  exit 1
@@ -62,13 +61,29 @@ class ClubPropsReader
62
61
  ## todo/fix: only updated "on-demand" from in-memory struct/records!!!!
63
62
 
64
63
  ## update attributes
65
- club_rec.key = rec['Key'] if rec['Key']
66
- club_rec.code = rec['Code'] if rec['Code']
64
+ club_rec.key = rec['Key'] if is_not_na?( rec['Key'] )
65
+ club_rec.code = rec['Code'] if is_not_na?( rec['Code'] )
67
66
  ## todo/fix: add (some) more props e.g. address, web, etc.
68
67
  end
69
68
  end
70
69
  end # method parse
71
70
 
71
+
72
+ ## allow various values for nil or n/a (not available/applicable) for now
73
+ ## add more or less - why? why not?
74
+ def is_not_na?( col ) !is_na?( col); end ## check: find a better name - why? why not?
75
+
76
+ NA_VARIANTS = ['-', '--', '---',
77
+ '?', '??', '???',
78
+ '_', '__', '___',
79
+ 'na', 'n/a',
80
+ 'nil', 'null']
81
+
82
+ def is_na?( col )
83
+ col.nil? || col.empty? || NA_VARIANTS.include?( col.downcase )
84
+ end
85
+
86
+
72
87
  end # class ClubPropsReader
73
88
 
74
89
  end ## module Import
@@ -6,8 +6,8 @@ module SportDb
6
6
  module Formats
7
7
 
8
8
  MAJOR = 1 ## todo: namespace inside version or something - why? why not??
9
- MINOR = 0
10
- PATCH = 6
9
+ MINOR = 1
10
+ PATCH = 4
11
11
  VERSION = [MAJOR,MINOR,PATCH].join('.')
12
12
 
13
13
  def self.version
@@ -1,5 +1,9 @@
1
1
  ## note: use the local version of gems
2
2
  $LOAD_PATH.unshift( File.expand_path( '../date-formats/lib' ))
3
+ $LOAD_PATH.unshift( File.expand_path( '../score-formats/lib' ))
4
+ $LOAD_PATH.unshift( File.expand_path( '../sportdb-langs/lib' ))
5
+ $LOAD_PATH.unshift( File.expand_path( '../sportdb-structs/lib' ))
6
+
3
7
 
4
8
 
5
9
  ## minitest setup
@@ -54,12 +58,56 @@ TXT
54
58
  = England
55
59
 
56
60
  Chelsea FC
57
- Arsenal FC
58
61
  Tottenham Hotspur
59
62
  West Ham United
60
63
  Crystal Palace
61
- Manchester United
62
- Manchester City
64
+
65
+ ### note add move entires for testing club name history
66
+ Manchester United FC
67
+ | Manchester United
68
+ | Newton Heath FC
69
+
70
+ Manchester City FC
71
+ | Manchester City
72
+ | Ardwick FC
73
+
74
+ Arsenal FC
75
+ | The Arsenal FC
76
+ | Woolwich Arsenal FC
77
+ | Royal Arsenal FC
78
+
79
+ Gateshead FC
80
+ | South Shields FC
81
+
82
+ Sheffield Wednesday
83
+ | The Wednesday FC
84
+
85
+ Port Vale FC
86
+ | Burslem Port Vale FC
87
+
88
+ Chesterfield FC
89
+ | Chesterfield Town FC
90
+
91
+ Birmingham FC
92
+ | Small Heath FC
93
+
94
+ Burton Swifts FC
95
+ Burton Wanderers FC
96
+ Burton United FC
97
+
98
+ Blackpool FC
99
+ South Shore FC
100
+
101
+ Glossop FC
102
+ | Glossop North End FC
103
+
104
+ Walsall FC
105
+ | Walsall Town Swifts FC
106
+
107
+
108
+ Newcastle West End FC
109
+ Newcastle East End FC
110
+ Newcastle United FC
63
111
  TXT
64
112
 
65
113
  index = ClubIndex.new
@@ -82,81 +130,3 @@ end # module SportDb
82
130
 
83
131
 
84
132
 
85
- ################
86
- ## helper
87
-
88
- def parse_auto_conf( txt, lang: 'en', start: nil )
89
- start = start ? start : Date.new( 2017, 7, 1 )
90
-
91
- SportDb::Import.config.lang = lang
92
-
93
- parser = SportDb::AutoConfParser.new( txt, start )
94
- parser.parse
95
- end
96
-
97
- def parse_conf( txt )
98
- parser = SportDb::ConfParser.new( txt )
99
- parser.parse
100
- end
101
-
102
-
103
- ## note: json always returns hash tables with string keys (not symbols),
104
- ## thus, always stringify keys before comparing!!!!
105
- class Object
106
- def deep_stringify_keys
107
- if self.is_a? Hash
108
- self.reduce({}) {|memo,(k,v)| memo[k.to_s] = v.deep_stringify_keys; memo }
109
- elsif self.is_a? Array
110
- self.reduce([]) {|memo,v | memo << v.deep_stringify_keys; memo }
111
- else
112
- self
113
- end
114
- end
115
- end
116
-
117
-
118
- def read_blocks( path )
119
- txt = File.open( path, 'r:utf-8' ).read
120
-
121
- blocks = []
122
- buf = String.new('')
123
- txt.each_line do |line|
124
- if line =~ /^[ ]*
125
- ([>]{3,} |
126
- [<]{3,})
127
- [ ]*
128
- $/x ## three or more markers
129
- blocks << buf
130
- buf = String.new('')
131
- else
132
- buf << line
133
- end
134
- end
135
- blocks << buf
136
- blocks
137
- end
138
-
139
-
140
- def parse_json( str )
141
- ## note: allow empty string; fall back to empty hash
142
- if str.strip.empty?
143
- {}
144
- else
145
- JSON.parse( str )
146
- end
147
- end
148
-
149
- def read_test( path )
150
- blocks = read_blocks( "#{SportDb::Test.data_dir}/football.txt/#{path}" )
151
-
152
- if blocks.size == 2
153
- [blocks[0], parse_json( blocks[1] )]
154
- elsif blocks.size == 3
155
- ## note: returned in different order
156
- ## optional option block that comes first returned last!
157
- [blocks[1], parse_json( blocks[2] ), blocks[0]]
158
- else
159
- puts "!! ERROR: expected two or three text blocks in >#{path}<; got #{blocks.size}"
160
- exit 1
161
- end
162
- end
@@ -0,0 +1,107 @@
1
+ # encoding: utf-8
2
+
3
+ ###
4
+ # to run use
5
+ # ruby -I ./lib -I ./test test/test_club_index_history.rb
6
+
7
+
8
+ require 'helper'
9
+
10
+ class TestClubHistoryIndex < MiniTest::Test
11
+
12
+ def test_eng
13
+ txt =<<TXT
14
+ = England
15
+
16
+ ## note: use history log by season (instead of by year) - why? why not?
17
+ ##
18
+ ## note/warn/remember !! a line starting with arrow (=>)
19
+ ## will get turned into a heading 1!!!
20
+ ## as an ascii-alternative to ⇒ use >> or -> or ??? - why? why not?
21
+
22
+ == 1930/1
23
+ MOVE South Shields FC, South Shields ⇒ Gateshead FC, Gateshead
24
+
25
+
26
+ == 1929/30
27
+ RENAME The Wednesday FC, Sheffield ⇒ Sheffield Wednesday
28
+
29
+ == 1927/8
30
+ RENAME The Arsenal FC, London ⇒ Arsenal FC
31
+
32
+
33
+ == 1914/5
34
+ RENAME Woolwich Arsenal FC, London ⇒ The Arsenal FC
35
+
36
+
37
+ == 1911/2
38
+ REFORM Burslem Port Vale FC, Burslem ⇒ Port Vale FC, Stoke-on-Trent
39
+ ## the towns of Burslem having been merged in 1910 with the towns of Fenton, Hanley,
40
+ ## Longton, Stoke-upon-Trent and Tunstall as the city of Stoke-on-Trent
41
+
42
+
43
+ == 1909/10
44
+ RENAME Chesterfield Town FC, Chesterfield ⇒ Chesterfield FC
45
+
46
+
47
+ == 1905/6
48
+ RENAME Chesterfield FC, Chesterfield ⇒ Chesterfield Town FC
49
+ Small Heath FC, Birmingham ⇒ Birmingham FC
50
+
51
+ == 1902/3
52
+ REFORM Newton Heath FC, Manchester ⇒ Manchester United
53
+
54
+ == 1901/2
55
+ MERGE Burton Swifts FC, Burton-upon-Trent
56
+ Burton Wanderers FC, Burton-upon-Trent
57
+ ⇒ Burton United FC
58
+
59
+ BANKRUPT Newton Heath FC, Manchester
60
+
61
+
62
+ == 1899/00
63
+ MERGE Blackpool FC, Blackpool
64
+ South Shore FC, Blackpool
65
+ ⇒ Blackpool FC
66
+
67
+ == 1898/9
68
+ RENAME Glossop North End FC, Glossop ⇒ Glossop FC
69
+
70
+
71
+ == 1895/6
72
+ RENAME Walsall Town Swifts FC, Walsall ⇒ Walsall FC
73
+
74
+
75
+ == 1894/5
76
+ REFORM Ardwick FC, Manchester ⇒ Manchester City FC
77
+
78
+ == 1893/4
79
+ BANKRUPT Ardwick FC, Manchester
80
+
81
+ MERGE Newcastle West End FC, Newcastle-upon-Tyne
82
+ Newcastle East End FC, Newcastle-upon-Tyne
83
+ ⇒ Newcastle United FC
84
+
85
+ == 1892/3
86
+ RENAME Royal Arsenal FC, London ⇒ Woolwich Arsenal FC
87
+ TXT
88
+
89
+ recs = SportDb::Import::ClubHistoryReader.parse( txt )
90
+
91
+ history = SportDb::Import::ClubHistoryIndex.new
92
+ history.add( recs )
93
+
94
+ pp history.errors
95
+ pp history.mappings
96
+
97
+ # [[1927/28, ["RENAME", [["The Arsenal FC, London", "eng"], ["Arsenal FC", "eng"]]]],
98
+ # [1914/15, ["RENAME", [["Woolwich Arsenal FC, London", "eng"], ["The Arsenal FC", "eng"]]]],
99
+ # [1892/93, ["RENAME", [["Royal Arsenal FC, London", "eng"], ["Woolwich Arsenal FC", "eng"]]]]],
100
+ assert_equal 'Arsenal FC', history.find_name_by( name: 'Arsenal FC', season: '2000/1' )
101
+ assert_equal 'Arsenal FC', history.find_name_by( name: 'Arsenal FC', season: '1927/8' )
102
+ assert_equal 'The Arsenal FC', history.find_name_by( name: 'Arsenal FC', season: '1926/7' )
103
+ assert_equal 'Woolwich Arsenal FC', history.find_name_by( name: 'Arsenal FC', season: '1913/4' )
104
+ assert_equal 'Royal Arsenal FC', history.find_name_by( name: 'Arsenal FC', season: '1891/2' )
105
+ end
106
+
107
+ end # class TestClubHistoryIndex
@@ -0,0 +1,212 @@
1
+ # encoding: utf-8
2
+
3
+ ###
4
+ # to run use
5
+ # ruby -I ./lib -I ./test test/test_club_reader_history.rb
6
+
7
+
8
+ require 'helper'
9
+
10
+
11
+ class TestClubHistoryReader < MiniTest::Test
12
+
13
+ def test_parse_eng
14
+ txt =<<TXT
15
+ = England
16
+
17
+ ## note: use history log by season (instead of by year) - why? why not?
18
+ ##
19
+ ## note/warn/remember !! a line starting with arrow (=>)
20
+ ## will get turned into a heading 1!!!
21
+ ## as an ascii-alternative to ⇒ use >> or -> or ??? - why? why not?
22
+
23
+
24
+
25
+ == 1958/9
26
+ RENAME Scunthorpe & Lindsey United FC, Scunthorpe ⇒ Scunthorpe United FC
27
+
28
+ == 1946/7
29
+ RENAME Clapton Orient FC, London ⇒ Leyton Orient FC
30
+
31
+ == 1945/6
32
+ RENAME Birmingham FC, Birmingham ⇒ Birmingham City FC
33
+
34
+ == 1930/1
35
+ MOVE South Shields FC, South Shields ⇒ Gateshead FC, Gateshead
36
+
37
+
38
+
39
+ == 1929/30
40
+ RENAME The Wednesday FC, Sheffield ⇒ Sheffield Wednesday
41
+
42
+ == 1927/8
43
+ RENAME The Arsenal FC, London ⇒ Arsenal FC
44
+
45
+ == 1925/6
46
+ RENAME Millwall Athletic FC, London ⇒ Millwall FC
47
+ Stoke FC, Stoke-on-Trent ⇒ Stoke City FC
48
+
49
+ MERGE Rotherham County FC, Rotherham
50
+ Rotherham Town FC, Rotherham
51
+ ⇒ Rotherham United FC
52
+
53
+ == 1914/5
54
+ RENAME Woolwich Arsenal FC, London ⇒ The Arsenal FC
55
+
56
+
57
+ == 1911/2
58
+ REFORM Burslem Port Vale FC, Burslem ⇒ Port Vale FC, Stoke-on-Trent
59
+ ## the towns of Burslem having been merged in 1910 with the towns of Fenton, Hanley,
60
+ ## Longton, Stoke-upon-Trent and Tunstall as the city of Stoke-on-Trent
61
+
62
+
63
+ == 1909/10
64
+ RENAME Chesterfield Town FC, Chesterfield ⇒ Chesterfield FC
65
+
66
+
67
+ == 1905/6
68
+ RENAME Chesterfield FC, Chesterfield ⇒ Chesterfield Town FC
69
+ Small Heath FC, Birmingham ⇒ Birmingham FC
70
+
71
+ == 1902/3
72
+ REFORM Newton Heath FC, Manchester ⇒ Manchester United
73
+
74
+ == 1901/2
75
+ MERGE Burton Swifts FC, Burton-upon-Trent
76
+ Burton Wanderers FC, Burton-upon-Trent
77
+ ⇒ Burton United FC
78
+
79
+ BANKRUPT Newton Heath FC, Manchester
80
+
81
+
82
+ == 1899/00
83
+ RENAME Barnsley St. Peter's FC, Barnsley ⇒ Barnsley FC
84
+
85
+ MERGE Blackpool FC, Blackpool
86
+ South Shore FC, Blackpool
87
+ ⇒ Blackpool FC
88
+
89
+ == 1898/9
90
+ RENAME Glossop North End FC, Glossop ⇒ Glossop FC
91
+
92
+
93
+ == 1895/6
94
+ RENAME Walsall Town Swifts FC, Walsall ⇒ Walsall FC
95
+
96
+
97
+ == 1894/5
98
+ REFORM Ardwick FC, Manchester ⇒ Manchester City FC
99
+
100
+ == 1893/4
101
+ BANKRUPT Ardwick FC, Manchester
102
+
103
+ MERGE Newcastle West End FC, Newcastle-upon-Tyne
104
+ Newcastle East End FC, Newcastle-upon-Tyne
105
+ ⇒ Newcastle United FC
106
+
107
+ == 1892/3
108
+ RENAME Royal Arsenal FC, London ⇒ Woolwich Arsenal FC
109
+ TXT
110
+
111
+ recs = SportDb::Import::ClubHistoryReader.parse( txt )
112
+
113
+ pp recs
114
+
115
+ exp = [["RENAME", "1958/59",
116
+ ["Scunthorpe & Lindsey United FC, Scunthorpe", "eng"],
117
+ ["Scunthorpe United FC", "eng"]],
118
+ ["RENAME", "1946/47",
119
+ ["Clapton Orient FC, London", "eng"],
120
+ ["Leyton Orient FC", "eng"]],
121
+ ["RENAME", "1945/46",
122
+ ["Birmingham FC, Birmingham", "eng"],
123
+ ["Birmingham City FC", "eng"]],
124
+ ["MOVE", "1930/31",
125
+ ["South Shields FC, South Shields", "eng"],
126
+ ["Gateshead FC, Gateshead", "eng"]],
127
+ ["RENAME",
128
+ "1929/30",
129
+ ["The Wednesday FC, Sheffield", "eng"],
130
+ ["Sheffield Wednesday", "eng"]],
131
+ ["RENAME",
132
+ "1927/28",
133
+ ["The Arsenal FC, London", "eng"],
134
+ ["Arsenal FC", "eng"]],
135
+ ["RENAME",
136
+ "1925/26",
137
+ ["Millwall Athletic FC, London", "eng"],
138
+ ["Millwall FC", "eng"]],
139
+ ["RENAME",
140
+ "1925/26",
141
+ ["Stoke FC, Stoke-on-Trent", "eng"],
142
+ ["Stoke City FC", "eng"]],
143
+ ["MERGE",
144
+ "1925/26",
145
+ [["Rotherham County FC, Rotherham", "eng"],
146
+ ["Rotherham Town FC, Rotherham", "eng"]],
147
+ ["Rotherham United FC", "eng"]],
148
+ ["RENAME",
149
+ "1914/15",
150
+ ["Woolwich Arsenal FC, London", "eng"],
151
+ ["The Arsenal FC", "eng"]],
152
+ ["REFORM",
153
+ "1911/12",
154
+ ["Burslem Port Vale FC, Burslem", "eng"],
155
+ ["Port Vale FC, Stoke-on-Trent", "eng"]],
156
+ ["RENAME",
157
+ "1909/10",
158
+ ["Chesterfield Town FC, Chesterfield", "eng"],
159
+ ["Chesterfield FC", "eng"]],
160
+ ["RENAME",
161
+ "1905/06",
162
+ ["Chesterfield FC, Chesterfield", "eng"],
163
+ ["Chesterfield Town FC", "eng"]],
164
+ ["RENAME",
165
+ "1905/06",
166
+ ["Small Heath FC, Birmingham", "eng"],
167
+ ["Birmingham FC", "eng"]],
168
+ ["REFORM",
169
+ "1902/03",
170
+ ["Newton Heath FC, Manchester", "eng"],
171
+ ["Manchester United", "eng"]],
172
+ ["MERGE",
173
+ "1901/02",
174
+ [["Burton Swifts FC, Burton-upon-Trent", "eng"],
175
+ ["Burton Wanderers FC, Burton-upon-Trent", "eng"]],
176
+ ["Burton United FC", "eng"]],
177
+ ["BANKRUPT", "1901/02", ["Newton Heath FC, Manchester", "eng"]],
178
+ ["RENAME",
179
+ "1899/00",
180
+ ["Barnsley St. Peter's FC, Barnsley", "eng"],
181
+ ["Barnsley FC", "eng"]],
182
+ ["MERGE",
183
+ "1899/00",
184
+ [["Blackpool FC, Blackpool", "eng"], ["South Shore FC, Blackpool", "eng"]],
185
+ ["Blackpool FC", "eng"]],
186
+ ["RENAME",
187
+ "1898/99",
188
+ ["Glossop North End FC, Glossop", "eng"],
189
+ ["Glossop FC", "eng"]],
190
+ ["RENAME",
191
+ "1895/96",
192
+ ["Walsall Town Swifts FC, Walsall", "eng"],
193
+ ["Walsall FC", "eng"]],
194
+ ["REFORM",
195
+ "1894/95",
196
+ ["Ardwick FC, Manchester", "eng"],
197
+ ["Manchester City FC", "eng"]],
198
+ ["BANKRUPT", "1893/94", ["Ardwick FC, Manchester", "eng"]],
199
+ ["MERGE",
200
+ "1893/94",
201
+ [["Newcastle West End FC, Newcastle-upon-Tyne", "eng"],
202
+ ["Newcastle East End FC, Newcastle-upon-Tyne", "eng"]],
203
+ ["Newcastle United FC", "eng"]],
204
+ ["RENAME",
205
+ "1892/93",
206
+ ["Royal Arsenal FC, London", "eng"],
207
+ ["Woolwich Arsenal FC", "eng"]]]
208
+
209
+ assert_equal exp, recs
210
+ end
211
+
212
+ end # class TestClubHistoryReader