sportdb 0.9.1 → 0.9.2

Sign up to get free protection for your applications and to get access to all the features.
data/lib/sportdb/utils.rb CHANGED
@@ -1,31 +1,243 @@
1
1
 
2
- ### some utils
2
+ ### some utils moved to worldbdb/utils for reuse
3
3
 
4
- class Time
4
+
5
+ module SportDB::FixtureHelpers
6
+
7
+ def is_round?( line )
8
+ line =~ /Spieltag|Runde|Achtelfinale|Viertelfinale|Halbfinale|Finale/
9
+ end
5
10
 
6
- def self.cet( str ) # central european time (cet) + central european summer time (cest)
7
- ActiveSupport::TimeZone['Vienna'].parse( str )
11
+ def is_group?( line )
12
+ # NB: check after is_round? (round may contain group reference!)
13
+ line =~ /Gruppe|Group/
14
+ end
15
+
16
+ def is_knockout_round?( line )
17
+ if line =~ /Achtelfinale|Viertelfinale|Halbfinale|Spiel um Platz 3|Finale|K\.O\.|Knockout/
18
+ puts " setting knockout flag to true"
19
+ true
20
+ else
21
+ false
22
+ end
8
23
  end
24
+
25
+ def find_group_title_and_pos!( line )
26
+ ## group pos - for now support single digit e.g 1,2,3 or letter e.g. A,B,C
27
+ ## nb: (?:) = is for non-capturing group(ing)
28
+ regex = /(?:Group|Gruppe)\s+((?:\d{1}|[A-Z]{1}))\b/
29
+
30
+ match = regex.match( line )
31
+
32
+ return [nil,nil] if match.nil?
33
+
34
+ pos = case match[1]
35
+ when 'A' then 1
36
+ when 'B' then 2
37
+ when 'C' then 3
38
+ when 'D' then 4
39
+ when 'E' then 5
40
+ when 'F' then 6
41
+ when 'G' then 7
42
+ when 'H' then 8
43
+ when 'I' then 9
44
+ when 'J' then 10
45
+ else match[1].to_i
46
+ end
47
+
48
+ title = match[0]
9
49
 
10
- def self.eet( str ) # eastern european time (eet) + 2 hours
11
- ActiveSupport::TimeZone['Bucharest'].parse( str )
50
+ puts " title: >#{title}<"
51
+ puts " pos: >#{pos}<"
52
+
53
+ line.sub!( regex, '[GROUP|TITLE+POS]' )
54
+
55
+ return [title,pos]
12
56
  end
13
57
 
14
- def self.cst( str ) # central standard time (cst) - 6 hours
15
- ActiveSupport::TimeZone['Mexico City'].parse( str )
58
+ def find_round_pos!( line )
59
+ ## fix/todo:
60
+ ## if no round found assume last_pos+1 ??? why? why not?
61
+
62
+ regex = /\b(\d+)\b/
63
+
64
+ if line =~ regex
65
+ value = $1.to_i
66
+ puts " pos: >#{value}<"
67
+
68
+ line.sub!( regex, '[ROUND|POS]' )
69
+
70
+ return value
71
+ else
72
+ return nil
73
+ end
16
74
  end
17
75
 
18
- end # class Time
76
+ def find_date!( line )
77
+ # extract date from line
78
+ # and return it
79
+ # NB: side effect - removes date from line string
80
+
81
+ # e.g. 2012-09-14 20:30 => YYYY-MM-DD HH:MM
82
+ regex_db = /\b(\d{4})-(\d{2})-(\d{2})\s+(\d{2}):(\d{2})\b/
83
+
84
+ # e.g. 14.09. 20:30 => DD.MM. HH:MM
85
+ regex_de = /\b(\d{2})\.(\d{2})\.\s+(\d{2}):(\d{2})\b/
86
+
87
+ if line =~ regex_db
88
+ value = "#{$1}-#{$2}-#{$3} #{$4}:#{$5}"
89
+ puts " date: >#{value}<"
19
90
 
91
+ ## todo: lets you configure year
92
+ ## and time zone (e.g. cet, eet, utc, etc.)
93
+
94
+ line.sub!( regex_db, '[DATE.DB]' )
20
95
 
