sportdb-formats 1.1.3 → 1.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/Manifest.txt +0 -24
  3. data/Rakefile +2 -5
  4. data/lib/sportdb/formats.rb +39 -74
  5. data/lib/sportdb/formats/event/event_reader.rb +1 -1
  6. data/lib/sportdb/formats/league/league_outline_reader.rb +18 -6
  7. data/lib/sportdb/formats/package.rb +2 -2
  8. data/lib/sportdb/formats/team/club_index_history.rb +2 -6
  9. data/lib/sportdb/formats/team/club_reader_history.rb +1 -1
  10. data/lib/sportdb/formats/team/club_reader_props.rb +18 -2
  11. data/lib/sportdb/formats/version.rb +1 -1
  12. data/test/helper.rb +3 -0
  13. metadata +5 -71
  14. data/lib/sportdb/formats/config.rb +0 -40
  15. data/lib/sportdb/formats/match/match_parser_csv.rb +0 -458
  16. data/lib/sportdb/formats/match/match_status_parser.rb +0 -86
  17. data/lib/sportdb/formats/name_helper.rb +0 -87
  18. data/lib/sportdb/formats/score/score_formats.rb +0 -239
  19. data/lib/sportdb/formats/score/score_parser.rb +0 -204
  20. data/lib/sportdb/formats/season_utils.rb +0 -16
  21. data/lib/sportdb/formats/structs/country.rb +0 -31
  22. data/lib/sportdb/formats/structs/group.rb +0 -18
  23. data/lib/sportdb/formats/structs/league.rb +0 -37
  24. data/lib/sportdb/formats/structs/match.rb +0 -157
  25. data/lib/sportdb/formats/structs/matchlist.rb +0 -220
  26. data/lib/sportdb/formats/structs/round.rb +0 -25
  27. data/lib/sportdb/formats/structs/season.rb +0 -192
  28. data/lib/sportdb/formats/structs/standings.rb +0 -268
  29. data/lib/sportdb/formats/structs/team.rb +0 -157
  30. data/lib/sportdb/formats/structs/team_usage.rb +0 -88
  31. data/test/test_clubs.rb +0 -40
  32. data/test/test_csv_reader.rb +0 -31
  33. data/test/test_match.rb +0 -30
  34. data/test/test_match_status_parser.rb +0 -49
  35. data/test/test_name_helper.rb +0 -67
  36. data/test/test_scores.rb +0 -124
  37. data/test/test_season.rb +0 -111
