sportdb-market 0.4.1 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +2 -2
- data/Rakefile +2 -64
- data/lib/sportdb/market.rb +7 -45
- data/lib/sportdb/market/reader.rb +117 -3
- data/lib/sportdb/market/schema.rb +7 -13
- data/lib/sportdb/market/version.rb +1 -1
- metadata +7 -7
data/README.md
CHANGED
@@ -2,8 +2,8 @@
|
|
2
2
|
|
3
3
|
sportdb plugin for market quotes (odds, etc)
|
4
4
|
|
5
|
-
* home :: [github.com/openbookie/sport.db
|
6
|
-
* bugs :: [github.com/openbookie/sport.db
|
5
|
+
* home :: [github.com/openbookie/sport.db.market](https://github.com/openbookie/sport.db.market)
|
6
|
+
* bugs :: [github.com/openbookie/sport.db.market/issues](https://github.com/openbookie/sport.db.market/issues)
|
7
7
|
* gem :: [rubygems.org/gems/sportdb-market](https://rubygems.org/gems/sportdb-market)
|
8
8
|
* rdoc :: [rubydoc.info/gems/sportdb-market](http://rubydoc.info/gems/sportdb-market)
|
9
9
|
* forum :: [groups.google.com/group/opensport](https://groups.google.com/group/opensport)
|
data/Rakefile
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
|
2
2
|
require 'hoe'
|
3
3
|
require './lib/sportdb/market/version.rb'
|
4
4
|
|
@@ -11,7 +11,7 @@ Hoe.spec 'sportdb-market' do
|
|
11
11
|
self.summary = 'sportdb plugin for market quotes (odds, etc)'
|
12
12
|
self.description = summary
|
13
13
|
|
14
|
-
self.urls = ['https://github.com/openbookie/sport.db
|
14
|
+
self.urls = ['https://github.com/openbookie/sport.db.market']
|
15
15
|
|
16
16
|
self.author = 'Gerald Bauer'
|
17
17
|
self.email = 'opensport@googlegroups.com'
|
@@ -27,65 +27,3 @@ Hoe.spec 'sportdb-market' do
|
|
27
27
|
}
|
28
28
|
|
29
29
|
end
|
30
|
-
|
31
|
-
|
32
|
-
namespace :dev do
|
33
|
-
|
34
|
-
|
35
|
-
### NB: use rake -I ./lib dev:test # fresh import (starts w/ clean wipe out)
|
36
|
-
### NB: use rake -I ./lib dev:update # just update quotes
|
37
|
-
|
38
|
-
BUILD_DIR = "./build"
|
39
|
-
|
40
|
-
SPORT_DB_PATH = "#{BUILD_DIR}/sport.db"
|
41
|
-
|
42
|
-
DB_CONFIG = {
|
43
|
-
:adapter => 'sqlite3',
|
44
|
-
:database => SPORT_DB_PATH
|
45
|
-
}
|
46
|
-
|
47
|
-
directory BUILD_DIR
|
48
|
-
|
49
|
-
task :clean do
|
50
|
-
rm SPORT_DB_PATH if File.exists?( SPORT_DB_PATH )
|
51
|
-
end
|
52
|
-
|
53
|
-
task :env => BUILD_DIR do
|
54
|
-
require 'sportdb'
|
55
|
-
require './lib/sportdb/market.rb'
|
56
|
-
|
57
|
-
pp DB_CONFIG
|
58
|
-
ActiveRecord::Base.establish_connection( DB_CONFIG )
|
59
|
-
end
|
60
|
-
|
61
|
-
task :create => :env do
|
62
|
-
WorldDB.create
|
63
|
-
SportDB.create
|
64
|
-
SportDB::Market.create
|
65
|
-
end
|
66
|
-
|
67
|
-
task :import => :env do
|
68
|
-
WorldDB.read_all # populate world tables
|
69
|
-
|
70
|
-
SportDB.load_all
|
71
|
-
SportDB.read_all
|
72
|
-
|
73
|
-
SportDB.stats
|
74
|
-
end
|
75
|
-
|
76
|
-
|
77
|
-
desc 'sportdb-market - test loading of builtin fixtures'
|
78
|
-
task :test => [:clean, :create, :import] do
|
79
|
-
SportDB::Market.load_all
|
80
|
-
SportDB::Market.read_all
|
81
|
-
end
|
82
|
-
|
83
|
-
desc 'sportdb-market - test loading of builtin fixtures (just update)'
|
84
|
-
task :update => :env do
|
85
|
-
SportDB::Market.delete!
|
86
|
-
SportDB::Market.load_all
|
87
|
-
SportDB::Market.read_all
|
88
|
-
end
|
89
|
-
|
90
|
-
|
91
|
-
end # namespace :dev
|
data/lib/sportdb/market.rb
CHANGED
@@ -31,59 +31,21 @@ module SportDb::Market
|
|
31
31
|
end
|
32
32
|
|
33
33
|
def self.create
|
34
|
-
CreateDb.up
|
34
|
+
CreateDb.new.up
|
35
|
+
# WorldDb::Models::Prop.create!( key: 'db.schema.sport.market.version', value: SportDb::Market::VERSION )
|
35
36
|
end
|
36
37
|
|
37
|
-
def self.fixtures_rb # all builtin ruby fixtures; helper for covenience
|
38
|
-
['services',
|
39
|
-
'at/2012_13/bl',
|
40
|
-
'at/2012_13/cup',
|
41
|
-
'cl/2012_13/cl',
|
42
|
-
## 'euro/2012'
|
43
|
-
]
|
44
|
-
end
|
45
|
-
|
46
|
-
def self.load_all( include_path )
|
47
|
-
load( fixtures_rb, include_path )
|
48
|
-
end
|
49
38
|
|
50
|
-
def self.
|
51
|
-
|
52
|
-
|
53
|
-
['betathome', 'at.cup.2012/13', 'at/2012_13/cup_betathome'],
|
54
|
-
['tipp3', 'at.cup.2012/13', 'at/2012_13/cup_tipp3'],
|
55
|
-
['betathome', 'cl.2012/13', 'cl/2012_13/cl_betathome'],
|
56
|
-
['tipp3', 'cl.2012/13', 'cl/2012_13/cl_tipp3'],
|
57
|
-
## ['tipico', 'euro.2012', 'euro/2012_tipico'],
|
58
|
-
## ['tipp3', 'euro.2012', 'euro/2012_tipp3' ],
|
59
|
-
['tipp3', 'world.quali.europe.2014', 'world/quali_tipp3']]
|
39
|
+
def self.read_setup( setup, include_path )
|
40
|
+
reader = Reader.new( include_path )
|
41
|
+
reader.load_setup( setup )
|
60
42
|
end
|
61
43
|
|
62
|
-
def self.read_all( include_path )
|
63
|
-
|
44
|
+
def self.read_all( include_path ) # convenience helper
|
45
|
+
read_setup( 'setups/all', include_path )
|
64
46
|
end
|
65
47
|
|
66
48
|
|
67
|
-
# load built-in (that is, bundled within the gem) named seeds
|
68
|
-
# - pass in an array of seed names e.g. [ 'cl/teams', 'cl/2012_13/cl' ] etc.
|
69
|
-
|
70
|
-
def self.load( ary, include_path )
|
71
|
-
loader = Loader.new( include_path )
|
72
|
-
ary.each do |name|
|
73
|
-
loader.load( name )
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
# load built-in (that is, bundled within the gem) named plain text seeds
|
78
|
-
# - pass in an array of pairs of event/seed names e.g. [['at.2012/13', 'at/2012_13/bl'], ['cl.2012/13', 'cl/2012_13/cl']] etc.
|
79
|
-
|
80
|
-
def self.read( ary, include_path )
|
81
|
-
reader = Reader.new( include_path )
|
82
|
-
ary.each do |rec|
|
83
|
-
reader.load( rec[0], rec[1], rec[2] ) # service_key, event_key, name
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
49
|
class Deleter
|
88
50
|
## todo: move into its own file???
|
89
51
|
|
@@ -12,12 +12,86 @@ class Reader
|
|
12
12
|
include SportDb::Models
|
13
13
|
|
14
14
|
attr_reader :include_path
|
15
|
-
|
15
|
+
attr_reader :loader
|
16
|
+
|
16
17
|
def initialize( include_path )
|
17
18
|
@include_path = include_path
|
19
|
+
@loader = Loader.new( include_path )
|
20
|
+
end
|
21
|
+
|
22
|
+
def load_setup( name )
|
23
|
+
path = "#{include_path}/#{name}.yml"
|
24
|
+
|
25
|
+
logger.info "parsing data '#{name}' (#{path})..."
|
26
|
+
|
27
|
+
reader = FixtureReader.new( path )
|
28
|
+
|
29
|
+
reader.each do |fixture_name|
|
30
|
+
load( fixture_name )
|
31
|
+
end
|
32
|
+
end # method load_setup
|
33
|
+
|
34
|
+
|
35
|
+
def load( name ) # convenience helper for all-in-one reader
|
36
|
+
|
37
|
+
logger.debug "enter load( name=>>#{name}<<, include_path=>>#{include_path}<<)"
|
38
|
+
|
39
|
+
# check if name exits if extension .rb ##
|
40
|
+
# if yes, use loader (for ruby code)
|
41
|
+
# otherwise assume
|
42
|
+
# plain text match/game quotes
|
43
|
+
|
44
|
+
## todo: add sub for !/ prefix in name
|
45
|
+
|
46
|
+
path = "#{@include_path}/#{name}.rb"
|
47
|
+
|
48
|
+
if File.exist?( path ) # if it's ruby use (code) loader
|
49
|
+
loader.load( name )
|
50
|
+
else
|
51
|
+
meta = fetch_quotes_meta( name )
|
52
|
+
|
53
|
+
service_key = meta['service_key']
|
54
|
+
event_key = "#{meta['league_key']}.#{meta['season_key']}"
|
55
|
+
|
56
|
+
load_quotes( service_key, event_key, name )
|
57
|
+
end
|
58
|
+
|
59
|
+
end # method load
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
def fetch_quotes_meta( name )
|
64
|
+
# get/fetch/find event from yml file
|
65
|
+
|
66
|
+
## todo/fix: use h = HashFile.load( path ) or similar instead of HashReader!!
|
67
|
+
|
68
|
+
## todo/fix: add option for not adding prop automatically?? w/ HashReaderV2
|
69
|
+
|
70
|
+
reader = HashReaderV2.new( name, include_path )
|
71
|
+
|
72
|
+
attribs = {}
|
73
|
+
|
74
|
+
reader.each_typed do |key, value|
|
75
|
+
|
76
|
+
## puts "processing event attrib >>#{key}<< >>#{value}<<..."
|
77
|
+
|
78
|
+
if key == 'league'
|
79
|
+
attribs[ 'league_key' ] = value.to_s.strip
|
80
|
+
elsif key == 'season'
|
81
|
+
attribs[ 'season_key' ] = value.to_s.strip
|
82
|
+
elsif key == 'service'
|
83
|
+
attribs[ 'service_key' ] = value.to_s.strip
|
84
|
+
else
|
85
|
+
puts "*** warn: skipping unknown quote config/meta key >#{key}< w/ value >#{value}<"
|
86
|
+
end
|
87
|
+
end # each key,value
|
88
|
+
|
89
|
+
attribs
|
18
90
|
end
|
19
91
|
|
20
|
-
|
92
|
+
|
93
|
+
|
94
|
+
def load_quotes( service_key, event_key, name )
|
21
95
|
path = "#{@include_path}/#{name}.txt"
|
22
96
|
|
23
97
|
puts "*** parsing data '#{name}' (#{path})..."
|
@@ -41,8 +115,16 @@ private
|
|
41
115
|
##
|
42
116
|
|
43
117
|
@service = Service.find_by_key!( service_key )
|
44
|
-
@event = Event.find_by_key!( event_key )
|
45
118
|
|
119
|
+
#### fix:
|
120
|
+
## for now skip if event not present
|
121
|
+
@event = Event.find_by_key( event_key )
|
122
|
+
|
123
|
+
unless @event.present?
|
124
|
+
puts "*** error: event key >>#{event_key}<< not found/present; skip loading quotes"
|
125
|
+
return
|
126
|
+
end
|
127
|
+
|
46
128
|
puts "Quote Service #{@service.key} >#{@service.title}<"
|
47
129
|
puts "Event #{@event.key} >#{@event.title}<"
|
48
130
|
|
@@ -56,6 +138,30 @@ private
|
|
56
138
|
include SportDb::FixtureHelpers
|
57
139
|
|
58
140
|
|
141
|
+
def find_handicap!( line )
|
142
|
+
# fix/todo:
|
143
|
+
# use find_handicap_team1! and
|
144
|
+
# find_handicap_team2! ??? why? why not??
|
145
|
+
# how can we know if the handicap is for team1 or team2
|
146
|
+
# needs to get fixed; find some
|
147
|
+
|
148
|
+
# for now ignore handicap e.g. +1 or +2 or +3 +4 +5
|
149
|
+
|
150
|
+
regex = /\+(\d)[ \t]+/
|
151
|
+
|
152
|
+
match = regex.match( line )
|
153
|
+
unless match.nil?
|
154
|
+
value = match[1].to_i
|
155
|
+
puts " handicap: >#{value}<"
|
156
|
+
|
157
|
+
line.sub!( regex, ' [HANDICAP] ' )
|
158
|
+
|
159
|
+
return value
|
160
|
+
end
|
161
|
+
nil # if no handicap found
|
162
|
+
end
|
163
|
+
|
164
|
+
|
59
165
|
def find_quotes!( line )
|
60
166
|
# extract quotes triplet from line
|
61
167
|
# and return it
|
@@ -117,10 +223,18 @@ private
|
|
117
223
|
team1_key = find_team1!( line )
|
118
224
|
team2_key = find_team2!( line )
|
119
225
|
|
226
|
+
handicap = find_handicap!( line )
|
227
|
+
|
120
228
|
quotes = find_quotes!( line )
|
121
229
|
|
122
230
|
puts " line: >#{line}<"
|
123
231
|
|
232
|
+
if quotes.nil?
|
233
|
+
puts 'no quotes found; skipping line' # skip lines w/o quotes
|
234
|
+
next
|
235
|
+
end
|
236
|
+
|
237
|
+
|
124
238
|
|
125
239
|
### todo: cache team lookups in hash?
|
126
240
|
|
@@ -1,17 +1,11 @@
|
|
1
|
+
# encoding: UTF-8
|
1
2
|
|
2
3
|
module SportDb::Market
|
3
4
|
|
4
5
|
|
5
|
-
class CreateDb
|
6
|
+
class CreateDb < ActiveRecord::Migration
|
6
7
|
|
7
|
-
|
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
|
8
|
+
def up
|
15
9
|
|
16
10
|
create_table :services do |t| # quote service (e.g. tipp3,tipico,etc.)
|
17
11
|
t.string :title, :null => false
|
@@ -47,11 +41,11 @@ create_table :group_quotes do |t|
|
|
47
41
|
t.timestamps
|
48
42
|
end
|
49
43
|
|
50
|
-
|
51
|
-
|
52
|
-
Prop.create!( key: 'db.schema.sport.market.version', value: SportDb::Market::VERSION )
|
44
|
+
end # method up
|
53
45
|
|
54
|
-
|
46
|
+
def down
|
47
|
+
raise ActiveRecord::IrreversibleMigration
|
48
|
+
end
|
55
49
|
|
56
50
|
end # class CreateDb
|
57
51
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sportdb-market
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.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-09-
|
12
|
+
date: 2013-09-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rdoc
|
16
|
-
requirement: &
|
16
|
+
requirement: &75451570 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '3.10'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *75451570
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: hoe
|
27
|
-
requirement: &
|
27
|
+
requirement: &75469300 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,7 +32,7 @@ dependencies:
|
|
32
32
|
version: '3.3'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *75469300
|
36
36
|
description: sportdb plugin for market quotes (odds, etc)
|
37
37
|
email: opensport@googlegroups.com
|
38
38
|
executables: []
|
@@ -55,7 +55,7 @@ files:
|
|
55
55
|
- lib/sportdb/market/schema.rb
|
56
56
|
- lib/sportdb/market/version.rb
|
57
57
|
- lib/sportdb_plugin.rb
|
58
|
-
homepage: https://github.com/openbookie/sport.db
|
58
|
+
homepage: https://github.com/openbookie/sport.db.market
|
59
59
|
licenses:
|
60
60
|
- Public Domain
|
61
61
|
post_install_message:
|