Sha256: de9b433f0e3c13b5c1ed12ada71d3deb598f117b42ed71454b92bc35d60c5927

Contents?: true

Size: 1.52 KB

Versions: 42

Compression:

Stored size: 1.52 KB

Contents

# encoding: utf-8

module SportDb
  module Model


class EventStanding < ActiveRecord::Base

  self.table_name = 'event_standings'

  has_many   :entries, class_name: 'SportDb::Model::EventStandingEntry', foreign_key: 'event_standing_id', :dependent => :delete_all
  belongs_to :event

  ## convenience helper; recalcs all records
  def self.recalc!( opts={} )  self.order(:id).each { |rec| rec.recalc!(opts) };  end


  def recalc!( opts={} )
    ##  will calculate event standing e.g.

    ## calc points (pts) - loop over all group games/matches
    # group.games.each do |game|
    # end

    #  todo/fix!!!!!!!!!!:
    # skip knockout rounds  - why? why not?
    #   make it configure-able?

    recs = StandingsHelper.calc( event.games, opts )

    ## - remove (if exit) old entries and add new entries
    entries.delete_all    # note: assoc dependent set to :delete_all (defaults to :nullify)

    ## add empty entries
    event.teams.each do |team|
      puts "   adding entry for team #{team.title} (#{team.code})"
      rec = recs[ team.key ]  # find  (in-memory) stats records
      entries.create!(
                team_id: team.id,
                pos:     rec.pos,
                played:  rec.played,
                won:     rec.won,
                drawn:   rec.drawn,
                lost:    rec.lost,
                goals_for: rec.goals_for,
                goals_against: rec.goals_against,
                pts:     rec.pts  )
    end
  end  # method recalc!


end # class EventStanding
  end # module Model

end # module SportDb

Version data entries

42 entries across 42 versions & 2 rubygems

Version Path
sportdb-models-1.19.1 lib/sportdb/models/stats/event_standing.rb
sportdb-models-1.19.0 lib/sportdb/models/stats/event_standing.rb
sportdb-models-1.18.6 lib/sportdb/models/stats/event_standing.rb
sportdb-models-1.18.5 lib/sportdb/models/stats/event_standing.rb
sportdb-models-1.18.4 lib/sportdb/models/stats/event_standing.rb
sportdb-models-1.18.3 lib/sportdb/models/stats/event_standing.rb
sportdb-models-1.18.2 lib/sportdb/models/stats/event_standing.rb
sportdb-models-1.18.1 lib/sportdb/models/stats/event_standing.rb
sportdb-models-1.18.0 lib/sportdb/models/stats/event_standing.rb
sportdb-models-1.17.0 lib/sportdb/models/stats/event_standing.rb
sportdb-models-1.16.2 lib/sportdb/models/stats/event_standing.rb
sportdb-models-1.16.1 lib/sportdb/models/stats/event_standing.rb
sportdb-models-1.16.0 lib/sportdb/models/stats/event_standing.rb
sportdb-models-1.15.2 lib/sportdb/models/stats/event_standing.rb
sportdb-models-1.15.1 lib/sportdb/models/stats/event_standing.rb
sportdb-models-1.15.0 lib/sportdb/models/stats/event_standing.rb
sportdb-models-1.14.2 lib/sportdb/models/stats/event_standing.rb
sportdb-models-1.14.1 lib/sportdb/models/stats/event_standing.rb
sportdb-models-1.14.0 lib/sportdb/models/stats/event_standing.rb
sportdb-models-1.13.0 lib/sportdb/models/stats/event_standing.rb