sportdb-formats 0.4.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/Manifest.txt +24 -4
  3. data/Rakefile +3 -3
  4. data/lib/sportdb/formats.rb +25 -2
  5. data/lib/sportdb/formats/config.rb +40 -0
  6. data/lib/sportdb/formats/datafile.rb +42 -62
  7. data/lib/sportdb/formats/datafile_package.rb +160 -0
  8. data/lib/sportdb/formats/match/conf_parser.rb +120 -0
  9. data/lib/sportdb/formats/match/mapper.rb +319 -0
  10. data/lib/sportdb/formats/match/mapper_teams.rb +23 -0
  11. data/lib/sportdb/formats/match/match_parser.rb +659 -0
  12. data/lib/sportdb/formats/match/match_parser_auto_conf.rb +202 -0
  13. data/lib/sportdb/formats/name_helper.rb +84 -0
  14. data/lib/sportdb/formats/outline_reader.rb +53 -15
  15. data/lib/sportdb/formats/package.rb +172 -160
  16. data/lib/sportdb/formats/parser_helper.rb +81 -0
  17. data/lib/sportdb/formats/score/score_formats.rb +180 -0
  18. data/lib/sportdb/formats/score/score_parser.rb +196 -0
  19. data/lib/sportdb/formats/structs/country.rb +1 -43
  20. data/lib/sportdb/formats/structs/group.rb +25 -0
  21. data/lib/sportdb/formats/structs/league.rb +7 -26
  22. data/lib/sportdb/formats/structs/match.rb +72 -51
  23. data/lib/sportdb/formats/structs/round.rb +14 -4
  24. data/lib/sportdb/formats/structs/season.rb +3 -0
  25. data/lib/sportdb/formats/structs/team.rb +144 -0
  26. data/lib/sportdb/formats/version.rb +2 -2
  27. data/test/helper.rb +83 -1
  28. data/test/test_clubs.rb +3 -3
  29. data/test/test_conf.rb +65 -0
  30. data/test/test_datafile.rb +21 -30
  31. data/test/test_match.rb +0 -6
  32. data/test/test_match_auto.rb +72 -0
  33. data/test/test_match_auto_champs.rb +45 -0
  34. data/test/test_match_auto_euro.rb +37 -0
  35. data/test/test_match_auto_worldcup.rb +61 -0
  36. data/test/test_match_champs.rb +27 -0
  37. data/test/test_match_eng.rb +26 -0
  38. data/test/test_match_euro.rb +27 -0
  39. data/test/test_match_worldcup.rb +27 -0
  40. data/test/test_name_helper.rb +67 -0
  41. data/test/test_outline_reader.rb +3 -3
  42. data/test/test_package.rb +21 -2
  43. data/test/test_package_match.rb +78 -0
  44. data/test/test_scores.rb +67 -51
  45. metadata +32 -12
  46. data/lib/sportdb/formats/scores.rb +0 -253
  47. data/lib/sportdb/formats/structs/club.rb +0 -213
  48. data/test/test_club_helpers.rb +0 -63
  49. data/test/test_datafile_match.rb +0 -65
