85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
|
# File 'lib/sportdb/formats/event/event_reader.rb', line 85
def parse
recs = []
parse_csv( @txt ).each do |row|
league_col = row['League']
season_col = row['Season'] || row['Year']
dates_col = row['Dates']
season = Import::Season.parse( season_col )
league = catalog.leagues.find!( league_col )
dates = []
if dates_col.nil? || dates_col.empty?
else
dates_col = dates_col.gsub( /[ ]{2,}/, ' ' )
puts "#{league.name} (#{league.key}) | #{season.key} | #{dates_col}"
parts = dates_col.split( /[ ]*[–-][ ]*/ )
if parts.size == 1
pp parts
dates << DateFormats.parse( parts[0], start: Date.new( season.start_year, 1, 1 ), lang: 'en' )
pp dates
elsif parts.size == 2
pp parts
dates << DateFormats.parse( parts[0], start: Date.new( season.start_year, 1, 1 ), lang: 'en' )
dates << DateFormats.parse( parts[1], start: Date.new( season.end_year ? season.end_year : season.start_year, 1, 1 ), lang: 'en' )
pp dates
diff = dates[1].to_date.jd - dates[0].to_date.jd
puts "#{diff}d"
if diff > 365
puts "!! ERROR - date range / period assertion failed; expected diff < 365 days"
exit 1
end
else
puts "!! ERRROR - expected data range / period - one or two dates; got #{parts.size}:"
pp dates_col
pp parts
exit 1
end
end
teams_col = row['Clubs'] || row['Teams']
goals_col = row['Goals']
teams_col = teams_col.gsub( /[^0-9]/, '' ) if teams_col
goals_col = goals_col.gsub( /[^0-9]/, '' ) if goals_col
teams = (teams_col.nil? || teams_col.empty?) ? nil : teams_col.to_i
goals = (goals_col.nil? || goals_col.empty?) ? nil : goals_col.to_i
matches_col = row['Matches']
matches_col = matches_col.gsub( /[^0-9+]/, '' ) if matches_col
matches = if matches_col.nil? || matches_col.empty?
nil
else
if matches_col.index( '+' ) matches_col.split( '+' ).reduce( 0 ) do |sum,str|
sum + str.to_i
end
else matches_col.to_i
end
end
rec = EventInfo.new( league: league,
season: season,
start_date: dates[0],
end_date: dates[1],
teams: teams,
matches: matches,
goals: goals
)
recs << rec
end recs
end
|