sportdb-market 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -16,8 +16,8 @@ db/euro/2012_tipico.txt
16
16
  db/euro/2012_tipp3.txt
17
17
  db/services.rb
18
18
  db/world/quali_tipp3.txt
19
+ lib/sportdb/market.rb
19
20
  lib/sportdb/market/loader.rb
20
- lib/sportdb/market/market.rb
21
21
  lib/sportdb/market/models/event_quote.rb
22
22
  lib/sportdb/market/models/game.rb
23
23
  lib/sportdb/market/models/group_quote.rb
@@ -6,6 +6,7 @@
6
6
  ## todo: how to include 'sportdb/market/version' - does it work? ?
7
7
 
8
8
  require 'sportdb/market/version'
9
+
9
10
  require 'sportdb/market/schema'
10
11
  require 'sportdb/market/models/service'
11
12
  require 'sportdb/market/models/group_quote'
@@ -22,9 +23,9 @@ module SportDB::Market
22
23
  "sportdb-market #{VERSION} on Ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}]"
23
24
  end
24
25
 
25
- ## cut off folders lib(#1)/sportdb(#2)/market(#3) to get to root
26
+ ## cut off folders lib(#1)/sportdb(#2) to get to root
26
27
  def self.root
27
- "#{File.expand_path( File.dirname(File.dirname(File.dirname(File.dirname(__FILE__)))) )}"
28
+ "#{File.expand_path( File.dirname(File.dirname(File.dirname(__FILE__))) )}"
28
29
  end
29
30
 
30
31
 
@@ -53,7 +54,7 @@ module SportDB::Market
53
54
  ['tipp3', 'cl.2012/13', 'cl/2012_13/cl_tipp3'],
54
55
  ['tipico', 'euro.2012', 'euro/2012_tipico'],
55
56
  ['tipp3', 'euro.2012', 'euro/2012_tipp3' ],
56
- ['tipp3', 'wmq.euro', 'world/quali_tipp3']]
57
+ ['tipp3', 'world.quali.euro.2012/13', 'world/quali_tipp3']]
57
58
  end
58
59
 
59
60
  def self.read_all
@@ -105,7 +106,8 @@ module SportDB::Market
105
106
  Deleter.new.run
106
107
  end # method delete!
107
108
 
108
- ## say hello
109
- puts SportDB::Market.banner
110
-
111
109
  end # module SportDB::Market
110
+
111
+
112
+ ## say hello
113
+ puts SportDB::Market.banner
@@ -23,13 +23,32 @@ class Loader
23
23
 
24
24
  puts "*** loading data '#{name}' (#{path})..."
25
25
 
26
- code = File.read( path )
26
+ code = File.read_utf8( path )
27
27
 
28
28
  load_worker( code )
29
+
30
+ ## for builtin fixtures use VERSION of gem
31
+
32
+ Prop.create!( key: "db.#{fixture_name_to_prop_key(name)}.version", value: "sport.market.rb.#{SportDB::Market::VERSION}" )
29
33
  end
30
34
 
31
35
 
32
36
  private
37
+
38
+ ##
39
+ # fix/todo: share helper w/ other readers
40
+
41
+ # helper
42
+ # change at/2012_13/bl to at.2012/13.bl
43
+ # or quali_2012_13_europe_c to quali.2012/13.europe.c
44
+
45
+ def fixture_name_to_prop_key( name )
46
+ prop_key = name.gsub( '/', '.' )
47
+ prop_key = prop_key.gsub( /(\d{4})_(\d{2})/, '\1/\2' ) # 2012_13 => 2012/13
48
+ prop_key = prop_key.gsub( '_', '.' )
49
+ prop_key
50
+ end
51
+
33
52
  def load_worker( code )
34
53
  self.class_eval( code )
35
54
  end
@@ -22,9 +22,11 @@ class Reader
22
22
 
23
23
  puts "*** parsing data '#{name}' (#{path})..."
24
24
 
25
- code = File.read( path )
25
+ code = File.read_utf8( path )
26
26
 
27
27
  load_worker( service_key, event_key, code )
28
+
29
+ Prop.create!( key: "db.#{fixture_name_to_prop_key(name)}.version", value: "file.txt.#{File.mtime(path).strftime('%Y.%m.%d')}" )
28
30
  end
29
31
 
30
32
  def load_builtin( service_key, event_key, name ) # load from gem (built-in)
@@ -32,12 +34,29 @@ class Reader
32
34
 
33
35
  puts "*** parsing data '#{name}' (#{path})..."
34
36
 
35
- code = File.read( path )
37
+ code = File.read_utf8( path )
36
38
 
37
39
  load_worker( service_key, event_key, code )
40
+
41
+ Prop.create!( key: "db.#{fixture_name_to_prop_key(name)}.version", value: "sport.market.txt.#{SportDB::Market::VERSION}" )
38
42
  end
39
43
 
40
44
  private
45
+
46
+ ##
47
+ # fix/todo: share helper w/ other readers
48
+
49
+ # helper
50
+ # change at/2012_13/bl to at.2012/13.bl
51
+ # or quali_2012_13_europe_c to quali.2012/13.europe.c
52
+
53
+ def fixture_name_to_prop_key( name )
54
+ prop_key = name.gsub( '/', '.' )
55
+ prop_key = prop_key.gsub( /(\d{4})_(\d{2})/, '\1/\2' ) # 2012_13 => 2012/13
56
+ prop_key = prop_key.gsub( '_', '.' )
57
+ prop_key
58
+ end
59
+
41
60
  def load_worker( service_key, event_key, data )
42
61
 
43
62
  ## assume active activerecord connection
@@ -48,43 +67,11 @@ private
48
67
 
49
68
  puts "Quote Service #{@service.key} >#{@service.title}<"
