Class WsbaBarr
In: app/models/competitions/wsba_barr.rb
Parent: Competition

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

Methods

Public Instance methods

[Source]

    # File app/models/competitions/wsba_barr.rb, line 11
11:   def create_races
12:     [
13:       "Men Cat 1-2",
14:       "Men Cat 3",
15:       "Men Cat 4-5",
16:       "Master Men 30-39 Cat 1-3",
17:       "Master Men 30-39 Cat 4-5",
18:       "Master Men 40-49 Cat 1-3",
19:       "Master Men 40-49 Cat 4-5",
20:       "Master Men 50+ Cat 1-5",
21:       "Women Cat 1-2",
22:       "Women Cat 3",
23:       "Women Cat 4",
24:       "Master Women 35+ Cat 1-3",
25:       "Master Women 35+ Cat 4"
26:     ].each do |category_name|
27:       category = Category.find_or_create_by_name(category_name)
28:       races.create(:category => category)
29:     end
30:   end

[Source]

   # File app/models/competitions/wsba_barr.rb, line 3
3:   def friendly_name
4:     'WSBA BARR'
5:   end

[Source]

    # File app/models/competitions/wsba_barr.rb, line 76
76:   def place_members_only?
77:      true
78:    end

[Source]

   # File app/models/competitions/wsba_barr.rb, line 7
7:   def point_schedule
8:     [ 0, 20, 17, 15, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2 ]
9:   end

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

[Source]

    # File app/models/competitions/wsba_barr.rb, line 60
60:   def points_for(source_result, team_size = nil)
61:     points = 0
62:     Bar.benchmark('points_for') {
63:       results_in_place = Result.count(:conditions => ["race_id =? and place = ?", source_result.race.id, source_result.place])
64:       if team_size.nil?
65:         # assume this is a TTT, score divided by 4 regardless of # of riders
66:         team_size = (results_in_place > 1) ? 4 : 1 
67:       end
68:       points_index = place_members_only? ? source_result.members_only_place.to_i : source_result.place.to_i
69:       points = point_schedule[points_index].to_f
70:       points *= points_factor(source_result)
71:       points /= team_size.to_f 
72:     }
73:     points
74:   end

source_results must be in person-order

[Source]

    # File app/models/competitions/wsba_barr.rb, line 33
33:   def source_results(race)
34:     return [] if source_events(true).empty?
35:     
36:     event_ids = source_events.collect do |event|
37:       event.id
38:     end
39:     event_ids = event_ids.join(', ')
40:     
41:     results = Result.find_by_sql(
42:       %Q{ SELECT results.*
43:           FROM results  
44:           LEFT OUTER JOIN races ON races.id = results.race_id 
45:           LEFT OUTER JOIN categories ON categories.id = races.category_id
46:           LEFT OUTER JOIN events ON races.event_id = events.id 
47:             WHERE races.category_id is not null 
48:               and members_only_place between 1 and 15
49:               and categories.id in (#{category_ids_for(race)})
50:               and (results.category_id is null or results.category_id in (#{category_ids_for(race)}))
51:               and (events.id in (#{event_ids}))
52:               and results.bar
53:          order by person_id
54:        }
55:     )
56:     results
57:   end

[Validate]