Class: SportDb::Model::EventStanding

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/sportdb/models/stats/event_standing.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.recalc!(opts = {}) ⇒ Object

convenience helper; recalcs all records



15
# File 'lib/sportdb/models/stats/event_standing.rb', line 15

def self.recalc!( opts={} )  self.order(:id).each { |rec| rec.recalc!(opts) };  end

Instance Method Details

#recalc!(opts = {}) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/sportdb/models/stats/event_standing.rb', line 18

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