@@ -0,0 +1,27 @@
1
+ # encoding: utf-8
2
+
3
+ ###
4
+ # to run use
5
+ # ruby -I ./lib -I ./test test/test_match_champs.rb
6
+
7
+
8
+ require 'helper'
9
+
10
+
11
+ class TestMatchChamps < MiniTest::Test
12
+
13
+ def test_parse
14
+ txt, exp, teams = read_test( 'match/champs_group.txt' )
15
+
16
+ start = Date.new( 2017, 7, 1 )
17
+
18
+ SportDb::Import.config.lang = 'en'
19
+
20
+ parser = SportDb::MatchParserSimpleV2.new( txt, teams, start )
21
+ matches, rounds, groups = parser.parse
22
+
23
+ pp rounds
24
+ pp groups
25
+ pp matches[-1] ## only dump last record for now
26
+ end # method test_parse
27
+ end # class TestMatchChamps
@@ -0,0 +1,26 @@
1
+ # encoding: utf-8
2
+
3
+ ###
4
+ # to run use
5
+ # ruby -I ./lib -I ./test test/test_match_eng.rb
6
+
7
+
8
+ require 'helper'
9
+
10
+
11
+ class TestMatchEng < MiniTest::Test
12
+
13
+ def test_eng
14
+ txt, exp, teams = read_test( 'match/eng.txt' )
15
+
16
+ SportDb::Import.config.lang = 'en'
17
+
18
+ start = Date.new( 2017, 7, 1 )
19
+
20
+ parser = SportDb::MatchParserSimpleV2.new( txt, teams, start )
21
+ matches, rounds = parser.parse
22
+
23
+ pp rounds
24
+ pp matches[-1] ## only dump last record for now
25
+ end # method test_end
26
+ end # class TestMatchEng
@@ -0,0 +1,27 @@
1
+ # encoding: utf-8
2
+
3
+ ###
4
+ # to run use
5
+ # ruby -I ./lib -I ./test test/test_match_euro.rb
6
+
7
+
8
+ require 'helper'
9
+
10
+
11
+ class TestMatchEuro < MiniTest::Test
12
+
13
+ def test_parse
14
+ txt, exp, teams = read_test( 'match/euro_2016.txt' )
15
+
16
+ start = Date.new( 2016, 1, 1 )
17
+
18
+ SportDb::Import.config.lang = 'en'
19
+
20
+ parser = SportDb::MatchParserSimpleV2.new( txt, teams, start )
21
+ matches, rounds, groups = parser.parse
22
+
23
+ pp rounds
24
+ pp groups
25
+ pp matches[-1] ## only dump last record for now
26
+ end # method test_parse
27
+ end # class TestMatchEuro
@@ -0,0 +1,27 @@
1
+ # encoding: utf-8
2
+
3
+ ###
4
+ # to run use
5
+ # ruby -I ./lib -I ./test test/test_match_worldcup.rb
6
+
7
+
8
+ require 'helper'
9
+
10
+
11
+ class TestMatchWorld < MiniTest::Test
12
+
13
+ def test_parse
14
+ txt, exp, teams = read_test( 'match/worldcup_2018_finals.txt' )
15
+
16
+ start = Date.new( 2018, 1, 1 )
17
+
18
+ SportDb::Import.config.lang = 'en'
19
+
20
+ parser = SportDb::MatchParserSimpleV2.new( txt, teams, start )
21
+ matches, rounds, groups = parser.parse
22
+
23
+ pp rounds
24
+ pp groups
25
+ pp matches[-1] ## only dump last record for now
26
+ end # method test_parse
27
+ end # class TestMatchWorld
@@ -0,0 +1,67 @@
1
+ # encoding: utf-8
2
+
3
+ ###
4
+ # to run use
5
+ # ruby -I ./lib -I ./test test/test_name_helper.rb
6
+
7
+
8
+ require 'helper'
9
+
10
+
11
+ class TestNameHelper < MiniTest::Test
12
+
13
+ include SportDb::NameHelper
14
+
15
+
16
+ def test_strip_norm ## strip (remove) non-norm characters e.g. ()'- etc.
17
+ [['Estudiantes (LP)', 'Estudiantes LP'],
18
+ ['Central Córdoba (SdE)', 'Central Córdoba SdE'],
19
+ ['Saint Patrick’s Athletic FC', 'Saint Patricks Athletic FC'],
20
+ ['Myllykosken Pallo −47', 'Myllykosken Pallo 47'],
21
+ ].each do |rec|
22
+ assert_equal rec[1], strip_norm( rec[0] )
23
+ end
24
+ end
25
+
26
+ def test_strip_year
27
+ [['A (1911-1912)', 'A'],
28
+ ['B (1911-1912, 1913-1915)', 'B'],
29
+ ['C (1911-___)', 'C'],
30
+ ['D (1911-???)', 'D'],
31
+ ['FC Linz (1946-2001, 2013-)', 'FC Linz'],
32
+ ['Admira Wien (-????)', 'Admira Wien'],
33
+ ['Admira Wien (-____)', 'Admira Wien'],
34
+ ].each do |rec|
35
+ assert_equal rec[1], strip_year( rec[0] )
36
+ end
37
+ end
38
+
39
+ def test_strip_lang
40
+ [['Bayern Munich [en]', 'Bayern Munich'],
41
+ ].each do |rec|
42
+ assert_equal rec[1], strip_lang( rec[0] )
43
+ end
44
+ end
45
+
46
+
47
+ def test_variants
48
+ ## hungarian
49
+ assert_equal ['Raba ETO Gyor'], variants( 'Rába ETO Győr' )
50
+ assert_equal ['Raba ETO Gyor', 'Rába ETO Gyoer'], variants( 'Rába ETO Györ' )
51
+
52
+ ## romanian
53
+ assert_equal ['Targu Mures'], variants( 'Târgu Mureș' )
54
+ assert_equal ['Targu Mures'], variants( 'Târgu Mureş' )
55
+ end
56
+
57
+
58
+ =begin
59
+ ### fix: move to ClubReader!!!!! not for general use
60
+ def test_wiki
61
+ assert_equal 'FC Wacker Innsbruck', strip_wiki( 'FC Wacker Innsbruck (2002)' )
62
+ assert_equal 'SK Austria Klagenfurt', strip_wiki( 'SK Austria Klagenfurt (2007)' )
63
+
64
+ assert_equal 'Willem II', strip_wiki( 'Willem II (football club)' )
65
+ end
66
+ =end
67
+ end # class TestNameHelper
@@ -21,11 +21,11 @@ TXT
21
21
 
