Permalink
Browse files

move code to play plugin

  • Loading branch information...
geraldb committed Dec 3, 2012
1 parent d2201d7 commit fb4494f3514a3352ee7a87ed1b3fba8f639f004b
View
@@ -10,6 +10,7 @@ gem 'sportdb', '0.8.1' # see https://github.com/geraldb/sport.db
### todo/fix: make it work w/ autoload - will sportdb/market work?
gem 'sportdb-market', '0.1.3', require: 'sportdb/market/market'
+gem 'sportdb-play', '0.1.0'
group :production do
gem 'pg'
View
@@ -101,6 +101,7 @@ GEM
activerecord (~> 3.2)
worlddb (~> 0.3.2)
sportdb-market (0.1.3)
+ sportdb-play (0.1.0)
sprockets (2.1.2)
hike (~> 1.2)
rack (~> 1.0)
@@ -141,6 +142,7 @@ DEPENDENCIES
sass-rails (~> 3.2.3)
sportdb (= 0.8.1)
sportdb-market (= 0.1.3)
+ sportdb-play (= 0.1.0)
sqlite3
thin
uglifier (>= 1.0.3)
@@ -15,10 +15,4 @@
# updated_at :datetime not null
#
-class BonusPoint < ActiveRecord::Base
-
- belongs_to :user
- belongs_to :pool
- belongs_to :round, :class_name => 'BonusRound', :foreign_key => 'round_id'
-
-end # class BonusPoint
+BonusPoint = SportDB::Models::BonusPoint
@@ -10,11 +10,5 @@
# updated_at :datetime not null
#
+BonusQuestion = SportDB::Models::BonusQuestion
-class BonusQuestion < ActiveRecord::Base
-
- self.table_name = 'bonus_questions'
-
- has_many :tips, :class_name => 'BonusTip', :foreign_key => 'question_id'
-
-end # class BonusQuestion
@@ -11,11 +11,4 @@
#
-class BonusRound < ActiveRecord::Base
-
- self.table_name = 'bonus_rounds'
-
- has_many :questions, :order => 'pos', :class_name => 'BonusQuestion', :foreign_key => 'round_id'
- belongs_to :pool
-
-end # class BonusRound
+BonusRound = SportDB::Models::BonusRound
View
@@ -11,10 +11,5 @@
#
-class BonusTip < ActiveRecord::Base
-
- self.table_name = 'bonus_tips'
+BonusTip = SportDB::Models::BonusTip
- belongs_to :user
-
-end # class BonusTip
View
@@ -26,8 +26,8 @@ class CalcTip < Tip
after_initialize :on_after_initialize
- belongs_to :calc_team1, :class_name => 'Team', :foreign_key => 'calc_team1_id'
- belongs_to :calc_team2, :class_name => 'Team', :foreign_key => 'calc_team2_id'
+ belongs_to :calc_team1, :class_name => 'SportDB::Models::Team', :foreign_key => 'calc_team1_id'
+ belongs_to :calc_team2, :class_name => 'SportDB::Models::Team', :foreign_key => 'calc_team2_id'
## note: use different calc forumula
# check for matching teams first
View
@@ -19,10 +19,10 @@ module SportDB::Models
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 :fix_rounds, :conditions => { :fix => true }, :order => 'pos', :class_name => 'SportDB::Models::Round', :foreign_key => 'event_id'
+ has_many :fix_playoff_rounds, :conditions => { :fix => true , :playoff => true }, :order => 'pos', :class_name => 'SportDB::Models::Round', :foreign_key => 'event_id'
- has_many :flex_rounds, :conditions => { :flex => true }, :order => 'pos', :class_name => 'Round', :foreign_key => 'event_id'
+ has_many :flex_rounds, :conditions => { :flex => true }, :order => 'pos', :class_name => 'SportDB::Models::Round', :foreign_key => 'event_id'
end # class Event
View
@@ -35,23 +35,10 @@ module SportDB::Models
class Game
- has_many :tips
-
-
after_save :log_action
- def job_running!
- @job_running = true
- end
-
- def job_done!
- @job_running = false
- end
-
- def job_running?
- (@job_running ||= false) == true
- end
-
+ ################
+ #### todo: move to sportdb.gem for reuse
def score_str
if score5.present? && score6.present? # im Elfmeterschiessen i.E.?
@@ -71,6 +58,9 @@ def score2_str
if score2.blank? then '-' else score2.to_s end
end
+ ## end move
+ ###################
+
def team1_style_class
buf = ''
buf << 'game-team-calc ' if team1.calc?
@@ -87,20 +77,7 @@ def team2_style_class
buf
end
-
- def tip_1_style_class
- toto12x == '1' ? ' bingo ' : ' '
- end
-
- def tip_2_style_class
- toto12x == '2' ? ' bingo ' : ' '
- end
-
- def tip_x_style_class
- toto12x == 'X' ? ' bingo ' : ' '
- end
-
-
+
def play_at_str
play_at.strftime( "%a. %d. %b. / %H:%M" )
end
@@ -111,45 +88,6 @@ def play_at_str_db
play_at.strftime( '%Y-%m-%d %H:%M %z' ) # NB: removed seconds (:%S)
end
-
- ############ some methods for stats
-
- def complete_tips
- tips.where( 'toto12x is not null' )
- end
-
- def complete_tips_1
- tips.where( 'toto12x is not null' ).where( :toto12x => '1' ).order( 'score1 desc,score2 desc')
- end
-
- def complete_tips_2
- tips.where( 'toto12x is not null' ).where( :toto12x => '2' ).order( 'score2 desc,score1 desc')
- end
-
- def complete_tips_x
- tips.where( 'toto12x is not null' ).where( :toto12x => 'X' ).order( 'score1 desc,score2 desc')
- end
-
-
- def incomplete_tips
- tips.where( 'toto12x is null' )
- end
-
- def tip_1_count
- complete_tips.where( :toto12x => '1' ).count()
- end
-
- def tip_2_count
- complete_tips.where( :toto12x => '2' ).count()
- end
-
- def tip_x_count
- complete_tips.where( :toto12x => 'X' ).count()
- end
-
- def tip_12x_count
- complete_tips.count()
- end
def log_action
# add news feed item after save
View
@@ -14,40 +14,17 @@
# updated_at :datetime not null
#
-
-class Play < ActiveRecord::Base
+module SportDB::Models
- belongs_to :user
- belongs_to :pool
+## NB: extend from sport.db-play gem
+
+
+class Play
- belongs_to :team1, :class_name => 'Team', :foreign_key => 'team1_id'
- belongs_to :team2, :class_name => 'Team', :foreign_key => 'team2_id'
- belongs_to :team3, :class_name => 'Team', :foreign_key => 'team3_id'
after_create :log_action_create
after_update :log_action_update
-
- def job_running!
- @job_running = true
- end
-
- def job_done!
- @job_running = false
- end
-
- def job_running?
- (@job_running ||= false) == true
- end
-
- def public?
- return true if pool.public?
-
- # team1, team2 public after kickoff of event
- ## use past?
- Time.now.utc > pool.event.start_at.utc
- end
-
def log_action_create
a = Action.new
@@ -83,25 +60,9 @@ def log_action_update
a.text = buf
a.save!
end
-
-
- ## todo/fix: can it be done w/ a has_many macro and a condition?
- def tips
- recs = Tip.where( :pool_id => pool_id, :user_id => user_id ).all
- recs
- end
-
- ## todo/fix: can it be done w/ a has_many macro and a condition?
- def complete_rankings # fix rename to points and remove points column from play table??
- recs = Point.where( :pool_id => pool_id, :user_id => user_id ).joins( :round ).order('rounds.pos').all
- recs
- end
-
- def export?
- # check if user entered some data
- # - do NOT export nil records (all teams blank)
- (team1_id.blank? && team2_id.blank? && team3_id.blank?)==false
- end
-
end # class Play
+
+end # module SportDB::Models
+
+Play = SportDB::Models::Play
View
@@ -17,48 +17,4 @@
# updated_at :datetime not null
#
-class Point < ActiveRecord::Base
-
- belongs_to :user
- belongs_to :pool
- belongs_to :round, :class_name => 'SportDB::Models::Round'
-
- def round_pts_str
- buf = ''
- round_pts.times { buf << '' }
- buf
- end
-
- def total_pts_str
- buf = ''
- total_pts.times { buf << '' }
- buf
- end
-
-
- def diff_total_pos_style_class
- if diff_total_pos > 0
- ' ranking-up '
- elsif diff_total_pos < 0
- ' ranking-down '
- else # == 0
- ' '
- end
- end
-
- def diff_total_pos_str
- ## todo: diff 2 use ⇑⇑
- # diff 3 use ⇑⇑⇑
- # diff 4 use ⇑⇑⇑⇑
- # etc.
-
- if diff_total_pos > 0
- "#{diff_total_pos}"
- elsif diff_total_pos < 0
- "#{diff_total_pos.abs}"
- else # == 0
- ""
- end
- end
-
-end # class Point
+Point = SportDB::Models::Point
View
@@ -16,18 +16,13 @@
# updated_at :datetime not null
#
-class Pool < ActiveRecord::Base
-
- belongs_to :user # is owner/admin/manager
-
- has_many :bonus_rounds
-
- has_many :plays # pools_users join table
-
- ## rename to users from players??
- has_many :players, :through => :plays, :source => :user
+module SportDB::Models
+
+## NB: extend from sport.db-play gem
+
- belongs_to :event, :class_name => 'SportDB::Models::Event'
+class Pool
+
after_create :log_action_create
@@ -65,9 +60,9 @@ def log_action_create
a.save!
end
- def full_title
- "#{title} #{event.title}#{fix? ? ' Fix' : ''}"
- end
+## def full_title
+## "#{title} #{event.title}#{fix? ? ' Fix' : ''}"
+## end
def fix?
fix == true
@@ -77,8 +72,9 @@ def flex?
fix != true
end
- def team3? # tip for 3rd place?
- event.team3 == true
- end
-end
+end # class Pool
+
+end # module SportDB::Models
+
+Pool = SportDB::Models::Pool
Oops, something went wrong.

0 comments on commit fb4494f

Please sign in to comment.