sportdb-formats 1.1.0 → 1.1.5

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.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/Manifest.txt +6 -34
  3. data/Rakefile +3 -6
  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 +24 -7
  10. data/lib/sportdb/formats/league/league_reader.rb +7 -1
  11. data/lib/sportdb/formats/match/match_parser.rb +47 -18
  12. data/lib/sportdb/formats/package.rb +59 -11
  13. data/lib/sportdb/formats/team/club_index.rb +13 -11
  14. data/lib/sportdb/formats/team/club_index_history.rb +134 -0
  15. data/lib/sportdb/formats/team/club_reader_history.rb +203 -0
  16. data/lib/sportdb/formats/team/club_reader_props.rb +20 -5
  17. data/lib/sportdb/formats/version.rb +1 -1
  18. data/test/helper.rb +50 -81
  19. data/test/test_club_index_history.rb +107 -0
  20. data/test/test_club_reader_history.rb +212 -0
  21. data/test/test_datafile_package.rb +1 -1
  22. metadata +11 -81
  23. data/lib/sportdb/formats/config.rb +0 -40
  24. data/lib/sportdb/formats/match/match_parser_csv.rb +0 -321
  25. data/lib/sportdb/formats/name_helper.rb +0 -84
  26. data/lib/sportdb/formats/score/score_formats.rb +0 -220
  27. data/lib/sportdb/formats/score/score_parser.rb +0 -202
  28. data/lib/sportdb/formats/season_utils.rb +0 -27
  29. data/lib/sportdb/formats/structs/country.rb +0 -31
  30. data/lib/sportdb/formats/structs/group.rb +0 -18
  31. data/lib/sportdb/formats/structs/league.rb +0 -37
  32. data/lib/sportdb/formats/structs/match.rb +0 -151
  33. data/lib/sportdb/formats/structs/matchlist.rb +0 -220
  34. data/lib/sportdb/formats/structs/round.rb +0 -25
  35. data/lib/sportdb/formats/structs/season.rb +0 -123
  36. data/lib/sportdb/formats/structs/standings.rb +0 -268
  37. data/lib/sportdb/formats/structs/team.rb +0 -150
  38. data/lib/sportdb/formats/structs/team_usage.rb +0 -88
  39. data/test/test_clubs.rb +0 -40
  40. data/test/test_conf.rb +0 -65
  41. data/test/test_csv_match_parser.rb +0 -114
  42. data/test/test_csv_match_parser_utils.rb +0 -20
  43. data/test/test_csv_reader.rb +0 -31
  44. data/test/test_match.rb +0 -30
  45. data/test/test_match_auto.rb +0 -72
  46. data/test/test_match_auto_champs.rb +0 -45
  47. data/test/test_match_auto_euro.rb +0 -37
  48. data/test/test_match_auto_relegation.rb +0 -41
  49. data/test/test_match_auto_worldcup.rb +0 -61
  50. data/test/test_match_champs.rb +0 -27
  51. data/test/test_match_eng.rb +0 -26
  52. data/test/test_match_euro.rb +0 -27
  53. data/test/test_match_worldcup.rb +0 -27
  54. data/test/test_name_helper.rb +0 -67
  55. data/test/test_scores.rb +0 -122
  56. data/test/test_season.rb +0 -62
@@ -7,7 +7,7 @@ module Formats
7
7
 
8
8
  MAJOR = 1 ## todo: namespace inside version or something - why? why not??
9
9
  MINOR = 1
10
- PATCH = 0
10
+ PATCH = 5
11
11
  VERSION = [MAJOR,MINOR,PATCH].join('.')
12
12
 
13
13
  def self.version
@@ -1,6 +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' ))
3
4
  $LOAD_PATH.unshift( File.expand_path( '../sportdb-langs/lib' ))
5
+ $LOAD_PATH.unshift( File.expand_path( '../sportdb-structs/lib' ))
6
+
4
7
 
5
8
 
6
9
  ## minitest setup
@@ -55,12 +58,56 @@ TXT
55
58
  = England
56
59
 
57
60
  Chelsea FC
58
- Arsenal FC
59
61
  Tottenham Hotspur
60
62
  West Ham United
61
63
  Crystal Palace
62
- Manchester United
63
- 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
64
111
  TXT
65
112
 
66
113
  index = ClubIndex.new
@@ -83,81 +130,3 @@ end # module SportDb
83
130
 
84
131
 
85
132
 
86
- ################
87
- ## helper
88
-
89
- def parse_auto_conf( txt, lang: 'en', start: nil )
90
- start = start ? start : Date.new( 2017, 7, 1 )
91
-
92
- SportDb::Import.config.lang = lang
93
-
94
- parser = SportDb::AutoConfParser.new( txt, start )
95
- parser.parse
96
- end
97
-
98
- def parse_conf( txt )
99
- parser = SportDb::ConfParser.new( txt )
100
- parser.parse
101
- end
102
-
103
-
104
- ## note: json always returns hash tables with string keys (not symbols),
105
- ## thus, always stringify keys before comparing!!!!
106
- class Object
107
- def deep_stringify_keys
108
- if self.is_a? Hash
109
- self.reduce({}) {|memo,(k,v)| memo[k.to_s] = v.deep_stringify_keys; memo }
110
- elsif self.is_a? Array
111
- self.reduce([]) {|memo,v | memo << v.deep_stringify_keys; memo }
112
- else
113
- self
114
- end
115
- end
116
- end
117
-
118
-
119
- def read_blocks( path )
120
- txt = File.open( path, 'r:utf-8' ).read
121
-
122
- blocks = []
123
- buf = String.new('')
124
- txt.each_line do |line|
125
- if line =~ /^[ ]*
126
- ([>]{3,} |
127
- [<]{3,})
128
- [ ]*
129
- $/x ## three or more markers
130
- blocks << buf
131
- buf = String.new('')
132
- else
133
- buf << line
134
- end
135
- end
136
- blocks << buf
137
- blocks
138
- end
139
-
140
-
141
- def parse_json( str )
142
- ## note: allow empty string; fall back to empty hash
143
- if str.strip.empty?
144
- {}
145
- else
146
- JSON.parse( str )
147
- end
148
- end
149
-
150
- def read_test( path )
151
- blocks = read_blocks( "#{SportDb::Test.data_dir}/football.txt/#{path}" )
152
-
153
- if blocks.size == 2
154
- [blocks[0], parse_json( blocks[1] )]
155
- elsif blocks.size == 3
156
- ## note: returned in different order
157
- ## optional option block that comes first returned last!
158
- [blocks[1], parse_json( blocks[2] ), blocks[0]]
159
- else
160
- puts "!! ERROR: expected two or three text blocks in >#{path}<; got #{blocks.size}"
161
- exit 1
162
- end
163
- 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