21
- class File
22
- def self.read_utf8( path )
23
- open( path, 'r:bom|utf-8' ) do |file|
24
- file.read
96
+ return DateTime.strptime( value, '%Y-%m-%d %H:%M' )
97
+ elsif line =~ regex_de
98
+ value = "2012-#{$2}-#{$1} #{$3}:#{$4}"
99
+ puts " date: >#{value}<"
100
+
101
+ ## todo: lets you configure year
102
+ ## and time zone (e.g. cet, eet, utc, etc.)
103
+
104
+ line.sub!( regex_de, '[DATE.DE]' )
105
+
106
+ return DateTime.strptime( value, '%Y-%m-%d %H:%M' )
107
+ else
108
+ return nil
25
109
  end
26
110
  end
27
- end # class File
28
111
 
29
112
 
113
+ def find_game_pos!( line )
114
+ # extract optional game pos from line
115
+ # and return it
116
+ # NB: side effect - removes pos from line string
117
+
118
+ # e.g. (1) - must start line
119
+ regex = /^[ \t]*\((\d{1,3})\)[ \t]+/
120
+ if line =~ regex
121
+ puts " pos: >#{$1}<"
122
+
123
+ line.sub!( regex, '[POS] ' )
124
+ return $1.to_i
125
+ else
126
+ return nil
127
+ end
128
+
129
+ end
130
+
131
+ def find_scores!( line )
132
+ # extract score from line
133
+ # and return it
134
+ # NB: side effect - removes date from line string
135
+
136
+ # e.g. 1:2 or 0:2 or 3:3
137
+ regex = /\b(\d):(\d)\b/
138
+
139
+ # e.g. 1:2nV => overtime
140
+ regex_ot = /\b(\d):(\d)[ \t]?[nN][vV]\b/
141
+
142
+ # e.g. 5:4iE => penalty
143
+ regex_p = /\b(\d):(\d)[ \t]?[iI][eE]\b/
144
+
145
+ scores = []
146
+
147
+ if line =~ regex
148
+ puts " score: >#{$1}-#{$2}<"
149
+
150
+ line.sub!( regex, '[SCORE]' )
151
+
152
+ scores << $1.to_i
153
+ scores << $2.to_i
154
+
155
+ if line =~ regex_ot
156
+ puts " score.ot: >#{$1}-#{$2}<"
157
+
158
+ line.sub!( regex_ot, '[SCORE.OT]' )
159
+
160
+ scores << $1.to_i
161
+ scores << $2.to_i
162
+
163
+ if line =~ regex_p
164
+ puts " score.p: >#{$1}-#{$2}<"
165
+
166
+ line.sub!( regex_p, '[SCORE.P]' )
167
+
168
+ scores << $1.to_i
169
+ scores << $2.to_i
170
+ end
171
+ end
172
+ end
173
+ scores
174
+ end # methdod find_scores!
175
+
176
+
177
+ def find_team_worker!( line, index )
178
+ regex = /@@oo([^@]+?)oo@@/ # e.g. everything in @@ .... @@ (use non-greedy +? plus all chars but not @, that is [^@])
179
+
180
+ if line =~ regex
181
+ value = "#{$1}"
182
+ puts " team#{index}: >#{value}<"
183
+
184
+ line.sub!( regex, "[TEAM#{index}]" )
185
+
186
+ return $1
187
+ else
188
+ return nil
189
+ end
190
+ end
191
+
192
+ def find_teams!( line )
193
+ counter = 1
194
+ teams = []
195
+
196
+ team = find_team_worker!( line, counter )
197
+ while team.present?
198
+ teams << team
199
+ counter += 1
200
+ team = find_team_worker!( line, counter )
201
+ end
202
+
203
+ teams
204
+ end
205
+
206
+ def find_team1!( line )
207
+ find_team_worker!( line, 1 )
208
+ end
209
+
210
+ def find_team2!( line )
211
+ find_team_worker!( line, 2 )
212
+ end
213
+
214
+
215
+ def match_team_worker!( line, key, values )
216
+ values.each do |value|
217
+ ## nb: \b does NOT include space or newline for word boundry (only alphanums e.g. a-z0-9)
218
+ ## (thus add it, allows match for Benfica Lis. for example - note . at the end)
219
+
220
+ ## check add $ e.g. (\b| |\t|$) does this work? - check w/ Benfica Lis.$
221
+ regex = /\b#{value}(\b| |\t|$)/ # wrap with world boundry (e.g. match only whole words e.g. not wac in wacker)
222
+ if line =~ regex
223
+ puts " match for team >#{key}< >#{value}<"
224
+ # make sure @@oo{key}oo@@ doesn't match itself with other key e.g. wacker, wac, etc.
225
+ line.sub!( regex, "@@oo#{key}oo@@ " ) # NB: add one space char at end
226
+ return true # break out after first match (do NOT continue)
227
+ end
228
+ end
229
+ return false
230
+ end
231
+
232
+ ## todo/fix: pass in known_teams as a parameter? why? why not?
233
+ def match_teams!( line )
234
+ @known_teams.each do |rec|
235
+ key = rec[0]
236
+ values = rec[1]
237
+ match_team_worker!( line, key, values )
238
+ end # each known_teams
239
+ end # method translate_teams!
240
+
30
241
 