22
22
  pp outline
23
23
 
24
- assert_equal 3, outline.size
24
+ assert_equal 2, outline.size
25
25
 
26
26
  assert_equal [:h1, 'ÖFB Cup 2011/12'], outline[0]
27
- assert_equal [:l, 'FC Red Bull Salzburg'], outline[1]
28
- assert_equal [:l, 'FK Austria Wien'], outline[2]
27
+ assert_equal [:p, ['FC Red Bull Salzburg',
28
+ 'FK Austria Wien']], outline[1]
29
29
  end
30
30
 
31
31
  end # class TestOutlineReader
data/test/test_package.rb CHANGED
@@ -12,16 +12,35 @@ class TestPackage < MiniTest::Test
12
12
 
13
13
  def test_read
14
14
  [Datafile::DirPackage.new( '../../../openfootball/england' ),
15
- Datafile::ZipPackage.new( 'tmp/england-master.zip' )].each do |eng|
15
+ Datafile::ZipPackage.new( 'tmp/england-master.zip' )
16
+ ].each do |eng|
16
17
  assert eng.find( '2015-16/.conf.txt' ).read.start_with?( '= English Premier League 2015/16' )
17
18
  assert eng.find( '2017-18/.conf.txt' ).read.start_with?( '= English Premier League 2017/18' )
18
19
  assert eng.find( '2015-16/1-premierleague-i.txt' ).read.start_with?( '= English Premier League 2015/16' )
19
20
  end
20
21
 
21
22
  [Datafile::DirPackage.new( '../../../openfootball/austria' ),
22
- Datafile::ZipPackage.new( 'tmp/austria-master.zip' )].each do |at|
23
+ Datafile::ZipPackage.new( 'tmp/austria-master.zip' )
24
+ ].each do |at|
23
25
  assert at.find( '2018-19/.conf.txt' ).read.start_with?( '= Österr. Bundesliga 2018/19' )
24
26
  end
27
+
28
+ puts "DirPackage:"
29
+ pack = Datafile::DirPackage.new( '../../../openfootball/austria' )
30
+ puts pack.name
31
+ puts " entries:"
32
+ pack.each( pattern: /\.txt$/ ) do |entry|
33
+ puts entry.name
34
+ end
35
+
36
+ puts "ZipPackage:"
37
+ pack = Datafile::ZipPackage.new( 'tmp/austria-master.zip' )
38
+ puts pack.name
39
+ puts " entries:"
40
+ pack.each( pattern: /\.txt$/ ) do |entry|
41
+ puts entry.name
42
+ end
43
+
25
44
  end # method test_read
26
45
 
27
46
  end # class TestPackage
