sportdb 1.9.5 → 1.9.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -16,9 +16,6 @@ lib/sportdb.rb
16
16
  lib/sportdb/calc.rb
17
17
  lib/sportdb/cli/main.rb
18
18
  lib/sportdb/cli/opts.rb
19
- lib/sportdb/console.rb
20
- lib/sportdb/data/keys.rb
21
- lib/sportdb/data/models.rb
22
19
  lib/sportdb/deleter.rb
23
20
  lib/sportdb/finders/date.rb
24
21
  lib/sportdb/finders/goals.rb
@@ -29,16 +26,13 @@ lib/sportdb/models/assoc.rb
29
26
  lib/sportdb/models/assoc_assoc.rb
30
27
  lib/sportdb/models/badge.rb
31
28
  lib/sportdb/models/event.rb
32
- lib/sportdb/models/event_comp.rb
33
29
  lib/sportdb/models/event_ground.rb
34
30
  lib/sportdb/models/event_team.rb
35
31
  lib/sportdb/models/forward.rb
36
32
  lib/sportdb/models/game.rb
37
- lib/sportdb/models/game_comp.rb
38
33
  lib/sportdb/models/goal.rb
39
34
  lib/sportdb/models/ground.rb
40
35
  lib/sportdb/models/group.rb
41
- lib/sportdb/models/group_comp.rb
42
36
  lib/sportdb/models/group_team.rb
43
37
  lib/sportdb/models/league.rb
44
38
  lib/sportdb/models/person.rb
@@ -69,23 +63,13 @@ lib/sportdb/readers/season.rb
69
63
  lib/sportdb/readers/squad.rb
70
64
  lib/sportdb/readers/team.rb
71
65
  lib/sportdb/schema.rb
72
- lib/sportdb/service.rb
73
- lib/sportdb/service/public/style.css
74
- lib/sportdb/service/public/style.css.scss
75
- lib/sportdb/service/server.rb
76
- lib/sportdb/service/views/_debug.erb
77
- lib/sportdb/service/views/_version.erb
78
- lib/sportdb/service/views/debug.erb
79
- lib/sportdb/service/views/index.erb
80
- lib/sportdb/service/views/layout.erb
66
+ lib/sportdb/standings.rb
81
67
  lib/sportdb/stats.rb
82
- lib/sportdb/updater.rb
83
68
  lib/sportdb/utils.rb
84
69
  lib/sportdb/utils_date.rb
85
70
  lib/sportdb/utils_goals.rb
86
71
  lib/sportdb/utils_group.rb
87
72
  lib/sportdb/utils_map.rb
88
- lib/sportdb/utils_record.rb
89
73
  lib/sportdb/utils_round.rb
90
74
  lib/sportdb/utils_scores.rb
91
75
  lib/sportdb/utils_teams.rb
@@ -149,5 +133,6 @@ test/test_round_header.rb
149
133
  test/test_scores.rb
150
134
  test/test_squad_reader.rb
151
135
  test/test_standings.rb
136
+ test/test_standings_ii.rb
152
137
  test/test_utils.rb
153
138
  test/test_winner.rb
data/Rakefile CHANGED
@@ -34,6 +34,12 @@ Hoe.spec 'sportdb' do
34
34
  ['activerecord-utils'], # extras e.g. rnd, find_by! for 3.x etc.
35
35
  ['fetcher', '>= 0.3'],
36
36
 
37
+ ### sportdb addons
38
+ ['sportdb-keys'],
39
+ ['sportdb-console'],
40
+ ['sportdb-update'],
41
+ ['sportdb-service'],
42
+
37
43
  ## 3rd party
38
44
  ['gli', '>= 2.5.6'],
39
45
 
@@ -55,12 +55,6 @@ require 'sportdb/models/season'
55
55
  require 'sportdb/models/team'
56
56
  require 'sportdb/models/team_comp'
57
57
 
58
- ### note: moved to racing.db !! - delete
59
- ## require 'sportdb/models/race'
60
- ## require 'sportdb/models/record'
61
- ## require 'sportdb/models/run'
62
- ## require 'sportdb/models/track'
63
-
64
58
 
