Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

upgrate schema to sportdb 0.4.1

  • Loading branch information...
commit 957552b00b398fa992947ee63877ac5c869a1c9f 1 parent 65f0845
@geraldb geraldb authored
View
2  Gemfile
@@ -6,7 +6,7 @@ gem 'kramdown' # all ruby markdown processor/engine
gem 'rails', '3.2.1'
gem 'rails-i18n' # see https://github.com/svenfuchs/rails-i18n
-gem 'sportdb', '0.3.0' # see https://github.com/geraldb/sport.db
+gem 'sportdb', '0.4.1' # see https://github.com/geraldb/sport.db
group :production do
gem 'pg'
View
5 Gemfile.lock
@@ -97,7 +97,8 @@ GEM
railties (~> 3.2.0)
sass (>= 3.1.10)
tilt (~> 1.3)
- sportdb (0.3.0)
+ sportdb (0.4.1)
+ activerecord (~> 3.2)
sprockets (2.1.2)
hike (~> 1.2)
rack (~> 1.0)
@@ -134,7 +135,7 @@ DEPENDENCIES
rails-i18n
ri_cal
sass-rails (~> 3.2.3)
- sportdb (= 0.3.0)
+ sportdb (= 0.4.1)
sqlite3
thin
uglifier (>= 1.0.3)
View
3  config/environment.rb
@@ -9,4 +9,5 @@
require "#{Rails.root}/lib/utils.rb"
require "#{Rails.root}/lib/lookups.rb"
require "#{Rails.root}/lib/backup.rb"
-require "#{Rails.root}/lib/recalc.rb"
+require "#{Rails.root}/lib/recalc.rb"
+require "#{Rails.root}/lib/quotes.rb"
View
16 db/migrate/20120305214015_create_db.rb
@@ -7,13 +7,24 @@ def up
t.string :value, :null => false
t.timestamps
end
-
+
+create_table :countries do |t|
+ t.string :title, :null => false
+ t.string :tag, :null => false # short three letter tag
+ t.string :key, :null => false
+ t.timestamps
+end
+
create_table :teams do |t|
t.string :title, :null => false
t.string :title2
t.string :key, :null => false # import/export key
t.string :img
t.string :tag # make it not null? - three letter tag (short title)
+ t.string :synonyms # comma separated list of synonyms
+ t.references :country, :null => false
+ t.boolean :club, :null => false, :default => false # is it a club (not a national team)?
+ t.boolean :national, :null => false, :default => false # is it a national selection team (not a club)?
t.string :type # NOTE: Rails System Attribute Required for Single-Table Inheritance (STI)
@@ -46,6 +57,9 @@ def up
t.integer :pos, :null => false
t.boolean :playoff, :null => false, :default => false # "regular" season (group) games or post-season (playoff) knockouts (k.o's)
+ t.datetime :start_at, :null => false
+ t.datetime :end_at # todo: make it required e.g. :null => false
+
# to avoid duplicates allow (re)use of rounds for fix/flex pools by default
# use :flex => true, :fix => false for flex only rounds
# use :flex => false, :fix => true for fix only rounds
View
14 db/schema.rb
@@ -69,6 +69,14 @@
t.datetime "updated_at", :null => false
end
+ create_table "countries", :force => true do |t|
+ t.string "title", :null => false
+ t.string "tag", :null => false
+ t.string "key", :null => false
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
+ end
+
create_table "event_quotes", :force => true do |t|
t.integer "service_id", :null => false
t.integer "event_id", :null => false
@@ -235,6 +243,8 @@
t.string "title2"
t.integer "pos", :null => false
t.boolean "playoff", :default => false, :null => false
+ t.datetime "start_at", :null => false
+ t.datetime "end_at"
t.boolean "flex", :default => true, :null => false
t.boolean "fix", :default => true, :null => false
t.string "type"
@@ -258,6 +268,10 @@
t.string "key", :null => false
t.string "img"
t.string "tag"
+ t.string "synonyms"
+ t.integer "country_id", :null => false
+ t.boolean "club", :default => false, :null => false
+ t.boolean "national", :default => false, :null => false
t.string "type"
t.boolean "calc", :default => false, :null => false
t.string "calc_rule"
View
2  db/seeds/uss/others_pools.rb
@@ -5,7 +5,7 @@
at_bl = Event.find_by_key!( 'at_bl_2012_13' )
at_cup = Event.find_by_key!( 'at_cup_2012_13' )
-wm_quali = Event.find_by_key!( 'wmql' )
+wm_quali = Event.find_by_key!( 'wmq' )
cl_2012_13 = Event.find_by_key!( 'cl.2012/13' )
nn = User.find_by_key!( 'nn' )
View
227 lib/quotes.rb
@@ -0,0 +1,227 @@
+
+### load quotes from plain text files
+
+class QuotesReader
+
+ def initialize
+ @logger = Logger.new(STDOUT)
+ @logger.level = Logger::INFO
+ end
+
+ attr_reader :logger
+
+ def load( service_key, event_key, data )
+
+
+ puts "working directory: #{Dir.pwd}"
+
+ ## assume active activerecord connection
+ ##
+
+ @event = Event.find_by_key!( event_key )
+
+ puts "Event #{@event.key} >#{@event.title}<"
+
+
+ ## build known teams table w/ synonyms e.g.
+ #
+ # nb: synonyms can be a regex not just a literal string
+ # [[ 'wolfsbrug', [ 'VfL Wolfsburg' ]],
+ # [ 'augsburg', [ 'FC Augsburg', 'Augi2', 'Augi3' ]],
+ # [ 'stuttgart', [ 'VfB Stuttgart' ]] ]
+
+ @known_teams = []
+
+ @event.teams.each_with_index do |team,index|
+
+ titles = []
+ titles << team.title
+ titles += team.synonyms.split('|') if team.synonyms.present?
+
+ ## NB: sort here by length (largest goes first - best match)
+ # exclude tag and key (key should always go last)
+ titles = titles.sort { |left,right| right.length <=> left.length }
+
+ titles << team.tag if team.tag.present?
+ titles << team.key
+
+ @known_teams << [ team.key, titles ]
+
+ puts " Team[#{index+1}] #{team.key} >#{titles.join('|')}<"
+ end
+
+
+ parse_quotes( data )
+
+ puts 'Done.'
+
+ end # method load
+
+
+ def is_round?( line )
+ line =~ /Spieltag|Runde/
+ end
+
+ def find_round_pos!( line )
+ regex = /\b(\d+)\b/
+
+ if line =~ regex
+ value = $1.to_i
+ puts " pos: >#{value}<"
+
+ line.sub!( regex, '[POS]' )
+
+ return value
+ else
+ return nil
+ end
+ end
+
+ def find_date!( line )
+ # extract date from line
+ # and return it
+ # NB: side effect - removes date from line string
+
+ # e.g. 14.09. 20:30
+ regex = /\b(\d{2})\.(\d{2})\.\s+(\d{2}):(\d{2})\b/
+
+ if line =~ regex
+ value = "2012-#{$2}-#{$1} #{$3}:#{$4}"
+ puts " date: >#{value}<"
+
+ ## todo: lets you configure year
+ ## and time zone (e.g. cet, eet, utc, etc.)
+
+ line.sub!( regex, '[DATE]' )
+
+ return DateTime.strptime( value, '%Y-%m-%d %H:%M' )
+ else
+ return nil
+ end
+ end
+
+ def find_score!( line )
+ # extract score from line
+ # and return it
+ # NB: side effect - removes date from line string
+
+ # e.g. 1:2 or 0:2 or 3:3
+ regex = /\b(\d):(\d)\b/
+
+ if line =~ regex
+ value = "#{$1}-#{$2}"
+ puts " score: >#{value}<"
+
+ line.sub!( regex, '[SCORE]' )
+
+ return [$1.to_i,$2.to_i]
+ else
+ return []
+ end
+ end
+
+
+ def find_team_worker!( line, index )
+ regex = /@@oo([^@]+?)oo@@/ # e.g. everything in @@ .... @@ (use non-greedy +? plus all chars but not @, that is [^@])
+
+ if line =~ regex
+ value = "#{$1}"
+ puts " team#{index}: >#{value}<"
+
+ line.sub!( regex, "[TEAM#{index}]" )
+
+ return $1
+ else
+ return nil
+ end
+ end
+
+ def find_team1!( line )
+ find_team_worker!( line, 1 )
+ end
+
+ def find_team2!( line )
+ find_team_worker!( line, 2 )
+ end
+
+
+ def match_team_worker!( line, key, values )
+ values.each do |value|
+ regex = Regexp.new( "\\b#{value}\\b" ) # wrap with world boundry (e.g. match only whole words e.g. not wac in wacker)
+ if line =~ regex
+ puts " match for team >#{key}< >#{value}<"
+ # make sure @@oo{key}oo@@ doesn't match itself with other key e.g. wacker, wac, etc.
+ line.sub!( regex, "@@oo#{key}oo@@" )
+ return true # break out after first match (do NOT continue)
+ end
+ end
+ return false
+ end
+
+ def match_teams!( line )
+ @known_teams.each do |rec|
+ key = rec[0]
+ values = rec[1]
+ match_team_worker!( line, key, values )
+ end # each known_teams
+ end # method translate_teams!
+
+
+ def parse_quotes( data )
+
+ data.each_line do |line|
+
+ if line =~ /^\s*#/
+ # skip komments and do NOT copy to result (keep comments secret!)
+ logger.debug 'skipping comment line'
+ next
+ end
+
+ if line =~ /^\s*$/
+ # kommentar oder leerzeile überspringen
+ logger.debug 'skipping blank line'
+ next
+ end
+
+ # remove leading and trailing whitespace
+ line = line.strip
+
+ if is_round?( line )
+ puts "parsing round line: >#{line}<"
+ pos = find_round_pos!( line )
+ puts " line: >#{line}<"
+
+ @round = Round.find_by_event_id_and_pos!( @event.id, pos )
+
+
+ else
+ puts "parsing game (fixture) line: >#{line}<"
+
+ ## date = find_date!( line )
+ ## score = find_score!( line )
+
+ match_teams!( line )
+ team1 = find_team1!( line )
+ team2 = find_team2!( line )
+
+ puts " line: >#{line}<"
+
+
+ ### todo: cache team lookups in hash?
+
+ team1_id = Team.find_by_key!( team1 ).id
+ team2_id = Team.find_by_key!( team2 ).id
+
+ ### check if games exists
+ ## with this teams in this round if yes only update
+ @game = Game.find_by_round_id_and_team1_id_and_team2_id!(
+ @round.id, team1_id, team2_id
+ )
+
+ end
+ end # oldlines.each
+
+
+ end # method parse_quotes
+
+end # class QuotesReader
View
19 lib/tasks/load_quotes.rake
@@ -0,0 +1,19 @@
+
+desc "sportbook: load quotes (e.g. bl_quotes_tipp3.txt)"
+task :load_quotes => [:environment] do |t|
+
+ quotes = [
+ [ 'tipp3', 'at_bl_2012_13', 'at/2012_13/bl_quotes_tipp3' ],
+ [ 'betathome', 'at_bl_2012_13', 'at/2012_13/bl_quotes_betathome' ]
+ ]
+
+ quotes.each do |rec|
+
+ puts "loading quotes in '#{rec[2]}'.txt..."
+ data = File.read( "#{Rails.root}/db/seeds/#{rec[2]}.txt" )
+ QuotesReader.new.load( rec[0], rec[1], data )
+
+ ## adding prop.create! here ?? why? why not??
+
+ end
+end
View
4 lib/tasks/load_uss_others.rake
@@ -4,12 +4,16 @@ task :load_uss_others => [:environment] do |t|
SportDB.load([
+ 'countries',
'at/teams',
'at/2012_13/bl',
'at/2012_13/cup',
'euro/teams',
'world/quali_2012_13',
+ 'world/quali_2012_13_c',
'cl/teams',
+ 'en/teams',
+ 'de/teams',
'cl/2012_13/cl'
])
Please sign in to comment.
Something went wrong with that request. Please try again.