app/controllers/swimmers_controller.rb
# Radiography for a specified swimmer id: "Full History: analysis" tab rendering.
# Create a grid for each event_by_pool_type swam
# For each show all results and passages ordered by timing descending
# The columns of every event_by_pool_type will meeting, timing
# reaction time, standard points, position, passage splits
# So every event shown will be different.
# The structure of event grids will depends on passages configuration
#
# == Params:
# id: the swimmer id to be processed
#
Radiography for a specified swimmer id: "Full History: analysis" tab rendering.
Create a grid for each event_by_pool_type swam
For each show all results and passages ordered by timing descending
The columns of every event_by_pool_type will meeting, timing
reaction time, standard points, position, passage splits
So every event shown will be different.
The structure of event grids will depends on passages configuration

the swimmer id to be processed
Radiography for a specified swimmer id : " Full History : analysis " tab rendering . Create a grid for each event_by_pool_type swam For each show all results and passages ordered by timing descending The columns of every event_by_pool_type will meeting timing reaction time standard points position passage splits So every event shown will be different . The structure of event grids will depends on passages configuration the swimmer id to be processed
def full_history_2
    @tab_title = I18n.t('radiography.full_history_by_event')
    @index_table = []
    @full_history_by_event = Hash.new
    EventsByPoolType.only_for_meetings.not_relays.sort_by_event.each do |events_by_pool_type|
      hash_key = events_by_pool_type.get_key
      results_by_time = @swimmer.meeting_individual_results
        .for_event_by_pool_type( events_by_pool_type )
        .sort_by_timing( 'ASC' )
        .select(
            'meeting_individual_results.id', 'minutes', 'seconds', 'hundreds', 'rank',
            'standard_points', 'reaction_time', 'meeting_program_id',
            'is_personal_best'
        )
      results_by_date = @swimmer.meeting_individual_results
        .is_valid.sort_by_date( 'ASC' )
        .for_event_by_pool_type( events_by_pool_type )
        .select(
            'meeting_individual_results.id', 'minutes', 'seconds', 'hundreds', 'rank',
            'standard_points', 'reaction_time', 'meeting_program_id',
            'is_personal_best'
        )
      Steve, 20160929] If we use #count here below, instead of #size, ActiveRecord will try
      if results_by_time.size > 0
        passages = Passage.joins( :event_type, :pool_type, :passage_type )
          .where( swimmer_id: @swimmer.id )
          .where( ['event_types.id = ? AND pool_types.id = ?', events_by_pool_type.event_type_id, events_by_pool_type.pool_type_id] )
          .select(
            'meeting_individual_result_id', 'passage_type_id',
            'minutes', 'seconds', 'hundreds',
            'passage_types.length_in_meters'
          )
        passages_list = passages.select( 'passage_types.length_in_meters' )
            .map{ |pt| pt.length_in_meters }.uniq.sort
        stroke_type_code = events_by_pool_type.stroke_type_code
        stroke_type_des = events_by_pool_type.stroke_type_i18n_description
        pool_type_des = events_by_pool_type.pool_type_i18n_verbose
        event_type_dist = events_by_pool_type.event_type_length_in_meters
        stroke_index = @index_table.rindex{ |hash_element| hash_element[:stroke_type] == stroke_type_des }
        if stroke_index
          if @index_table[stroke_index][pool_type_des]
            @index_table[stroke_index][pool_type_des] << event_type_dist if not @index_table[stroke_index][pool_type_des].rindex(event_type_dist)
          else
            @index_table[stroke_index][pool_type_des] = [event_type_dist]
          end
        else
          new_hash = Hash.new
          new_hash[:stroke_type] = stroke_type_des
          new_hash[:stroke_code] = stroke_type_code
          new_hash[pool_type_des] = [event_type_dist]
          @index_table << new_hash
        end
      else
        passages = nil
        passages_list = []
      end
      @full_history_by_event[hash_key] = [
        passages_list,
        results_by_time,
        passages,
        events_by_pool_type.i18n_description,
        results_by_date
      ]
    end
  end