65
59
  require 'sportdb/models/stats/alltime_standing'
66
60
  require 'sportdb/models/stats/alltime_standing_entry'
@@ -87,13 +81,14 @@ require 'sportdb/utils'
87
81
  require 'sportdb/utils_date'
88
82
  require 'sportdb/utils_group'
89
83
  require 'sportdb/utils_map'
90
- require 'sportdb/utils_record'
91
84
  require 'sportdb/utils_round'
92
85
  require 'sportdb/utils_scores'
93
86
  require 'sportdb/utils_teams'
94
87
  require 'sportdb/utils_goals'
95
88
  require 'sportdb/matcher'
96
- require 'sportdb/calc'
89
+ require 'sportdb/calc' # fix/todo: obsolete - replace w/ standings
90
+ require 'sportdb/standings'
91
+
97
92
 
98
93
  require 'sportdb/finders/goals' # no: requires FixturesHelpers
99
94
 
@@ -108,43 +103,15 @@ require 'sportdb/readers/team'
108
103
  require 'sportdb/reader'
109
104
 
110
105
 
111
- ### note: moved to racing.db !! - delete
112
- ## require 'sportdb/readers/race'
113
- ## require 'sportdb/readers/record'
114
- ## require 'sportdb/readers/race_team'
115
- ## require 'sportdb/readers/track'
116
-
117
106
 
118
107
  require 'sportdb/lang'
119
108
 
120
- require 'sportdb/updater'
121
109
  require 'sportdb/deleter'
122
110
  require 'sportdb/stats'
123
111
 
124
112
 
125
- ###############
126
- # optional: for convenience add some finders etc. for known fixtures
127
- #
128
- # only used for sportdb/console.rb
129
- # and sportdb/tasks/test.rb -> rename to tasks.rb?
130
- #
131
- # todo/fix => remove from here and move into console.rb and tasks.rb
132
-
133
- require 'sportdb/data/keys'
134
- require 'sportdb/data/models' # add convenience finders for known fixtures
135
-
136
-
137
-
138
113
  module SportDb
139
114
 
140
- def self.banner
141
- "sportdb/#{VERSION} on Ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}]"
142
- end
143
-
144
- def self.root
145
- "#{File.expand_path( File.dirname(File.dirname(__FILE__)) )}"
146
- end
147
-
148
115
  def self.config_path
149
116
  "#{root}/config"
150
117
  end
@@ -236,6 +203,7 @@ module SportDb
236
203
  Stats.new.props
237
204
  end
238
205
 
206
+
239
207
  def self.setup_in_memory_db
240
208
  # Database Setup & Config
241
209
 
@@ -260,43 +228,16 @@ module SportDb
260
228
  end # setup_in_memory_db (using SQLite :memory:)
261
229
 
262
230
 
263
- def self.load_plugins
264
-
265
- @found ||= []
266
- @loaded ||= {}
267
- @files ||= Gem.find_files( 'sportdb_plugin.rb' )
231
+ end # module SportDb
268
232
 
269
- puts "#{@files.size} plugin files found:"
270
- @files.each do |file|
271
- puts " >#{file}<"
272
- end
273
-
274
- ## todo: extract version and name of gem?
275
- puts "normalized/match pattern:"
276
- @files.each do |file|
277
- if file =~ /sportdb-([a-z]+)-(\d\.\d.\d)/
278
- puts " >#{$1}< | >#{$2}<"
279
- @found << file
280
- else
281
- puts "*** error: ignoring plugin script >#{file}< not matching gem naming pattern"
282
- end
283
- end
284
-
285
- @found.each do |file|
286
- begin
287
- puts "loading plugin script #{file}"
288
- require file
289
- rescue LoadError => e
290
- puts "*** error loading plugin script #{file.inspect}: #{e.message}. skipping..."
291
- end
292
- end
293
233
 
294
- end
234
+ #####
235
+ # auto-load/require some addons
295
236
 
296
- end # module SportDb
237
+ require 'sportdb/update'
238
+ require 'sportdb/service'
297
239
 
298
240
 
