sportdb 0.9.7 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Manifest.txt +12 -55
- data/Rakefile +11 -10
- data/bin/sportdb +1 -2
- data/config/fixtures.de.yml +42 -0
- data/config/fixtures.en.yml +52 -0
- data/config/fixtures.es.yml +44 -0
- data/config/fixtures.pt.yml +44 -0
- data/lib/sportdb/cli/main.rb +189 -0
- data/lib/sportdb/cli/opts.rb +15 -69
- data/lib/sportdb/data/fixtures.rb +205 -0
- data/lib/sportdb/{keys.rb → data/keys.rb} +9 -2
- data/lib/sportdb/data/models.rb +43 -0
- data/lib/sportdb/deleter.rb +27 -0
- data/lib/sportdb/lang.rb +265 -0
- data/lib/sportdb/models/event.rb +0 -34
- data/lib/sportdb/reader.rb +322 -78
- data/lib/sportdb/stats.rb +28 -0
- data/lib/sportdb/utils.rb +90 -13
- data/lib/sportdb/version.rb +1 -1
- data/lib/sportdb.rb +49 -198
- data/tasks/test.rb +163 -0
- metadata +46 -71
- data/data/america/2011.rb +0 -36
- data/data/america/2011.txt +0 -110
- data/data/america/2011.yml +0 -30
- data/data/america/teams.txt +0 -26
- data/data/at/2011_12/bl.rb +0 -30
- data/data/at/2011_12/bl.txt +0 -79
- data/data/at/2011_12/cup.rb +0 -66
- data/data/at/2012_13/bl.rb +0 -33
- data/data/at/2012_13/bl.txt +0 -198
- data/data/at/2012_13/cup.rb +0 -111
- data/data/at/2012_13/cup.txt +0 -89
- data/data/at/badges.rb +0 -22
- data/data/at/teams.txt +0 -88
- data/data/cl/2011_12/cl.rb +0 -88
- data/data/cl/2011_12/el.rb +0 -65
- data/data/cl/2012_13/cl.rb +0 -324
- data/data/cl/badges.rb +0 -68
- data/data/cl/teams.txt +0 -46
- data/data/copa/sud_2012_13.rb +0 -38
- data/data/copa/sud_2012_13.txt +0 -49
- data/data/copa/teams.txt +0 -35
- data/data/de/2012_13/bl.rb +0 -38
- data/data/de/2012_13/bl.txt +0 -216
- data/data/de/teams.txt +0 -23
- data/data/en/2012_13/pl.rb +0 -39
- data/data/en/2012_13/pl.txt +0 -291
- data/data/en/teams.txt +0 -26
- data/data/es/teams.txt +0 -8
- data/data/euro/2008.rb +0 -30
- data/data/euro/2008.txt +0 -114
- data/data/euro/2012.rb +0 -25
- data/data/euro/2012.txt +0 -114
- data/data/euro/teams.txt +0 -36
- data/data/leagues.rb +0 -68
- data/data/mx/apertura_2012.rb +0 -35
- data/data/mx/apertura_2012.txt +0 -106
- data/data/mx/teams.txt +0 -20
- data/data/nfl/teams.txt +0 -46
- data/data/nhl/teams.txt +0 -40
- data/data/ro/l1_2012_13.rb +0 -137
- data/data/ro/teams.txt +0 -26
- data/data/seasons.rb +0 -22
- data/data/world/2010.rb +0 -93
- data/data/world/2010.txt +0 -215
- data/data/world/quali_2012_13_america.rb +0 -25
- data/data/world/quali_2012_13_america.txt +0 -41
- data/data/world/quali_2012_13_europe.rb +0 -32
- data/data/world/quali_2012_13_europe_c.txt +0 -85
- data/data/world/quali_2012_13_europe_i.txt +0 -74
- data/data/world/teams.txt +0 -25
- data/lib/sportdb/cli/runner.rb +0 -147
- data/lib/sportdb/loader.rb +0 -82
- data/lib/sportdb/templater.rb +0 -81
- data/templates/fixtures.rb.erb +0 -51
data/lib/sportdb/utils.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# encoding: utf-8
|
1
2
|
|
2
3
|
### some utils moved to worldbdb/utils for reuse
|
3
4
|
|
@@ -5,33 +6,43 @@
|
|
5
6
|
module SportDB::FixtureHelpers
|
6
7
|
|
7
8
|
def is_round?( line )
|
8
|
-
line =~
|
9
|
+
line =~ SportDB.lang.regex_round
|
9
10
|
end
|
10
|
-
|
11
|
+
|
11
12
|
def is_group?( line )
|
12
13
|
# NB: check after is_round? (round may contain group reference!)
|
13
|
-
line =~
|
14
|
+
line =~ SportDB.lang.regex_group
|
14
15
|
end
|
15
|
-
|
16
|
+
|
16
17
|
def is_knockout_round?( line )
|
17
|
-
|
18
|
+
|
19
|
+
## todo: check for adding ignore case for regex (e.g. 1st leg/1st Leg)
|
20
|
+
|
21
|
+
if line =~ SportDB.lang.regex_leg1
|
22
|
+
puts " two leg knockout; skip knockout flag on first leg"
|
23
|
+
false
|
24
|
+
elsif line =~ SportDB.lang.regex_knockout_round
|
18
25
|
puts " setting knockout flag to true"
|
19
26
|
true
|
27
|
+
elsif line =~ /K\.O\.|Knockout/
|
28
|
+
## NB: add two language independent markers, that is, K.O. and Knockout
|
29
|
+
puts " setting knockout flag to true (lang independent marker)"
|
30
|
+
true
|
20
31
|
else
|
21
32
|
false
|
22
33
|
end
|
23
34
|
end
|
24
35
|
|
25
36
|
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
|
37
|
+
## group pos - for now support single digit e.g 1,2,3 or letter e.g. A,B,C or HEX
|
27
38
|
## nb: (?:) = is for non-capturing group(ing)
|
28
|
-
regex = /(?:Group|Gruppe)\s+((?:\d{1}|[A-Z]{1}))\b/
|
39
|
+
regex = /(?:Group|Gruppe|Grupo)\s+((?:\d{1}|[A-Z]{1,3}))\b/
|
29
40
|
|
30
41
|
match = regex.match( line )
|
31
42
|
|
32
43
|
return [nil,nil] if match.nil?
|
33
44
|
|
34
|
-
pos = case match[1]
|
45
|
+
pos = case match[1]
|
35
46
|
when 'A' then 1
|
36
47
|
when 'B' then 2
|
37
48
|
when 'C' then 3
|
@@ -42,6 +53,9 @@ module SportDB::FixtureHelpers
|
|
42
53
|
when 'H' then 8
|
43
54
|
when 'I' then 9
|
44
55
|
when 'J' then 10
|
56
|
+
when 'K' then 11
|
57
|
+
when 'L' then 12
|
58
|
+
when 'HEX' then 666 # HEX for Hexagonal - todo/check: map to something else ??
|
45
59
|
else match[1].to_i
|
46
60
|
end
|
47
61
|
|
@@ -56,9 +70,42 @@ module SportDB::FixtureHelpers
|
|
56
70
|
end
|
57
71
|
|
58
72
|
def find_round_pos!( line )
|
73
|
+
|
74
|
+
## todo: let title2 go first to cut off //
|
75
|
+
## todo: cut of end of line comments w/ # ???
|
76
|
+
|
59
77
|
## fix/todo:
|
60
78
|
## if no round found assume last_pos+1 ??? why? why not?
|
61
79
|
|
80
|
+
# extract optional round pos from line
|
81
|
+
# e.g. (1) - must start line
|
82
|
+
regex = /^[ \t]*\((\d{1,3})\)[ \t]+/
|
83
|
+
if line =~ regex
|
84
|
+
puts " pos: >#{$1}<"
|
85
|
+
|
86
|
+
line.sub!( regex, '[ROUND|POS] ' ) ## NB: add back trailing space that got swallowed w/ regex -> [ \t]+
|
87
|
+
return $1.to_i
|
88
|
+
end
|
89
|
+
|
90
|
+
# continue; try some other options
|
91
|
+
|
92
|
+
# NB: do not search string after free standing / or //
|
93
|
+
# cut-off optional trailing part w/ starting w/ / or //
|
94
|
+
#
|
95
|
+
# e.g. Viertelfinale // Di+Mi 10.+11. April 2012 becomes just
|
96
|
+
# Viertelfinale
|
97
|
+
|
98
|
+
cutoff_regex = /^(.+?)[ \t]\/{1,3}[ \t]/
|
99
|
+
|
100
|
+
if line =~ cutoff_regex
|
101
|
+
line = $1.to_s # cut off the rest if regex matches
|
102
|
+
end
|
103
|
+
|
104
|
+
## fix/todo: use cutoff_line for search
|
105
|
+
## and use line.sub! to change original string
|
106
|
+
# e.g. Jornada 3 // 1,2 y 3 febrero
|
107
|
+
# only replaces match in local string w/ [ROUND|POS]
|
108
|
+
|
62
109
|
regex = /\b(\d+)\b/
|
63
110
|
|
64
111
|
if line =~ regex
|
@@ -70,7 +117,7 @@ module SportDB::FixtureHelpers
|
|
70
117
|
return value
|
71
118
|
else
|
72
119
|
return nil
|
73
|
-
end
|
120
|
+
end
|
74
121
|
end
|
75
122
|
|
76
123
|
def find_date!( line )
|
@@ -80,9 +127,15 @@ module SportDB::FixtureHelpers
|
|
80
127
|
|
81
128
|
# e.g. 2012-09-14 20:30 => YYYY-MM-DD HH:MM
|
82
129
|
regex_db = /\b(\d{4})-(\d{2})-(\d{2})\s+(\d{2}):(\d{2})\b/
|
130
|
+
|
131
|
+
# e.g. 2012-09-14 w/ implied hours (set to 12:00)
|
132
|
+
regex_db2 = /\b(\d{4})-(\d{2})-(\d{2})\b/
|
83
133
|
|
84
134
|
# e.g. 14.09. 20:30 => DD.MM. HH:MM
|
85
135
|
regex_de = /\b(\d{2})\.(\d{2})\.\s+(\d{2}):(\d{2})\b/
|
136
|
+
|
137
|
+
# e.g. 14.09.2012 20:30 => DD.MM.YYYY HH:MM
|
138
|
+
regex_de2 = /\b(\d{2})\.(\d{2})\.(\d{4})\s+(\d{2}):(\d{2})\b/
|
86
139
|
|
87
140
|
if line =~ regex_db
|
88
141
|
value = "#{$1}-#{$2}-#{$3} #{$4}:#{$5}"
|
@@ -93,6 +146,23 @@ module SportDB::FixtureHelpers
|
|
93
146
|
|
94
147
|
line.sub!( regex_db, '[DATE.DB]' )
|
95
148
|
|
149
|
+
return DateTime.strptime( value, '%Y-%m-%d %H:%M' )
|
150
|
+
elsif line =~ regex_db2
|
151
|
+
value = "#{$1}-#{$2}-#{$3} 12:00"
|
152
|
+
puts " date: >#{value}<"
|
153
|
+
|
154
|
+
line.sub!( regex_db2, '[DATE.DB2]' )
|
155
|
+
|
156
|
+
return DateTime.strptime( value, '%Y-%m-%d %H:%M' )
|
157
|
+
elsif line =~ regex_de2
|
158
|
+
value = "#{$3}-#{$2}-#{$1} #{$4}:#{$5}"
|
159
|
+
puts " date: >#{value}<"
|
160
|
+
|
161
|
+
## todo: lets you configure year
|
162
|
+
## and time zone (e.g. cet, eet, utc, etc.)
|
163
|
+
|
164
|
+
line.sub!( regex_de2, '[DATE.DE2]' )
|
165
|
+
|
96
166
|
return DateTime.strptime( value, '%Y-%m-%d %H:%M' )
|
97
167
|
elsif line =~ regex_de
|
98
168
|
value = "2012-#{$2}-#{$1} #{$3}:#{$4}"
|
@@ -129,18 +199,25 @@ module SportDB::FixtureHelpers
|
|
129
199
|
end
|
130
200
|
|
131
201
|
def find_scores!( line )
|
202
|
+
|
203
|
+
### fix: depending on language allow 1:1 or 1-1
|
204
|
+
## do NOT allow mix and match
|
205
|
+
## e.g. default to en is 1-1
|
206
|
+
## de is 1:1 etc.
|
207
|
+
|
208
|
+
|
132
209
|
# extract score from line
|
133
210
|
# and return it
|
134
211
|
# NB: side effect - removes date from line string
|
135
212
|
|
136
|
-
# e.g. 1:2 or 0:2 or 3:3
|
137
|
-
regex = /\b(\d)
|
213
|
+
# e.g. 1:2 or 0:2 or 3:3 // 1-1 or 0-2 or 3-3
|
214
|
+
regex = /\b(\d)[:\-](\d)\b/
|
138
215
|
|
139
216
|
# e.g. 1:2nV => overtime
|
140
|
-
regex_ot = /\b(\d)
|
217
|
+
regex_ot = /\b(\d)[:\-](\d)[ \t]?[nN][vV]\b/
|
141
218
|
|
142
219
|
# e.g. 5:4iE => penalty
|
143
|
-
regex_p = /\b(\d)
|
220
|
+
regex_p = /\b(\d)[:\-](\d)[ \t]?[iI][eE]\b/
|
144
221
|
|
145
222
|
scores = []
|
146
223
|
|
data/lib/sportdb/version.rb
CHANGED
data/lib/sportdb.rb
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
|
1
4
|
###
|
2
5
|
# NB: for local testing run like:
|
3
6
|
#
|
@@ -7,14 +10,17 @@
|
|
7
10
|
|
8
11
|
require 'yaml'
|
9
12
|
require 'pp'
|
10
|
-
require 'logger'
|
11
|
-
require 'optparse'
|
13
|
+
require 'logger' ## todo/fix: no longer needed - replaced by logutils??
|
12
14
|
require 'fileutils'
|
13
15
|
require 'erb'
|
14
16
|
|
15
|
-
# rubygems
|
17
|
+
# rubygems / 3rd party libs
|
16
18
|
|
17
19
|
require 'active_record' ## todo: add sqlite3? etc.
|
20
|
+
|
21
|
+
require 'logutils'
|
22
|
+
require 'textutils'
|
23
|
+
|
18
24
|
require 'worlddb'
|
19
25
|
|
20
26
|
|
@@ -22,7 +28,6 @@ require 'worlddb'
|
|
22
28
|
|
23
29
|
require 'sportdb/version'
|
24
30
|
|
25
|
-
require 'sportdb/keys'
|
26
31
|
require 'sportdb/models/forward'
|
27
32
|
require 'sportdb/models/badge'
|
28
33
|
require 'sportdb/models/city'
|
@@ -40,11 +45,24 @@ require 'sportdb/models/season'
|
|
40
45
|
require 'sportdb/models/team'
|
41
46
|
require 'sportdb/schema' # NB: requires sportdb/models (include SportDB::Models)
|
42
47
|
require 'sportdb/utils'
|
43
|
-
require 'sportdb/loader'
|
44
48
|
require 'sportdb/reader'
|
45
|
-
require 'sportdb/
|
46
|
-
|
47
|
-
require 'sportdb/
|
49
|
+
require 'sportdb/lang'
|
50
|
+
|
51
|
+
require 'sportdb/deleter'
|
52
|
+
require 'sportdb/stats'
|
53
|
+
|
54
|
+
###############
|
55
|
+
# optional: for convenience add some finders etc. for known fixtures
|
56
|
+
#
|
57
|
+
# only used for sportdb/console.rb
|
58
|
+
# and sportdb/tasks/test.rb -> rename to tasks.rb?
|
59
|
+
#
|
60
|
+
# todo/fix => remove from here and move into console.rb and tasks.rb
|
61
|
+
|
62
|
+
require 'sportdb/data/keys'
|
63
|
+
require 'sportdb/data/fixtures'
|
64
|
+
require 'sportdb/data/models' # add convenience finders for known fixtures
|
65
|
+
|
48
66
|
|
49
67
|
|
50
68
|
module SportDB
|
@@ -56,192 +74,49 @@ module SportDB
|
|
56
74
|
def self.root
|
57
75
|
"#{File.expand_path( File.dirname(File.dirname(__FILE__)) )}"
|
58
76
|
end
|
59
|
-
|
60
|
-
# builtin path to fixture data
|
61
|
-
def self.data_path
|
62
|
-
"#{root}/data"
|
63
|
-
end
|
64
|
-
|
65
77
|
|
66
|
-
def self.
|
67
|
-
|
78
|
+
def self.config_path
|
79
|
+
"#{root}/config"
|
68
80
|
end
|
69
81
|
|
70
|
-
def self.
|
71
|
-
|
82
|
+
def self.lang
|
83
|
+
# todo/fix: find a better way for single instance ??
|
84
|
+
if @lang.nil?
|
85
|
+
@lang = Lang.new
|
86
|
+
end
|
87
|
+
@lang
|
72
88
|
end
|
73
89
|
|
74
|
-
class Fixtures
|
75
|
-
## todo: move into its own file???
|
76
|
-
|
77
|
-
## make constants in Keys availabe (get include in Models) - do NOT pollute/include in SportDB
|
78
|
-
## make models available in sportdb module by default with namespace
|
79
|
-
# e.g. lets you use Team instead of Models::Team
|
80
|
-
include SportDB::Models
|
81
|
-
|
82
|
-
|
83
|
-
def self.fixtures_rb_test
|
84
|
-
['leagues',
|
85
|
-
'seasons',
|
86
|
-
# 'at/2011_12/bl',
|
87
|
-
# 'at/2011_12/cup',
|
88
|
-
# 'at/2012_13/bl',
|
89
|
-
# 'at/2012_13/cup',
|
90
|
-
# 'copa/sud_2012_13',
|
91
|
-
# 'world/quali_2012_13_america'
|
92
|
-
]
|
93
|
-
end
|
94
|
-
|
95
|
-
def self.fixtures_txt_test
|
96
|
-
[
|
97
|
-
# [ AT_2011_12, 'at/2011_12/bl'],
|
98
|
-
# [ AT_2012_13, 'at/2012_13/bl'],
|
99
|
-
# [ AT_CUP_2012_13, 'at/2012_13/cup'],
|
100
|
-
# ['copa.sud.2012/13', 'copa/sud_2012_13'],
|
101
|
-
# [ WORLD_QUALI_AMERICA_2012_13, 'world/quali_2012_13_america']
|
102
|
-
]
|
103
|
-
end
|
104
|
-
|
105
|
-
|
106
|
-
def self.team_fixtures
|
107
|
-
at = Country.find_by_key!( 'at' )
|
108
|
-
de = Country.find_by_key!( 'de' )
|
109
|
-
en = Country.find_by_key!( 'en' )
|
110
|
-
es = Country.find_by_key!( 'es' )
|
111
|
-
ro = Country.find_by_key!( 'ro' )
|
112
|
-
mx = Country.find_by_key!( 'mx' )
|
113
|
-
|
114
|
-
[
|
115
|
-
[ 'america/teams', { national: true } ],
|
116
|
-
[ 'euro/teams', { national: true } ],
|
117
|
-
[ 'world/teams', { national: true } ],
|
118
|
-
[ 'at/teams', { club: true, country_id: at.id } ],
|
119
|
-
[ 'de/teams', { club: true, country_id: de.id } ],
|
120
|
-
[ 'en/teams', { club: true, country_id: en.id } ],
|
121
|
-
[ 'es/teams', { club: true, country_id: es.id } ],
|
122
|
-
# [ 'ro/teams', { club: true, country_id: ro.id } ],
|
123
|
-
[ 'mx/teams', { club: true, country_id: mx.id } ],
|
124
|
-
[ 'cl/teams', { club: true } ],
|
125
|
-
[ 'copa/teams', { club: true } ],
|
126
|
-
[ 'nhl/teams', { club: true } ]
|
127
|
-
]
|
128
|
-
end
|
129
|
-
|
130
|
-
def self.fixtures_rb # all builtin ruby fixtures; helper for covenience
|
131
|
-
['leagues',
|
132
|
-
'seasons',
|
133
|
-
'at/badges',
|
134
|
-
'at/2011_12/bl',
|
135
|
-
'at/2011_12/cup',
|
136
|
-
'at/2012_13/bl',
|
137
|
-
'at/2012_13/cup',
|
138
|
-
'cl/badges',
|
139
|
-
'cl/2011_12/cl',
|
140
|
-
'cl/2011_12/el',
|
141
|
-
'cl/2012_13/cl',
|
142
|
-
'de/2012_13/bl',
|
143
|
-
'en/2012_13/pl',
|
144
|
-
'euro/2008',
|
145
|
-
'euro/2012',
|
146
|
-
'america/2011',
|
147
|
-
'copa/sud_2012_13',
|
148
|
-
'mx/apertura_2012',
|
149
|
-
'world/2010',
|
150
|
-
'world/quali_2012_13_europe',
|
151
|
-
'world/quali_2012_13_america'
|
152
|
-
]
|
153
|
-
end
|
154
|
-
|
155
|
-
def self.fixtures_txt
|
156
|
-
[[ AT_2011_12, 'at/2011_12/bl'],
|
157
|
-
[ AT_2012_13, 'at/2012_13/bl'],
|
158
|
-
[ AT_CUP_2012_13, 'at/2012_13/cup'],
|
159
|
-
['de.2012/13', 'de/2012_13/bl'],
|
160
|
-
['en.2012/13', 'en/2012_13/pl'],
|
161
|
-
['america.2011', 'america/2011'],
|
162
|
-
['mx.apertura.2012', 'mx/apertura_2012'],
|
163
|
-
['copa.sud.2012/13', 'copa/sud_2012_13'],
|
164
|
-
[ EURO_2008, 'euro/2008'],
|
165
|
-
[ WORLD_2010, 'world/2010'],
|
166
|
-
[ WORLD_QUALI_EURO_2012_13, 'world/quali_2012_13_europe_c'],
|
167
|
-
[ WORLD_QUALI_AMERICA_2012_13, 'world/quali_2012_13_america']]
|
168
|
-
end
|
169
|
-
end # class Fixtures
|
170
90
|
|
171
|
-
def self.
|
172
|
-
|
91
|
+
def self.main
|
92
|
+
## Runner.new.run(ARGV) - old code
|
93
|
+
require 'sportdb/cli/main'
|
173
94
|
end
|
174
95
|
|
175
|
-
def self.
|
176
|
-
|
177
|
-
end
|
178
|
-
|
179
|
-
def self.fixtures_txt
|
180
|
-
Fixtures.fixtures_txt
|
96
|
+
def self.create
|
97
|
+
CreateDB.up
|
181
98
|
end
|
182
99
|
|
183
|
-
def self.
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
load( fixtures_rb )
|
100
|
+
def self.read_setup( setup, include_path )
|
101
|
+
reader = Reader.new
|
102
|
+
reader.load_setup_with_include_path( setup, include_path )
|
188
103
|
end
|
189
104
|
|
190
|
-
|
191
|
-
|
192
|
-
## todo/fix: remove!! roll into load_all
|
193
|
-
read( fixtures_txt )
|
105
|
+
def self.read_all( include_path ) # convenience helper
|
106
|
+
read_setup( 'setups/all', include_path )
|
194
107
|
end
|
195
108
|
|
196
|
-
# load built-in (that is, bundled within the gem) named seeds
|
197
|
-
# - pass in an array of seed names e.g. [ 'cl/teams', 'cl/2012_13/cl' ] etc.
|
198
|
-
|
199
|
-
def self.load( ary )
|
200
|
-
loader = Loader.new
|
201
|
-
ary.each do |name|
|
202
|
-
loader.load_fixtures_builtin( name )
|
203
|
-
end
|
204
|
-
end
|
205
109
|
|
206
110
|
# load built-in (that is, bundled within the gem) named plain text seeds
|
207
|
-
# - pass in an array of pairs of event/seed names e.g.
|
111
|
+
# - pass in an array of pairs of event/seed names e.g.
|
112
|
+
# [['at.2012/13', 'at/2012_13/bl'],
|
113
|
+
# ['cl.2012/13', 'cl/2012_13/cl']] etc.
|
208
114
|
|
209
|
-
def self.read( ary )
|
115
|
+
def self.read( ary, include_path )
|
210
116
|
reader = Reader.new
|
211
|
-
|
212
|
-
## todo: check for teams in name too?
|
213
|
-
if rec[1].nil? || rec[1].kind_of?( Hash ) ## assume team fixtures
|
214
|
-
reader.load_teams_builtin( rec[0], rec[1] ) ## NB: name goes first than opt more_values hash
|
215
|
-
else
|
216
|
-
reader.load_fixtures_builtin( rec[0], rec[1] ) # event_key, name -- assume game fixtures
|
217
|
-
end
|
218
|
-
end
|
117
|
+
reader.load_with_include_path( ary, include_path )
|
219
118
|
end
|
220
|
-
|
221
119
|
|
222
|
-
class Deleter
|
223
|
-
## todo: move into its own file???
|
224
|
-
|
225
|
-
## make models available in sportdb module by default with namespace
|
226
|
-
# e.g. lets you use Team instead of Models::Team
|
227
|
-
include SportDB::Models
|
228
|
-
|
229
|
-
def run( args=[] )
|
230
|
-
# for now delete all tables
|
231
|
-
|
232
|
-
Team.delete_all
|
233
|
-
Game.delete_all
|
234
|
-
Event.delete_all
|
235
|
-
EventTeam.delete_all
|
236
|
-
Group.delete_all
|
237
|
-
GroupTeam.delete_all
|
238
|
-
Round.delete_all
|
239
|
-
Badge.delete_all
|
240
|
-
League.delete_all
|
241
|
-
Season.delete_all
|
242
|
-
end
|
243
|
-
|
244
|
-
end
|
245
120
|
|
246
121
|
# delete ALL records (use with care!)
|
247
122
|
def self.delete!
|
@@ -250,29 +125,6 @@ module SportDB
|
|
250
125
|
end # method delete!
|
251
126
|
|
252
127
|
|
253
|
-
class Stats
|
254
|
-
include SportDB::Models
|
255
|
-
|
256
|
-
def tables
|
257
|
-
puts "Stats:"
|
258
|
-
puts " #{Event.count} events / #{Round.count} rounds / #{Group.count} groups"
|
259
|
-
puts " #{League.count} leagues / #{Season.count} seasons"
|
260
|
-
puts " #{Country.count} countries / #{Region.count} regions / #{City.count} cities"
|
261
|
-
puts " #{Team.count} teams"
|
262
|
-
puts " #{Game.count} games"
|
263
|
-
puts " #{Badge.count} badges"
|
264
|
-
|
265
|
-
## todo: add tags / taggings from worlddb
|
266
|
-
end
|
267
|
-
|
268
|
-
def props
|
269
|
-
puts "Props:"
|
270
|
-
Prop.order( 'created_at asc' ).all.each do |prop|
|
271
|
-
puts " #{prop.key} / #{prop.value} || #{prop.created_at}"
|
272
|
-
end
|
273
|
-
end
|
274
|
-
end
|
275
|
-
|
276
128
|
def self.stats
|
277
129
|
stats = Stats.new
|
278
130
|
stats.tables
|
@@ -289,7 +141,6 @@ module SportDB
|
|
289
141
|
|
290
142
|
|
291
143
|
|
292
|
-
|
293
144
|
def self.load_plugins
|
294
145
|
|
295
146
|
@found ||= []
|
data/tasks/test.rb
ADDED
@@ -0,0 +1,163 @@
|
|
1
|
+
|
2
|
+
#########################
|
3
|
+
# Fill up sport.db w/ football.db fixtures
|
4
|
+
|
5
|
+
|
6
|
+
##############################
|
7
|
+
## for testing
|
8
|
+
##
|
9
|
+
## NB: use
|
10
|
+
# rake -I ../world.db.ruby/lib -I ../sport.db.ruby/lib update
|
11
|
+
|
12
|
+
|
13
|
+
include SportDB::Fixtures # include fixture constants like WORLD_FIXTURES, EN_FIXTURES etc.
|
14
|
+
|
15
|
+
|
16
|
+
##########
|
17
|
+
# TODO: configure - copy to your rake file
|
18
|
+
|
19
|
+
# INCLUDE_PATH = "../football.db"
|
20
|
+
|
21
|
+
# BUILD_DIR = "./db"
|
22
|
+
|
23
|
+
# SPORT_DB_PATH = "#{BUILD_DIR}/sport.db"
|
24
|
+
|
25
|
+
|
26
|
+
################
|
27
|
+
|
28
|
+
DB_CONFIG = {
|
29
|
+
:adapter => 'sqlite3',
|
30
|
+
:database => SPORT_DB_PATH
|
31
|
+
}
|
32
|
+
|
33
|
+
directory BUILD_DIR
|
34
|
+
|
35
|
+
# task :clean do
|
36
|
+
# rm SPORT_DB_PATH if File.exists?( SPORT_DB_PATH )
|
37
|
+
# end
|
38
|
+
|
39
|
+
task :env => BUILD_DIR do
|
40
|
+
pp DB_CONFIG
|
41
|
+
ActiveRecord::Base.establish_connection( DB_CONFIG )
|
42
|
+
end
|
43
|
+
|
44
|
+
# task :create => :env do
|
45
|
+
# WorldDB.create
|
46
|
+
# end
|
47
|
+
|
48
|
+
task :import => :env do
|
49
|
+
reader = SportDB::Reader.new
|
50
|
+
|
51
|
+
reader.load_seasons_with_include_path( 'seasons', INCLUDE_PATH )
|
52
|
+
|
53
|
+
reader.load_leagues_with_include_path( 'leagues', INCLUDE_PATH )
|
54
|
+
reader.load_leagues_with_include_path( 'leagues_club', INCLUDE_PATH, { club: true } )
|
55
|
+
end
|
56
|
+
|
57
|
+
### club europe (cl,el)
|
58
|
+
task :club_europe => [:import] do
|
59
|
+
import_fixtures( CLUB_EUROPE_TEAMS, CLUB_EUROPE_FIXTURES )
|
60
|
+
end
|
61
|
+
|
62
|
+
### club america
|
63
|
+
task :club_america => [:import] do
|
64
|
+
import_fixtures( CLUB_AMERICA_TEAMS, CLUB_AMERICA_FIXTURES )
|
65
|
+
end
|
66
|
+
|
67
|
+
task :europe => [:import] do
|
68
|
+
import_fixtures( EUROPE_TEAMS, EUROPE_FIXTURES )
|
69
|
+
end
|
70
|
+
|
71
|
+
task :america => [:import] do
|
72
|
+
import_fixtures( AMERICA_TEAMS, AMERICA_FIXTURES )
|
73
|
+
end
|
74
|
+
|
75
|
+
task :world => [:import] do
|
76
|
+
import_fixtures( WORLD_TEAMS, WORLD_FIXTURES )
|
77
|
+
end
|
78
|
+
|
79
|
+
### ar - Argentina
|
80
|
+
task :ar => [:import] do
|
81
|
+
import_fixtures( AR_TEAMS, AR_FIXTURES )
|
82
|
+
end
|
83
|
+
|
84
|
+
### br - Brasil
|
85
|
+
task :br => [:import] do
|
86
|
+
import_fixtures( BR_TEAMS, BR_FIXTURES )
|
87
|
+
end
|
88
|
+
|
89
|
+
### mx - Mexico
|
90
|
+
task :mx => [:import] do
|
91
|
+
import_fixtures( MX_TEAMS, MX_FIXTURES )
|
92
|
+
end
|
93
|
+
|
94
|
+
#### at - Austria
|
95
|
+
task :at => [:import] do
|
96
|
+
import_fixtures( AT_TEAMS, AT_FIXTURES )
|
97
|
+
end
|
98
|
+
|
99
|
+
#### de - Deutschland/Germany
|
100
|
+
task :de => [:import] do
|
101
|
+
import_fixtures( DE_TEAMS, DE_FIXTURES )
|
102
|
+
end
|
103
|
+
|
104
|
+
#### en - England
|
105
|
+
task :en => [:import] do
|
106
|
+
import_fixtures( EN_TEAMS, EN_FIXTURES )
|
107
|
+
end
|
108
|
+
|
109
|
+
#### ro - Romania
|
110
|
+
task :ro => [:import] do
|
111
|
+
import_fixtures( RO_TEAMS, RO_FIXTURES )
|
112
|
+
end
|
113
|
+
|
114
|
+
|
115
|
+
|
116
|
+
desc 'worlddb - test loading of builtin fixtures (update)'
|
117
|
+
task :update => [:world]
|
118
|
+
# task :update => [:at, :de, :en, :ro, :ar, :br, :mx]
|
119
|
+
|
120
|
+
|
121
|
+
|
122
|
+
def import_fixtures( teams, fixtures )
|
123
|
+
reader = SportDB::Reader.new
|
124
|
+
reader.load_with_include_path( teams, INCLUDE_PATH )
|
125
|
+
reader.load_with_include_path( fixtures, INCLUDE_PATH )
|
126
|
+
end
|
127
|
+
|
128
|
+
|
129
|
+
|
130
|
+
=begin
|
131
|
+
|
132
|
+
##################
|
133
|
+
# usage sample
|
134
|
+
##################
|
135
|
+
|
136
|
+
#### step 1) configure tasks in test.rb in your rake file
|
137
|
+
|
138
|
+
Rakefile:
|
139
|
+
|
140
|
+
INCLUDE_PATH = "../football.db"
|
141
|
+
|
142
|
+
BUILD_DIR = "./db"
|
143
|
+
|
144
|
+
SPORT_DB_PATH = "#{BUILD_DIR}/sport.db"
|
145
|
+
|
146
|
+
|
147
|
+
#### step 2) include tasks in test.rb
|
148
|
+
|
149
|
+
SPORT_DB_RUBY_PATH = "../sport.db.ruby"
|
150
|
+
WORLD_DB_RUBY_PATH = "../world.db.ruby"
|
151
|
+
|
152
|
+
require "#{WORLD_DB_RUBY_PATH}/lib/worlddb.rb"
|
153
|
+
require "#{SPORT_DB_RUBY_PATH}/lib/sportdb.rb"
|
154
|
+
|
155
|
+
require "#{SPORT_DB_RUBY_PATH}/tasks/test.rb"
|
156
|
+
|
157
|
+
Shell:
|
158
|
+
|
159
|
+
### step 3) call on command line
|
160
|
+
|
161
|
+
$ rake -I ../world.db.ruby/lib -I ../sport.db.ruby/lib update
|
162
|
+
|
163
|
+
=end
|