242
+ end # module SportDB::FixtureHelpers
31
243
 
@@ -1,4 +1,4 @@
1
1
 
2
2
  module SportDB
3
- VERSION = '0.9.1'
3
+ VERSION = '0.9.2'
4
4
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sportdb
3
3
  version: !ruby/object:Gem::Version
4
- hash: 57
4
+ hash: 63
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 9
9
- - 1
10
- version: 0.9.1
9
+ - 2
10
+ version: 0.9.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Gerald Bauer
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-11-20 00:00:00 Z
18
+ date: 2012-11-21 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: activerecord
@@ -40,12 +40,12 @@ dependencies:
40
40
  requirements:
41
41
  - - ~>
42
42
  - !ruby/object:Gem::Version
43
- hash: 23
43
+ hash: 11
44
44
  segments:
45
45
  - 0
46
- - 3
47
- - 2
48
- version: 0.3.2
46
+ - 5
47
+ - 0
48
+ version: 0.5.0
49
49
  type: :runtime
50
50
  version_requirements: *id002
51
51
  - !ruby/object:Gem::Dependency
@@ -87,18 +87,31 @@ extensions: []
87
87
  extra_rdoc_files:
88
88
  - Manifest.txt
89
89
  - db/america/2011.txt
90
+ - db/america/teams.txt
90
91
  - db/at/2011_12/bl.txt
91
92
  - db/at/2012_13/bl.txt
92
93
  - db/at/2012_13/cup.txt
94
+ - db/at/teams.txt
95
+ - db/cl/teams.txt
93
96
  - db/copa/sud_2012_13.txt
97
+ - db/copa/teams.txt
94
98
  - db/de/2012_13/bl.txt
99
+ - db/de/teams.txt
95
100
  - db/en/2012_13/pl.txt
101
+ - db/en/teams.txt
102
+ - db/es/teams.txt
96
103
  - db/euro/2008.txt
104
+ - db/euro/2012.txt
105
+ - db/euro/teams.txt
97
106
  - db/mx/apertura_2012.txt
107
+ - db/mx/teams.txt
108
+ - db/nhl/teams.txt
109
+ - db/ro/teams.txt
98
110
  - db/world/2010.txt
99
111
  - db/world/quali_2012_13_america.txt
100
112
  - db/world/quali_2012_13_europe_c.txt
101
113
  - db/world/quali_2012_13_europe_i.txt
114
+ - db/world/teams.txt
102
115
  files:
103
116
  - History.markdown
104
117
  - Manifest.txt
@@ -107,7 +120,8 @@ files:
107
120
  - bin/sportdb
108
121
  - db/america/2011.rb
109
122
  - db/america/2011.txt
110
- - db/america/teams.rb
123
+ - db/america/2011.yml
124
+ - db/america/teams.txt
111
125
  - db/at/2011_12/bl.rb
112
126
  - db/at/2011_12/bl.txt
113
127
  - db/at/2011_12/cup.rb
@@ -116,34 +130,35 @@ files:
116
130
  - db/at/2012_13/cup.rb
117
131
  - db/at/2012_13/cup.txt
118
132
  - db/at/badges.rb
119
- - db/at/teams.rb
133
+ - db/at/teams.txt
120
134
  - db/cl/2011_12/cl.rb
121
135
  - db/cl/2011_12/el.rb
122
136
  - db/cl/2012_13/cl.rb
123
137
  - db/cl/badges.rb
124
- - db/cl/teams.rb
138
+ - db/cl/teams.txt
125
139
  - db/copa/sud_2012_13.rb
126
140
  - db/copa/sud_2012_13.txt