299
- ## SportDb::load_plugins
300
241
 
301
242
 
302
243
  if __FILE__ == $0
@@ -2,6 +2,11 @@
2
2
 
3
3
  module SportDb
4
4
 
5
+ ############
6
+ ##
7
+ ## fix/todo: obsolete
8
+ ## - use new Standings class
9
+
5
10
 
6
11
  ##############################################
7
12
  # helper/ builds standings table in memory
@@ -13,6 +18,7 @@ module StandingsHelper
13
18
  ## todo:
14
19
  ## add team_id to struct - why? why not? - saves a db lookup?
15
20
  class Stats
21
+ ### fix/todo: change/rename :pos to :rank
16
22
  attr_accessor :pos, :played, :won, :lost, :drawn,
17
23
  :goals_for, :goals_against, :pts,
18
24
  :recs
@@ -202,6 +202,8 @@ command [:load, :l] do |c|
202
202
  end # command load
203
203
 
204
204
 
205
+ if defined?( SportDb::Updater ) ## add only if Updater class loaded/defined
206
+
205
207
  desc 'Pull - Auto-update event fixtures from upstream online sources'
206
208
  command :pull do |c|
207
209
  c.action do |g,o,args|
@@ -214,6 +216,8 @@ command :pull do |c|
214
216
  end # action
215
217
  end # command pull
216
218
 
219
+ end ## if defined?( SportDb::Updater )
220
+
217
221
 
218
222
 
219
223
  desc 'Start web service (HTTP JSON API)'
@@ -223,8 +227,9 @@ command [:serve,:server] do |c|
223
227
 
224
228
  connect_to_db( opts )
225
229
 
226
- # NB: server (HTTP service) not included in standard default require
227
- require 'sportdb/service'
230
+ # note: server (HTTP service) not included in standard default require
231
+ ## -- note - now included!!!
232
+ ## require 'sportdb/service'
228
233
 
229
234
  # make sure connections get closed after every request e.g.
230
235
  #
@@ -306,11 +311,12 @@ command :test do |c|
306
311
  pp o
307
312
  puts "g (#{g.class.name}):"
308
313
  pp g
309
-
310
- LogUtils::Logger.root.debug 'test debug msg'
311
- LogUtils::Logger.root.info 'test info msg'
312
- LogUtils::Logger.root.warn 'test warn msg'
313
-
314
+
315
+ logger = LogUtils::Logger.root
316
+ logger.debug 'test debug msg'
317
+ logger.info 'test info msg'
318
+ logger.warn 'test warn msg'
319
+
314
320
  puts 'Done.'
315
321
  end
316
322
  end
