app/controllers/championships_controller.rb
# Seasonal event ranking (gender, category, evet_type)
# for CSI regional ER championships
#
Seasonal event ranking (gender, category, evet_type)
for CSI regional ER championships
Seasonal event ranking ( gender category evet_type ) for CSI regional ER championships
def event_ranking_regional_er_csi
    @title = I18n.t('championships.event_ranking') + ' ' + @season_type.get_full_name
    @event_types    = EventType.for_season( @season.id ).are_not_relays.distinct.sort_by_style
    @category_types = @season.category_types.are_not_relays.sort_by_age
    @ranking_updated_at = @season.meeting_individual_results.exists? ?
      @season.meeting_individual_results.select( "meeting_individual_results.updated_at" ).order(:updated_at).last.updated_at.to_i :
      0
    timing_converter = TimingCourseConverter.new( @season )
    @season_ranking = []
    GenderType.individual_only.sort_by_courtesy.each do |gender_type|
      gender_ranking = {}
      gender_ranking[:gender_type] = gender_type
      gender_ranking[:categories] = []
      @category_types.each do |category_type|
        category_ranking = {}
        category_ranking[:category_type] = category_type
        category_ranking[:events] = []
        @event_types.each do |event_type|
          event_ranking = {}
          event_ranking[:event_type] = event_type
          event_ranking[:mirs] = []
          event_ranking[:event_count] = EventType.for_season( @season.id ).where(['event_types.code = ?', event_type.code]).count
          event_ranking[:event_swam]  = EventType.for_season( @season.id ).where(['event_types.code = ? and meetings.are_results_acquired', event_type.code]).count
          @season.meeting_individual_results.is_valid.for_gender_type(gender_type).for_category_type(category_type).for_event_type(event_type).sort_by_timing.each do |mir|
            if not event_ranking[:mirs].any?{ |collected_mir| collected_mir.swimmer_id == mir.swimmer_id and collected_mir.pool_type.id == mir.pool_type.id }
              if mir.pool_type.code == '50' and timing_converter.is_conversion_possible?( mir.gender_type, mir.event_type )
                time_converted = timing_converter.convert_time_to_short( mir.get_timing_instance, mir.gender_type, mir.event_type )
                mir.minutes  = time_converted.minutes
                mir.seconds  = time_converted.seconds
                mir.hundreds = time_converted.hundreds
              end
              event_ranking[:mirs] << mir
            end
          end
          event_ranking[:mirs].sort!{|p,n| p.get_timing_instance.to_hundreds <=> n.get_timing_instance.to_hundreds }
          event_ranking[:mirs].each do |mir|
            duplicate = event_ranking[:mirs].index{ |collected_mir| collected_mir.swimmer_id == mir.swimmer_id and collected_mir.id != mir.id }
            event_ranking[:mirs].delete_at( duplicate ) if duplicate
          end
          event_ranking[:mirs] = event_ranking[:mirs].take(15)
          category_ranking[:events] << event_ranking
        end
        gender_ranking[:categories] << category_ranking
      end
      @season_ranking << gender_ranking
    end
  end
def event_ranking_regional_er_csi @title = I18n . t ( 'championships.event_ranking' ) + ' ' + @season_type . get_full_name @event_types = EventType . for_season ( @season . id ) . are_not_relays . distinct . sort_by_style @category_types = @season . category_types . are_not_relays . sort_by_age @ranking_updated_at = @season . meeting_individual_results . exists? ? @season . meeting_individual_results . select ( "meeting_individual_results.updated_at" ) . order ( :updated_at ) . last . updated_at . to_i : 0 timing_converter = TimingCourseConverter . new ( @season ) @season_ranking = [ ] GenderType . individual_only . sort_by_courtesy . each do | gender_type | gender_ranking = { } gender_ranking [ :gender_type ] = gender_type gender_ranking [ :categories ] = [ ] @category_types . each do | category_type | category_ranking = { } category_ranking [ :category_type ] = category_type category_ranking [ :events ] = [ ] @event_types . each do | event_type | event_ranking = { } event_ranking [ :event_type ] = event_type event_ranking [ :mirs ] = [ ] event_ranking [ :event_count ] = EventType . for_season ( @season . id ) . where ( [ 'event_types.code = ?' , event_type . code ] ) . count event_ranking [ :event_swam ] = EventType . for_season ( @season . id ) . where ( [ 'event_types.code = ? and meetings.are_results_acquired' , event_type . code ] ) . count @season . meeting_individual_results . is_valid . for_gender_type ( gender_type ) . for_category_type ( category_type ) . for_event_type ( event_type ) . sort_by_timing . each do | mir | if not event_ranking [ :mirs ] . any? { | collected_mir | collected_mir . swimmer_id == mir . swimmer_id and collected_mir . pool_type . id == mir . pool_type . id } if mir . pool_type . code == '50' and timing_converter . is_conversion_possible? ( mir . gender_type , mir . event_type ) time_converted = timing_converter . convert_time_to_short ( mir . get_timing_instance , mir . gender_type , mir . event_type ) mir . minutes = time_converted . minutes mir . seconds = time_converted . seconds mir . hundreds = time_converted . hundreds end event_ranking [ :mirs ] << mir end end event_ranking [ :mirs ] . sort! { | p , n | p . get_timing_instance . to_hundreds <=> n . get_timing_instance . to_hundreds } event_ranking [ :mirs ] . each do | mir | duplicate = event_ranking [ :mirs ] . index { | collected_mir | collected_mir . swimmer_id == mir . swimmer_id and collected_mir . id != mir . id } event_ranking [ :mirs ] . delete_at ( duplicate ) if duplicate end event_ranking [ :mirs ] = event_ranking [ :mirs ] . take ( 15 ) category_ranking [ :events ] << event_ranking end gender_ranking [ :categories ] << category_ranking end @season_ranking << gender_ranking end end
Seasonal event ranking (gender, category, evet_type)
for CSI regional ER championships
Seasonal event ranking ( gender category evet_type ) for CSI regional ER championships
# Check for different event types and categories for the season and manage updates for the cache: # Calculate ranking for each event/category/gender types # Find out total events in championship (season), count and swam # [Steve, 20170912] *** See note above *** Old implementation was: # event_ranking[:event_count] = @season.event_types.where(['event_types.code = ?', event_type.code]).count # event_ranking[:event_swam]  = @season.event_types.where(['event_types.code = ? and meetings.are_results_acquired', event_type.code]).count #best_result = @season.meeting_individual_results.is_valid.for_gender_type(gender_type).for_category_type(category_type).for_event_type(event_type).sort_by_timing.first #top_timing = Timing.new(best_result.minutes, best_result.seconds, best_result.hundreds) if best_result # Skip swimmers already ranked # Convert 50 meters to 25 meters timing # Remove duplicated swimmer entry (due to conversions from 50 to 25) # Trim to 15 results