sportdb-models 1.18.5 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Manifest.txt +27 -145
- data/Rakefile +4 -5
- data/lib/sportdb/models.rb +93 -160
- data/lib/sportdb/{deleter.rb → models/deleter.rb} +4 -10
- data/lib/sportdb/models/formats.rb +23 -0
- data/lib/sportdb/models/models/assoc.rb +38 -0
- data/lib/sportdb/models/{badge.rb → models/badge.rb} +1 -1
- data/lib/sportdb/models/models/event.rb +55 -0
- data/lib/sportdb/models/{forward.rb → models/forward.rb} +3 -3
- data/lib/sportdb/models/{goal.rb → models/goal.rb} +1 -1
- data/lib/sportdb/models/models/ground.rb +16 -0
- data/lib/sportdb/models/{group.rb → models/group.rb} +10 -7
- data/lib/sportdb/models/models/league.rb +20 -0
- data/lib/sportdb/models/{roster.rb → models/lineup.rb} +3 -4
- data/lib/sportdb/models/{game.rb → models/match.rb} +18 -61
- data/lib/sportdb/models/{person.rb → models/person.rb} +0 -0
- data/lib/sportdb/models/{round.rb → models/round.rb} +1 -6
- data/lib/sportdb/models/{season.rb → models/season.rb} +2 -1
- data/lib/sportdb/models/{stage.rb → models/stage.rb} +9 -5
- data/lib/sportdb/models/{stats/alltime_standing_entry.rb → models/stats/alltime_standing.rb} +9 -1
- data/lib/sportdb/models/{stats/event_standing_entry.rb → models/stats/event_standing.rb} +11 -1
- data/lib/sportdb/models/{stats/group_standing_entry.rb → models/stats/group_standing.rb} +10 -1
- data/lib/sportdb/models/models/team.rb +56 -0
- data/lib/sportdb/models/{world → models/world}/city.rb +2 -2
- data/lib/sportdb/models/{world → models/world}/continent.rb +0 -0
- data/lib/sportdb/models/{world → models/world}/country.rb +0 -0
- data/lib/sportdb/models/{world → models/world}/state.rb +0 -0
- data/lib/sportdb/{schema.rb → models/schema.rb} +165 -100
- data/lib/sportdb/models/stats.rb +23 -0
- data/lib/sportdb/models/utils.rb +24 -24
- data/lib/sportdb/{version.rb → models/version.rb} +12 -5
- data/test/helper.rb +10 -114
- data/test/test_changes.rb +38 -38
- data/test/test_cursor.rb +15 -15
- data/test/test_winner.rb +75 -70
- metadata +29 -161
- data/lib/sportdb/calc.rb +0 -279
- data/lib/sportdb/indexers/team.rb +0 -87
- data/lib/sportdb/mapper_teams.rb +0 -24
- 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/event.rb +0 -66
- data/lib/sportdb/models/event_ground.rb +0 -15
- data/lib/sportdb/models/event_team.rb +0 -16
- data/lib/sportdb/models/ground.rb +0 -100
- data/lib/sportdb/models/group_team.rb +0 -14
- data/lib/sportdb/models/league.rb +0 -83
- data/lib/sportdb/models/stage_team.rb +0 -14
- data/lib/sportdb/models/stats/alltime_standing.rb +0 -44
- data/lib/sportdb/models/stats/event_standing.rb +0 -55
- data/lib/sportdb/models/stats/group_standing.rb +0 -50
- data/lib/sportdb/models/team.rb +0 -119
- data/lib/sportdb/models/team_compat.rb +0 -64
- data/lib/sportdb/patterns.rb +0 -37
- data/lib/sportdb/pretty_printer.rb +0 -175
- data/lib/sportdb/reader.rb +0 -132
- data/lib/sportdb/reader_file.rb +0 -131
- data/lib/sportdb/reader_zip.rb +0 -172
- data/lib/sportdb/readers/assoc.rb +0 -54
- data/lib/sportdb/readers/event.rb +0 -253
- data/lib/sportdb/readers/event_meta.rb +0 -133
- data/lib/sportdb/readers/event_table.rb +0 -196
- data/lib/sportdb/readers/game.rb +0 -912
- 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/rsssf_reader.rb +0 -367
- 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 -48
- 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/2014_15/1-bundesliga-ii.txt +0 -158
- data/test/data/at-austria/2014_15/1-bundesliga.yml +0 -18
- data/test/data/at-austria/2015_16/1-bundesliga-v2.conf.txt +0 -20
- data/test/data/at-austria/2015_16/1-bundesliga-v2.yml +0 -20
- data/test/data/at-austria/2015_16/1-bundesliga.conf.txt +0 -20
- data/test/data/at-austria/2015_16/1-bundesliga.yml +0 -24
- data/test/data/at-austria/2015_16/cup.yml +0 -77
- data/test/data/at-austria/leagues.txt +0 -11
- data/test/data/at-austria/teams.txt +0 -68
- data/test/data/at-austria/teams_2.txt +0 -21
- data/test/data/csv/de-2013-14--1-bundesliga.txt +0 -307
- data/test/data/de-deutschland/2013-14/1-bundesliga.yml +0 -26
- data/test/data/de-deutschland/leagues.txt +0 -4
- data/test/data/de-deutschland/teams.txt +0 -53
- data/test/data/eng-england/2015-16/1-premierleague-v2.yml +0 -2
- data/test/data/eng-england/2015-16/1-premierleague.yml +0 -5
- 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/rsssf/at-2014-15--1-bundesliga.txt +0 -339
- data/test/data/rsssf/at-2015-16--1-bundesliga.txt +0 -18
- 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/test_assoc_reader.rb +0 -199
- data/test/test_event_meta_reader.rb +0 -47
- data/test/test_event_reader.rb +0 -64
- data/test/test_event_table_reader.rb +0 -57
- data/test/test_goals.rb +0 -107
- data/test/test_indexer_team.rb +0 -34
- data/test/test_load.rb +0 -61
- data/test/test_pp.rb +0 -35
- data/test/test_reader.rb +0 -88
- data/test/test_reader_from_string.rb +0 -63
- 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_rsssf_reader.rb +0 -76
- 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/lib/sportdb/patterns.rb
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
module SportDb
|
4
|
-
|
5
|
-
# collection of regex patterns for reuse (SportDb specific)
|
6
|
-
|
7
|
-
### todo: add a patterns.md page to github ??
|
8
|
-
## - add regexper pics??
|
9
|
-
|
10
|
-
############
|
11
|
-
# about ruby regexps
|
12
|
-
#
|
13
|
-
# try the rubular - Ruby regular expression editor and tester
|
14
|
-
# -> http://rubular.com
|
15
|
-
# code -> ?? by ??
|
16
|
-
#
|
17
|
-
#
|
18
|
-
# Jeff Avallone's Regexper - Shows State-Automata Diagrams
|
19
|
-
# try -> http://regexper.com
|
20
|
-
# code -> https://github.com/javallone/regexper
|
21
|
-
#
|
22
|
-
#
|
23
|
-
# Regular Expressions | The Bastards Book of Ruby by Dan Nguyen
|
24
|
-
# http://ruby.bastardsbook.com/chapters/regexes/
|
25
|
-
#
|
26
|
-
# move to notes regex|patterns on geraldb.github.io ??
|
27
|
-
#
|
28
|
-
|
29
|
-
TEAM_KEY_PATTERN = '\A[a-z]{3,}\z'
|
30
|
-
TEAM_KEY_PATTERN_MESSAGE = "expected three or more lowercase letters a-z /#{TEAM_KEY_PATTERN}/"
|
31
|
-
|
32
|
-
# must start w/ letter A-Z (2nd,3rd,4th or 5th can be number or underscore _)
|
33
|
-
TEAM_CODE_PATTERN = '\A[A-Z_][A-Z0-9_]{1,4}\z'
|
34
|
-
TEAM_CODE_PATTERN_MESSAGE = "expected two or three or four or five uppercase letters A-Z (and 0-9_; must start with A-Z) /#{TEAM_CODE_PATTERN}/"
|
35
|
-
|
36
|
-
|
37
|
-
end # module SportDb
|
@@ -1,175 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
module SportDb
|
4
|
-
|
5
|
-
|
6
|
-
###
|
7
|
-
## reads in a text files
|
8
|
-
## and tries to fix up/patch some parts
|
9
|
-
|
10
|
-
|
11
|
-
class Patcher
|
12
|
-
|
13
|
-
include LogUtils::Logging
|
14
|
-
|
15
|
-
def initialize( root, opts={} )
|
16
|
-
@root = root
|
17
|
-
@path = opts[:path] || opts[:paths] # pass in regex as string
|
18
|
-
@names = opts[:name] || opts[:names] # pass in regex as string
|
19
|
-
|
20
|
-
@path_regex = Regexp.new( @path ) if @path
|
21
|
-
@names_regex = Regexp.new( @names ) if @names
|
22
|
-
end
|
23
|
-
|
24
|
-
|
25
|
-
def find_files
|
26
|
-
## note: for now always filter by .txt extension
|
27
|
-
files = Dir[ "#{@root}/**/*.txt" ]
|
28
|
-
|
29
|
-
puts "before filter:"
|
30
|
-
pp files
|
31
|
-
|
32
|
-
files = files.select do |f|
|
33
|
-
|
34
|
-
basename = File.basename( f )
|
35
|
-
dirname = File.dirname( f ) # note: add trailing slash
|
36
|
-
dirname = "#{dirname}/"
|
37
|
-
|
38
|
-
puts " basename=>#{basename}<, dirname=>#{dirname}<"
|
39
|
-
|
40
|
-
if @path_regex
|
41
|
-
match_dirname = @path_regex === dirname # note: use === (triple) for true/false regex match
|
42
|
-
else
|
43
|
-
match_dirname = true
|
44
|
-
end
|
45
|
-
|
46
|
-
if @names_regex
|
47
|
-
match_basename = @names_regex === basename
|
48
|
-
else
|
49
|
-
match_basename = true
|
50
|
-
end
|
51
|
-
|
52
|
-
match_basename && match_dirname
|
53
|
-
end
|
54
|
-
|
55
|
-
puts "after filter:"
|
56
|
-
pp files
|
57
|
-
|
58
|
-
files
|
59
|
-
end # method find_files
|
60
|
-
|
61
|
-
|
62
|
-
def patch( save=false)
|
63
|
-
files = find_files
|
64
|
-
change_logs = []
|
65
|
-
|
66
|
-
files.each do |file|
|
67
|
-
p = PrettyPrinter.from_file( file )
|
68
|
-
new_text, change_log = p.patch
|
69
|
-
|
70
|
-
next if change_log.empty? ## no changes
|
71
|
-
|
72
|
-
if save
|
73
|
-
File.open( file, 'w' ) do |f|
|
74
|
-
f.write new_text
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
change_logs << [file, change_log]
|
79
|
-
end
|
80
|
-
|
81
|
-
change_logs ## return change_logs or empty array
|
82
|
-
end # method patch
|
83
|
-
|
84
|
-
end ## class Patcher
|
85
|
-
|
86
|
-
|
87
|
-
class PrettyPrinter
|
88
|
-
|
89
|
-
include LogUtils::Logging
|
90
|
-
|
91
|
-
def self.from_file( path, opts={} )
|
92
|
-
## note: assume/enfore utf-8 encoding (with or without BOM - byte order mark)
|
93
|
-
## - see textutils/utils.rb
|
94
|
-
text = File.read_utf8( path )
|
95
|
-
self.from_string( text, opts )
|
96
|
-
end
|
97
|
-
|
98
|
-
def self.from_string( text, opts={} )
|
99
|
-
self.new( text, opts )
|
100
|
-
end
|
101
|
-
|
102
|
-
|
103
|
-
def initialize( text, opts={} )
|
104
|
-
@old_text = text
|
105
|
-
@opts = opts
|
106
|
-
end
|
107
|
-
|
108
|
-
|
109
|
-
## change to DE_SCORES_REGEX or SCORES_DE_REGEX ??
|
110
|
-
SCORES_REGEX = /\b
|
111
|
-
(?<score1>\d{1,2})
|
112
|
-
-
|
113
|
-
(?<score2>\d{1,2})
|
114
|
-
\b
|
115
|
-
/x
|
116
|
-
|
117
|
-
def patch ## return new text (and change log??)
|
118
|
-
new_text = ''
|
119
|
-
change_log = [] ## track changes - rename - use edits? changes? etc.
|
120
|
-
line_no = 0
|
121
|
-
|
122
|
-
@old_text.each_line do |line|
|
123
|
-
line_no +=1
|
124
|
-
|
125
|
-
# comments allow:
|
126
|
-
# 1) ##### (shell/ruby style)
|
127
|
-
# 2) -- comment here (haskel/?? style)
|
128
|
-
# 3) % comment here (tex/latex style)
|
129
|
-
|
130
|
-
if line =~ /^\s*#/ || line =~ /^\s*--/ || line =~ /^\s*%/
|
131
|
-
# skip komments and do NOT copy to result (keep comments secret!)
|
132
|
-
logger.debug "[#{line_no}] add comment line >#{line}<"
|
133
|
-
new_text << line
|
134
|
-
next
|
135
|
-
end
|
136
|
-
|
137
|
-
if line =~ /^\s*$/
|
138
|
-
# kommentar oder leerzeile überspringen
|
139
|
-
logger.debug "[#{line_no}] add blank line >#{line}<"
|
140
|
-
new_text << line
|
141
|
-
next
|
142
|
-
end
|
143
|
-
|
144
|
-
## do nothing for now
|
145
|
-
if line =~ SCORES_REGEX
|
146
|
-
## patch scores format
|
147
|
-
logger.debug "** found scores >#{line}<"
|
148
|
-
|
149
|
-
new_line = line.dup
|
150
|
-
new_line.gsub!( SCORES_REGEX ) do |m|
|
151
|
-
logger.debug " match: >#{m}< : #{m.class.name}"
|
152
|
-
|
153
|
-
old_scores = m
|
154
|
-
## todo: how to use named captures? possible?
|
155
|
-
new_scores = "#{$1}:#{$2}"
|
156
|
-
|
157
|
-
change_log << [line_no, "changed >#{old_scores}< to >#{new_scores}< in >#{line}<"]
|
158
|
-
|
159
|
-
new_scores
|
160
|
-
end
|
161
|
-
|
162
|
-
logger.debug "[#{line_no}] add patched line >#{new_line}<"
|
163
|
-
new_text << new_line
|
164
|
-
else
|
165
|
-
logger.debug "[#{line_no}] add >#{line}<"
|
166
|
-
new_text << line
|
167
|
-
end
|
168
|
-
end # each lines
|
169
|
-
|
170
|
-
[new_text, change_log]
|
171
|
-
end # method patch
|
172
|
-
|
173
|
-
|
174
|
-
end # class PrettyPrinter
|
175
|
-
end # module SportDb
|
data/lib/sportdb/reader.rb
DELETED
@@ -1,132 +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 =~ /\.conf$/ ## e.g. 1-premierleague.conf => 1-premierleague.conf.txt
|
109
|
-
reader = create_event_table_reader( name )
|
110
|
-
reader.read()
|
111
|
-
# note: keep a "public" reference of last event in @event - e.g. used/required by squads etc.
|
112
|
-
@event = reader.event
|
113
|
-
elsif name =~ /\/(\d{4}|\d{4}[_\-]\d{2})(--[^\/]+)?\// ||
|
114
|
-
name =~ /\/(\d{4}|\d{4}[_\-]\d{2})$/
|
115
|
-
|
116
|
-
# note: allow 2013_14 or 2013-14 (that, is dash or underscore)
|
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
|
-
# note: keep a "public" reference of last event in @event - e.g. used/required by squads etc.
|
123
|
-
@event = reader.event
|
124
|
-
else
|
125
|
-
logger.error "unknown sportdb fixture type >#{name}<"
|
126
|
-
# todo/fix: exit w/ error
|
127
|
-
end
|
128
|
-
end # method load
|
129
|
-
|
130
|
-
|
131
|
-
end # class Reader
|
132
|
-
end # module SportDb
|
data/lib/sportdb/reader_file.rb
DELETED
@@ -1,131 +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_event_table_reader( name, more_attribs={} )
|
88
|
-
real_name = name_to_real_name( name )
|
89
|
-
path = "#{@include_path}/#{real_name}.txt"
|
90
|
-
|
91
|
-
logger.info "parsing data (event table) '#{name}' (#{path})..."
|
92
|
-
EventTableReader.from_file( path, more_attribs )
|
93
|
-
end
|
94
|
-
|
95
|
-
def create_game_reader( name, more_attribs={} )
|
96
|
-
real_name = name_to_real_name( name )
|
97
|
-
|
98
|
-
## NOTE: pass in .yml as path (that is, event config!!!!)
|
99
|
-
path = "#{@include_path}/#{real_name}.yml"
|
100
|
-
|
101
|
-
logger.info "parsing data (fixture) '#{name}' (#{path})..."
|
102
|
-
GameReader.from_file( path, more_attribs )
|
103
|
-
end
|
104
|
-
|
105
|
-
|
106
|
-
def create_person_reader( name, more_attribs={} )
|
107
|
-
## fix-fix-fix: change to new format e.g. from_file, from_zip etc!!!
|
108
|
-
## reader = PersonDb::PersonReader.new( include_path )
|
109
|
-
# reader.read( name, country_id: country.id )
|
110
|
-
end
|
111
|
-
|
112
|
-
private
|
113
|
-
|
114
|
-
def name_to_real_name( name )
|
115
|
-
# map name to real_name path
|
116
|
-
# name might include !/ for virtual path (gets cut off)
|
117
|
-
# e.g. at-austria!/w-wien/beers becomse w-wien/beers
|
118
|
-
pos = name.index( '!/')
|
119
|
-
if pos.nil?
|
120
|
-
name # not found; real path is the same as name
|
121
|
-
else
|
122
|
-
# cut off everything until !/ e.g.
|
123
|
-
# at-austria!/w-wien/beers becomes
|
124
|
-
# w-wien/beers
|
125
|
-
name[ (pos+2)..-1 ]
|
126
|
-
end
|
127
|
-
end # method name_to_real_name
|
128
|
-
|
129
|
-
|
130
|
-
end # class Reader
|
131
|
-
end # module SportDb
|