Class RiderRankings
In: app/models/competitions/rider_rankings.rb
Parent: Competition

WSBA rider rankings. Members get points for top-10 finishes in any event

Methods

Public Instance methods

[Source]

    # File app/models/competitions/rider_rankings.rb, line 26
26:   def create_races
27:     association_category = Category.find_or_create_by_name(RacingAssociation.current.short_name)
28:     for category_name in [
29:       'Junior Men A', 'Junior Men B', 'Junior Men C', 'Junior Men D',
30:       'Junior Women A', 'Junior Women B', 'Junior Women C', 'Junior Women D',
31:       'Men Cat 1-2', 'Men Cat 3', 'Men Cat 4-5', 
32:       'Master Men 30+ Cat 1-3', 'Master Men 30+ Cat 4-5 & 50+', 
33:       'Masters Women A', 'Masters Women B', 
34:       'Women Cat 1-2', 'Women Cat 3', 'Women Cat 4']
35: 
36:       category = Category.find_or_create_by_name(category_name)
37:       unless category.parent
38:         category.parent = association_category
39:         category.save!
40:       end
41:       self.races.create(:category => category)
42:     end
43:   end

[Source]

   # File app/models/competitions/rider_rankings.rb, line 3
3:   def friendly_name
4:     'Rider Rankings'
5:   end

[Source]

    # File app/models/competitions/rider_rankings.rb, line 63
63:   def member?(person, date)
64:     person && person.member?(date)
65:   end

[Source]

    # File app/models/competitions/rider_rankings.rb, line 22
22:   def place_members_only?
23:     true
24:   end

[Source]

   # File app/models/competitions/rider_rankings.rb, line 7
7:   def point_schedule
8:     [ 0, 100, 70, 50, 40, 36, 32, 28, 24, 20, 16 ]
9:   end

Apply points from point_schedule, and adjust for team size

[Source]

    # File app/models/competitions/rider_rankings.rb, line 12
12:   def points_for(source_result)
13:     team_size = Result.count(:conditions => ["race_id =? and place = ?", source_result.race.id, source_result.place])
14:     points = point_schedule[source_result.members_only_place.to_i].to_f
15:     if points
16:       points / team_size
17:     else
18:       0
19:     end
20:   end

source_results must be in person-order

[Source]

    # File app/models/competitions/rider_rankings.rb, line 46
46:   def source_results(race)
47:     Result.find(:all,
48:                 :include => [:race, {:person => :team}, :team, {:race => [:event, :category]}],
49:                 :conditions => [%Q{
50:                   members_only_place between 1 AND #{point_schedule.size - 1}
51:                     and results.person_id is not null
52:                     and events.type = 'SingleDayEvent' 
53:                     and events.sanctioned_by = "#{RacingAssociation.current.default_sanctioned_by}"
54:                     and categories.id in (#{category_ids_for(race)})
55:                     and (races.bar_points > 0 or (races.bar_points is null and events.bar_points > 0))
56:                     and events.date >= '#{date.year}-01-01' 
57:                     and events.date <= '#{date.year}-12-31'
58:                 }],
59:                 :order => 'person_id'
60:     )
61:   end

[Validate]