50
69
  puts "Event #{@event.key} >#{@event.title}<"
51
-
52
-
53
- ## build known teams table w/ synonyms e.g.
54
- #
55
- # nb: synonyms can be a regex not just a literal string
56
- # [[ 'wolfsbrug', [ 'VfL Wolfsburg' ]],
57
- # [ 'augsburg', [ 'FC Augsburg', 'Augi2', 'Augi3' ]],
58
- # [ 'stuttgart', [ 'VfB Stuttgart' ]] ]
59
70
 
60
- ### todo/fix: move known_teams code to model and reuse in readers!!
61
- ## do NOT duplicate
71
+ @known_teams = @event.known_teams_table
62
72
 
63
- @known_teams = []
64
-
65
- @event.teams.each_with_index do |team,index|
66
-
67
- titles = []
68
- titles << team.title
69
- titles += team.synonyms.split('|') if team.synonyms.present?
70
-
71
- ## NB: sort here by length (largest goes first - best match)
72
- # exclude code and key (key should always go last)
73
- titles = titles.sort { |left,right| right.length <=> left.length }
74
-
75
- titles << team.code if team.code.present?
76
- titles << team.key
77
-
78
- @known_teams << [ team.key, titles ]
79
-
80
- puts " Team[#{index+1}] #{team.key} >#{titles.join('|')}<"
81
- end
82
-
83
-
84
73
  parse_quotes( data )
85
-
86
- puts 'Done.'
87
-
74
+
88
75
  end # method load
89
76
 
90
77
 
@@ -123,25 +110,29 @@ private
123
110
  regex1 = /[ \t]+(\d{1,3}(?:\.\d{1,3})?)[ \t]+(\d{1,3}(?:\.\d{1,3})?)[ \t]+(\d{1,3}(?:\.\d{1,3})?)/
124
111
  regex2 = /[ \t]+(\d{1,3}(?:,\d{1,3})?)[ \t]+(\d{1,3}(?:,\d{1,3})?)[ \t]+(\d{1,3}(?:,\d{1,3})?)/
125
112
 
126
- if line =~ regex1
127
- values = [$1.to_f, $2.to_f, $3.to_f]
113
+ match = regex1.match( line )
114
+ unless match.nil?
115
+ values = [match[1].to_f, match[2].to_f, match[3].to_f]
128
116
  puts " quotes: >#{values.join('|')}<"
129
117
 
130
118
  line.sub!( regex1, ' [QUOTES.EN]' )
131
119
 
132
120
  return values
133
- elsif line =~ regex2
134
- values = [$1.tr(',','.').to_f,
135
- $2.tr(',','.').to_f,
136
- $3.tr(',','.').to_f]
121
+ end
122
+
123
+ match = regex2.match( line )
124
+ unless match.nil?
125
+ values = [match[1].tr(',','.').to_f,
126
+ match[2].tr(',','.').to_f,
127
+ match[3].tr(',','.').to_f]
137
128
  puts " quotes: >#{values.join('|')}<"
138
129
 
139
130
  line.sub!( regex2, ' [QUOTES.DE]' )
140
131
 
141
132
  return values
142
- else
143
- return nil
144
133
  end
134
+
135
+ nil # return nil; nothing found
145
136
  end
146
137
 
147
138
 
@@ -171,18 +162,10 @@ private
171
162
 
172
163
  def match_team_worker!( line, key, values )
173
164
  values.each do |value|
174
- ## todo: how to mark value as regex?
175
- ## for now escape regex special chars e.g. . to \.
176
- value_for_regex = value.gsub( '.', '\.' ) # e.g. Benfica Lis.
177
-
178
- ## fix: todo: match accented char with or without accents
179
- ## add (ü|ue) etc.
180
- ## also make - optional change to (-| ) e.g. Blau-Weiss == Blau Weiss
181
- ## reuse for all readers!
182
-
165
+
183
166
  ## nb: \b does NOT include space or newline for word boundry (only alphanums e.g. a-z0-9)
184
167
  ## (thus add it, allows match for Benfica Lis. for example - note . at the end)
185
- regex = /\b#{value_for_regex}[\b\s]/ # wrap with world boundry (e.g. match only whole words e.g. not wac in wacker)
168
+ regex = /\b#{value}(\b| |\t|$)/ # wrap with world boundry (e.g. match only whole words e.g. not wac in wacker)
186
169
  if line =~ regex
187
170
  puts " match for team >#{key}< >#{value}<"
188
171
  # make sure @@oo{key}oo@@ doesn't match itself with other key e.g. wacker, wac, etc.
@@ -2,5 +2,5 @@
2
2
  module SportDB ; end # forward reference (for hoe require)
3
3
 
4
4
  module SportDB::Market
5
- VERSION = '0.1.3'
5
+ VERSION = '0.1.4'
6
6
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  puts "hello from sportdb_plugin script (sportdb-market)"
4
4
 
5
- require 'sportdb/market/market'
5
+ require 'sportdb/market'
6
6
 
7
7
 
8
8
  #require 'rubygems/command_manager'
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sportdb-market
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 3
10
- version: 0.1.3
9
+ - 4
10
+ version: 0.1.4
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-18 00:00:00 Z
18
+ date: 2012-11-20 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: rdoc
@@ -83,8 +83,8 @@ files:
83
83
  - db/euro/2012_tipp3.txt
84
84
  - db/services.rb
85
85
  - db/world/quali_tipp3.txt
86
+ - lib/sportdb/market.rb
86
87
  - lib/sportdb/market/loader.rb
87
- - lib/sportdb/market/market.rb
88
88
  - lib/sportdb/market/models/event_quote.rb
89
89
  - lib/sportdb/market/models/game.rb
90
90
  - lib/sportdb/market/models/group_quote.rb