def full_history_2 @tab_title = I18n . t ( 'radiography.full_history_by_event' ) @index_table = [ ] @full_history_by_event = Hash . new EventsByPoolType . only_for_meetings . not_relays . sort_by_event . each do | events_by_pool_type | hash_key = events_by_pool_type . get_key results_by_time = @swimmer . meeting_individual_results . for_event_by_pool_type ( events_by_pool_type ) . sort_by_timing ( 'ASC' ) . select ( 'meeting_individual_results.id' , 'minutes' , 'seconds' , 'hundreds' , 'rank' , 'standard_points' , 'reaction_time' , 'meeting_program_id' , 'is_personal_best' ) results_by_date = @swimmer . meeting_individual_results . is_valid . sort_by_date ( 'ASC' ) . for_event_by_pool_type ( events_by_pool_type ) . select ( 'meeting_individual_results.id' , 'minutes' , 'seconds' , 'hundreds' , 'rank' , 'standard_points' , 'reaction_time' , 'meeting_program_id' , 'is_personal_best' ) if results_by_time . size > 0 passages = Passage . joins ( :event_type , :pool_type , :passage_type ) . where ( swimmer_id : @swimmer . id ) . where ( [ 'event_types.id = ? AND pool_types.id = ?' , events_by_pool_type . event_type_id , events_by_pool_type . pool_type_id ] ) . select ( 'meeting_individual_result_id' , 'passage_type_id' , 'minutes' , 'seconds' , 'hundreds' , 'passage_types.length_in_meters' ) passages_list = passages . select ( 'passage_types.length_in_meters' ) . map { | pt | pt . length_in_meters } . uniq . sort stroke_type_code = events_by_pool_type . stroke_type_code stroke_type_des = events_by_pool_type . stroke_type_i18n_description pool_type_des = events_by_pool_type . pool_type_i18n_verbose event_type_dist = events_by_pool_type . event_type_length_in_meters stroke_index = @index_table . rindex { | hash_element | hash_element [ :stroke_type ] == stroke_type_des } if stroke_index if @index_table [ stroke_index ] [ pool_type_des ] @index_table [ stroke_index ] [ pool_type_des ] << event_type_dist if not @index_table [ stroke_index ] [ pool_type_des ] . rindex ( event_type_dist ) else @index_table [ stroke_index ] [ pool_type_des ] = [ event_type_dist ] end else new_hash = Hash . new new_hash [ :stroke_type ] = stroke_type_des new_hash [ :stroke_code ] = stroke_type_code new_hash [ pool_type_des ] = [ event_type_dist ] @index_table << new_hash end else passages = nil passages_list = [ ] end @full_history_by_event [ hash_key ] = [ passages_list , results_by_time , passages , events_by_pool_type . i18n_description , results_by_date ] end end
Radiography for a specified swimmer id: "Full History: analysis" tab rendering.
Radiography for a specified swimmer id : " Full History : analysis " tab rendering .
# --- "Full History by time" tab: --- # Prepares an array for the index table # Every element of the array is an hash with style and event list arrays # with pool type code as key # Eg: # [ #   { stroke_type: 'SL', #     stroke_code: 'SL', #     25: {50, 100, 200, 800}, #     50: {50, 200, 800}, #   } #   { stroke_type: 'FA', #     stroke_code: 'FA', #     25: {50, 100}, #     50: {50, 100}, #   } #   ... # ] # Creates an hash with event_by_pool_type as code # Every element is an array of hashes # Every hash element of the array has: # - meeting # - result # - passages # Cycles between pool types suitable for meetings #hash_key = events_by_pool_type.i18n_description # This is used only for the graphs: # If has results collect passages and prepares hash for index table # [Steve, 20160929] If we use #count here below, instead of #size, ActiveRecord will try # to convert results_by_time.count into a query and this will yield an error. Stick with #size here: # Collect all passages # Collects the passage list # Adds the event type in the hash index table # The stroke type already exist. Check for the pool type # The pool type already exists. Check for event type and, if not, add # Creates the pool type with event # Creates the element for the stroke type # Create has element with event type by pool data