Hello,
To calculate the winner as an example see the calc_winner "formula"
in the Game (soon Match) model source [1]:
def calc_winner
if score1.nil? || score2.nil?
self.winner90 = nil
self.winner = nil
else
if score1 > score2
self.winner90 = 1
elsif score1 < score2
self.winner90 = 2
else # assume score1 == score2 - draw
self.winner90 = 0
end
## todo/fix:
# check for next-game/pre-game !!!
# use 1st leg and 2nd leg - use for winner too
# or add new winner_total or winner_aggregated method ???
## check for penalty - note: some games might only have penalty
and no extra time (e.g. copa liberatadores)
if score1p.present? && score2p.present?
if score1p > score2p
self.winner = 1
elsif score1p < score2p
self.winner = 2
else
# issue warning! - should not happen; penalty goes on until
winner found!
puts "*** warn: should not happen; penalty goes on until winner found"
end
## check for extra time
elsif score1et.present? && score2et.present?
if score1et > score2et
self.winner = 1
elsif score1et < score2et
self.winner = 2
else # assume score1et == score2et - draw
self.winner = 0
end
else
# assume no penalty and no extra time; same as 90min result
self.winner = self.winner90
end
end
end
Looks more complicated than it is:
1) check 90 minute score
2) if equal check extra time score (if present otherwise draw/tie)
3) if equal check penalty shootout score (if present otherwise draw/tie)
Cheers.
[1]
github.com/geraldb/sport.db.ruby/blob/master/lib/sportdb/models/game.rb
> --
> You received this message because you are subscribed to the Google Groups
> "Open Sport(s) Database - football.db, formula1.db, ski.db, and Friends"
> group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to
opensport+...@googlegroups.com.
> For more options, visit
https://groups.google.com/d/optout.