class WsbaBarr

Year-long best road rider competition for senior & masters men and women in Washington. WSBA member’s only.

Public Instance Methods

create_races() click to toggle source
# File app/models/competitions/wsba_barr.rb, line 11
def create_races
  [
    "Men Cat 1-2",
    "Men Cat 3",
    "Men Cat 4-5",
    "Master Men 30-39 Cat 1-3",
    "Master Men 30-39 Cat 4-5",
    "Master Men 40-49 Cat 1-3",
    "Master Men 40-49 Cat 4-5",
    "Master Men 50+ Cat 1-5",
    "Women Cat 1-2",
    "Women Cat 3",
    "Women Cat 4",
    "Master Women 35+ Cat 1-3",
    "Master Women 35+ Cat 4"
  ].each do |category_name|
    category = Category.find_or_create_by_name(category_name)
    races.create(:category => category)
  end
end
friendly_name() click to toggle source
# File app/models/competitions/wsba_barr.rb, line 3
def friendly_name
  'WSBA BARR'
end
place_members_only?() click to toggle source
# File app/models/competitions/wsba_barr.rb, line 73
def place_members_only?
   true
 end
point_schedule() click to toggle source
# File app/models/competitions/wsba_barr.rb, line 7
def point_schedule
  [ 0, 20, 17, 15, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2 ]
end
points_for(source_result, team_size = nil) click to toggle source

Override of base BAR rules, mainly due to TTT rules on dividing points always by 4. Also, no points multiplier

# File app/models/competitions/wsba_barr.rb, line 57
def points_for(source_result, team_size = nil)
  points = 0
  WsbaBarr.benchmark('points_for') {
    results_in_place = Result.count(:conditions => ["race_id =? and place = ?", source_result.race.id, source_result.place])
    if team_size.nil?
      # assume this is a TTT, score divided by 4 regardless of # of riders
      team_size = (results_in_place > 1) ? 4 : 1 
    end
    points_index = place_members_only? ? source_result.members_only_place.to_i : source_result.place.to_i
    points = point_schedule[points_index].to_f
    points *= points_factor(source_result)
    points /= team_size.to_f 
  }
  points
end
source_results(race) click to toggle source

#source_results must be in person-order

# File app/models/competitions/wsba_barr.rb, line 33
def source_results(race)
  return [] if source_events(true).empty?
  
  event_ids = source_events.map(&:id).join(', ')
  
  results = Result.find_by_sql(
    %Q{ SELECT results.*
        FROM results  
        LEFT OUTER JOIN races ON races.id = results.race_id 
        LEFT OUTER JOIN categories ON categories.id = races.category_id
        LEFT OUTER JOIN events ON races.event_id = events.id 
          WHERE races.category_id is not null 
            and members_only_place between 1 and 15
            and categories.id in (#{category_ids_for(race).join(', ')})
            and (results.category_id is null or results.category_id in (#{category_ids_for(race).join(', ')}))
            and (events.id in (#{event_ids}))
            and results.bar
       order by person_id
     }
  )
  results
end