sportdb 1.9.16 → 1.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/HISTORY.md +2 -19
- data/Manifest.txt +1 -137
- data/README.md +2 -21
- data/Rakefile +14 -25
- data/lib/sportdb.rb +9 -260
- data/lib/sportdb/cli/main.rb +5 -14
- data/lib/sportdb/cli/opts.rb +2 -0
- data/lib/sportdb/cli/version.rb +26 -0
- metadata +10 -278
- data/.gemtest +0 -0
- data/config/fixtures/de.yml +0 -46
- data/config/fixtures/en.yml +0 -54
- data/config/fixtures/es.yml +0 -48
- data/config/fixtures/fr.yml +0 -53
- data/config/fixtures/it.yml +0 -55
- data/config/fixtures/pt.yml +0 -46
- data/config/fixtures/ro.yml +0 -55
- data/data/seasons.txt +0 -74
- data/data/setups/all.txt +0 -5
- data/lib/sportdb/calc.rb +0 -279
- data/lib/sportdb/deleter.rb +0 -52
- data/lib/sportdb/finders/date.rb +0 -374
- data/lib/sportdb/finders/goals.rb +0 -260
- data/lib/sportdb/finders/scores.rb +0 -122
- data/lib/sportdb/lang.rb +0 -216
- data/lib/sportdb/matcher.rb +0 -31
- data/lib/sportdb/models/assoc.rb +0 -106
- data/lib/sportdb/models/assoc_assoc.rb +0 -15
- data/lib/sportdb/models/badge.rb +0 -14
- data/lib/sportdb/models/event.rb +0 -65
- data/lib/sportdb/models/event_ground.rb +0 -15
- data/lib/sportdb/models/event_team.rb +0 -16
- data/lib/sportdb/models/forward.rb +0 -55
- data/lib/sportdb/models/game.rb +0 -244
- data/lib/sportdb/models/goal.rb +0 -15
- data/lib/sportdb/models/ground.rb +0 -100
- data/lib/sportdb/models/group.rb +0 -23
- data/lib/sportdb/models/group_team.rb +0 -14
- data/lib/sportdb/models/league.rb +0 -83
- data/lib/sportdb/models/person.rb +0 -21
- data/lib/sportdb/models/roster.rb +0 -18
- data/lib/sportdb/models/round.rb +0 -22
- data/lib/sportdb/models/season.rb +0 -14
- data/lib/sportdb/models/stats/alltime_standing.rb +0 -44
- data/lib/sportdb/models/stats/alltime_standing_entry.rb +0 -23
- data/lib/sportdb/models/stats/event_standing.rb +0 -55
- data/lib/sportdb/models/stats/event_standing_entry.rb +0 -21
- data/lib/sportdb/models/stats/group_standing.rb +0 -50
- data/lib/sportdb/models/stats/group_standing_entry.rb +0 -22
- data/lib/sportdb/models/team.rb +0 -119
- data/lib/sportdb/models/team_comp.rb +0 -64
- data/lib/sportdb/models/utils.rb +0 -78
- data/lib/sportdb/models/world/city.rb +0 -21
- data/lib/sportdb/models/world/continent.rb +0 -20
- data/lib/sportdb/models/world/country.rb +0 -19
- data/lib/sportdb/models/world/region.rb +0 -19
- data/lib/sportdb/patterns.rb +0 -38
- data/lib/sportdb/reader.rb +0 -130
- data/lib/sportdb/reader_file.rb +0 -123
- data/lib/sportdb/reader_zip.rb +0 -165
- data/lib/sportdb/readers/assoc.rb +0 -54
- data/lib/sportdb/readers/event.rb +0 -200
- data/lib/sportdb/readers/game.rb +0 -877
- data/lib/sportdb/readers/ground.rb +0 -53
- data/lib/sportdb/readers/league.rb +0 -54
- data/lib/sportdb/readers/season.rb +0 -83
- data/lib/sportdb/readers/squad_club.rb +0 -201
- data/lib/sportdb/readers/squad_national_team.rb +0 -173
- data/lib/sportdb/readers/team.rb +0 -53
- data/lib/sportdb/schema.rb +0 -373
- data/lib/sportdb/standings.rb +0 -178
- data/lib/sportdb/stats.rb +0 -27
- data/lib/sportdb/utils.rb +0 -89
- data/lib/sportdb/utils_date.rb +0 -26
- data/lib/sportdb/utils_goals.rb +0 -20
- data/lib/sportdb/utils_group.rb +0 -63
- data/lib/sportdb/utils_map.rb +0 -44
- data/lib/sportdb/utils_round.rb +0 -165
- data/lib/sportdb/utils_scores.rb +0 -17
- data/lib/sportdb/utils_teams.rb +0 -43
- data/lib/sportdb/version.rb +0 -22
- data/test/data/at-austria/2013_14/bl.txt +0 -227
- data/test/data/at-austria/2013_14/bl.yml +0 -30
- data/test/data/at-austria/2013_14/bl_ii.txt +0 -154
- data/test/data/at-austria/2013_14/el.txt +0 -4
- data/test/data/at-austria/2013_14/el.yml +0 -25
- data/test/data/at-austria/2013_14/squads/austria.txt +0 -40
- data/test/data/at-austria/2013_14/squads/salzburg.txt +0 -35
- data/test/data/at-austria/leagues.txt +0 -11
- data/test/data/at-austria/teams.txt +0 -75
- data/test/data/at-austria/teams_2.txt +0 -34
- data/test/data/national-teams/assocs.txt +0 -231
- data/test/data/national-teams/europe/assocs.txt +0 -13
- data/test/data/national-teams/europe/teams.txt +0 -13
- data/test/data/national-teams/north-america/assocs.txt +0 -10
- data/test/data/national-teams/north-america/teams.txt +0 -7
- data/test/data/national-teams/teams.txt +0 -19
- data/test/data/players/europe/at-austria/players.txt +0 -45
- data/test/data/players/europe/de-deutschland/players.txt +0 -41
- data/test/data/players/south-america/br-brazil/players.txt +0 -51
- data/test/data/world-cup/1930/cup.txt +0 -71
- data/test/data/world-cup/1930/cup.yml +0 -23
- data/test/data/world-cup/1930/cup_goals.txt +0 -47
- data/test/data/world-cup/1930/cup_goals.yml +0 -23
- data/test/data/world-cup/1954/cup.txt +0 -90
- data/test/data/world-cup/1954/cup.yml +0 -30
- data/test/data/world-cup/1962/cup.txt +0 -86
- data/test/data/world-cup/1962/cup.yml +0 -32
- data/test/data/world-cup/1974/cup.yml +0 -35
- data/test/data/world-cup/1974/cup_finals.txt +0 -14
- data/test/data/world-cup/1974/cup_i.txt +0 -55
- data/test/data/world-cup/1974/cup_ii.txt +0 -34
- data/test/data/world-cup/2014/cup.txt +0 -5
- data/test/data/world-cup/2014/cup.yml +0 -54
- data/test/data/world-cup/2014/squads/br-brazil.txt +0 -46
- data/test/data/world-cup/2014/squads/de-deutschland.txt +0 -8
- data/test/data/world-cup/2014/squads/jp-japan.txt +0 -30
- data/test/data/world-cup/2014/squads/uy-uruguay.txt +0 -32
- data/test/data/world-cup/leagues.txt +0 -5
- data/test/data/world-cup/seasons_1930.txt +0 -4
- data/test/data/world-cup/seasons_1954.txt +0 -4
- data/test/data/world-cup/seasons_1962.txt +0 -4
- data/test/data/world-cup/seasons_1974.txt +0 -5
- data/test/data/world-cup/teams_1930.txt +0 -26
- data/test/data/world-cup/teams_1954.txt +0 -30
- data/test/data/world-cup/teams_1962.txt +0 -29
- data/test/data/world-cup/teams_1974.txt +0 -29
- data/test/helper.rb +0 -120
- data/test/test_assoc_reader.rb +0 -201
- data/test/test_changes.rb +0 -74
- data/test/test_cursor.rb +0 -50
- data/test/test_date.rb +0 -100
- data/test/test_goals.rb +0 -109
- data/test/test_lang.rb +0 -130
- data/test/test_load.rb +0 -61
- data/test/test_reader.rb +0 -88
- data/test/test_reader_from_string.rb +0 -65
- data/test/test_round_auto.rb +0 -370
- data/test/test_round_def.rb +0 -109
- data/test/test_round_header.rb +0 -183
- data/test/test_scores.rb +0 -70
- data/test/test_squad_club_reader.rb +0 -76
- data/test/test_squad_national_team_reader.rb +0 -116
- data/test/test_standings.rb +0 -279
- data/test/test_standings_ii.rb +0 -46
- data/test/test_utils.rb +0 -124
- data/test/test_winner.rb +0 -95
data/lib/sportdb/reader.rb
DELETED
@@ -1,130 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
module SportDb
|
4
|
-
|
5
|
-
class ReaderBase
|
6
|
-
|
7
|
-
include LogUtils::Logging
|
8
|
-
|
9
|
-
|
10
|
-
## make models available in sportdb module by default with namespace
|
11
|
-
# e.g. lets you use Team instead of Model::Team
|
12
|
-
include SportDb::Models
|
13
|
-
include SportDb::Matcher # lets us use match_teams_for_country etc.
|
14
|
-
|
15
|
-
|
16
|
-
def load_setup( name )
|
17
|
-
reader = create_fixture_reader( name )
|
18
|
-
|
19
|
-
reader.each do |fixture_name|
|
20
|
-
load( fixture_name )
|
21
|
-
end
|
22
|
-
end # method load_setup
|
23
|
-
|
24
|
-
|
25
|
-
def load( name ) # convenience helper for all-in-one reader
|
26
|
-
|
27
|
-
logger.debug "enter load( name=>>#{name}<<)" ## formerly also printed -> include_path=>>#{include_path}<<
|
28
|
-
|
29
|
-
if match_players_for_country( name ) do |country_key|
|
30
|
-
## country = Country.find_by_key!( country_key )
|
31
|
-
## fix-fix-fix-fix-fix-fix: change to new format e.g. from_file, from_zip etc!!!
|
32
|
-
## reader = PersonDb::PersonReader.new( include_path )
|
33
|
-
## reader.read( name, country_id: country.id )
|
34
|
-
end
|
35
|
-
elsif name =~ /\/squads\/([a-z0-9]{3,})$/ # e.g. ajax.txt bayern.txt etc.
|
36
|
-
## note: for now assume club (e.g. no dash (-) allowed for country code e.g. br-brazil etc.)
|
37
|
-
team = Team.find_by_key!( $1 )
|
38
|
-
## note: pass in @event.id - that is, last seen event (e.g. parsed via GameReader/MatchReader)
|
39
|
-
reader = create_club_squad_reader( name, team_id: team.id, event_id: @event.id )
|
40
|
-
reader.read()
|
41
|
-
elsif name =~ /\/squads\/([a-z]{2,3})-[^\/]+$/
|
42
|
-
## fix: add to country matcher new format
|
43
|
-
## name is country! and parent folder is type name e.g. /squads/br-brazil
|
44
|
-
|
45
|
-
# note: if two letters, assume country key
|
46
|
-
# if three letters, assume team key
|
47
|
-
|
48
|
-
## allow three letter codes
|
49
|
-
## assume three letter code are *team* codes (e.g. fdr, gdr, etc)
|
50
|
-
## not country code (allows multiple teams per country)
|
51
|
-
|
52
|
-
if $1.length == 2
|
53
|
-
## get national team via country
|
54
|
-
country = Country.find_by_key!( $1 )
|
55
|
-
### for now assume country code matches team for now (do NOT forget to downcase e.g. BRA==bra)
|
56
|
-
logger.info " assume country code == team code for #{country.code}"
|
57
|
-
team = Team.find_by_key!( country.code.downcase )
|
58
|
-
else # assume length == 3
|
59
|
-
## get national team directly (use three letter fifa code)
|
60
|
-
team = Team.find_by_key!( $1 )
|
61
|
-
end
|
62
|
-
## note: pass in @event.id - that is, last seen event (e.g. parsed via GameReader/MatchReader)
|
63
|
-
reader = create_national_team_squad_reader( name, team_id: team.id, event_id: @event.id )
|
64
|
-
reader.read()
|
65
|
-
elsif name =~ /(?:^|\/)seasons/ # NB: ^seasons or also possible at-austria!/seasons
|
66
|
-
reader = create_season_reader( name )
|
67
|
-
reader.read()
|
68
|
-
elsif name =~ /(?:^|\/)assocs/ # NB: ^assocs or also possible national-teams!/assocs
|
69
|
-
reader = create_assoc_reader( name )
|
70
|
-
reader.read()
|
71
|
-
elsif match_stadiums_for_country( name ) do |country_key|
|
72
|
-
country = Country.find_by_key!( country_key )
|
73
|
-
reader = create_ground_reader( name, country_id: country.id )
|
74
|
-
reader.read()
|
75
|
-
end
|
76
|
-
elsif match_leagues_for_country( name ) do |country_key| # name =~ /^([a-z]{2})\/leagues/
|
77
|
-
# auto-add country code (from folder structure) for country-specific leagues
|
78
|
-
# e.g. at/leagues
|
79
|
-
country = Country.find_by_key!( country_key )
|
80
|
-
reader = create_league_reader( name, club: true, country_id: country.id )
|
81
|
-
reader.read()
|
82
|
-
end
|
83
|
-
elsif name =~ /(?:^|\/)leagues/ # NB: ^leagues or also possible world!/leagues - NB: make sure goes after leagues_for_country!!
|
84
|
-
reader = create_league_reader( name )
|
85
|
-
reader.read()
|
86
|
-
elsif match_teams_for_country( name ) do |country_key| # name =~ /^([a-z]{2})\/teams/
|
87
|
-
# auto-add country code (from folder structure) for country-specific teams
|
88
|
-
# e.g. at/teams at/teams.2 de/teams etc.
|
89
|
-
country = Country.find_by_key!( country_key )
|
90
|
-
reader = create_team_reader( name, country_id: country.id )
|
91
|
-
reader.read()
|
92
|
-
end
|
93
|
-
elsif match_clubs_for_country( name ) do |country_key| # name =~ /^([a-z]{2})\/clubs/
|
94
|
-
# auto-add country code (from folder structure) for country-specific clubs
|
95
|
-
# e.g. at/teams at/teams.2 de/teams etc.
|
96
|
-
country = Country.find_by_key!( country_key )
|
97
|
-
reader = create_team_reader( name, club: true, country_id: country.id ) ## note: always sets club flag to true
|
98
|
-
reader.read()
|
99
|
-
end
|
100
|
-
elsif name =~ /(?:^|\/)teams/ ## fix: check if teams rule above (e.g. /^teams/ )conflicts/matches first ???
|
101
|
-
### fix: use new NationalTeamReader ??? why? why not?
|
102
|
-
reader = create_team_reader( name ) ## note: always sets club flag to true / national to true
|
103
|
-
reader.read()
|
104
|
-
elsif name =~ /(?:^|\/)clubs/
|
105
|
-
### fix: use new ClubReader ??? why? why not?
|
106
|
-
reader = create_team_reader( name, club: true ) ## note: always sets club flag to true / national to false
|
107
|
-
reader.read()
|
108
|
-
elsif name =~ /\/(\d{4}|\d{4}[_\-]\d{2})(--[^\/]+)?\// ||
|
109
|
-
name =~ /\/(\d{4}|\d{4}[_\-]\d{2})$/
|
110
|
-
|
111
|
-
# note: allow 2013_14 or 2013-14 (that, is dash or underscore)
|
112
|
-
|
113
|
-
# note: keep a "public" reference of last event in @event - e.g. used/required by squads etc.
|
114
|
-
eventreader = create_event_reader( name )
|
115
|
-
eventreader.read()
|
116
|
-
@event = eventreader.event
|
117
|
-
|
118
|
-
# e.g. must match /2012/ or /2012_13/ or /2012--xxx/ or /2012_13--xx/
|
119
|
-
# or /2012 or /2012_13 e.g. brazil/2012 or brazil/2012_13
|
120
|
-
reader = create_game_reader( name )
|
121
|
-
reader.read()
|
122
|
-
else
|
123
|
-
logger.error "unknown sportdb fixture type >#{name}<"
|
124
|
-
# todo/fix: exit w/ error
|
125
|
-
end
|
126
|
-
end # method load
|
127
|
-
|
128
|
-
|
129
|
-
end # class Reader
|
130
|
-
end # module SportDb
|
data/lib/sportdb/reader_file.rb
DELETED
@@ -1,123 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
module SportDb
|
4
|
-
|
5
|
-
## todo: "old" classic reader - rename to FileReader ?? why? why not?
|
6
|
-
|
7
|
-
class Reader < ReaderBase
|
8
|
-
|
9
|
-
attr_reader :include_path
|
10
|
-
|
11
|
-
def initialize( include_path, opts={})
|
12
|
-
@include_path = include_path
|
13
|
-
end
|
14
|
-
|
15
|
-
def create_fixture_reader( name )
|
16
|
-
path = "#{@include_path}/#{name}.txt"
|
17
|
-
|
18
|
-
logger.info "parsing data (setup) '#{name}' (#{path})..."
|
19
|
-
|
20
|
-
FixtureReader.from_file( path )
|
21
|
-
end
|
22
|
-
|
23
|
-
def create_club_squad_reader( name, more_attribs={} )
|
24
|
-
real_name = name_to_real_name( name )
|
25
|
-
path = "#{@include_path}/#{real_name}.txt"
|
26
|
-
|
27
|
-
logger.info "parsing data (club squad) '#{name}' (#{path})..."
|
28
|
-
ClubSquadReader.from_file( path, more_attribs )
|
29
|
-
end
|
30
|
-
|
31
|
-
def create_national_team_squad_reader( name, more_attribs={} )
|
32
|
-
real_name = name_to_real_name( name )
|
33
|
-
path = "#{@include_path}/#{real_name}.txt"
|
34
|
-
|
35
|
-
logger.info "parsing data (national team squad) '#{name}' (#{path})..."
|
36
|
-
NationalTeamSquadReader.from_file( path, more_attribs )
|
37
|
-
end
|
38
|
-
|
39
|
-
def create_season_reader( name )
|
40
|
-
real_name = name_to_real_name( name )
|
41
|
-
path = "#{@include_path}/#{real_name}.txt"
|
42
|
-
|
43
|
-
logger.info "parsing data (season) '#{name}' (#{path})..."
|
44
|
-
SeasonReader.from_file( path )
|
45
|
-
end
|
46
|
-
|
47
|
-
def create_assoc_reader( name )
|
48
|
-
real_name = name_to_real_name( name )
|
49
|
-
path = "#{@include_path}/#{real_name}.txt"
|
50
|
-
|
51
|
-
logger.info "parsing data (assoc) '#{name}' (#{path})..."
|
52
|
-
AssocReader.from_file( path )
|
53
|
-
end
|
54
|
-
|
55
|
-
def create_ground_reader( name, more_attribs={} )
|
56
|
-
real_name = name_to_real_name( name )
|
57
|
-
path = "#{@include_path}/#{real_name}.txt"
|
58
|
-
|
59
|
-
logger.info "parsing data (ground) '#{name}' (#{path})..."
|
60
|
-
GroundReader.from_file( path, more_attribs )
|
61
|
-
end
|
62
|
-
|
63
|
-
def create_league_reader( name, more_attribs={} )
|
64
|
-
real_name = name_to_real_name( name )
|
65
|
-
path = "#{@include_path}/#{real_name}.txt"
|
66
|
-
|
67
|
-
logger.info "parsing data (league) '#{name}' (#{path})..."
|
68
|
-
LeagueReader.from_file( path, more_attribs )
|
69
|
-
end
|
70
|
-
|
71
|
-
def create_team_reader( name, more_attribs={} )
|
72
|
-
real_name = name_to_real_name( name )
|
73
|
-
path = "#{@include_path}/#{real_name}.txt"
|
74
|
-
|
75
|
-
logger.info "parsing data (team) '#{name}' (#{path})..."
|
76
|
-
TeamReader.from_file( path, more_attribs )
|
77
|
-
end
|
78
|
-
|
79
|
-
def create_event_reader( name, more_attribs={} )
|
80
|
-
real_name = name_to_real_name( name )
|
81
|
-
path = "#{@include_path}/#{real_name}.yml"
|
82
|
-
|
83
|
-
logger.info "parsing data (event) '#{name}' (#{path})..."
|
84
|
-
EventReader.from_file( path, more_attribs )
|
85
|
-
end
|
86
|
-
|
87
|
-
def create_game_reader( name, more_attribs={} )
|
88
|
-
real_name = name_to_real_name( name )
|
89
|
-
|
90
|
-
## NOTE: pass in .yml as path (that is, event config!!!!)
|
91
|
-
path = "#{@include_path}/#{real_name}.yml"
|
92
|
-
|
93
|
-
logger.info "parsing data (fixture) '#{name}' (#{path})..."
|
94
|
-
GameReader.from_file( path, more_attribs )
|
95
|
-
end
|
96
|
-
|
97
|
-
|
98
|
-
def create_person_reader( name, more_attribs={} )
|
99
|
-
## fix-fix-fix: change to new format e.g. from_file, from_zip etc!!!
|
100
|
-
## reader = PersonDb::PersonReader.new( include_path )
|
101
|
-
# reader.read( name, country_id: country.id )
|
102
|
-
end
|
103
|
-
|
104
|
-
private
|
105
|
-
|
106
|
-
def name_to_real_name( name )
|
107
|
-
# map name to real_name path
|
108
|
-
# name might include !/ for virtual path (gets cut off)
|
109
|
-
# e.g. at-austria!/w-wien/beers becomse w-wien/beers
|
110
|
-
pos = name.index( '!/')
|
111
|
-
if pos.nil?
|
112
|
-
name # not found; real path is the same as name
|
113
|
-
else
|
114
|
-
# cut off everything until !/ e.g.
|
115
|
-
# at-austria!/w-wien/beers becomes
|
116
|
-
# w-wien/beers
|
117
|
-
name[ (pos+2)..-1 ]
|
118
|
-
end
|
119
|
-
end # method name_to_real_name
|
120
|
-
|
121
|
-
|
122
|
-
end # class Reader
|
123
|
-
end # module SportDb
|
data/lib/sportdb/reader_zip.rb
DELETED
@@ -1,165 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
module SportDb
|
4
|
-
|
5
|
-
|
6
|
-
class ZipReader < ReaderBase
|
7
|
-
|
8
|
-
def initialize( name, include_path, opts = {} )
|
9
|
-
|
10
|
-
## todo/fix: make include_path an opts (included in opts?) - why? why not??
|
11
|
-
|
12
|
-
path = "#{include_path}/#{name}.zip"
|
13
|
-
## todo: check if zip exists
|
14
|
-
|
15
|
-
@zip_file = Zip::File.open( path ) ## NOTE: do NOT create if file is missing; let it crash
|
16
|
-
|
17
|
-
### allow prefix (path) in name
|
18
|
-
### e.g. assume all files relative to setup manifest
|
19
|
-
## e.g. at-austria-master/setups/all.txt or
|
20
|
-
## be-belgium-master/setups/all.txt
|
21
|
-
## for
|
22
|
-
## setups/all.txt
|
23
|
-
###
|
24
|
-
## will get (re)set w/ fixture/setup reader
|
25
|
-
##
|
26
|
-
## todo/fix: change/rename to @relative_path ?? - why? why not?
|
27
|
-
@zip_prefix = ''
|
28
|
-
end
|
29
|
-
|
30
|
-
def close
|
31
|
-
## todo/check: add a close method - why? why not ???
|
32
|
-
@zip_file.close
|
33
|
-
end
|
34
|
-
|
35
|
-
|
36
|
-
def create_fixture_reader( name )
|
37
|
-
## e.g. pass in => setups/all or setups/test etc. e.g. w/o .txt extension
|
38
|
-
query = "**/#{name}.txt"
|
39
|
-
|
40
|
-
## note: returns an array of Zip::Entry
|
41
|
-
candidates = @zip_file.glob( query )
|
42
|
-
pp candidates
|
43
|
-
|
44
|
-
## use first candidates entry as match
|
45
|
-
## todo/fix: issue warning if more than one entries/matches!!
|
46
|
-
|
47
|
-
## get fullpath e.g. at-austria-master/setups/all.txt
|
48
|
-
path = candidates[0].name
|
49
|
-
logger.debug " zip entry path >>#{path}<<"
|
50
|
-
|
51
|
-
## cut-off at-austria-master/ NOTE: includes trailing slash (if present)
|
52
|
-
## logger.debug " path.size #{path.size} >>#{path}<<"
|
53
|
-
## logger.debug " name.size #{name.size+4} >>#{name}<<"
|
54
|
-
|
55
|
-
## note: add +4 for extension (.txt)
|
56
|
-
@zip_prefix = path[ 0...(path.size-(name.size+4)) ]
|
57
|
-
logger.debug " zip entry prefix >>#{@zip_prefix}<<"
|
58
|
-
|
59
|
-
logger.info "parsing data in zip '#{name}' (#{path})..."
|
60
|
-
|
61
|
-
FixtureReader.from_zip( @zip_file, path )
|
62
|
-
end
|
63
|
-
|
64
|
-
def create_club_squad_reader( name, more_attribs={} )
|
65
|
-
path = name_to_zip_entry_path( name )
|
66
|
-
|
67
|
-
logger.info "parsing data in zip (club squad) '#{name}' (#{path})..."
|
68
|
-
ClubSquadReader.from_zip( @zip_file, path, more_attribs )
|
69
|
-
end
|
70
|
-
|
71
|
-
def create_national_team_squad_reader( name, more_attribs={} )
|
72
|
-
path = name_to_zip_entry_path( name )
|
73
|
-
|
74
|
-
logger.info "parsing data in zip (national team squad) '#{name}' (#{path})..."
|
75
|
-
NationalTeamSquadReader.from_zip( @zip_file, path, more_attribs )
|
76
|
-
end
|
77
|
-
|
78
|
-
def create_season_reader( name )
|
79
|
-
path = name_to_zip_entry_path( name )
|
80
|
-
|
81
|
-
logger.info "parsing data in zip (season) '#{name}' (#{path})..."
|
82
|
-
SeasonReader.from_zip( @zip_file, path )
|
83
|
-
end
|
84
|
-
|
85
|
-
def create_assoc_reader( name )
|
86
|
-
path = name_to_zip_entry_path( name )
|
87
|
-
|
88
|
-
logger.info "parsing data in zip (assoc) '#{name}' (#{path})..."
|
89
|
-
AssocReader.from_zip( @zip_file, path )
|
90
|
-
end
|
91
|
-
|
92
|
-
def create_ground_reader( name, more_attribs={} )
|
93
|
-
path = name_to_zip_entry_path( name )
|
94
|
-
|
95
|
-
logger.info "parsing data in zip (ground) '#{name}' (#{path})..."
|
96
|
-
GroundReader.from_zip( @zip_file, path, more_attribs )
|
97
|
-
end
|
98
|
-
|
99
|
-
def create_league_reader( name, more_attribs={} )
|
100
|
-
path = name_to_zip_entry_path( name )
|
101
|
-
|
102
|
-
logger.info "parsing data in zip (league) '#{name}' (#{path})..."
|
103
|
-
LeagueReader.from_zip( @zip_file, path, more_attribs )
|
104
|
-
end
|
105
|
-
|
106
|
-
def create_team_reader( name, more_attribs={} )
|
107
|
-
path = name_to_zip_entry_path( name )
|
108
|
-
|
109
|
-
logger.info "parsing data in zip (team) '#{name}' (#{path})..."
|
110
|
-
TeamReader.from_zip( @zip_file, path, more_attribs )
|
111
|
-
end
|
112
|
-
|
113
|
-
def create_event_reader( name, more_attribs={} )
|
114
|
-
path = name_to_zip_entry_path( name, '.yml' ) ## NOTE: use .yml extension
|
115
|
-
|
116
|
-
logger.info "parsing data in zip (event) '#{name}' (#{path})..."
|
117
|
-
EventReader.from_zip( @zip_file, path, more_attribs )
|
118
|
-
end
|
119
|
-
|
120
|
-
def create_game_reader( name, more_attribs={} )
|
121
|
-
## NOTE: pass in .yml as path (that is, event config!!!!)
|
122
|
-
path = name_to_zip_entry_path( name, '.yml' ) ## NOTE: use .yml extension
|
123
|
-
|
124
|
-
logger.info "parsing data in zip (fixture) '#{name}' (#{path})..."
|
125
|
-
GameReader.from_zip( @zip_file, path, more_attribs )
|
126
|
-
end
|
127
|
-
|
128
|
-
|
129
|
-
def create_person_reader( name, more_attribs={} )
|
130
|
-
## fix-fix-fix: change to new format e.g. from_file, from_zip etc!!!
|
131
|
-
## reader = PersonDb::PersonReader.new( include_path )
|
132
|
-
# reader.read( name, country_id: country.id )
|
133
|
-
end
|
134
|
-
|
135
|
-
private
|
136
|
-
|
137
|
-
def path_to_real_path( path )
|
138
|
-
# map name to name_real_path
|
139
|
-
# name might include !/ for virtual path (gets cut off)
|
140
|
-
# e.g. at-austria!/w-wien/beers becomse w-wien/beers
|
141
|
-
pos = path.index( '!/')
|
142
|
-
if pos.nil?
|
143
|
-
path # not found; real path is the same as name
|
144
|
-
else
|
145
|
-
# cut off everything until !/ e.g.
|
146
|
-
# at-austria!/w-wien/beers becomes
|
147
|
-
# w-wien/beers
|
148
|
-
path[ (pos+2)..-1 ]
|
149
|
-
end
|
150
|
-
end
|
151
|
-
|
152
|
-
def name_to_zip_entry_path( name, extension='.txt' )
|
153
|
-
path = "#{name}#{extension}"
|
154
|
-
|
155
|
-
real_path = path_to_real_path( path )
|
156
|
-
|
157
|
-
# NOTE: add possible zip entry prefix path
|
158
|
-
# (if present includes trailing slash e.g. /)
|
159
|
-
entry_path = "#{@zip_prefix}#{real_path}"
|
160
|
-
entry_path
|
161
|
-
end
|
162
|
-
|
163
|
-
end # class ZipReader
|
164
|
-
|
165
|
-
end # module SportDb
|
@@ -1,54 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
module SportDb
|
4
|
-
|
5
|
-
|
6
|
-
class AssocReader
|
7
|
-
|
8
|
-
include LogUtils::Logging
|
9
|
-
|
10
|
-
## make models available by default with namespace
|
11
|
-
# e.g. lets you use Usage instead of Model::Usage
|
12
|
-
include Models
|
13
|
-
|
14
|
-
|
15
|
-
def self.from_zip( zip_file, entry_path, more_attribs={} )
|
16
|
-
## get text content from zip
|
17
|
-
entry = zip_file.find_entry( entry_path )
|
18
|
-
|
19
|
-
text = entry.get_input_stream().read()
|
20
|
-
text = text.force_encoding( Encoding::UTF_8 )
|
21
|
-
|
22
|
-
self.from_string( text, more_attribs )
|
23
|
-
end
|
24
|
-
|
25
|
-
def self.from_file( path, more_attribs={} )
|
26
|
-
## note: assume/enfore utf-8 encoding (with or without BOM - byte order mark)
|
27
|
-
## - see textutils/utils.rb
|
28
|
-
text = File.read_utf8( path )
|
29
|
-
self.from_string( text, more_attribs )
|
30
|
-
end
|
31
|
-
|
32
|
-
def self.from_string( text, more_attribs={} )
|
33
|
-
AssocReader.new( text, more_attribs )
|
34
|
-
end
|
35
|
-
|
36
|
-
|
37
|
-
def initialize( text, more_attribs={} )
|
38
|
-
## todo/fix: how to add opts={} ???
|
39
|
-
@text = text
|
40
|
-
@more_attribs = more_attribs
|
41
|
-
end
|
42
|
-
|
43
|
-
|
44
|
-
def read()
|
45
|
-
reader = ValuesReader.from_string( @text, @more_attribs )
|
46
|
-
|
47
|
-
reader.each_line do |new_attributes, values|
|
48
|
-
Assoc.create_or_update_from_values( new_attributes, values )
|
49
|
-
end # each lines
|
50
|
-
end
|
51
|
-
|
52
|
-
|
53
|
-
end # class AssocReader
|
54
|
-
end # module SportDb
|