Permalink
Browse files

cleanup models cont.

  • Loading branch information...
1 parent 1351bd7 commit 6b6ee98231797e1fdbcbf2fef2e881419939e1ba @geraldb geraldb committed Nov 14, 2012
View
@@ -9,7 +9,7 @@ gem 'rails-i18n' # see https://github.com/svenfuchs/rails-i18n
gem 'sportdb', '0.7.1' # see https://github.com/geraldb/sport.db
### todo/fix: make it work w/ autoload - will sportdb/market work?
-gem 'sportdb-market', '0.0.7', require: 'sportdb/market/market'
+gem 'sportdb-market', '0.0.9', require: 'sportdb/market/market'
group :production do
gem 'pg'
View
@@ -100,7 +100,7 @@ GEM
sportdb (0.7.1)
activerecord (~> 3.2)
worlddb (~> 0.2.0)
- sportdb-market (0.0.7)
+ sportdb-market (0.0.9)
sprockets (2.1.2)
hike (~> 1.2)
rack (~> 1.0)
@@ -140,7 +140,7 @@ DEPENDENCIES
ri_cal
sass-rails (~> 3.2.3)
sportdb (= 0.7.1)
- sportdb-market (= 0.0.7)
+ sportdb-market (= 0.0.9)
sqlite3
thin
uglifier (>= 1.0.3)
View
@@ -12,18 +12,17 @@
#
-class Event < ActiveRecord::Base
+module SportDB::Models
- has_many :rounds, :order => 'pos' # all (fix and flex) rounds
+class Event
has_many :fix_rounds, :conditions => { :fix => true }, :order => 'pos', :class_name => 'Round', :foreign_key => 'event_id'
has_many :fix_playoff_rounds, :conditions => { :fix => true , :playoff => true }, :order => 'pos', :class_name => 'Round', :foreign_key => 'event_id'
has_many :flex_rounds, :conditions => { :flex => true }, :order => 'pos', :class_name => 'Round', :foreign_key => 'event_id'
-
- has_many :groups, :order => 'pos'
-
- has_many :event_teams, :class_name => 'EventTeam'
- has_many :teams, :through => :event_teams
-end # class Event
+end # class Event
+
+end # module SportDB::Models
+
+Event = SportDB::Models::Event
View
@@ -1,21 +1,3 @@
-class EventQuote < ActiveRecord::Base
-
- self.table_name = 'event_quotes'
-
- belongs_to :service
- belongs_to :event
- belongs_to :team
+EventQuote = SportDB::Models::EventQuote
- def self.create_from_ary!( teams_with_odds, service, event )
- teams_with_odds.each do |values|
- EventQuote.create!(
- :service => service,
- :event => event,
- :team => values[0],
- :odds => values[1] )
- end # each team
- end
-
-
-end # class EventQuote
View
@@ -9,9 +9,5 @@
# updated_at :datetime not null
#
-class EventTeam < ActiveRecord::Base
- self.table_name = 'events_teams'
-
- belongs_to :event
- belongs_to :team
-end
+EventTeam = SportDB::Models::EventTeam
+
View
@@ -27,18 +27,14 @@
# updated_at :datetime not null
#
-class Game < ActiveRecord::Base
- belongs_to :team1, :class_name => 'Team', :foreign_key => 'team1_id'
- belongs_to :team2, :class_name => 'Team', :foreign_key => 'team2_id'
-
- belongs_to :round
- belongs_to :group # group is optional
+module SportDB::Models
+
+### todo/fix: move more methods to sport.db for reuse
- has_many :tips
- has_many :quotes
- before_save :calc_toto12x
+class Game
+
after_save :log_action
def job_running!
@@ -53,105 +49,7 @@ def job_running?
(@job_running ||= false) == true
end
-
- def self.create_knockouts_from_ary!( games, round )
- Game.create_from_ary!( games, round, true )
- end
-
- def self.create_from_ary!( games, round, knockout=false )
- games.each do |values|
- Game.create!(
- :round =>round,
- :pos =>values[0],
- :team1 =>values[1],
- :score1 =>values[2][0],
- :score2 =>values[2][1],
- :score3 =>values[2][2],
- :score4 =>values[2][3],
- :score5 =>values[2][4],
- :score6 =>values[2][5],
- :team2 =>values[3],
- :play_at =>values[4],
- :group =>values[5], # Note: group is optional (may be null/nil)
- :knockout =>knockout )
- end # each games
- end
-
-
- def self.create_pairs_from_ary_for_group!( pairs, group )
-
- pairs.each do |pair|
- game1_attribs = {
- :round =>pair[0][5],
- :pos =>pair[0][0],
- :team1 =>pair[0][1],
- :score1 =>pair[0][2][0],
- :score2 =>pair[0][2][1],
- :team2 =>pair[0][3],
- :play_at =>pair[0][4],
- :group =>group }
-
- game2_attribs = {
- :round =>pair[1][5],
- :pos =>pair[1][0],
- :team1 =>pair[1][1],
- :score1 =>pair[1][2][0],
- :score2 =>pair[1][2][1],
- :team2 =>pair[1][3],
- :play_at =>pair[1][4],
- :group =>group }
-
- game1 = Game.create!( game1_attribs )
- game2 = Game.create!( game2_attribs )
-
- # linkup games
- game1.next_game_id = game2.id
- game1.save!
-
- game2.prev_game_id = game1.id
- game2.save!
- end # each pair
- end
-
-
- def self.create_knockout_pairs_from_ary!( pairs, round1, round2 )
-
- pairs.each do |pair|
- game1_attribs = {
- :round =>round1,
- :pos =>pair[0][0],
- :team1 =>pair[0][1],
- :score1 =>pair[0][2][0],
- :score2 =>pair[0][2][1],
- :team2 =>pair[0][3],
- :play_at =>pair[0][4] }
-
- game2_attribs = {
- :round =>round2,
- :pos =>pair[1][0],
- :team1 =>pair[1][1],
- :score1 =>pair[1][2][0],
- :score2 =>pair[1][2][1],
- :score3 =>pair[1][2][2],
- :score4 =>pair[1][2][3],
- :score5 =>pair[1][2][4],
- :score6 =>pair[1][2][5],
- :team2 =>pair[1][3],
- :play_at =>pair[1][4],
- :knockout =>true }
-
- game1 = Game.create!( game1_attribs )
- game2 = Game.create!( game2_attribs )
-
- # linkup games
- game1.next_game_id = game2.id
- game1.save!
-
- game2.prev_game_id = game1.id
- game2.save!
- end # each pair
- end
-
+
def over? # game over?
play_at <= Time.now
end
@@ -198,17 +96,6 @@ def team2_style_class
buf
end
- def calc_toto12x
- if score1.nil? || score2.nil?
- self.toto12x = nil
- elsif score1 == score2
- self.toto12x = 'X'
- elsif score1 > score2
- self.toto12x = '1'
- elsif score1 < score2
- self.toto12x = '2'
- end
- end
def tip_1_style_class
toto12x == '1' ? ' bingo ' : ' '
@@ -295,3 +182,7 @@ def log_action
end
end # class Game
+
+end # module SportDB::Models
+
+Game = SportDB::Models::Game
View
@@ -11,12 +11,4 @@
#
-class Group < ActiveRecord::Base
-
- has_many :games, :order => 'pos'
- belongs_to :event
-
- has_many :group_teams, :class_name => 'GroupTeam'
- has_many :teams, :through => :group_teams
-
-end # class Group
+Group = SportDB::Models::Group
View
@@ -1,21 +1,4 @@
-class GroupQuote < ActiveRecord::Base
-
- self.table_name = 'group_quotes'
-
- belongs_to :service
- belongs_to :group
- belongs_to :team
-
- def self.create_from_ary!( teams_with_odds, service, group )
- teams_with_odds.each do |values|
- GroupQuote.create!(
- :service => service,
- :group => group,
- :team => values[0],
- :odds => values[1] )
- end # each team
- end
-
-end # class GroupQuote
+GroupQuote = SportDB::Models::GroupQuote
+
View
@@ -10,9 +10,5 @@
#
-class GroupTeam < ActiveRecord::Base
- self.table_name = 'groups_teams'
-
- belongs_to :group
- belongs_to :team
-end
+GroupTeam = SportDB::Models::GroupTeam
+
View
@@ -9,7 +9,5 @@
# updated_at :datetime not null
#
+Prop = SportDB::Models::Prop
-class Prop < ActiveRecord::Base
-
-end # class Prop
View
@@ -1,30 +1,2 @@
-class Quote < ActiveRecord::Base
-
- belongs_to :service
- belongs_to :game
-
- def self.create_from_ary!( games_with_odds, service )
- games_with_odds.each do |values|
- Quote.create!(
- :service => service,
- :game => values[0],
- :odds1 => values[1],
- :oddsx => values[2],
- :odds2 => values[3])
- end # each games
- end
-
- def self.create_from_ary_for_round!( games_with_odds, service, round )
- games_with_odds.each do |values|
- Quote.create!(
- :service => service,
- :game => Game.find_by_round_id_and_team1_id_and_team2_id!( round.id, values[0].id, values[1].id),
- :odds1 => values[2],
- :oddsx => values[3],
- :odds2 => values[4])
- end # each games
- end
-
-
-end # class Quote
+Quote = SportDB::Models::Quote

0 comments on commit 6b6ee98

Please sign in to comment.