# File app/models/race.rb, line 213defcalculate_members_only_places!event_notification_was_enabled = event.notification_enabled?event.disable_notification!begin# count up from zerolast_members_only_place = 0# assuming first result starting at zero+one (better than sorting results twice?)last_result_place = 0results.sort.eachdo|result|place_before = result.members_only_place.to_iresult.members_only_place = ''ifresult.place.to_i>0if ((result.person.nil?|| (result.person&&result.person.member?(result.date))) &&!non_members_on_team(result))
# only increment if we have moved onto a new placelast_members_only_place+=1if (result.place.to_i!=last_members_only_place&&result.place.to_i!=last_result_place)
result.members_only_place = last_members_only_place.to_send# Slight optimization. Most of the time, no point in saving a result that hasn't changedresult.update_attribute('members_only_place', result.members_only_place) ifplace_before!=result.members_only_place# store to know when switching to new placement (team result feature)last_result_place = result.place.to_iendendensureevent.enable_notification!ifevent_notification_was_enabledendend

Ensure child team and people are not duplicates of existing records Tricky
side effect – external references to new association records (category,
bar_category, person, team) will not point to associated records FIXME
Handle people with only a number

# File app/models/race.rb, line 241defnon_members_on_team(result)
non_members = false# if this is undeclared in environment.rb, assume this rule does not applyexempt_cats = RacingAssociation.current.exempt_team_categoriesif (exempt_cats.nil?||exempt_cats.include?(result.race.category.name))
returnnon_memberselseother_results_in_place = Result.all( :conditions => ["race_id = ? and place = ?", result.race.id, result.place])
other_results_in_place.each { |orip|unlessorip.person.nil?if!orip.person.member?(result.date)
# might as well blank out this result while we're here, saves some future workresult.members_only_place = ''result.update_attribute'members_only_place', result.members_only_place# could also use other_results_in_place.size if needed for calculationsnon_members = trueendend
}
# still false if no others found, or all are members, or could not be determined (non-person)non_membersendend