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
@@ -1,88 +0,0 @@
1
- # encoding: utf-8
2
-
3
-
4
- module SportDb
5
- module Import
6
-
7
-
8
- class TeamUsage
9
-
10
- class TeamUsageLine ## nested class
11
- attr_accessor :team,
12
- :matches, ## number of matches (played),
13
- :seasons, ## (optianl) array of seasons, use seasons.size for count
14
- :levels ## (optional) hash of levels (holds mapping level to TeamUsageLine)
15
-
16
- def initialize( team )
17
- @team = team
18
-
19
- @matches = 0
20
- @seasons = []
21
- @levels = {}
22
- end
23
- end # (nested) class TeamUsageLine
24
-
25
-
26
-
27
- def initialize( opts={} )
28
- @lines = {} # StandingsLines cached by team name/key
29
- end
30
-
31
-
32
- def update( matches, season: '?', level: nil )
33
- ## convenience - update all matches at once
34
- matches.each_with_index do |match,i| # note: index(i) starts w/ zero (0)
35
- update_match( match, season: season, level: level )
36
- end
37
- self # note: return self to allow chaining
38
- end
39
-
40
- def to_a
41
- ## return lines; sort
42
-
43
- # build array from hash
44
- ary = []
45
- @lines.each do |k,v|
46
- ary << v
47
- end
48
-
49
- ## for now sort just by name (a-z)
50
- ary.sort! do |l,r|
51
- ## note: reverse order (thus, change l,r to r,l)
52
- l.team <=> r.team
53
- end
54
-
55
- ary
56
- end # to_a
57
-
58
-
59
- private
60
- def update_match( m, season: '?', level: nil ) ## add a match
61
-
62
- line1 = @lines[ m.team1 ] ||= TeamUsageLine.new( m.team1 )
63
- line2 = @lines[ m.team2 ] ||= TeamUsageLine.new( m.team2 )
64
-
65
- line1.matches +=1
66
- line2.matches +=1
67
-
68
- ## include season if not seen before (allow season in multiple files!!!)
69
- line1.seasons << season unless line1.seasons.include?( season )
70
- line2.seasons << season unless line2.seasons.include?( season )
71
-
72
- if level
73
- line1_level = line1.levels[ level ] ||= TeamUsageLine.new( m.team1 )
74
- line2_level = line2.levels[ level ] ||= TeamUsageLine.new( m.team2 )
75
-
76
- line1_level.matches +=1
77
- line2_level.matches +=1
78
-
79
- line1_level.seasons << season unless line1_level.seasons.include?( season )
80
- line2_level.seasons << season unless line2_level.seasons.include?( season )
81
- end
82
- end # method update_match
83
-
84
-
85
- end # class TeamUsage
86
-
87
- end # module Import
88
- end # module SportDb
@@ -1,40 +0,0 @@
1
- # encoding: utf-8
2
-
3
- ###
4
- # to run use
5
- # ruby -I ./lib -I ./test test/test_clubs.rb
6
-
7
-
8
- require 'helper'
9
-
10
- class TestClubs < MiniTest::Test
11
-
12
- Club = SportDb::Import::Club
13
-
14
-
15
- def test_new
16
- club = Club.new( name: 'Rapid Wien' )
17
-
18
- assert_equal 'Rapid Wien', club.name
19
- assert_equal ['Rapid Wien'], club.names
20
- end
21
-
22
- def test_duplicates
23
- club = Club.new
24
- club.name = 'Rapid Wien'
25
-
26
- assert_equal false, club.duplicates?
27
- duplicates = {}
28
- assert_equal duplicates, club.duplicates
29
-
30
- club.alt_names_auto += ['Rapid', 'Rapid Wien', 'SK Rapid Wien']
31
-
32
- pp club
33
-
34
- assert_equal true, club.duplicates?
35
- duplicates = {'rapidwien'=>['Rapid Wien','Rapid Wien']}
36
- pp club.duplicates
37
- assert_equal duplicates, club.duplicates
38
- end
39
-
40
- end # class TestClubs
@@ -1,65 +0,0 @@
1
- # encoding: utf-8
2
-
3
- ###
4
- # to run use
5
- # ruby -I ./lib -I ./test test/test_conf.rb
6
-
7
-
8
- require 'helper'
9
-
10
-
11
- class TestConf < MiniTest::Test
12
-
13
- COUNTRY_RE = SportDb::ConfParser::COUNTRY_RE
14
- TABLE_RE = SportDb::ConfParser::TABLE_RE
15
-
16
- def test_re
17
- m=COUNTRY_RE.match( 'Manchester United › ENG' )
18
- pp m
19
- pp m[0]
20
- assert_equal 'ENG', m[:country]
21
-
22
- m=COUNTRY_RE.match( 'Manchester United›ENG' )
23
- pp m
24
- pp m[0]
25
- assert_equal 'ENG', m[:country]
26
-
27
-
28
- m=TABLE_RE.match( '1 Manchester City 38 32 4 2 106-27 100' )
29
- pp m
30
- assert_equal 'Manchester City', m[:team]
31
-
32
- m=TABLE_RE.match( '1. Manchester City 38 32 4 2 106:27 100' )
33
- pp m
34
- assert_equal 'Manchester City', m[:team]
35
-
36
- m=TABLE_RE.match( '- Manchester City 38 32 4 2 106 - 27 100' )
37
- pp m
38
- assert_equal 'Manchester City', m[:team]
39
-
40
-
41
- m=TABLE_RE.match( '1. 1. FC Mainz 38 32 4 2 106-27 100 [-7]' )
42
- pp m
43
- assert_equal '1. FC Mainz', m[:team]
44
- end
45
-
46
-
47
- def test_conf
48
- %w[conf/at_cup.txt
49
- conf/at_reg.txt
50
- conf/at_champs.txt
51
- conf/eng.txt
52
- conf/champs.txt
53
- ].each do |path|
54
- txt, exp = read_test( path )
55
-
56
- puts "testing conf #{path}..."
57
- teams = parse_conf( txt )
58
-
59
- ## note: json always returns hash tables with string keys (not symbols),
60
- ## thus, always stringify keys before comparing!!!!
61
- assert_equal exp, teams.deep_stringify_keys
62
- end
63
- end
64
-
65
- end # class TestConf
@@ -1,114 +0,0 @@
1
- # encoding: utf-8
2
-
3
- ###
4
- # to run use
5
- # ruby -I ./lib -I ./test test/test_csv_match_parser.rb
6
-
7
-
8
- require 'helper'
9
-
10
-
11
- class TestCsvMatchParser < MiniTest::Test
12
-
13
- ##
14
- # Div,Date,HomeTeam,AwayTeam,FTHG,FTAG,FTR,HTHG,HTAG,HTR,
15
- # Referee,HS,AS,HST,AST,HF,AF,HC,AC,HY,AY,HR,AR,
16
- # B365H,B365D,B365A,BWH,BWD,BWA,IWH,IWD,IWA,LBH,LBD,LBA,PSH,PSD,PSA,
17
- # WHH,WHD,WHA,VCH,VCD,VCA,
18
- # Bb1X2,BbMxH,BbAvH,BbMxD,BbAvD,BbMxA,BbAvA,BbOU,BbMx>2.5,BbAv>2.5,BbMx<2.5,BbAv<2.5,
19
- # BbAH,BbAHh,BbMxAHH,BbAvAHH,BbMxAHA,BbAvAHA,PSCH,PSCD,PSCA
20
- def test_eng_filters
21
- path = "#{SportDb::Test.data_dir}/england/2017-18/E0.csv"
22
-
23
- matches = SportDb::CsvMatchParser.read( path,
24
- filters: { 'HomeTeam' => 'Arsenal' } )
25
-
26
- pp path
27
- pp matches[0..2]
28
-
29
- m=matches[0]
30
- assert_equal '2017-08-11', m.date
31
- assert_equal 4, m.score1
32
- assert_equal 3, m.score2
33
- assert_equal 2, m.score1i
34
- assert_equal 2, m.score2i
35
- assert_equal 'Arsenal', m.team1
36
- assert_equal 'Leicester', m.team2
37
-
38
- m=matches[1]
39
- assert_equal '2017-09-09', m.date
40
- assert_equal 3, m.score1
41
- assert_equal 0, m.score2
42
- assert_equal 2, m.score1i
43
- assert_equal 0, m.score2i
44
- assert_equal 'Arsenal', m.team1
45
- assert_equal 'Bournemouth', m.team2
46
- end
47
-
48
-
49
- def test_eng_headers
50
- path = "#{SportDb::Test.data_dir}/england/2017-18/E0.csv"
51
-
52
- headers = { team1: 'HomeTeam',
53
- team2: 'AwayTeam',
54
- date: 'Date',
55
- score1: 'FTHG',
56
- score2: 'FTAG' }
57
-
58
- matches = SportDb::CsvMatchParser.read( path, headers: headers )
59
-
60
- pp path
61
- pp matches[0..2]
62
-
63
- m=matches[0]
64
- assert_equal '2017-08-11', m.date
65
- assert_equal 4, m.score1
66
- assert_equal 3, m.score2
67
- assert_nil m.score1i ## todo/fix: missing half time (ht) score !!!!
68
- assert_nil m.score2i ## todo/fix: missing half time (ht) score !!!!
69
- assert_equal 'Arsenal', m.team1
70
- assert_equal 'Leicester', m.team2
71
-
72
- m=matches[1]
73
- assert_equal '2017-08-12', m.date
74
- assert_equal 0, m.score1
75
- assert_equal 2, m.score2
76
- assert_nil m.score1i ## todo/fix: missing half time (ht) score !!!!
77
- assert_nil m.score2i ## todo/fix: missing half time (ht) score !!!!
78
- assert_equal 'Brighton', m.team1
79
- assert_equal 'Man City', m.team2
80
- end
81
-
82
-
83
- ###
84
- # Country,League,Season,Date,Time,Home,Away,HG,AG,
85
- # Res,PH,PD,PA,MaxH,MaxD,MaxA,AvgH,AvgD,AvgA
86
- def test_at
87
- path = "#{SportDb::Test.data_dir}/austria/AUT.csv"
88
-
89
- matches = SportDb::CsvMatchParser.read( path, filters: { 'Season' => '2017/2018' } )
90
-
91
- pp matches[0..2]
92
- pp path
93
-
94
- m=matches[0]
95
- assert_equal '2017-07-22', m.date
96
- assert_equal 2, m.score1
97
- assert_equal 2, m.score2
98
- assert_nil m.score1i ## todo/fix: missing half time (ht) score !!!!
99
- assert_nil m.score2i ## todo/fix: missing half time (ht) score !!!!
100
- assert_equal 'Rapid Vienna', m.team1
101
- assert_equal 'Mattersburg', m.team2
102
-
103
- m=matches[1]
104
- assert_equal '2017-07-22', m.date
105
- assert_equal 0, m.score1
106
- assert_equal 2, m.score2
107
- assert_nil m.score1i ## todo/fix: missing half time (ht) score !!!!
108
- assert_nil m.score2i ## todo/fix: missing half time (ht) score !!!!
109
- assert_equal 'AC Wolfsberger', m.team1
110
- assert_equal 'Salzburg', m.team2
111
- end
112
-
113
-
114
- end # class TestCsvMatchParser
@@ -1,20 +0,0 @@
1
- # encoding: utf-8
2
-
3
- ###
4
- # to run use
5
- # ruby -I ./lib -I ./test test/test_csv_match_parser_utils.rb
6
-
7
-
8
- require 'helper'
9
-
10
- class TestCsvMatchParserUtils < MiniTest::Test
11
-
12
- def test_find_seasons
13
- pp = SportDb::CsvMatchParser.find_seasons( "#{SportDb::Test.data_dir}/dl/AUT.csv" ) ## defaults to col: 'Season', col_sep: ','
14
- pp = SportDb::CsvMatchParser.find_seasons( "#{SportDb::Test.data_dir}/dl/Bundesliga_1963_2014.csv", col: 'Saison', sep: ';' )
15
- assert true
16
- end
17
-
18
- end # class TestCsvMatchParserUtils
19
-
20
-
@@ -1,31 +0,0 @@
1
- # encoding: utf-8
2
-
3
- ###
4
- # to run use
5
- # ruby -I ./lib -I ./test test/test_csv_reader.rb
6
-
7
-
8
- require 'helper'
9
-
10
- class TestCsvReader < MiniTest::Test
11
-
12
- def test_parse
13
- recs = parse_csv( <<TXT )
14
- ### World Countries
15
-
16
- Key, Code, Name
17
- af, AFG, Afghanistan
18
- al, ALB, Albania
19
- dz, ALG, Algeria
20
- as, ASA, American Samoa (US)
21
- TXT
22
-
23
- pp recs
24
- assert_equal [{ 'Key' => 'af', 'Code' => 'AFG', 'Name' => 'Afghanistan'},
25
- { 'Key' => 'al', 'Code' => 'ALB', 'Name' => 'Albania'},
26
- { 'Key' => 'dz', 'Code' => 'ALG', 'Name' => 'Algeria'},
27
- { 'Key' => 'as', 'Code' => 'ASA', 'Name' => 'American Samoa (US)'},
28
- ], recs[0..3]
29
- end
30
-
31
- end # class TestCsvReader
@@ -1,30 +0,0 @@
1
- # encoding: utf-8
2
-
3
- ###
4
- # to run use
5
- # ruby -I ./lib -I ./test test/test_match.rb
6
-
7
-
8
- require 'helper'
9
-
10
- class TestMatch < MiniTest::Test
11
-
12
- Match = SportDb::Import::Match
13
-
14
-
15
- def test_round
16
- m = Match.new( team1: 'Team 1',
17
- team2: 'Team 2',
18
- round: 3 )
19
- pp m
20
- assert_equal 3, m.round
21
- assert_nil m.score1
22
- assert_nil m.score2
23
-
24
- m = Match.new
25
- m.update( round: 4 )
26
- pp m
27
- assert_equal 4, m.round
28
- end # method test_round
29
-
30
- end # class TestMatch
@@ -1,72 +0,0 @@
1
- # encoding: utf-8
2
-
3
- ###
4
- # to run use
5
- # ruby -I ./lib -I ./test test/test_match_auto.rb
6
-
7
-
8
- require 'helper'
9
-
10
-
11
- class TestMatchAuto < MiniTest::Test
12
-
13
- def test_pt
14
- txt, exp = read_test( 'match_auto/pt/br.txt' )
15
-
16
- teams, rounds = parse_auto_conf( txt, lang: 'pt' )
17
-
18
- assert_equal exp['teams'], teams.deep_stringify_keys
19
- assert_equal exp['rounds'], rounds.deep_stringify_keys
20
- end
21
-
22
-
23
- def test_de
24
- txt, exp = read_test( 'match_auto/de/at.txt' )
25
-
26
- teams, rounds = parse_auto_conf( txt, lang: 'de' )
27
-
28
- assert_equal exp['teams'], teams.deep_stringify_keys
29
- assert_equal exp['rounds'], rounds.deep_stringify_keys
30
- end
31
-
32
- def test_es
33
- %w[match_auto/es/es.txt
34
- match_auto/es/mx.txt
35
- ].each do |path|
36
- txt, exp = read_test( path )
37
-
38
- puts "testing match auto conf #{path}..."
39
- teams, rounds = parse_auto_conf( txt, lang: 'es' )
40
-
41
- assert_equal exp['teams'], teams.deep_stringify_keys
42
- assert_equal exp['rounds'], rounds.deep_stringify_keys
43
- end
44
- end
45
-
46
-
47
- def test_fr
48
- txt, exp = read_test( 'match_auto/fr/fr.txt' )
49
-
50
- teams, rounds = parse_auto_conf( txt, lang: 'fr' )
51
-
52
- assert_equal exp['teams'], teams.deep_stringify_keys
53
- assert_equal exp['rounds'], rounds.deep_stringify_keys
54
- end
55
-
56
-
57
- def test_en
58
- %w[match_auto/eng.txt
59
- match_auto/eng_ii.txt
60
- match_auto/mu.txt
61
- ].each do |path|
62
- txt, exp = read_test( path )
63
-
64
- puts "testing match auto conf #{path}..."
65
- teams, rounds = parse_auto_conf( txt )
66
-
67
- assert_equal exp['teams'], teams.deep_stringify_keys
68
- assert_equal exp['rounds'], rounds.deep_stringify_keys
69
- end
70
- end # method test_parse
71
-
72
- end # class TestMatchAuto