@@ -0,0 +1,78 @@
1
+ # encoding: utf-8
2
+
3
+ ###
4
+ # to run use
5
+ # ruby -I ./lib -I ./test test/test_package_match.rb
6
+
7
+
8
+ require 'helper'
9
+
10
+ class TestPackageMatch < MiniTest::Test
11
+
12
+ CLUBS_DIR = '../../../openfootball/clubs' ## source repo directory path
13
+ LEAGUES_DIR = '../../../openfootball/leagues'
14
+ AUSTRIA_DIR = '../../../openfootball/austria'
15
+
16
+ def test_find
17
+ datafiles = SportDb::Package.find_clubs( CLUBS_DIR )
18
+ pp datafiles
19
+
20
+ datafiles = SportDb::Package.find_clubs_wiki( CLUBS_DIR )
21
+ pp datafiles
22
+
23
+ datafiles = SportDb::Package.find_leagues( LEAGUES_DIR )
24
+ pp datafiles
25
+
26
+ datafiles = SportDb::Package.find_conf( AUSTRIA_DIR )
27
+ pp datafiles
28
+ end
29
+
30
+
31
+ CLUBS_TXT = [ ## with country code
32
+ 'de.clubs.txt',
33
+ 'deutschland/de.clubs.txt',
34
+ ## without country code
35
+ 'europe/de-deutschland/clubs.txt',
36
+ 'de-deutschland/clubs.txt',
37
+ 'deutschland/clubs.txt',
38
+ 'clubs.txt' ]
39
+
40
+ CLUBS_WIKI_TXT = [ ## with country code
41
+ 'de.clubs.wiki.txt',
42
+ 'deutschland/de.clubs.wiki.txt',
43
+ ## without country code
44
+ 'europe/de-deutschland/clubs.wiki.txt',
45
+ 'de-deutschland/clubs.wiki.txt',
46
+ 'deutschland/clubs.wiki.txt',
47
+ 'clubs.wiki.txt' ]
48
+
49
+ LEAGUES_TXT = [ 'europe/england/leagues.txt',
50
+ 'england/leagues.txt',
51
+ 'leagues.txt' ]
52
+
53
+ CONF_TXT = [ 'austria/archives/2000s/2001-02/.conf.txt',
54
+ 'austria/2019-20/.conf.txt',
55
+ '.conf.txt' ]
56
+
57
+
58
+ def test_match_clubs
59
+ CLUBS_TXT.each { |path| assert SportDb::Package.match_clubs?( path ) }
60
+
61
+ CLUBS_WIKI_TXT.each { |path| assert !SportDb::Package.match_clubs?( path ) }
62
+ end
63
+
64
+ def test_match_clubs_wiki
65
+ CLUBS_WIKI_TXT.each { |path| assert SportDb::Package.match_clubs_wiki?( path ) }
66
+
67
+ CLUBS_TXT.each { |path| assert !SportDb::Package.match_clubs_wiki?( path ) }
68
+ end
69
+
70
+ def test_match_leagues
71
+ LEAGUES_TXT.each { |path| assert SportDb::Package.match_leagues?( path ) }
72
+ end
73
+
74
+ def test_match_conf
75
+ CONF_TXT.each { |path| assert SportDb::Package.match_conf?( path ) }
76
+ end
77
+
78
+ end # class TestPackageMatch
data/test/test_scores.rb CHANGED
@@ -9,62 +9,69 @@ require 'helper'
9
9
 
10
10
  class TestScores < MiniTest::Test
11
11
 