@@ -256,13 +256,13 @@ class DateFinder
256
256
  (?<month_es>#{MONTH_ES})
257
257
  \b/x
258
258
 
259
- # e.g. Ven 8. Août or [Ven 8. Août]
259
+ # e.g. Ven 8 Août or [Ven 8 Août] or Ven 8. Août or [Ven 8. Août]
260
260
  ### note: do NOT consume [] in regex (use lookahead assert)
261
261
  FR__WEEKDAY_DD_MONTH__DATE_REGEX = /\b
262
262
  (?:#{WEEKDAY_FR}) # note: skip weekday for now; do NOT capture
263
263
  \s+
264
264
  (?<day>\d{1,2})
265
- \.
265
+ \.? # note: make dot optional
266
266
  \s+
267
267
  (?<month_fr>#{MONTH_FR})
268
268
  (?=\s+|$|[\]])/x ## note: allow end-of-string/line too
@@ -18,14 +18,6 @@ module Matcher
18
18
  match_xxx_for_country( name, 'clubs', &blk )
19
19
  end
20
20
 
21
- def match_tracks_for_country( name, &blk )
22
- match_xxx_for_country( name, 'tracks', &blk )
23
- end
24
-
25
- def match_skiers_for_country( name, &blk )
26
- match_xxx_for_country( name, 'skiers', &blk )
27
- end
28
-
29
21
  def match_players_for_country( name, &blk )
30
22
  match_xxx_for_country( name, 'players', &blk )
31
23
  end
@@ -20,6 +20,10 @@ class Game < ActiveRecord::Base
20
20
  before_save :calc_winner
21
21
 
22
22
 
23
+ def team1_name() team1.name; end
24
+ def team2_name() team2.name; end
25
+
26
+
23
27
  def toto12x() toto1x2; end # alias for toto12x - todo/fix: use ruby alias helper
24
28
  def toto1x2
25
29
  ## note: will return string e.g. 1-X-2 (winner will return int e.g. 1-0-2)
@@ -120,6 +124,7 @@ class Game < ActiveRecord::Base
120
124
 
121
125
  # game over?
122
126
  def over?() play_at <= Time.now; end
127
+
123
128
  ## fix/todo: already added by ar magic ??? remove code
124
129
  def knockout?() knockout == true; end
125
130
  def complete?() score1.present? && score2.present?; end
@@ -52,6 +52,9 @@ class Team < ActiveRecord::Base
52
52
  belongs_to :city, class_name: 'WorldDb::Model::City', foreign_key: 'city_id'
53
53
 
54
54
 
55
+ ## fix/todo: change title to name; title2 to name2 etc.
56
+ def name() title; end
57
+
55
58
 
56
59
  def self.create_or_update_from_values( new_attributes, values )
57
60
 
@@ -21,14 +21,6 @@ class Reader
21
21
 
22
22
  def load_setup( name )
23
23
  path = "#{include_path}/#{name}.txt"
24
-
25
- ## depcrecated - for now check if "new" format exsits
26
- ## - if not fall back to old format
27
- unless File.exists?( path )
28
- puts " deprecated manifest/setup format [SportDb.Reader]; use new plain text format"
29
- ## try old yml format
30
- path = "#{include_path}/#{name}.yml"
31
- end
32
24
 
33
25
  logger.info "parsing data '#{name}' (#{path})..."
34
26
 
@@ -40,77 +32,6 @@ class Reader
40
32
  end # method load_setup
41
33
 
42
34
 
43
- def is_club_fixture?( name )
44
- ## guess (heuristic) if it's a national team event (e.g. world cup, copa america, etc.)
45
- ## or club event (e.g. bundesliga, club world cup, etc.)
46
-
47
- if name =~ /club-world-cup!?\// # NB: must go before -cup (special case)
48
- true
49
- elsif name =~ /copa-america!?\// || # NB: copa-america/ or copa-america!/
50
- name =~ /-cup!?\// # NB: -cup/ or -cup!/
51
- false
52
- else
53
- true
54
- end
55
- end
56
-
57
- def fix_fix_load_racing_fix_fix
58
- =begin
59
- if name =~ /^circuits/ # e.g. circuits.txt in formula1.db
60
- reader = TrackReader.new( include_path )
61
- reader.read( name )
62
- elsif match_tracks_for_country( name ) do |country_key| # name =~ /^([a-z]{2})\/tracks/
63
- # auto-add country code (from folder structure) for country-specific tracks
64
- # e.g. at/tracks or at-austria/tracks
65
- country = Country.find_by_key!( country_key )
66
- reader = TrackReader.new( include_path )
67
- reader.read( name, country_id: country.id )
68
- end
69
- elsif name =~ /^tracks/ # e.g. tracks.txt in ski.db
70
- reader = TrackReader.new( include_path )
71
- reader.read( name )
72
- elsif name =~ /^drivers/ # e.g. drivers.txt in formula1.db
73
- reader = PersonDb::PersonReader.new( include_path )
74
- reader.read( name )
75
- elsif match_skiers_for_country( name ) do |country_key| # name =~ /^([a-z]{2})\/skiers/
76
- # auto-add country code (from folder structure) for country-specific skiers (persons)
77
- # e.g. at/skiers or at-austria/skiers.men
78
- country = Country.find_by_key!( country_key )
79
- reader = PersonDb::PersonReader.new( include_path )
80
- reader.read( name, country_id: country.id )
81
- end
82
- elsif name =~ /^skiers/ # e.g. skiers.men.txt in ski.db
83
- reader = PersonDb::PersonReader.new( include_path )
84
- reader.read( name )
85
- elsif name =~ /\/races/ # e.g. 2013/races.txt in formula1.db
86
- ## fix/bug: NOT working for now; sorry
87
- # need to read event first and pass along to read (event_id: event.id) etc.
88
- reader = RaceReader.new( include_path )
89
- reader.read( name )
90
- elsif name =~ /^teams/ # e.g. teams.txt in formula1.db ### fix: check if used for football ? - add clubs
91
- reader = TeamReader.new( include_path )
92
- reader.read( name )
93
- ## fix!!! - find a better unique pattern to generic???
94
- ##
95
- ## fix: use two routes/tracks/modes:
96
- ##
97
- ## races w/ records etc and teams/matches etc. split into two to make code easier to read/extend!!!
98
- ##
99
- elsif name =~ /\/([0-9]{2})-/
100
- race_pos = $1.to_i
101
- # NB: assume @event is set from previous load
102
- race = Race.find_by_event_id_and_pos( @event.id, race_pos )
103
- reader = RecordReader.new( include_path )
104
- reader.read( name, race_id: race.id ) # e.g. 2013/04-gp-monaco.txt in formula1.db
105
-
106
- elsif name =~ /\/squads/ || name =~ /\/rosters/ # e.g. 2013/squads.txt in formula1.db
107
- reader = RaceTeamReader.new( include_path )
108
- reader.read( name )
109
-
110
- =end
111
- end
112
-
113
-
114
35
  def load( name ) # convenience helper for all-in-one reader
115
36
 
116
37
  logger.debug "enter load( name=>>#{name}<<, include_path=>>#{include_path}<<)"
@@ -164,13 +85,13 @@ class Reader
164
85
  end
165
86
  elsif name =~ /(?:^|\/)leagues/ # NB: ^leagues or also possible world!/leagues - NB: make sure goes after leagues_for_country!!
166
87
  reader = LeagueReader.new( include_path )
167
- reader.read( name, club: is_club_fixture?( name ) )
88
+ reader.read( name )
168
89
  elsif match_teams_for_country( name ) do |country_key| # name =~ /^([a-z]{2})\/teams/
169
90
  # auto-add country code (from folder structure) for country-specific teams
170
- # e.g. at/teams at/teams.2 de/teams etc.
91
+ # e.g. at/teams at/teams.2 de/teams etc.
171
92
  country = Country.find_by_key!( country_key )
172
93
  reader = TeamReader.new( include_path )
173
- reader.read( name, club: true, country_id: country.id ) ## fix: club flag - do NOT set - why? why not?
94
+ reader.read( name, country_id: country.id )
174
95
  end
175
96
  elsif match_clubs_for_country( name ) do |country_key| # name =~ /^([a-z]{2})\/clubs/
176
97
  # auto-add country code (from folder structure) for country-specific clubs
@@ -180,11 +101,13 @@ class Reader
180
101
  reader.read( name, club: true, country_id: country.id ) ## note: always sets club flag to true
181
102
  end
182
103
  elsif name =~ /(?:^|\/)teams/ ## fix: check if teams rule above (e.g. /^teams/ )conflicts/matches first ???
104
+ ### fix: use new NationalTeamReader ??? why? why not?
183
105
  reader = TeamReader.new( include_path )
184
- reader.read( name, club: is_club_fixture?( name ) ) ## fix: cleanup - use is_club_fixture? still needed w/ new clubs in name?
106
+ reader.read( name ) ## note: always sets club flag to true / national to true
185
107
  elsif name =~ /(?:^|\/)clubs/
108
+ ### fix: use new ClubReader ??? why? why not?
186
109
  reader = TeamReader.new( include_path )
187
- reader.read( name, club: true ) ## note: always sets club flag to true
110
+ reader.read( name, club: true ) ## note: always sets club flag to true / national to false
188
111
  elsif name =~ /\/(\d{4}|\d{4}[_\-]\d{2})(--[^\/]+)?\// ||
189
112
  name =~ /\/(\d{4}|\d{4}[_\-]\d{2})$/
190
113