module Concerns::Competition::Points::InstanceMethods

Public Instance Methods

ascending_points?() click to toggle source
# File app/models/competitions/concerns/competition/points.rb, line 58
def ascending_points?
  true
end
consider_points_factor?() click to toggle source
# File app/models/competitions/concerns/competition/points.rb, line 66
def consider_points_factor?
  true
end
consider_team_size?() click to toggle source
# File app/models/competitions/concerns/competition/points.rb, line 62
def consider_team_size?
  true
end
default_bar_points() click to toggle source
# File app/models/competitions/concerns/competition/points.rb, line 74
def default_bar_points
  0
end
double_points_for_last_event?() click to toggle source
# File app/models/competitions/concerns/competition/points.rb, line 70
def double_points_for_last_event?
  false
end
member?(person_or_team, date) click to toggle source

Member this date year?

# File app/models/competitions/concerns/competition/points.rb, line 89
def member?(person_or_team, date)
  person_or_team && person_or_team.member_in_year?(date)
end
members_only?() click to toggle source

Only members can score points?

# File app/models/competitions/concerns/competition/points.rb, line 84
def members_only?
  true
end
place_members_only?() click to toggle source

Use the recorded place with all finishers? Or only place with just Assoication member finishers?

# File app/models/competitions/concerns/competition/points.rb, line 79
def place_members_only?
  false
end
point_schedule() click to toggle source
# File app/models/competitions/concerns/competition/points.rb, line 7
def point_schedule
  @point_schedule ||= []
end
point_schedule=(value) click to toggle source
# File app/models/competitions/concerns/competition/points.rb, line 11
def point_schedule=(value)
  @point_schedule = value
end
points_factor(source_result) click to toggle source

multiplier from the CompetitionEventsMembership if it exists FIXME inefficient

# File app/models/competitions/concerns/competition/points.rb, line 48
def points_factor(source_result)
  cem = source_result.event.competition_event_memberships.detect{|comp| comp.competition_id == self.id}
  # factor is one if membership is not found
  cem ? cem.points_factor : 1
end
points_for(source_result, team_size = nil) click to toggle source

Apply points from #point_schedule, and split across team

# File app/models/competitions/concerns/competition/points.rb, line 16
def points_for(source_result, team_size = nil)
  points = 0
  
  if place_members_only?
    points = point_schedule[source_result.members_only_place.to_i].to_f || 0
  else
    points = point_schedule[source_result.place.to_i].to_f || 0
  end

  if points > 0
    factor = 1
    if consider_points_factor?
      factor = points_factor(source_result)
    end

    if consider_team_size?
      team_size = team_size || team_size_from_result(source_result)
      points = points * factor / team_size.to_f
    else
      points = points * factor
    end
    
    if double_points_for_last_event? && source_result.last_event?
      points = points * 2
    end
  end
  
  points
end
team_size_from_result(source_result) click to toggle source
# File app/models/competitions/concerns/competition/points.rb, line 54
def team_size_from_result(source_result)
  ::Result.count(:conditions => ["race_id =? and place = ?", source_result.race_id, source_result.place])
end