sportdb 1.5.0 → 1.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +71 -3
- data/bin/sportdb +1 -1
- data/lib/sportdb/cli/main.rb +23 -23
- data/lib/sportdb/cli/opts.rb +2 -2
- data/lib/sportdb/console.rb +16 -16
- data/lib/sportdb/data/fixtures.rb +2 -2
- data/lib/sportdb/data/keys.rb +3 -3
- data/lib/sportdb/data/models.rb +3 -3
- data/lib/sportdb/deleter.rb +3 -3
- data/lib/sportdb/lang.rb +2 -2
- data/lib/sportdb/models/badge.rb +2 -2
- data/lib/sportdb/models/city.rb +6 -6
- data/lib/sportdb/models/country.rb +7 -7
- data/lib/sportdb/models/event.rb +2 -2
- data/lib/sportdb/models/event_team.rb +2 -2
- data/lib/sportdb/models/forward.rb +9 -9
- data/lib/sportdb/models/game.rb +45 -10
- data/lib/sportdb/models/group.rb +2 -2
- data/lib/sportdb/models/group_team.rb +2 -2
- data/lib/sportdb/models/league.rb +3 -3
- data/lib/sportdb/models/prop.rb +3 -3
- data/lib/sportdb/models/region.rb +6 -6
- data/lib/sportdb/models/round.rb +2 -2
- data/lib/sportdb/models/season.rb +2 -2
- data/lib/sportdb/models/team.rb +2 -2
- data/lib/sportdb/reader.rb +28 -25
- data/lib/sportdb/schema.rb +15 -27
- data/lib/sportdb/stats.rb +3 -3
- data/lib/sportdb/utils.rb +6 -6
- data/lib/sportdb/version.rb +7 -2
- data/lib/sportdb.rb +12 -11
- metadata +10 -10
data/Rakefile
CHANGED
@@ -2,12 +2,12 @@ require 'hoe'
|
|
2
2
|
require './lib/sportdb/version.rb'
|
3
3
|
|
4
4
|
## NB: plugin (hoe-manifest) not required; just used for future testing/development
|
5
|
-
Hoe::plugin :manifest # more options for manifests (in the future; not yet)
|
5
|
+
## Hoe::plugin :manifest # more options for manifests (in the future; not yet)
|
6
6
|
|
7
7
|
|
8
8
|
Hoe.spec 'sportdb' do
|
9
9
|
|
10
|
-
self.version =
|
10
|
+
self.version = SportDb::VERSION
|
11
11
|
|
12
12
|
self.summary = 'sportdb - sport.db command line tool'
|
13
13
|
self.description = summary
|
@@ -50,4 +50,72 @@ https://groups.google.com/group/opensport
|
|
50
50
|
******************************************************************************
|
51
51
|
EOS
|
52
52
|
|
53
|
-
end
|
53
|
+
end
|
54
|
+
|
55
|
+
|
56
|
+
##############################
|
57
|
+
## for testing
|
58
|
+
##
|
59
|
+
## NB: use rake -I ../world.db.ruby/lib -I ./lib sportdb:build
|
60
|
+
|
61
|
+
namespace :sportdb do
|
62
|
+
|
63
|
+
BUILD_DIR = "./build"
|
64
|
+
|
65
|
+
SPORT_DB_PATH = "#{BUILD_DIR}/sport.db"
|
66
|
+
|
67
|
+
DB_CONFIG = {
|
68
|
+
:adapter => 'sqlite3',
|
69
|
+
:database => SPORT_DB_PATH
|
70
|
+
}
|
71
|
+
|
72
|
+
directory BUILD_DIR
|
73
|
+
|
74
|
+
task :clean do
|
75
|
+
rm SPORT_DB_PATH if File.exists?( SPORT_DB_PATH )
|
76
|
+
end
|
77
|
+
|
78
|
+
task :env => BUILD_DIR do
|
79
|
+
require 'worlddb' ### NB: for local testing use rake -I ./lib dev:test e.g. do NOT forget to add -I ./lib
|
80
|
+
require 'sportdb'
|
81
|
+
require 'logutils/db'
|
82
|
+
|
83
|
+
LogUtils::Logger.root.level = :info
|
84
|
+
|
85
|
+
pp DB_CONFIG
|
86
|
+
ActiveRecord::Base.establish_connection( DB_CONFIG )
|
87
|
+
end
|
88
|
+
|
89
|
+
task :create => :env do
|
90
|
+
LogDb.create
|
91
|
+
WorldDb.create
|
92
|
+
SportDb.create
|
93
|
+
end
|
94
|
+
|
95
|
+
task :importworld => :env do
|
96
|
+
WorldDb.read_setup( 'setups/sport.db.admin', '../world.db', skip_tags: true ) # populate world tables
|
97
|
+
# WorldDb.stats
|
98
|
+
end
|
99
|
+
|
100
|
+
task :importsport => :env do
|
101
|
+
SportDb.read_setup( 'setups/at', '../football.db' )
|
102
|
+
# SportDb.stats
|
103
|
+
end
|
104
|
+
|
105
|
+
task :deletesport => :env do
|
106
|
+
SportDb.delete!
|
107
|
+
end
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
desc 'sportdb - build from scratch'
|
112
|
+
task :build => [:clean, :create, :importworld, :importsport] do
|
113
|
+
puts 'Done.'
|
114
|
+
end
|
115
|
+
|
116
|
+
desc 'sportdb - update'
|
117
|
+
task :update => [:deletesport, :importsport] do
|
118
|
+
puts 'Done.'
|
119
|
+
end
|
120
|
+
|
121
|
+
end # namespace :sportdb
|
data/bin/sportdb
CHANGED
data/lib/sportdb/cli/main.rb
CHANGED
@@ -19,8 +19,8 @@ require 'sportdb/cli/opts'
|
|
19
19
|
LogUtils::Logger.root.level = :info # set logging level to info
|
20
20
|
|
21
21
|
program :name, 'sportdb'
|
22
|
-
program :version,
|
23
|
-
program :description, "sport.db command line tool, version #{
|
22
|
+
program :version, SportDb::VERSION
|
23
|
+
program :description, "sport.db command line tool, version #{SportDb::VERSION}"
|
24
24
|
|
25
25
|
|
26
26
|
# default_command :help
|
@@ -47,7 +47,7 @@ Further information:
|
|
47
47
|
|
48
48
|
|
49
49
|
## todo: find a better name e.g. change to settings? config? safe_opts? why? why not?
|
50
|
-
myopts =
|
50
|
+
myopts = SportDb::Opts.new
|
51
51
|
|
52
52
|
### global option (required)
|
53
53
|
## todo: add check that path is valid?? possible?
|
@@ -62,7 +62,7 @@ global_option '-w', '--verbose', "Show debug messages"
|
|
62
62
|
|
63
63
|
|
64
64
|
def connect_to_db( options )
|
65
|
-
puts
|
65
|
+
puts SportDb.banner
|
66
66
|
|
67
67
|
puts "working directory: #{Dir.pwd}"
|
68
68
|
|
@@ -91,9 +91,9 @@ command :create do |c|
|
|
91
91
|
myopts.merge_commander_options!( options.__hash__ )
|
92
92
|
connect_to_db( myopts )
|
93
93
|
|
94
|
-
|
95
|
-
|
96
|
-
|
94
|
+
LogDb.create
|
95
|
+
WorldDb.create
|
96
|
+
SportDb.create
|
97
97
|
puts 'Done.'
|
98
98
|
end # action
|
99
99
|
end # command create
|
@@ -127,25 +127,25 @@ command :setup do |c|
|
|
127
127
|
# delete sport first
|
128
128
|
|
129
129
|
if options.delete.present?
|
130
|
-
|
131
|
-
|
130
|
+
SportDb.delete! if options.sport.present?
|
131
|
+
WorldDb.delete! if options.world.present?
|
132
132
|
end
|
133
133
|
|
134
134
|
if options.world.present?
|
135
|
-
|
135
|
+
WorldDb.read_all( myopts.world_data_path )
|
136
136
|
end
|
137
137
|
|
138
138
|
if options.sport.present?
|
139
|
-
|
139
|
+
SportDb.read_setup( "setups/#{setup}", myopts.data_path )
|
140
140
|
end
|
141
141
|
|
142
142
|
else # assume "plain" regular setup
|
143
|
-
|
144
|
-
|
145
|
-
|
143
|
+
LogDb.create
|
144
|
+
WorldDb.create
|
145
|
+
SportDb.create
|
146
146
|
|
147
|
-
|
148
|
-
|
147
|
+
WorldDb.read_all( myopts.world_data_path )
|
148
|
+
SportDb.read_setup( "setups/#{setup}", myopts.data_path )
|
149
149
|
end
|
150
150
|
puts 'Done.'
|
151
151
|
end # action
|
@@ -167,21 +167,21 @@ command :load do |c|
|
|
167
167
|
myopts.merge_commander_options!( options.__hash__ )
|
168
168
|
connect_to_db( myopts )
|
169
169
|
|
170
|
-
|
170
|
+
SportDb.delete! if options.delete.present?
|
171
171
|
|
172
|
-
reader =
|
172
|
+
reader = SportDb::Reader.new( myopts.data_path )
|
173
173
|
|
174
174
|
args.each do |arg|
|
175
175
|
name = arg # File.basename( arg, '.*' )
|
176
176
|
|
177
177
|
if myopts.event.present?
|
178
178
|
## fix: rename to load_event_fixtures_w... or similar
|
179
|
-
reader.load_fixtures( myopts.event, name
|
179
|
+
reader.load_fixtures( myopts.event, name )
|
180
180
|
else
|
181
181
|
## fix> add a convenience method for loading single fixture
|
182
182
|
ary = []
|
183
183
|
ary << name
|
184
|
-
reader.load( ary
|
184
|
+
reader.load( ary )
|
185
185
|
end
|
186
186
|
end # each arg
|
187
187
|
|
@@ -201,7 +201,7 @@ command :logs do |c|
|
|
201
201
|
myopts.merge_commander_options!( options.__hash__ )
|
202
202
|
connect_to_db( myopts )
|
203
203
|
|
204
|
-
|
204
|
+
LogDb::Models::Log.all.each do |log|
|
205
205
|
puts "[#{log.level}] -- #{log.msg}"
|
206
206
|
end
|
207
207
|
|
@@ -221,7 +221,7 @@ command :stats do |c|
|
|
221
221
|
myopts.merge_commander_options!( options.__hash__ )
|
222
222
|
connect_to_db( myopts )
|
223
223
|
|
224
|
-
|
224
|
+
SportDb.tables
|
225
225
|
|
226
226
|
puts 'Done.'
|
227
227
|
end
|
@@ -239,7 +239,7 @@ command :props do |c|
|
|
239
239
|
myopts.merge_commander_options!( options.__hash__ )
|
240
240
|
connect_to_db( myopts )
|
241
241
|
|
242
|
-
|
242
|
+
SportDb.props
|
243
243
|
|
244
244
|
puts 'Done.'
|
245
245
|
end
|
data/lib/sportdb/cli/opts.rb
CHANGED
data/lib/sportdb/console.rb
CHANGED
@@ -14,21 +14,21 @@ require 'yaml'
|
|
14
14
|
|
15
15
|
## shortcuts for models
|
16
16
|
|
17
|
-
Event =
|
18
|
-
Team =
|
19
|
-
Game =
|
20
|
-
Group =
|
21
|
-
Round =
|
22
|
-
Season =
|
23
|
-
League =
|
24
|
-
Badge =
|
25
|
-
|
26
|
-
Tag =
|
27
|
-
Tagging =
|
28
|
-
Country =
|
29
|
-
Region =
|
30
|
-
City =
|
31
|
-
Prop =
|
17
|
+
Event = SportDb::Models::Event
|
18
|
+
Team = SportDb::Models::Team
|
19
|
+
Game = SportDb::Models::Game
|
20
|
+
Group = SportDb::Models::Group
|
21
|
+
Round = SportDb::Models::Round
|
22
|
+
Season = SportDb::Models::Season
|
23
|
+
League = SportDb::Models::League
|
24
|
+
Badge = SportDb::Models::Badge
|
25
|
+
|
26
|
+
Tag = WorldDb::Models::Tag
|
27
|
+
Tagging = WorldDb::Models::Tagging
|
28
|
+
Country = WorldDb::Models::Country
|
29
|
+
Region = WorldDb::Models::Region
|
30
|
+
City = WorldDb::Models::City
|
31
|
+
Prop = WorldDb::Models::Prop
|
32
32
|
|
33
33
|
## connect to db
|
34
34
|
|
@@ -42,7 +42,7 @@ ActiveRecord::Base.establish_connection( DB_CONFIG )
|
|
42
42
|
|
43
43
|
## test drive
|
44
44
|
|
45
|
-
puts "Welcome to sport.db, version #{
|
45
|
+
puts "Welcome to sport.db, version #{SportDb::VERSION} (world.db, version #{WorldDb::VERSION})!"
|
46
46
|
puts " #{'%5d' % Event.count} events"
|
47
47
|
puts " #{'%5d' % Team.count} teams"
|
48
48
|
puts " #{'%5d' % Game.count} games"
|
data/lib/sportdb/data/keys.rb
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
### fix: rename to ::Key (singular) - why? why not??
|
7
7
|
|
8
|
-
module
|
8
|
+
module SportDb::Keys
|
9
9
|
|
10
10
|
module EventKeys
|
11
11
|
# use constants for known keys; lets us define aliases (if things change)
|
@@ -29,6 +29,6 @@ module SportDB::Keys
|
|
29
29
|
## NB: see db/leagues.rb for keys in use
|
30
30
|
end
|
31
31
|
|
32
|
-
include
|
32
|
+
include SportDb::Keys::EventKeys
|
33
33
|
|
34
|
-
end # module
|
34
|
+
end # module SportDb::Keys
|
data/lib/sportdb/data/models.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
module
|
3
|
+
module SportDb::Models
|
4
4
|
|
5
5
|
## add convenience finders to some model classes
|
6
6
|
|
7
7
|
class Event
|
8
8
|
|
9
|
-
include
|
9
|
+
include SportDb::Keys::EventKeys
|
10
10
|
|
11
11
|
def self.find_at_2012_13!
|
12
12
|
self.find_by_key!( AT_2012_13 )
|
@@ -38,6 +38,6 @@ module SportDB::Models
|
|
38
38
|
|
39
39
|
end # class Event
|
40
40
|
|
41
|
-
end # module
|
41
|
+
end # module SportDb::Models
|
42
42
|
|
43
43
|
|
data/lib/sportdb/deleter.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
|
2
|
-
module
|
2
|
+
module SportDb
|
3
3
|
|
4
4
|
class Deleter
|
5
5
|
######
|
6
6
|
# NB: make models available in sportdb module by default with namespace
|
7
7
|
# e.g. lets you use Team instead of Models::Team
|
8
|
-
include
|
8
|
+
include SportDb::Models
|
9
9
|
|
10
10
|
def run
|
11
11
|
# for now delete all tables
|
@@ -24,4 +24,4 @@ module SportDB
|
|
24
24
|
|
25
25
|
end # class Deleter
|
26
26
|
|
27
|
-
end # module
|
27
|
+
end # module SportDb
|
data/lib/sportdb/lang.rb
CHANGED
data/lib/sportdb/models/badge.rb
CHANGED
data/lib/sportdb/models/city.rb
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
|
2
2
|
## todo: how to best extends city model?
|
3
3
|
|
4
|
-
module
|
4
|
+
module WorldDb::Models
|
5
5
|
class City
|
6
|
-
has_many :teams, :class_name => '
|
6
|
+
has_many :teams, :class_name => 'SportDb::Models::Team', :foreign_key => 'city_id'
|
7
7
|
end
|
8
|
-
end # module
|
8
|
+
end # module WorldDb::Models
|
9
9
|
|
10
10
|
|
11
11
|
## moved to models/forward
|
12
|
-
# module
|
13
|
-
# City =
|
14
|
-
# end # module
|
12
|
+
# module SportDb::Models
|
13
|
+
# City = WorldDb::Models::City
|
14
|
+
# end # module SportDb::Models
|
@@ -2,17 +2,17 @@
|
|
2
2
|
|
3
3
|
## todo: how to best extends country model?
|
4
4
|
|
5
|
-
module
|
5
|
+
module WorldDb::Models
|
6
6
|
|
7
7
|
class Country
|
8
|
-
has_many :teams, :class_name => '
|
9
|
-
has_many :leagues, :class_name => '
|
8
|
+
has_many :teams, :class_name => 'SportDb::Models::Team', :foreign_key => 'country_id'
|
9
|
+
has_many :leagues, :class_name => 'SportDb::Models::League', :foreign_key => 'country_id'
|
10
10
|
end # class Country
|
11
11
|
|
12
|
-
end # module
|
12
|
+
end # module WorldDb::Models
|
13
13
|
|
14
14
|
|
15
15
|
## moved to models/forward
|
16
|
-
# module
|
17
|
-
# Country =
|
18
|
-
# end # module
|
16
|
+
# module SportDb::Models
|
17
|
+
# Country = WorldDb::Models::Country
|
18
|
+
# end # module SportDb::Models
|
data/lib/sportdb/models/event.rb
CHANGED
@@ -2,14 +2,14 @@
|
|
2
2
|
### forward references
|
3
3
|
## require first to resolve circular references
|
4
4
|
|
5
|
-
module
|
5
|
+
module SportDb::Models
|
6
6
|
|
7
|
-
## todo: why? why not use include
|
7
|
+
## todo: why? why not use include WorldDb::Models here???
|
8
8
|
|
9
|
-
Country =
|
10
|
-
Region =
|
11
|
-
City =
|
12
|
-
Prop =
|
9
|
+
Country = WorldDb::Models::Country
|
10
|
+
Region = WorldDb::Models::Region
|
11
|
+
City = WorldDb::Models::City
|
12
|
+
Prop = WorldDb::Models::Prop
|
13
13
|
|
14
14
|
## nb: for now only team and league use worlddb tables
|
15
15
|
# e.g. with belongs_to assoc (country,region)
|
@@ -20,12 +20,12 @@ module SportDB::Models
|
|
20
20
|
end
|
21
21
|
|
22
22
|
|
23
|
-
module
|
23
|
+
module WorldDb::Models
|
24
24
|
|
25
25
|
# add alias? why? why not? # is there a better way?
|
26
26
|
# - just include SportDB::Models - why? why not?
|
27
27
|
# - just include once in loader??
|
28
|
-
Team =
|
29
|
-
League =
|
28
|
+
Team = SportDb::Models::Team
|
29
|
+
League = SportDb::Models::League
|
30
30
|
|
31
31
|
end
|
data/lib/sportdb/models/game.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
module
|
1
|
+
module SportDb::Models
|
2
2
|
|
3
3
|
|
4
4
|
class Game < ActiveRecord::Base
|
@@ -11,6 +11,41 @@ class Game < ActiveRecord::Base
|
|
11
11
|
|
12
12
|
before_save :calc_toto12x
|
13
13
|
|
14
|
+
### getter/setters for deprecated attribs (score3,4,5,6) n national
|
15
|
+
|
16
|
+
def score3
|
17
|
+
score1ot
|
18
|
+
end
|
19
|
+
|
20
|
+
def score4
|
21
|
+
score2ot
|
22
|
+
end
|
23
|
+
|
24
|
+
def score5
|
25
|
+
score1p
|
26
|
+
end
|
27
|
+
|
28
|
+
def score6
|
29
|
+
score2p
|
30
|
+
end
|
31
|
+
|
32
|
+
def score3=(value)
|
33
|
+
self.score1ot = value
|
34
|
+
end
|
35
|
+
|
36
|
+
def score4=(value)
|
37
|
+
self.score2ot = value
|
38
|
+
end
|
39
|
+
|
40
|
+
def score5=(value)
|
41
|
+
self.score1p = value
|
42
|
+
end
|
43
|
+
|
44
|
+
def score6=(value)
|
45
|
+
self.score2p = value
|
46
|
+
end
|
47
|
+
|
48
|
+
|
14
49
|
|
15
50
|
def self.create_knockouts_from_ary!( games, round )
|
16
51
|
Game.create_from_ary!( games, round, true )
|
@@ -58,10 +93,10 @@ class Game < ActiveRecord::Base
|
|
58
93
|
:team1 => value_teams[0],
|
59
94
|
:score1 => value_scores[0],
|
60
95
|
:score2 => value_scores[1],
|
61
|
-
:
|
62
|
-
:
|
63
|
-
:
|
64
|
-
:
|
96
|
+
:score1ot => value_scores[2],
|
97
|
+
:score2ot => value_scores[3],
|
98
|
+
:score1p => value_scores[4],
|
99
|
+
:score2p => value_scores[5],
|
65
100
|
:team2 => value_teams[1],
|
66
101
|
:play_at => value_play_at,
|
67
102
|
:group => value_group, # Note: group is optional (may be null/nil)
|
@@ -122,10 +157,10 @@ class Game < ActiveRecord::Base
|
|
122
157
|
:team1 =>pair[1][1],
|
123
158
|
:score1 =>pair[1][2][0],
|
124
159
|
:score2 =>pair[1][2][1],
|
125
|
-
:
|
126
|
-
:
|
127
|
-
:
|
128
|
-
:
|
160
|
+
:score1ot =>pair[1][2][2],
|
161
|
+
:score2ot =>pair[1][2][3],
|
162
|
+
:score1p =>pair[1][2][4],
|
163
|
+
:score1p =>pair[1][2][5],
|
129
164
|
:team2 =>pair[1][3],
|
130
165
|
:play_at =>pair[1][4],
|
131
166
|
:knockout =>true }
|
@@ -194,4 +229,4 @@ class Game < ActiveRecord::Base
|
|
194
229
|
end # class Game
|
195
230
|
|
196
231
|
|
197
|
-
end # module
|
232
|
+
end # module SportDb::Models
|
data/lib/sportdb/models/group.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
module
|
1
|
+
module SportDb::Models
|
2
2
|
|
3
3
|
|
4
4
|
class League < ActiveRecord::Base
|
@@ -10,7 +10,7 @@ class League < ActiveRecord::Base
|
|
10
10
|
has_many :events
|
11
11
|
has_many :seasons, :through => :events
|
12
12
|
|
13
|
-
belongs_to :country, :class_name => '
|
13
|
+
belongs_to :country, :class_name => 'WorldDb::Models::Country', :foreign_key => 'country_id'
|
14
14
|
|
15
15
|
|
16
16
|
def self.create_from_ary!( leagues, more_values={} )
|
@@ -40,4 +40,4 @@ class League < ActiveRecord::Base
|
|
40
40
|
end # class League
|
41
41
|
|
42
42
|
|
43
|
-
end # module
|
43
|
+
end # module SportDb::Models
|
data/lib/sportdb/models/prop.rb
CHANGED
@@ -2,15 +2,15 @@
|
|
2
2
|
|
3
3
|
## todo: how to best extends country model?
|
4
4
|
|
5
|
-
module
|
5
|
+
module WorldDb::Models
|
6
6
|
|
7
7
|
class Region
|
8
|
-
has_many :teams, :class_name => '
|
8
|
+
has_many :teams, :class_name => 'SportDb::Models::Team', :through => :cities
|
9
9
|
end # class Region
|
10
10
|
|
11
|
-
end # module
|
11
|
+
end # module WorldDb::Models
|
12
12
|
|
13
13
|
## moved to models/forward
|
14
|
-
# module
|
15
|
-
# Region =
|
16
|
-
# end # module
|
14
|
+
# module SportDb::Models
|
15
|
+
# Region = WorldDb::Models::Region
|
16
|
+
# end # module SportDb::Models
|
data/lib/sportdb/models/round.rb
CHANGED
data/lib/sportdb/models/team.rb
CHANGED
data/lib/sportdb/reader.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
module
|
3
|
+
module SportDb
|
4
4
|
|
5
5
|
class Reader
|
6
6
|
|
@@ -11,17 +11,20 @@ class Reader
|
|
11
11
|
include SportDB::Models
|
12
12
|
|
13
13
|
|
14
|
-
|
14
|
+
attr_reader :include_path
|
15
|
+
|
16
|
+
def initialize( include_path, opts={})
|
17
|
+
@include_path = include_path
|
15
18
|
end
|
16
19
|
|
17
|
-
def load_setup( setup
|
18
|
-
ary = load_fixture_setup( setup
|
19
|
-
load( ary
|
20
|
+
def load_setup( setup )
|
21
|
+
ary = load_fixture_setup( setup )
|
22
|
+
load( ary )
|
20
23
|
end # method load_setup
|
21
24
|
|
22
25
|
|
23
26
|
## fix/todo: rename ??
|
24
|
-
def load_fixture_setup( name
|
27
|
+
def load_fixture_setup( name )
|
25
28
|
|
26
29
|
## todo/fix: cleanup quick and dirty code
|
27
30
|
|
@@ -70,7 +73,7 @@ class Reader
|
|
70
73
|
end # load_fixture_setup
|
71
74
|
|
72
75
|
|
73
|
-
def load( ary
|
76
|
+
def load( ary ) # convenience helper for all-in-one reader
|
74
77
|
|
75
78
|
logger.debug "enter load(include_path=>>#{include_path}<<):"
|
76
79
|
logger.debug ary.to_json
|
@@ -81,30 +84,30 @@ class Reader
|
|
81
84
|
name = rec
|
82
85
|
|
83
86
|
if name =~ /^seasons/
|
84
|
-
load_seasons( name
|
87
|
+
load_seasons( name )
|
85
88
|
elsif name =~ /^leagues/
|
86
89
|
if name =~ /club/
|
87
90
|
# e.g. leagues_club
|
88
|
-
load_leagues( name,
|
91
|
+
load_leagues( name, club: true )
|
89
92
|
else
|
90
93
|
# e.g. leagues
|
91
|
-
load_leagues( name
|
94
|
+
load_leagues( name )
|
92
95
|
end
|
93
96
|
elsif name =~ /^([a-z]{2})\/teams/
|
94
97
|
# auto-add country code (from folder structure) for country-specific teams
|
95
98
|
# e.g. at/teams at/teams2 de/teams etc.
|
96
99
|
country_key = $1
|
97
100
|
country = Country.find_by_key!( country_key )
|
98
|
-
load_teams( name,
|
101
|
+
load_teams( name, club: true, country_id: country.id )
|
99
102
|
elsif name =~ /\/teams/
|
100
103
|
if name =~ /club/
|
101
104
|
# club teams (many countries)
|
102
105
|
# e.g. club/europe/teams
|
103
|
-
load_teams( name,
|
106
|
+
load_teams( name, club: true )
|
104
107
|
else
|
105
108
|
# assume national teams
|
106
109
|
# e.g. world/teams amercia/teams_n
|
107
|
-
load_teams( name,
|
110
|
+
load_teams( name, national: true )
|
108
111
|
end
|
109
112
|
else
|
110
113
|
logger.error "unknown sportdb fixture type >#{name}<"
|
@@ -119,9 +122,9 @@ class Reader
|
|
119
122
|
event_name = rec[1] # e.g. at/2012_13/bl
|
120
123
|
fixture_names = rec[1..-1] # e.g. at/2012_13/bl, at/2012_13/bl2
|
121
124
|
|
122
|
-
load_event( event_name
|
125
|
+
load_event( event_name )
|
123
126
|
fixture_names.each do |fixture_name|
|
124
|
-
load_fixtures( event_key, fixture_name
|
127
|
+
load_fixtures( event_key, fixture_name )
|
125
128
|
end
|
126
129
|
end
|
127
130
|
|
@@ -129,7 +132,7 @@ class Reader
|
|
129
132
|
end # method load
|
130
133
|
|
131
134
|
|
132
|
-
def load_leagues( name,
|
135
|
+
def load_leagues( name, more_values={} )
|
133
136
|
|
134
137
|
path = "#{include_path}/#{name}.txt"
|
135
138
|
|
@@ -144,7 +147,7 @@ class Reader
|
|
144
147
|
end # load_leagues
|
145
148
|
|
146
149
|
|
147
|
-
def load_seasons( name
|
150
|
+
def load_seasons( name )
|
148
151
|
path = "#{include_path}/#{name}.yml"
|
149
152
|
|
150
153
|
puts "*** parsing data '#{name}' (#{path})..."
|
@@ -193,7 +196,7 @@ class Reader
|
|
193
196
|
|
194
197
|
|
195
198
|
|
196
|
-
def load_event( name
|
199
|
+
def load_event( name )
|
197
200
|
path = "#{include_path}/#{name}.yml"
|
198
201
|
|
199
202
|
logger.info "parsing data '#{name}' (#{path})..."
|
@@ -291,7 +294,7 @@ class Reader
|
|
291
294
|
### Prop.create!( key: "db.#{fixture_name_to_prop_key(name)}.version", value: "file.txt.#{File.mtime(path).strftime('%Y.%m.%d')}" )
|
292
295
|
end
|
293
296
|
|
294
|
-
def load_fixtures( event_key, name
|
297
|
+
def load_fixtures( event_key, name ) # load from file system
|
295
298
|
|
296
299
|
path = "#{include_path}/#{name}.txt"
|
297
300
|
|
@@ -307,7 +310,7 @@ class Reader
|
|
307
310
|
end
|
308
311
|
|
309
312
|
|
310
|
-
def load_teams( name,
|
313
|
+
def load_teams( name, more_values={} )
|
311
314
|
path = "#{include_path}/#{name}.txt"
|
312
315
|
|
313
316
|
puts "*** parsing data '#{name}' (#{path})..."
|
@@ -540,10 +543,10 @@ private
|
|
540
543
|
game_attribs = {
|
541
544
|
score1: scores[0],
|
542
545
|
score2: scores[1],
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
546
|
+
score1ot: scores[2],
|
547
|
+
score2ot: scores[3],
|
548
|
+
score1p: scores[4],
|
549
|
+
score2p: scores[5],
|
547
550
|
play_at: date,
|
548
551
|
knockout: @knockout_flag,
|
549
552
|
group_id: @group.present? ? @group.id : nil
|
@@ -614,4 +617,4 @@ private
|
|
614
617
|
|
615
618
|
|
616
619
|
end # class Reader
|
617
|
-
end # module
|
620
|
+
end # module SportDb
|
data/lib/sportdb/schema.rb
CHANGED
@@ -1,18 +1,9 @@
|
|
1
1
|
|
2
|
-
module
|
2
|
+
module SportDb
|
3
3
|
|
4
|
-
class
|
5
|
-
|
6
|
-
|
7
|
-
## make models available in sportdb module by default with namespace
|
8
|
-
# e.g. lets you use Team instead of Models::Team
|
9
|
-
include SportDB::Models
|
10
|
-
|
11
|
-
|
12
|
-
def self.up
|
13
|
-
|
14
|
-
ActiveRecord::Schema.define do
|
4
|
+
class CreateDb < ActiveRecord::Migration
|
15
5
|
|
6
|
+
def up
|
16
7
|
|
17
8
|
create_table :teams do |t|
|
18
9
|
t.string :title, :null => false
|
@@ -23,6 +14,8 @@ create_table :teams do |t|
|
|
23
14
|
t.references :country, :null => false
|
24
15
|
t.references :city # NB: city is optional (should be required for clubs e.g. non-national teams)
|
25
16
|
t.boolean :club, :null => false, :default => false # is it a club (not a national team)?
|
17
|
+
|
18
|
+
### fix: remove and add virtual attribute in model instead
|
26
19
|
t.boolean :national, :null => false, :default => false # is it a national selection team (not a club)?
|
27
20
|
t.timestamps
|
28
21
|
end
|
@@ -34,8 +27,8 @@ create_table :events do |t|
|
|
34
27
|
t.string :key, :null => false # import/export key
|
35
28
|
t.references :league, :null => false
|
36
29
|
t.references :season, :null => false
|
37
|
-
t.
|
38
|
-
t.
|
30
|
+
t.date :start_at, :null => false # NB: only use date (w/o time)
|
31
|
+
t.date :end_at # make it required??? # NB: only use date (w/o time)
|
39
32
|
t.boolean :team3, :null => false, :default => true ## e.g. Champions League has no 3rd place (only 1st and 2nd/final)
|
40
33
|
t.timestamps
|
41
34
|
end
|
@@ -51,8 +44,8 @@ create_table :rounds do |t|
|
|
51
44
|
## add new table stage/stages for grouping rounds in group rounds and playoff rounds, for example???
|
52
45
|
## # "regular" season (group) games or post-season (playoff) knockouts (k.o's)
|
53
46
|
t.boolean :knockout, :null => false, :default => false
|
54
|
-
t.
|
55
|
-
t.
|
47
|
+
t.date :start_at, :null => false # NB: only use date (w/o time)
|
48
|
+
t.date :end_at # todo: make it required e.g. :null => false # NB: only use date (w/o time)
|
56
49
|
t.timestamps
|
57
50
|
end
|
58
51
|
|
@@ -96,11 +89,6 @@ create_table :games do |t|
|
|
96
89
|
t.string :toto12x # 1,2,X,nil calculate on save
|
97
90
|
t.string :key # import/export key
|
98
91
|
|
99
|
-
t.integer :score3 # deprecated - remove todo: change to score1o or score1o overtime # verlaengerung (opt)
|
100
|
-
t.integer :score4 # deprecated - remove todo> change to score2o
|
101
|
-
t.integer :score5 # deprecated - remove elfmeter (opt) ## todo> change to score1p - penality
|
102
|
-
t.integer :score6 # deprecated - remove
|
103
|
-
|
104
92
|
t.timestamps
|
105
93
|
end
|
106
94
|
|
@@ -161,14 +149,14 @@ create_table :badges do |t|
|
|
161
149
|
t.string :title, :null => false # Meister, Weltmeister, Europameister, Cupsieger, Vize-Meister, Aufsteiger, Absteiger, etc.
|
162
150
|
t.timestamps
|
163
151
|
end
|
164
|
-
|
165
|
-
end # block Schema.define
|
166
152
|
|
153
|
+
end # method up
|
167
154
|
|
168
|
-
|
155
|
+
def down
|
156
|
+
raise ActiveRecord::IrreversibleMigration
|
157
|
+
end
|
169
158
|
|
170
|
-
end # method up
|
171
159
|
|
172
|
-
end # class
|
160
|
+
end # class CreateDb
|
173
161
|
|
174
|
-
end # module
|
162
|
+
end # module SportDb
|
data/lib/sportdb/stats.rb
CHANGED
data/lib/sportdb/utils.rb
CHANGED
@@ -3,25 +3,25 @@
|
|
3
3
|
### some utils moved to worldbdb/utils for reuse
|
4
4
|
|
5
5
|
|
6
|
-
module
|
6
|
+
module SportDb::FixtureHelpers
|
7
7
|
|
8
8
|
def is_round?( line )
|
9
|
-
line =~
|
9
|
+
line =~ SportDb.lang.regex_round
|
10
10
|
end
|
11
11
|
|
12
12
|
def is_group?( line )
|
13
13
|
# NB: check after is_round? (round may contain group reference!)
|
14
|
-
line =~
|
14
|
+
line =~ SportDb.lang.regex_group
|
15
15
|
end
|
16
16
|
|
17
17
|
def is_knockout_round?( line )
|
18
18
|
|
19
19
|
## todo: check for adding ignore case for regex (e.g. 1st leg/1st Leg)
|
20
20
|
|
21
|
-
if line =~
|
21
|
+
if line =~ SportDb.lang.regex_leg1
|
22
22
|
logger.debug " two leg knockout; skip knockout flag on first leg"
|
23
23
|
false
|
24
|
-
elsif line =~
|
24
|
+
elsif line =~ SportDb.lang.regex_knockout_round
|
25
25
|
logger.debug " setting knockout flag to true"
|
26
26
|
true
|
27
27
|
elsif line =~ /K\.O\.|K\.o\.|Knockout/
|
@@ -328,4 +328,4 @@ module SportDB::FixtureHelpers
|
|
328
328
|
end # method translate_teams!
|
329
329
|
|
330
330
|
|
331
|
-
end # module
|
331
|
+
end # module SportDb::FixtureHelpers
|
data/lib/sportdb/version.rb
CHANGED
data/lib/sportdb.rb
CHANGED
@@ -94,12 +94,13 @@ module SportDB
|
|
94
94
|
end
|
95
95
|
|
96
96
|
def self.create
|
97
|
-
|
97
|
+
CreateDb.new.up
|
98
|
+
WorldDb::Models::Prop.create!( key: 'db.schema.sport.version', value: VERSION )
|
98
99
|
end
|
99
100
|
|
100
101
|
def self.read_setup( setup, include_path )
|
101
|
-
reader = Reader.new
|
102
|
-
reader.load_setup( setup
|
102
|
+
reader = Reader.new( include_path )
|
103
|
+
reader.load_setup( setup )
|
103
104
|
end
|
104
105
|
|
105
106
|
def self.read_all( include_path ) # convenience helper
|
@@ -113,11 +114,11 @@ module SportDB
|
|
113
114
|
# ['cl.2012/13', 'cl/2012_13/cl']] etc.
|
114
115
|
|
115
116
|
def self.read( ary, include_path )
|
116
|
-
reader = Reader.new
|
117
|
-
reader.load( ary
|
117
|
+
reader = Reader.new( include_path )
|
118
|
+
reader.load( ary )
|
118
119
|
end
|
119
|
-
|
120
|
-
|
120
|
+
|
121
|
+
|
121
122
|
# delete ALL records (use with care!)
|
122
123
|
def self.delete!
|
123
124
|
puts '*** deleting sport table records/data...'
|
@@ -174,15 +175,15 @@ module SportDB
|
|
174
175
|
|
175
176
|
end
|
176
177
|
|
177
|
-
end # module
|
178
|
+
end # module SportDb
|
178
179
|
|
179
180
|
|
180
|
-
##
|
181
|
+
## SportDb::load_plugins
|
181
182
|
|
182
183
|
|
183
184
|
if __FILE__ == $0
|
184
|
-
|
185
|
+
SportDb.main
|
185
186
|
else
|
186
187
|
## say hello
|
187
|
-
puts
|
188
|
+
puts SportDb.banner
|
188
189
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sportdb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.6.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-03-
|
12
|
+
date: 2013-03-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: worlddb
|
16
|
-
requirement: &
|
16
|
+
requirement: &81812490 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 1.5.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *81812490
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: commander
|
27
|
-
requirement: &
|
27
|
+
requirement: &81812230 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 4.1.3
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *81812230
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rdoc
|
38
|
-
requirement: &
|
38
|
+
requirement: &81811960 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '3.10'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *81811960
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: hoe
|
49
|
-
requirement: &
|
49
|
+
requirement: &81811710 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
@@ -54,7 +54,7 @@ dependencies:
|
|
54
54
|
version: '3.3'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *81811710
|
58
58
|
description: sportdb - sport.db command line tool
|
59
59
|
email: opensport@googlegroups.com
|
60
60
|
executables:
|