127
- - db/copa/teams.rb
141
+ - db/copa/teams.txt
128
142
  - db/de/2012_13/bl.rb
129
143
  - db/de/2012_13/bl.txt
130
- - db/de/teams.rb
144
+ - db/de/teams.txt
131
145
  - db/en/2012_13/pl.rb
132
146
  - db/en/2012_13/pl.txt
133
- - db/en/teams.rb
134
- - db/es/teams.rb
147
+ - db/en/teams.txt
148
+ - db/es/teams.txt
135
149
  - db/euro/2008.rb
136
150
  - db/euro/2008.txt
137
151
  - db/euro/2012.rb
138
- - db/euro/teams.rb
152
+ - db/euro/2012.txt
153
+ - db/euro/teams.txt
139
154
  - db/leagues.rb
140
155
  - db/mx/apertura_2012.rb
141
156
  - db/mx/apertura_2012.txt
142
- - db/mx/teams.rb
157
+ - db/mx/teams.txt
143
158
  - db/nfl/teams.rb
144
- - db/nhl/teams.rb
159
+ - db/nhl/teams.txt
145
160
  - db/ro/l1_2012_13.rb
146
- - db/ro/teams.rb
161
+ - db/ro/teams.txt
147
162
  - db/seasons.rb
148
163
  - db/world/2010.rb
149
164
  - db/world/2010.txt
@@ -152,7 +167,7 @@ files:
152
167
  - db/world/quali_2012_13_europe.rb
153
168
  - db/world/quali_2012_13_europe_c.txt
154
169
  - db/world/quali_2012_13_europe_i.txt
155
- - db/world/teams.rb
170
+ - db/world/teams.txt
156
171
  - lib/sportdb.rb
157
172
  - lib/sportdb/cli/opts.rb
158
173
  - lib/sportdb/cli/runner.rb
data/db/america/teams.rb DELETED
@@ -1,57 +0,0 @@
1
- # encoding: utf-8
2
-
3
- ##############
4
- ## south america
5
-
6
- ar = Country.find_by_key!( 'ar' )
7
- br = Country.find_by_key!( 'br' )
8
- cl = Country.find_by_key!( 'cl' )
9
- py = Country.find_by_key!( 'py' )
10
- uy = Country.find_by_key!( 'uy' )
11
- co = Country.find_by_key!( 'co' )
12
- ec = Country.find_by_key!( 'ec' )
13
- pe = Country.find_by_key!( 'pe' )
14
- ve = Country.find_by_key!( 've' )
15
- bo = Country.find_by_key!( 'bo' )
16
-
17
- teams_america1 = [
18
- [ 'arg', 'Argentinien', 'ARG', ar ],
19
- [ 'bra', 'Brasilien', 'BRA', br ],
20
- [ 'chi', 'Chile', 'CHI', cl ],
21
- [ 'par', 'Paraguay', 'PAR', py ],
22
- [ 'uru', 'Uruguay', 'URU', uy ],
23
- [ 'col', 'Kolumbien', 'COL', co ],
24
- [ 'ecu', 'Ecuador', 'ECU', ec ],
25
- [ 'per', 'Peru', 'PER', pe ],
26
- [ 'ven', 'Venezuela', 'VEN', ve ],
27
- [ 'bol', 'Bolivien', 'BOL', bo ]
28
- ]
29
-
30
-
31
- #####################
32
- #### north/central america & caribbean islands
33
-
34
- mx = Country.find_by_key!( 'mx' )
35
- us = Country.find_by_key!( 'us' )
36
- hn = Country.find_by_key!( 'hn' )
37
- cr = Country.find_by_key!( 'cr' )
38
- sv = Country.find_by_key!( 'sv' )
39
- gy = Country.find_by_key!( 'gy' )
40
-
41
- teams_america2 = [
42
- [ 'mex', 'Mexiko|México', 'MEX', mx ],
43
- [ 'usa', 'Vereinigte Staaten|United States', 'USA', us ],
44
- [ 'hon', 'Honduras', 'HON', hn ],
45
- [ 'crc', 'Costa Rica', 'CRC', cr ],
46
- [ 'slv', 'El Salvador', 'SLV', sv ],
47
- [ 'guy', 'Guyana', 'GUY', gy ],
48
- ]
49
-
50
-
51
- teams = teams_america1 + teams_america2
52
-
53
- Team.create_from_ary!( teams, national: true )
54
-
55
-
56
- ## The End
57
- #################