12
+ def test_de
13
+ ScoreFormats.lang = :de
14
+ data = [
15
+ [ '10:0', [nil,nil,10,0]],
16
+ [ '1:22', [nil,nil,1,22]],
17
+ [ '1-22', [nil,nil,1,22]],
18
+
19
+ ## do not support three digits for now - why? why not?
20
+ [ '1:222', []],
21
+ [ '111:0', []],
22
+ [ '1-222', []],
23
+ [ '111-0', []],
24
+
25
+ [ '2:2 (1:1, 1:0) n.V. 5:1 i.E.', [1,0,1,1,2,2,5,1]],
26
+ [ '2:2 (1:1, 1:0) n.V.', [1,0,1,1,2,2]],
27
+ [ '2:2 (1:1, ) n.V. 5:1 i.E.', [nil,nil,1,1,2,2,5,1]],
28
+ [ '2:2 (1:1, ) n.V.', [nil,nil,1,1,2,2]],
29
+
30
+ [ '2:2 (1:1) n.V. 5:1 i.E.', [nil,nil,1,1,2,2,5,1]],
31
+ [ '2:2 (1:1) n.V.', [nil,nil,1,1,2,2]],
32
+
33
+ [ '2-2 (1-1, 1-0) n.V. 5-1 i.E.', [1,0,1,1,2,2,5,1]],
34
+ [ '2-2 (1-1, 1-0) n.V.', [1,0,1,1,2,2]],
35
+ [ '2-2 (1-1, ) n.V. 5-1 i.E.', [nil,nil,1,1,2,2,5,1]],
36
+ [ '2-2 (1-1, ) n.V.', [nil,nil,1,1,2,2]],
37
+
38
+ [ '2 : 2 ( 1 : 1 , 1 : 0 ) n.V. 5 : 1 i.E.', [1,0,1,1,2,2,5,1]],
39
+ [ '2 : 2 ( 1 : 1 , 1 : 0 ) n.V.', [1,0,1,1,2,2]],
40
+ [ '2 : 2 ( 1 : 1 , ) n.V. 5 : 1 i.E.', [nil,nil,1,1,2,2,5,1]],
41
+ [ '2 : 2 ( 1 : 1 , ) n.V.', [nil,nil,1,1,2,2]],
42
+ ]
43
+
44
+ assert_score( data )
45
+ end
46
+
47
+ def test_en
48
+ ScoreFormats.lang = :en
12
49
 
