sportdb-models 1.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gemtest +0 -0
- data/HISTORY.md +21 -0
- data/Manifest.txt +142 -0
- data/README.md +28 -0
- data/Rakefile +59 -0
- data/config/fixtures/de.yml +46 -0
- data/config/fixtures/en.yml +54 -0
- data/config/fixtures/es.yml +48 -0
- data/config/fixtures/fr.yml +53 -0
- data/config/fixtures/it.yml +55 -0
- data/config/fixtures/pt.yml +46 -0
- data/config/fixtures/ro.yml +55 -0
- data/data/seasons.txt +74 -0
- data/data/setups/all.txt +5 -0
- data/lib/sportdb/calc.rb +279 -0
- data/lib/sportdb/deleter.rb +52 -0
- data/lib/sportdb/finders/date.rb +374 -0
- data/lib/sportdb/finders/goals.rb +260 -0
- data/lib/sportdb/finders/scores.rb +122 -0
- data/lib/sportdb/lang.rb +216 -0
- data/lib/sportdb/matcher.rb +31 -0
- data/lib/sportdb/models.rb +259 -0
- data/lib/sportdb/models/assoc.rb +106 -0
- data/lib/sportdb/models/assoc_assoc.rb +15 -0
- data/lib/sportdb/models/badge.rb +14 -0
- data/lib/sportdb/models/event.rb +65 -0
- data/lib/sportdb/models/event_ground.rb +15 -0
- data/lib/sportdb/models/event_team.rb +16 -0
- data/lib/sportdb/models/forward.rb +55 -0
- data/lib/sportdb/models/game.rb +244 -0
- data/lib/sportdb/models/goal.rb +15 -0
- data/lib/sportdb/models/ground.rb +100 -0
- data/lib/sportdb/models/group.rb +23 -0
- data/lib/sportdb/models/group_team.rb +14 -0
- data/lib/sportdb/models/league.rb +83 -0
- data/lib/sportdb/models/person.rb +21 -0
- data/lib/sportdb/models/roster.rb +18 -0
- data/lib/sportdb/models/round.rb +22 -0
- data/lib/sportdb/models/season.rb +14 -0
- data/lib/sportdb/models/stats/alltime_standing.rb +44 -0
- data/lib/sportdb/models/stats/alltime_standing_entry.rb +23 -0
- data/lib/sportdb/models/stats/event_standing.rb +55 -0
- data/lib/sportdb/models/stats/event_standing_entry.rb +21 -0
- data/lib/sportdb/models/stats/group_standing.rb +50 -0
- data/lib/sportdb/models/stats/group_standing_entry.rb +22 -0
- data/lib/sportdb/models/team.rb +119 -0
- data/lib/sportdb/models/team_comp.rb +64 -0
- data/lib/sportdb/models/utils.rb +78 -0
- data/lib/sportdb/models/world/city.rb +21 -0
- data/lib/sportdb/models/world/continent.rb +20 -0
- data/lib/sportdb/models/world/country.rb +19 -0
- data/lib/sportdb/models/world/region.rb +19 -0
- data/lib/sportdb/patterns.rb +38 -0
- data/lib/sportdb/reader.rb +130 -0
- data/lib/sportdb/reader_file.rb +123 -0
- data/lib/sportdb/reader_zip.rb +165 -0
- data/lib/sportdb/readers/assoc.rb +54 -0
- data/lib/sportdb/readers/event.rb +200 -0
- data/lib/sportdb/readers/game.rb +877 -0
- data/lib/sportdb/readers/ground.rb +53 -0
- data/lib/sportdb/readers/league.rb +54 -0
- data/lib/sportdb/readers/season.rb +83 -0
- data/lib/sportdb/readers/squad_club.rb +201 -0
- data/lib/sportdb/readers/squad_national_team.rb +173 -0
- data/lib/sportdb/readers/team.rb +53 -0
- data/lib/sportdb/schema.rb +373 -0
- data/lib/sportdb/standings.rb +178 -0
- data/lib/sportdb/stats.rb +27 -0
- data/lib/sportdb/utils.rb +89 -0
- data/lib/sportdb/utils_date.rb +26 -0
- data/lib/sportdb/utils_goals.rb +20 -0
- data/lib/sportdb/utils_group.rb +63 -0
- data/lib/sportdb/utils_map.rb +44 -0
- data/lib/sportdb/utils_round.rb +165 -0
- data/lib/sportdb/utils_scores.rb +17 -0
- data/lib/sportdb/utils_teams.rb +43 -0
- data/lib/sportdb/version.rb +23 -0
- data/test/data/at-austria/2013_14/bl.txt +227 -0
- data/test/data/at-austria/2013_14/bl.yml +30 -0
- data/test/data/at-austria/2013_14/bl_ii.txt +154 -0
- data/test/data/at-austria/2013_14/el.txt +4 -0
- data/test/data/at-austria/2013_14/el.yml +25 -0
- data/test/data/at-austria/2013_14/squads/austria.txt +40 -0
- data/test/data/at-austria/2013_14/squads/salzburg.txt +35 -0
- data/test/data/at-austria/leagues.txt +11 -0
- data/test/data/at-austria/teams.txt +75 -0
- data/test/data/at-austria/teams_2.txt +34 -0
- data/test/data/national-teams/assocs.txt +231 -0
- data/test/data/national-teams/europe/assocs.txt +13 -0
- data/test/data/national-teams/europe/teams.txt +13 -0
- data/test/data/national-teams/north-america/assocs.txt +10 -0
- data/test/data/national-teams/north-america/teams.txt +7 -0
- data/test/data/national-teams/teams.txt +19 -0
- data/test/data/players/europe/at-austria/players.txt +45 -0
- data/test/data/players/europe/de-deutschland/players.txt +41 -0
- data/test/data/players/south-america/br-brazil/players.txt +51 -0
- data/test/data/world-cup/1930/cup.txt +71 -0
- data/test/data/world-cup/1930/cup.yml +23 -0
- data/test/data/world-cup/1930/cup_goals.txt +47 -0
- data/test/data/world-cup/1930/cup_goals.yml +23 -0
- data/test/data/world-cup/1954/cup.txt +90 -0
- data/test/data/world-cup/1954/cup.yml +30 -0
- data/test/data/world-cup/1962/cup.txt +86 -0
- data/test/data/world-cup/1962/cup.yml +32 -0
- data/test/data/world-cup/1974/cup.yml +35 -0
- data/test/data/world-cup/1974/cup_finals.txt +14 -0
- data/test/data/world-cup/1974/cup_i.txt +55 -0
- data/test/data/world-cup/1974/cup_ii.txt +34 -0
- data/test/data/world-cup/2014/cup.txt +5 -0
- data/test/data/world-cup/2014/cup.yml +54 -0
- data/test/data/world-cup/2014/squads/br-brazil.txt +46 -0
- data/test/data/world-cup/2014/squads/de-deutschland.txt +8 -0
- data/test/data/world-cup/2014/squads/jp-japan.txt +30 -0
- data/test/data/world-cup/2014/squads/uy-uruguay.txt +32 -0
- data/test/data/world-cup/leagues.txt +5 -0
- data/test/data/world-cup/seasons_1930.txt +4 -0
- data/test/data/world-cup/seasons_1954.txt +4 -0
- data/test/data/world-cup/seasons_1962.txt +4 -0
- data/test/data/world-cup/seasons_1974.txt +5 -0
- data/test/data/world-cup/teams_1930.txt +26 -0
- data/test/data/world-cup/teams_1954.txt +30 -0
- data/test/data/world-cup/teams_1962.txt +29 -0
- data/test/data/world-cup/teams_1974.txt +29 -0
- data/test/helper.rb +120 -0
- data/test/test_assoc_reader.rb +201 -0
- data/test/test_changes.rb +74 -0
- data/test/test_cursor.rb +50 -0
- data/test/test_date.rb +100 -0
- data/test/test_goals.rb +109 -0
- data/test/test_lang.rb +130 -0
- data/test/test_load.rb +61 -0
- data/test/test_reader.rb +88 -0
- data/test/test_reader_from_string.rb +65 -0
- data/test/test_round_auto.rb +370 -0
- data/test/test_round_def.rb +109 -0
- data/test/test_round_header.rb +183 -0
- data/test/test_scores.rb +70 -0
- data/test/test_squad_club_reader.rb +76 -0
- data/test/test_squad_national_team_reader.rb +116 -0
- data/test/test_standings.rb +279 -0
- data/test/test_standings_ii.rb +46 -0
- data/test/test_utils.rb +124 -0
- data/test/test_winner.rb +95 -0
- metadata +378 -0
data/test/test_load.rb
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
###
|
4
|
+
# to run use
|
5
|
+
# ruby -I ./lib -I ./test test/test_load.rb
|
6
|
+
# or better
|
7
|
+
# rake -I ./lib test
|
8
|
+
|
9
|
+
|
10
|
+
require 'helper'
|
11
|
+
|
12
|
+
class TestLoad < MiniTest::Test
|
13
|
+
|
14
|
+
def setup
|
15
|
+
WorldDb.delete!
|
16
|
+
SportDb.delete!
|
17
|
+
PersonDb.delete!
|
18
|
+
SportDb.read_builtin # add 2014 season
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
def test_br
|
23
|
+
br = Country.create!( key: 'br', title: 'Brazil', code: 'BRA', pop: 1, area: 1)
|
24
|
+
bra = Team.create!( key: 'bra', title: 'Brazil', code: 'BRA', country_id: br.id )
|
25
|
+
|
26
|
+
reader = Reader.new( SportDb.test_data_path )
|
27
|
+
|
28
|
+
## fix: add to country_matcher - allow players/br-brazil.txt e.g. country encode in file
|
29
|
+
## reader.load( 'players/south-america/br-brazil/players' )
|
30
|
+
## assert_equal 30, Person.count
|
31
|
+
|
32
|
+
reader.load( 'world-cup/leagues' )
|
33
|
+
assert_equal 1, League.count
|
34
|
+
reader.load( 'world-cup/2014/cup' )
|
35
|
+
assert_equal 1, Event.count
|
36
|
+
|
37
|
+
reader.load( 'world-cup/2014/squads/br-brazil' )
|
38
|
+
assert_equal 23, Roster.count
|
39
|
+
end # method test_br
|
40
|
+
|
41
|
+
|
42
|
+
def test_de
|
43
|
+
de = Country.create!( key: 'de', title: 'Germany', code: 'GER', pop: 1, area: 1)
|
44
|
+
ger = Team.create!( key: 'ger', title: 'Germany', code: 'GER', country_id: de.id )
|
45
|
+
|
46
|
+
reader = Reader.new( SportDb.test_data_path )
|
47
|
+
|
48
|
+
## reader.load( 'players/europe/de-deutschland/players' )
|
49
|
+
## assert_equal 27, Person.count
|
50
|
+
|
51
|
+
reader.load( 'world-cup/leagues' )
|
52
|
+
assert_equal 1, League.count
|
53
|
+
reader.load( 'world-cup/2014/cup' )
|
54
|
+
assert_equal 1, Event.count
|
55
|
+
|
56
|
+
reader.load( 'world-cup/2014/squads/de-deutschland' )
|
57
|
+
assert_equal 3, Roster.count
|
58
|
+
end # method test_de
|
59
|
+
|
60
|
+
|
61
|
+
end # class TestLoad
|
data/test/test_reader.rb
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
###
|
4
|
+
# to run use
|
5
|
+
# ruby -I ./lib -I ./test test/test_reader.rb
|
6
|
+
# or better
|
7
|
+
# rake -I ./lib test
|
8
|
+
|
9
|
+
|
10
|
+
require 'helper'
|
11
|
+
|
12
|
+
class TestReader < MiniTest::Test
|
13
|
+
|
14
|
+
def setup
|
15
|
+
WorldDb.delete!
|
16
|
+
SportDb.delete!
|
17
|
+
SportDb.read_builtin
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_bl
|
21
|
+
at = Country.create!( key: 'at', name: 'Austria', code: 'AUT', pop: 1, area: 1)
|
22
|
+
|
23
|
+
teamreader = TestTeamReader.from_file( 'at-austria/teams', country_id: at.id )
|
24
|
+
teamreader.read()
|
25
|
+
|
26
|
+
leaguereader = TestLeagueReader.from_file( 'at-austria/leagues', country_id: at.id )
|
27
|
+
leaguereader.read()
|
28
|
+
|
29
|
+
## check/fix: is country_id more_attribs needed? why? why not?
|
30
|
+
gamereader = TestGameReader.from_file( 'at-austria/2013_14/bl', country_id: at.id )
|
31
|
+
gamereader.read()
|
32
|
+
|
33
|
+
bl = Event.find_by_key!( 'at.2013/14' )
|
34
|
+
|
35
|
+
assert_equal 10, bl.teams.count
|
36
|
+
assert_equal 36, bl.rounds.count
|
37
|
+
assert_equal 180, bl.games.count # 36x5 = 180
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
def test_game_reader
|
42
|
+
at = Country.create!( key: 'at', name: 'Austria', code: 'AUT', pop: 1, area: 1)
|
43
|
+
|
44
|
+
teamreader = TestTeamReader.from_file( 'at-austria/teams', country_id: at.id )
|
45
|
+
teamreader.read()
|
46
|
+
teamreader = TestTeamReader.from_file( 'at-austria/teams_2', country_id: at.id )
|
47
|
+
teamreader.read()
|
48
|
+
|
49
|
+
austria = Team.find_by_key!( 'austria' )
|
50
|
+
rapid = Team.find_by_key!( 'rapid' )
|
51
|
+
sturm = Team.find_by_key!( 'sturm' )
|
52
|
+
|
53
|
+
assert_equal 'FK Austria Wien', austria.title
|
54
|
+
assert_equal 'SK Rapid Wien', rapid.title
|
55
|
+
assert_equal 'SK Sturm Graz', sturm.title
|
56
|
+
|
57
|
+
assert_equal 'AUS', austria.code
|
58
|
+
assert_equal 'RAP', rapid.code
|
59
|
+
assert_equal 'STU', sturm.code
|
60
|
+
|
61
|
+
leaguereader = TestLeagueReader.from_file( 'at-austria/leagues', country_id: at.id )
|
62
|
+
leaguereader.read()
|
63
|
+
|
64
|
+
at1 = League.find_by_key!( 'at' )
|
65
|
+
at2 = League.find_by_key!( 'at.2' )
|
66
|
+
atcup = League.find_by_key!( 'at.cup' )
|
67
|
+
|
68
|
+
assert_equal 'Österr. Bundesliga', at1.title
|
69
|
+
assert_equal 'Österr. Erste Liga', at2.title
|
70
|
+
assert_equal 'ÖFB Cup', atcup.title
|
71
|
+
|
72
|
+
## check/fix: is country_id more_attribs needed? why? why not?
|
73
|
+
gamereader = TestGameReader.from_file( 'at-austria/2013_14/bl', country_id: at.id )
|
74
|
+
gamereader.read()
|
75
|
+
gamereader = TestGameReader.from_file( 'at-austria/2013_14/el', country_id: at.id )
|
76
|
+
gamereader.read()
|
77
|
+
|
78
|
+
bl = Event.find_by_key!( 'at.2013/14' )
|
79
|
+
el = Event.find_by_key!( 'at.2.2013/14' )
|
80
|
+
|
81
|
+
assert_equal 10, bl.teams.count
|
82
|
+
assert_equal 36, bl.rounds.count
|
83
|
+
assert_equal 180, bl.games.count # 36x5 = 180
|
84
|
+
|
85
|
+
assert_equal 10, el.teams.count
|
86
|
+
end
|
87
|
+
|
88
|
+
end # class TestReader
|
@@ -0,0 +1,65 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
###
|
4
|
+
# to run use
|
5
|
+
# ruby -I ./lib -I ./test test/test_reader_from_string.rb
|
6
|
+
# or better
|
7
|
+
# rake -I ./lib test
|
8
|
+
|
9
|
+
|
10
|
+
require 'helper'
|
11
|
+
|
12
|
+
class TestReaderFromString < MiniTest::Test
|
13
|
+
|
14
|
+
def setup
|
15
|
+
WorldDb.delete!
|
16
|
+
SportDb.delete!
|
17
|
+
SportDb.read_builtin
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_bl
|
21
|
+
at = Country.create!( key: 'at', name: 'Austria', code: 'AUT', pop: 1, area: 1)
|
22
|
+
|
23
|
+
teamreader = TestTeamReader.from_file( 'at-austria/teams', country_id: at.id )
|
24
|
+
teamreader.read()
|
25
|
+
|
26
|
+
leaguereader = TestLeagueReader.from_file( 'at-austria/leagues', country_id: at.id )
|
27
|
+
leaguereader.read()
|
28
|
+
|
29
|
+
eventreader = TestEventReader.from_file( 'at-austria/2013_14/bl' )
|
30
|
+
eventreader.read()
|
31
|
+
|
32
|
+
bl = Event.find_by_key!( 'at.2013/14' )
|
33
|
+
|
34
|
+
assert_equal 10, bl.teams.count
|
35
|
+
assert_equal 0, bl.rounds.count
|
36
|
+
assert_equal 0, bl.games.count # 36x5 = 180
|
37
|
+
|
38
|
+
|
39
|
+
## fix: use File.readutf8 ??? why?? why not??
|
40
|
+
bl_txt = File.read( "#{SportDb.test_data_path}/at-austria/2013_14/bl.txt" )
|
41
|
+
bl_txt_ii = File.read( "#{SportDb.test_data_path}/at-austria/2013_14/bl_ii.txt" )
|
42
|
+
|
43
|
+
text_ary = [bl_txt,bl_txt_ii]
|
44
|
+
|
45
|
+
gamereader = GameReader.from_string( bl, text_ary )
|
46
|
+
gamereader.read()
|
47
|
+
|
48
|
+
## fix: add bl.key - allow event_keys too
|
49
|
+
## gamereader = GameReader.from_string( bl.key, text_ary )
|
50
|
+
## gamereader.read()
|
51
|
+
|
52
|
+
|
53
|
+
assert_equal 36, bl.rounds.count
|
54
|
+
assert_equal 180, bl.games.count # 36x5 = 180
|
55
|
+
|
56
|
+
## check if is stable (update will not create new matches and rounds) on second pass/rerun
|
57
|
+
gamereader.read()
|
58
|
+
|
59
|
+
assert_equal 36, bl.rounds.count
|
60
|
+
assert_equal 180, bl.games.count # 36x5 = 180
|
61
|
+
end
|
62
|
+
|
63
|
+
|
64
|
+
end # class TestReaderFromString
|
65
|
+
|
@@ -0,0 +1,370 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
###
|
4
|
+
# to run use
|
5
|
+
# ruby -I ./lib -I ./test test/test_round_auto.rb
|
6
|
+
# or better
|
7
|
+
# rake -I ./lib test
|
8
|
+
|
9
|
+
|
10
|
+
require 'helper'
|
11
|
+
|
12
|
+
class TestRoundAuto < MiniTest::Test
|
13
|
+
|
14
|
+
def setup
|
15
|
+
WorldDb.delete!
|
16
|
+
SportDb.delete!
|
17
|
+
## SportDb.read_builtin
|
18
|
+
|
19
|
+
add_countries
|
20
|
+
end
|
21
|
+
|
22
|
+
def add_countries
|
23
|
+
countries = [
|
24
|
+
['cd', 'Congo DR', 'COD' ],
|
25
|
+
['kr', 'South Korea', 'KOR' ],
|
26
|
+
['au', 'Australia', 'AUS' ],
|
27
|
+
|
28
|
+
['ar', 'Argentina', 'ARG' ],
|
29
|
+
['br', 'Brazil', 'BRA' ],
|
30
|
+
['bo', 'Bolivia', 'BOL' ],
|
31
|
+
['cl', 'Chile', 'CHI' ],
|
32
|
+
['co', 'Colombia', 'COL' ],
|
33
|
+
['uy', 'Uruguay', 'URU' ],
|
34
|
+
['pe', 'Peru', 'PER' ],
|
35
|
+
['py', 'Paraguay', 'PAR' ],
|
36
|
+
|
37
|
+
['mx', 'Mexico', 'MEX' ],
|
38
|
+
['us', 'United States', 'USA' ],
|
39
|
+
['ht', 'Haiti', 'HAI' ],
|
40
|
+
|
41
|
+
['at', 'Austria', 'AUT' ],
|
42
|
+
['be', 'Belgium', 'BEL' ],
|
43
|
+
['fr', 'France', 'FRA' ],
|
44
|
+
['rs', 'Serbia', 'SRB' ],
|
45
|
+
['ro', 'Romania', 'ROU' ],
|
46
|
+
['bg', 'Bulgaria', 'BUL' ],
|
47
|
+
['cz', 'Czech Republic', 'CZE' ],
|
48
|
+
['en', 'England', 'ENG' ],
|
49
|
+
['de', 'Germany', 'GER' ],
|
50
|
+
['hu', 'Hungary', 'HUN' ],
|
51
|
+
['it', 'Italy', 'ITA' ],
|
52
|
+
['ru', 'Russia', 'RUS' ],
|
53
|
+
['es', 'Spain', 'ESP' ],
|
54
|
+
['ch', 'Switzerland', 'SUI' ],
|
55
|
+
['sc', 'Scotland', 'SCO' ],
|
56
|
+
['tr', 'Turkey', 'TUR' ],
|
57
|
+
['nl', 'Netherlands', 'NED' ],
|
58
|
+
['pl', 'Poland', 'POL' ],
|
59
|
+
['se', 'Sweden', 'SWE' ],
|
60
|
+
]
|
61
|
+
|
62
|
+
countries.each do |country|
|
63
|
+
key = country[0]
|
64
|
+
name = country[1]
|
65
|
+
code = country[2]
|
66
|
+
Country.create!( key: key, name: name, code: code, pop: 1, area: 1)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
|
71
|
+
def test_world_cup_1974
|
72
|
+
teamreader = TestTeamReader.from_file( 'world-cup/teams_1974' )
|
73
|
+
teamreader.read()
|
74
|
+
|
75
|
+
assert_equal 16, Team.count
|
76
|
+
|
77
|
+
seasonreader = TestSeasonReader.from_file( 'world-cup/seasons_1974' )
|
78
|
+
seasonreader.read()
|
79
|
+
|
80
|
+
assert_equal 1, Season.count
|
81
|
+
|
82
|
+
y = Season.find_by_key!( '1974' )
|
83
|
+
assert_equal '1974', y.title
|
84
|
+
|
85
|
+
leaguereader = TestLeagueReader.from_file( 'world-cup/leagues' )
|
86
|
+
leaguereader.read()
|
87
|
+
|
88
|
+
assert_equal 1, League.count
|
89
|
+
|
90
|
+
l = League.find_by_key!( 'world' )
|
91
|
+
assert_equal 'World Cup', l.title
|
92
|
+
|
93
|
+
gamereader = TestGameReader.from_file( 'world-cup/1974/cup' )
|
94
|
+
gamereader.read()
|
95
|
+
|
96
|
+
assert_equal 1, Event.count
|
97
|
+
|
98
|
+
w = Event.find_by_key!( 'world.1974' )
|
99
|
+
|
100
|
+
assert_equal 16, w.teams.count
|
101
|
+
assert_equal 38, w.games.count
|
102
|
+
assert_equal 12, w.rounds.count
|
103
|
+
|
104
|
+
rounds_exp = [
|
105
|
+
[1, 'Matchday 1', '1974-06-13', 1], # first group stage
|
106
|
+
[2, 'Matchday 2', '1974-06-14', 3],
|
107
|
+
[3, 'Matchday 3', '1974-06-15', 4],
|
108
|
+
[4, 'Matchday 4', '1974-06-18', 4],
|
109
|
+
[5, 'Matchday 5', '1974-06-19', 4],
|
110
|
+
[6, 'Matchday 6', '1974-06-22', 4],
|
111
|
+
[7, 'Matchday 7', '1974-06-23', 4],
|
112
|
+
[8, 'Matchday 8', '1974-06-26', 4], # second group stage
|
113
|
+
[9, 'Matchday 9', '1974-06-30', 4],
|
114
|
+
[10, 'Matchday 10', '1974-07-03', 4],
|
115
|
+
[11, 'Match for third place', '1974-07-06', 1], # finals
|
116
|
+
[12, 'Final', '1974-07-07', 1],
|
117
|
+
]
|
118
|
+
|
119
|
+
assert_rounds( rounds_exp )
|
120
|
+
|
121
|
+
#########################
|
122
|
+
## 2nd run
|
123
|
+
### try update (e.g. read again - should NOT create new rounds/games/teams)
|
124
|
+
#
|
125
|
+
# note: update only works if rounds get not deleted or added
|
126
|
+
# - (adding for updates works only at the end/tail - not at the beginning or inbetween, for example)
|
127
|
+
|
128
|
+
gamereader = TestGameReader.from_file( 'world-cup/1974/cup' )
|
129
|
+
gamereader.read()
|
130
|
+
|
131
|
+
assert_equal 1, Event.count
|
132
|
+
|
133
|
+
w = Event.find_by_key!( 'world.1974' )
|
134
|
+
|
135
|
+
assert_equal 16, w.teams.count
|
136
|
+
assert_equal 38, w.games.count
|
137
|
+
assert_equal 12, w.rounds.count
|
138
|
+
|
139
|
+
assert_rounds( rounds_exp )
|
140
|
+
|
141
|
+
end # method test_world_cup_1974
|
142
|
+
|
143
|
+
|
144
|
+
def test_world_cup_1954
|
145
|
+
teamreader = TestTeamReader.from_file( 'world-cup/teams_1954' )
|
146
|
+
teamreader.read()
|
147
|
+
|
148
|
+
assert_equal 16, Team.count
|
149
|
+
|
150
|
+
assert_teams( [
|
151
|
+
[ 'bra', 'Brazil', 'BRA' ],
|
152
|
+
[ 'uru', 'Uruguay', 'URU' ],
|
153
|
+
[ 'bel', 'Belgium', 'BEL' ] ] )
|
154
|
+
|
155
|
+
seasonreader = TestSeasonReader.from_file( 'world-cup/seasons_1954' )
|
156
|
+
seasonreader.read()
|
157
|
+
|
158
|
+
assert_equal 1, Season.count
|
159
|
+
|
160
|
+
y = Season.find_by_key!( '1954' )
|
161
|
+
assert_equal '1954', y.title
|
162
|
+
|
163
|
+
|
164
|
+
leaguereader = TestLeagueReader.from_file( 'world-cup/leagues' )
|
165
|
+
leaguereader.read()
|
166
|
+
|
167
|
+
assert_equal 1, League.count
|
168
|
+
|
169
|
+
l = League.find_by_key!( 'world' )
|
170
|
+
assert_equal 'World Cup', l.title
|
171
|
+
|
172
|
+
|
173
|
+
gamereader = TestGameReader.from_file( 'world-cup/1954/cup' )
|
174
|
+
gamereader.read()
|
175
|
+
|
176
|
+
assert_equal 1, Event.count
|
177
|
+
|
178
|
+
w = Event.find_by_key!( 'world.1954' )
|
179
|
+
|
180
|
+
assert_equal 16, w.teams.count
|
181
|
+
assert_equal 26, w.games.count
|
182
|
+
assert_equal 10, w.rounds.count
|
183
|
+
|
184
|
+
rounds_exp = [
|
185
|
+
[1, 'Matchday 1', '1954-06-16', 4],
|
186
|
+
[2, 'Matchday 2', '1954-06-17', 4],
|
187
|
+
[3, 'Matchday 3', '1954-06-19', 4],
|
188
|
+
[4, 'Matchday 4', '1954-06-20', 4],
|
189
|
+
[5, 'Group-2 Play-off', '1954-06-23', 1],
|
190
|
+
[6, 'Group-4 Play-off', '1954-06-23', 1],
|
191
|
+
[7, 'Quarter-finals', '1954-06-26', 4],
|
192
|
+
[8, 'Semi-finals', '1954-06-30', 2],
|
193
|
+
[9, 'Third place match', '1954-07-03', 1],
|
194
|
+
[10, 'Final', '1954-07-04', 1],
|
195
|
+
]
|
196
|
+
|
197
|
+
assert_rounds( rounds_exp )
|
198
|
+
|
199
|
+
end # test_world_cup_1954
|
200
|
+
|
201
|
+
|
202
|
+
def test_world_cup_1930
|
203
|
+
teamreader = TestTeamReader.from_file( 'world-cup/teams_1930' )
|
204
|
+
teamreader.read()
|
205
|
+
|
206
|
+
assert_equal 13, Team.count
|
207
|
+
|
208
|
+
assert_teams( [
|
209
|
+
[ 'arg', 'Argentina', 'ARG' ],
|
210
|
+
[ 'bra', 'Brazil', 'BRA' ],
|
211
|
+
[ 'bel', 'Belgium', 'BEL' ] ] )
|
212
|
+
|
213
|
+
seasonreader = TestSeasonReader.from_file( 'world-cup/seasons_1930' )
|
214
|
+
seasonreader.read()
|
215
|
+
|
216
|
+
assert_equal 1, Season.count
|
217
|
+
|
218
|
+
y = Season.find_by_key!( '1930' )
|
219
|
+
assert_equal '1930', y.title
|
220
|
+
|
221
|
+
|
222
|
+
leaguereader = TestLeagueReader.from_file( 'world-cup/leagues' )
|
223
|
+
leaguereader.read()
|
224
|
+
|
225
|
+
assert_equal 1, League.count
|
226
|
+
|
227
|
+
l = League.find_by_key!( 'world' )
|
228
|
+
assert_equal 'World Cup', l.title
|
229
|
+
|
230
|
+
|
231
|
+
gamereader = TestGameReader.from_file( 'world-cup/1930/cup' )
|
232
|
+
gamereader.read()
|
233
|
+
|
234
|
+
assert_equal 1, Event.count
|
235
|
+
|
236
|
+
w = Event.find_by_key!( 'world.1930' )
|
237
|
+
|
238
|
+
assert_equal 13, w.teams.count
|
239
|
+
assert_equal 18, w.games.count
|
240
|
+
assert_equal 12, w.rounds.count
|
241
|
+
|
242
|
+
rounds_exp = [
|
243
|
+
[1, 'Matchday 1', '1930-07-13', 2],
|
244
|
+
[2, 'Matchday 2', '1930-07-14', 2],
|
245
|
+
[3, 'Matchday 3', '1930-07-15', 1],
|
246
|
+
[4, 'Matchday 4', '1930-07-16', 1],
|
247
|
+
[5, 'Matchday 5', '1930-07-17', 2],
|
248
|
+
[6, 'Matchday 6', '1930-07-18', 1],
|
249
|
+
[7, 'Matchday 7', '1930-07-19', 2],
|
250
|
+
[8, 'Matchday 8', '1930-07-20', 2],
|
251
|
+
[9, 'Matchday 9', '1930-07-21', 1],
|
252
|
+
[10, 'Matchday 10', '1930-07-22', 1],
|
253
|
+
[11, 'Semi-finals', '1930-07-26', 2],
|
254
|
+
[12, 'Final' , '1930-07-30', 1],
|
255
|
+
]
|
256
|
+
|
257
|
+
assert_rounds( rounds_exp )
|
258
|
+
end # method test_world_cup_1930
|
259
|
+
|
260
|
+
|
261
|
+
def test_world_cup_1962
|
262
|
+
teamreader = TestTeamReader.from_file( 'world-cup/teams_1962' )
|
263
|
+
teamreader.read()
|
264
|
+
|
265
|
+
assert_equal 16, Team.count
|
266
|
+
|
267
|
+
assert_teams( [
|
268
|
+
[ 'arg', 'Argentina', 'ARG' ],
|
269
|
+
[ 'bra', 'Brazil', 'BRA' ],
|
270
|
+
[ 'ita', 'Italy', 'ITA' ] ] )
|
271
|
+
|
272
|
+
seasonreader = TestSeasonReader.from_file( 'world-cup/seasons_1962' )
|
273
|
+
seasonreader.read()
|
274
|
+
|
275
|
+
assert_equal 1, Season.count
|
276
|
+
|
277
|
+
y = Season.find_by_key!( '1962' )
|
278
|
+
assert_equal '1962', y.title
|
279
|
+
|
280
|
+
|
281
|
+
leaguereader = TestLeagueReader.from_file( 'world-cup/leagues' )
|
282
|
+
leaguereader.read()
|
283
|
+
|
284
|
+
assert_equal 1, League.count
|
285
|
+
|
286
|
+
l = League.find_by_key!( 'world' )
|
287
|
+
assert_equal 'World Cup', l.title
|
288
|
+
|
289
|
+
|
290
|
+
gamereader = TestGameReader.from_file( 'world-cup/1962/cup' )
|
291
|
+
gamereader.read()
|
292
|
+
|
293
|
+
assert_equal 1, Event.count
|
294
|
+
|
295
|
+
w = Event.find_by_key!( 'world.1962' )
|
296
|
+
|
297
|
+
assert_equal 16, w.teams.count
|
298
|
+
assert_equal 32, w.games.count
|
299
|
+
assert_equal 10, w.rounds.count
|
300
|
+
|
301
|
+
rounds_exp = [
|
302
|
+
[1, 'Matchday 1', '1962-05-30', 4],
|
303
|
+
[2, 'Matchday 2', '1962-05-31', 4],
|
304
|
+
[3, 'Matchday 3', '1962-06-02', 4],
|
305
|
+
[4, 'Matchday 4', '1962-06-03', 4],
|
306
|
+
[5, 'Matchday 5', '1962-06-06', 4],
|
307
|
+
[6, 'Matchday 6', '1962-06-07', 4],
|
308
|
+
[7, 'Quarter-finals', '1962-06-10', 4],
|
309
|
+
[8, 'Semi-finals', '1962-06-13', 2],
|
310
|
+
[9, 'Third place match', '1962-06-16', 1],
|
311
|
+
[10, 'Final' , '1962-06-17', 1],
|
312
|
+
]
|
313
|
+
|
314
|
+
assert_rounds( rounds_exp )
|
315
|
+
|
316
|
+
#########################
|
317
|
+
## 2nd run
|
318
|
+
### try update (e.g. read again - should NOT create new rounds/games/teams)
|
319
|
+
#
|
320
|
+
# note: update only works if rounds get not deleted or added
|
321
|
+
# - (adding for updates works only at the end/tail - not at the beginning or inbetween, for example)
|
322
|
+
|
323
|
+
gamereader = TestGameReader.from_file( 'world-cup/1962/cup' )
|
324
|
+
gamereader.read()
|
325
|
+
|
326
|
+
assert_equal 1, Event.count
|
327
|
+
|
328
|
+
w = Event.find_by_key!( 'world.1962' )
|
329
|
+
|
330
|
+
assert_equal 16, w.teams.count
|
331
|
+
assert_equal 32, w.games.count
|
332
|
+
assert_equal 10, w.rounds.count
|
333
|
+
|
334
|
+
assert_rounds( rounds_exp )
|
335
|
+
|
336
|
+
end # method test_world_cup_1962
|
337
|
+
|
338
|
+
####
|
339
|
+
# helpers
|
340
|
+
|
341
|
+
def assert_rounds( rounds_exp )
|
342
|
+
rounds_exp.each do |round_exp|
|
343
|
+
round = Round.find_by_pos!( round_exp[0] )
|
344
|
+
|
345
|
+
assert_equal round_exp[1], round.title
|
346
|
+
|
347
|
+
if round_exp[2]
|
348
|
+
start_at = Date.parse( round_exp[2] )
|
349
|
+
## puts "round.start_at.class.name: #{round.start_at.class.name}"
|
350
|
+
assert_equal start_at, round.start_at ## check works for date?
|
351
|
+
end
|
352
|
+
|
353
|
+
if round_exp[3]
|
354
|
+
count = round_exp[3]
|
355
|
+
assert_equal( count, round.games.count, "round.games.count #{count} != #{round.games.count} - #{round.title}")
|
356
|
+
end
|
357
|
+
end
|
358
|
+
end # method assert_rounds
|
359
|
+
|
360
|
+
def assert_teams( teams_exp )
|
361
|
+
teams_exp.each do |team_exp|
|
362
|
+
team = Team.find_by_key!( team_exp[0] )
|
363
|
+
|
364
|
+
assert_equal team_exp[1], team.title
|
365
|
+
assert_equal team_exp[2], team.code
|
366
|
+
end
|
367
|
+
end # method assert_teams
|
368
|
+
|
369
|
+
|
370
|
+
end # class TestRoundAuto
|