@@ -1,157 +0,0 @@
1
- # encoding: utf-8
2
-
3
- module SportDb
4
- module Import
5
-
6
-
7
- ##
8
- ## todo/fix: remove self.create in structs!!! use just new!!!
9
-
10
- class Team
11
- ## todo: use just names for alt_names - why? why not?
12
- attr_accessor :key, :name, :alt_names,
13
- :code, ## code == abbreviation e.g. ARS etc.
14
- :year, :year_end, ## todo/fix: change year to start_year and year_end to end_year (like in season)!!!
15
- :country
16
-
17
-
18
- def names
19
- ## todo/check: add alt_names_auto too? - why? why not?
20
- [@name] + @alt_names
21
- end ## all names
22
-
23
- def key
24
- ## note: auto-generate key "on-the-fly" if missing for now - why? why not?
25
- ## note: quick hack - auto-generate key, that is, remove all non-ascii chars and downcase
26
- @key || @name.downcase.gsub( /[^a-z]/, '' )
27
- end
28
-
29
-
30
- ## special import only attribs
31
- attr_accessor :alt_names_auto ## auto-generated alt names
32
- attr_accessor :wikipedia # wikipedia page name (for english (en))
33
-
34
-
35
- def historic?() @year_end ? true : false; end
36
- alias_method :past?, :historic?
37
-
38
- def wikipedia?() @wikipedia; end
39
- def wikipedia_url
40
- if @wikipedia
41
- ## note: replace spaces with underscore (-)
42
- ## e.g. Club Brugge KV => Club_Brugge_KV
43
- ## todo/check/fix:
44
- ## check if "plain" dash (-) needs to get replaced with typographic dash??
45
- "https://en.wikipedia.org/wiki/#{@wikipedia.gsub(' ','_')}"
46
- else
47
- nil
48
- end
49
- end
50
-
51
-
52
- def initialize( **kwargs )
53
- @alt_names = []
54
- @alt_names_auto = []
55
-
56
- update( kwargs ) unless kwargs.empty?
57
- end
58
-
59
- def update( **kwargs )
60
- @key = kwargs[:key] if kwargs.has_key? :key
61
- @name = kwargs[:name] if kwargs.has_key? :name
62
- @code = kwargs[:code] if kwargs.has_key? :code
63
- @alt_names = kwargs[:alt_names] if kwargs.has_key? :alt_names
64
- self ## note - MUST return self for chaining
65
- end
66
-
67
-
68
- ## add convenience lookup helper / method for name by season for now
69
- ## use clubs history - for now kept separate from struct - why? why not?
70
- def name_by_season( season )
71
- ## note: returns / fallback to "regular" name if no records found in history
72
- SportDb::Import.catalog.clubs_history.find_name_by( name: name, season: season ) || name
73
- end
74
-
75
- ## helper methods for import only
76
- ## check for duplicates
77
- include NameHelper
78
-
79
- def duplicates?
80
- names = [name] + alt_names + alt_names_auto
81
- names = names.map { |name| normalize( sanitize(name) ) }
82
-
83
- names.size != names.uniq.size
84
- end
85
-
86
- def duplicates
87
- names = [name] + alt_names + alt_names_auto
88
-
89
- ## calculate (count) frequency and select if greater than one
90
- names.reduce( {} ) do |h,name|
91
- norm = normalize( sanitize(name) )
92
- h[norm] ||= []
93
- h[norm] << name; h
94
- end.select { |norm,names| names.size > 1 }
95
- end
96
-
97
-
98
- def add_variants( name_or_names )
99
- names = name_or_names.is_a?(Array) ? name_or_names : [name_or_names]
100
- names.each do |name|
101
- name = sanitize( name )
102
- self.alt_names_auto += variants( name )
103
- end
104
- end
105
- end # class Team
106
-
107
-
108
-
109
- class NationalTeam < Team
110
- def initialize( **kwargs )
111
- super
112
- end
113
-
114
- def update( **kwargs )
115
- super
116
- self ## note - MUST return self for chaining
117
- end
118
-
119
- end # class NationalTeam
120
-
121
-
122
- ########
123
- # more attribs - todo/fix - also add "upstream" to struct & model!!!!!
124
- # district, geos, year_end, country, etc.
125
-
126
- class Club < Team
127
- attr_accessor :ground
128
-
129
- attr_accessor :a, :b
130
- def a?() @a == nil; end ## is a (1st) team / club (i)? if a is NOT set
131
- def b?() @a != nil; end ## is b (2nd/reserve/jr) team / club (ii) if a is set
132
-
133
- ## note: delegate/forward all geo attributes for team b for now (to team a) - keep - why? why not?
134
- attr_writer :city, :district, :geos
135
- def city() @a == nil ? @city : @a.city; end
136
- def district() @a == nil ? @district : @a.district; end
137
- def country() @a == nil ? @country : @a.country; end
138
- def geos() @a == nil ? @geos : @a.geos; end
139
-
140
-
141
- def initialize( **kwargs )
142
- super
143
- end
144
-
145
- def update( **kwargs )
146
- super
147
- @city = kwargs[:city] if kwargs.has_key? :city
148
- ## todo/fix: use city struct - why? why not?
149
- ## todo/fix: add country too or report unused keywords / attributes - why? why not?
150
-
151
- self ## note - MUST return self for chaining
152
- end
153
- end # class Club
154
-
155
-
156
- end # module Import
157
- end # module SportDb
@@ -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,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,49 +0,0 @@
1
- # encoding: utf-8
2
-
3
- ###
4
- # to run use
5
- # ruby -I ./lib -I ./test test/test_match_status_parser.rb
6
-
7
-
8
- require 'helper'
9
-
10
-
11
- class TestMatchStatusParser < MiniTest::Test
12
-
13
- Status = SportDb::Status
14
- StatusParser = SportDb::StatusParser
15
-
16
- def test_find
17
- [['awarded [cancelled] canceled [ddd]', Status::CANCELLED],
18
- ['awarded [bbb; canceled] canceled [awarded; comments] eeee', Status::AWARDED],
19
- ['aaa bbb ccc ddd eeee', nil],
20
- ].each do |rec|
21
- line = rec[0]
22
- status_exp = rec[1]
23
- puts "line (before): >#{line}<"
24
- status = StatusParser.find!( line )
25
- puts "status: >#{status}<"
26
- puts "line (after): >#{line}<"
27
- puts
28
-
29
- assert_equal status_exp, status
30
- end
31
- end # method test_find
32
-
33
- def test_parse
34
- [['cancelled ddd', Status::CANCELLED],
35
- ['CANCELLED', Status::CANCELLED],
36
- ['can.', Status::CANCELLED],
37
- ['awarded; comments', Status::AWARDED],
38
- ['awd. - comments', Status::AWARDED],
39
- ['aaa bbb ccc ddd eeee', nil],
40
- ].each do |rec|
41
- str = rec[0]
42
- status_exp = rec[1]
43
- assert_equal status_exp, StatusParser.parse( str )
44
- end
45
- end
46
-
47
- end # class TestMatchStatusParser
48
-
49
-
@@ -1,67 +0,0 @@
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