13
- def test_scores
14
50
  data = [
15
- [ '10:0', [nil,nil,10,0]],
16
- [ '1:22', [nil,nil,1,22]],
17
51
  [ '1-22', [nil,nil,1,22]],
18
52
  [ '1x22', [nil,nil,1,22]],
19
53
  [ '1X22', [nil,nil,1,22]],
20
54
 
21
-
22
- ## do not support three digits
55
+ ## do not support three digits for now - why? why not?
23
56
  [ '1-222', []],
24
57
  [ '111-0', []],
25
- [ '1:222', []],
26
- [ '111:0', []],
27
58
  [ '111x0', []],
28
59
  [ '111X0', []],
29
60
 
30
- ## penality only
31
- [ '3-4iE', [nil,nil,nil,nil,nil,nil,3,4]],
32
- [ '3:4iE', [nil,nil,nil,nil,nil,nil,3,4]],
33
- [ '3:4 iE', [nil,nil,nil,nil,nil,nil,3,4]],
34
- [ '3:4 i.E.', [nil,nil,nil,nil,nil,nil,3,4]],
35
- [ '3-4 pen', [nil,nil,nil,nil,nil,nil,3,4]],
36
- [ '3-4 PSO', [nil,nil,nil,nil,nil,nil,3,4]], # PSO => penalty shotout
37
- [ '3-4p', [nil,nil,nil,nil,nil,nil,3,4]],
38
- [ '3-4 p', [nil,nil,nil,nil,nil,nil,3,4]],
39
-
40
- ## extra time only - allow ?? why not ?? only allow penalty w/ missing extra time?
41
- ## todo/fix: issue warning or error in parser!!!
42
- [ '3-4nV', [nil,nil,nil,nil,3,4]],
43
- [ '3:4nV', [nil,nil,nil,nil,3,4]],
44
- [ '3-4 aet', [nil,nil,nil,nil,3,4]],
45
- [ '3-4 a.e.t.', [nil,nil,nil,nil,3,4]],
46
-
47
- [ '3:4nV 1:1', [nil,nil,1,1,3,4]],
48
- [ '1:1 3:4nV', [nil,nil,1,1,3,4]],
49
- [ '3:4 nV 1:1', [nil,nil,1,1,3,4]],
50
- [ '3:4 n.V. 1:1', [nil,nil,1,1,3,4]],
51
-
52
- [ '3:4iE 1:1', [nil,nil,1,1,nil,nil,3,4]],
53
- [ '1:1 3:4iE', [nil,nil,1,1,nil,nil,3,4]],
54
-
55
- [ '1:1 2:2nV 3:4iE', [nil,nil,1,1,2,2,3,4]],
56
- [ '3:4iE 2:2nV 1:1', [nil,nil,1,1,2,2,3,4]],
57
- [ '3:4 i.E. 2:2 n.V. 1:1', [nil,nil,1,1,2,2,3,4]],
58
- [ '3-4p 2-2aet 1-1', [nil,nil,1,1,2,2,3,4]],
59
- [ '3-4 pen 2-2 aet 1-1', [nil,nil,1,1,2,2,3,4]],
60
-
61
- #####################################################
62
- ## check new all-in-one english (en) formats / patterns
61
+ ## do not support colon sep for now in en locale - why? why not?
62
+ [ '2:1', []],
63
+ [ '2:1 (1:1)', []],
64
+
65
+
63
66
  [ '2-1 (1-1)', [1,1,2,1]],
67
+ [ '2x1 (1x1)', [1,1,2,1]],
68
+ [ '2X1 (1X1)', [1,1,2,1]],
69
+
64
70
  [ '2-1 a.e.t. (1-1, 0-0)', [0,0,1,1,2,1]],
65
71
  [ '2-1aet (1-1, 0-0)', [0,0,1,1,2,1]],
66
72
  [ '2-1 A.E.T. (1-1, 0-0)', [0,0,1,1,2,1]],
67
73
  [ '2-1AET (1-1, 0-0)', [0,0,1,1,2,1]],
74
+
68
75
  [ '3-4 pen. 2-2 a.e.t. (1-1, 1-1)', [1,1,1,1,2,2,3,4]],
69
76
  [ '3-4 pen 2-2 a.e.t. (1-1, 1-1)', [1,1,1,1,2,2,3,4]],
70
77
  [ '3-4 pen 2-2 a.e.t. (1-1, 1-1)', [1,1,1,1,2,2,3,4]],
@@ -74,24 +81,33 @@ class TestScores < MiniTest::Test
74
81
  [ '4-3 pen. 1-0 a.e.t. (1-0, )', [nil,nil,1,0,1,0,4,3]],
75
82
  [ '3-4 pen. 2-1 a.e.t. (2-1, )', [nil,nil,2,1,2,1,3,4]],
76
83
  [ '4-1 a.e.t. (3-1, )', [nil,nil,3,1,4,1]],
77
- ]
84
+ [ '3-4aet (1-1,)', [nil,nil,1,1,3,4]],
85
+ [ '3-4 a.e.t. (1-1,)', [nil,nil,1,1,3,4]],
86
+
87
+ [ '4-3 pen. 1-0 a.e.t. (1-0)', [nil,nil,1,0,1,0,4,3]],
88
+ [ '3-4 pen. 2-1 a.e.t. (2-1)', [nil,nil,2,1,2,1,3,4]],
89
+ [ '4-1 a.e.t. (3-1)', [nil,nil,3,1,4,1]],
90
+ [ '3-4aet (1-1)', [nil,nil,1,1,3,4]],
91
+ [ '3-4 a.e.t. (1-1)', [nil,nil,1,1,3,4]],
92
+
93
+ [ '3-1 pen (1-1)', [nil,nil,1,1, nil, nil, 3,1]],
78
94
 
79
- assert_scores( data )
95
+ ## try with more "liberal" spaces
96
+ [ '2 - 1 ( 1 - 1 )', [1,1,2,1]],
97
+ [ '2 - 1 a.e.t. ( 1 - 1 , 0 - 0 )', [0,0,1,1,2,1]],
98
+ [ '4 - 1 a.e.t. ( 3 - 1, )', [nil,nil,3,1,4,1]],
99
+ ]
100
+
101
+ assert_score( data )
80
102
  end
81
103
 
82
104
  private
83
- def assert_scores( data )
105
+ def assert_score( data )
84
106
  data.each do |rec|
85
- line = rec[0]
107
+ line = rec[0].dup
86
108
  exp = rec[1]
87
109
 
88
- assert_equal exp, parse_scores( line )
110
+ assert_equal exp, ScoreFormats.find!( line ).to_a, "failed >#{rec[0]}< - >#{line}<"
89
111
  end
90
112
  end
91
-
92
- def parse_scores( line )
93
- finder = SportDb::ScoresFinder.new
94
- finder.find!( line )
95
- end
96
-
97
113
  end # class TestScores