app/strategies/passage_updater.rb
# Prepares the required timing fields for the specified passage instance row,
# given a parsed timing instance containing the values used to update the Passage.
#
# When specified, the MeetingIndividualResult instance (mir) parameter will take
# precedence over any other supplied meeting_program_id, swimmer_id & team_id.
# (These 3 must all be present in order to be used when the +mir+ parameter is +nil+)
#
# === Returns:
# The updated Passage instance
#
Prepares the required timing fields for the specified passage instance row,
given a parsed timing instance containing the values used to update the Passage.

When specified, the MeetingIndividualResult instance (mir) parameter will take
precedence over any other supplied meeting_program_id, swimmer_id & team_id.
(These 3 must all be present in order to be used when the +mir+ parameter is +nil+)

The updated Passage instance
Prepares the required timing fields for the specified passage instance row given a parsed timing instance containing the values used to update the Passage . When specified the MeetingIndividualResult instance ( mir ) parameter will take precedence over any other supplied meeting_program_id swimmer_id & team_id . ( These 3 must all be present in order to be used when the + mir + parameter is + nil + ) The updated Passage instance
def prepare_passage_fields( passage, timing_instance, reaction_time_instance = nil, mir = nil, passage_type_id = nil,
                              meeting_program_id = nil, swimmer_id = nil, team_id = nil )
    passage.user_id = @current_user.id
    prev_timing_instance = nil
    if mir.instance_of?( MeetingIndividualResult )
      puts "Passage->MIR link valid"
      passage.meeting_program_id = mir.meeting_program_id
      passage.meeting_individual_result_id = mir.id
      passage.swimmer_id = mir.swimmer_id
      passage.team_id = mir.team_id
      prev_timing_instance = if passage.get_previous_passage
        passage.get_previous_passage.compute_incremental_time
      else
        nil
      end
      puts "passage.get_previous_passage....: #{ passage.get_previous_passage.inspect }"
      puts "passage.get_total_distance......: #{ passage.get_total_distance }"
      puts "passage.get_passage_distance....: #{ passage.get_passage_distance }"
      puts "passage.get_passages count......: #{ passage.get_passages.count }"
      puts "passage.get_passages filtered...: #{ passage.get_passages.where( 'length_in_meters < ?', passage.get_passage_distance ).count }"
    else
      puts "Passage->MIR link NULL"
      passage.meeting_program_id = meeting_program_id if meeting_program_id.present?
      passage.swimmer_id = swimmer_id if swimmer_id.present?
      passage.team_id    = team_id if team_id.present?
    end
    passage.passage_type_id = passage_type_id if passage_type_id
    passage.minutes  = timing_instance.minutes
    passage.seconds  = timing_instance.seconds
    passage.hundreds = timing_instance.hundreds
    passage.reaction_time = reaction_time_instance ? reaction_time_instance.to_hundreds / 100.0 : 0.0
    is_delta = PassageUpdater.is_delta?( passage )
    if is_delta == true
      puts "is_delta? == TRUE"
      passage.minutes  = timing_instance.minutes
      passage.seconds  = timing_instance.seconds
      passage.hundreds = timing_instance.hundreds
      timing_instance += Timing.new(
        prev_timing_instance.hundreds,
        prev_timing_instance.seconds,
        prev_timing_instance.minutes
      ) if prev_timing_instance
      passage.minutes_from_start  = timing_instance.minutes
      passage.seconds_from_start  = timing_instance.seconds
      passage.hundreds_from_start = timing_instance.hundreds
    else
      puts "is_delta? == FALSE"
      delta_timing_instance = prev_timing_instance ? timing_instance - prev_timing_instance : timing_instance
      passage.minutes  = delta_timing_instance.minutes
      passage.seconds  = delta_timing_instance.seconds
      passage.hundreds = delta_timing_instance.hundreds
      passage.minutes_from_start  = timing_instance.minutes
      passage.seconds_from_start  = timing_instance.seconds
      passage.hundreds_from_start = timing_instance.hundreds
    end
    puts "\r\n- prepare_passage_fields(mir: #{mir ? mir.id : 'nil'}): " << passage.inspect
    passage
  end
def prepare_passage_fields ( passage , timing_instance , reaction_time_instance = nil , mir = nil , passage_type_id = nil , meeting_program_id = nil , swimmer_id = nil , team_id = nil ) passage . user_id = @current_user . id prev_timing_instance = nil if mir . instance_of? ( MeetingIndividualResult ) puts "Passage->MIR link valid" passage . meeting_program_id = mir . meeting_program_id passage . meeting_individual_result_id = mir . id passage . swimmer_id = mir . swimmer_id passage . team_id = mir . team_id prev_timing_instance = if passage . get_previous_passage passage . get_previous_passage . compute_incremental_time else nil end puts "passage.get_previous_passage....: #{ passage.get_previous_passage.inspect }" puts "passage.get_total_distance......: #{ passage.get_total_distance }" puts "passage.get_passage_distance....: #{ passage.get_passage_distance }" puts "passage.get_passages count......: #{ passage.get_passages.count }" puts "passage.get_passages filtered...: #{ passage.get_passages.where( 'length_in_meters < ?', passage.get_passage_distance ).count }" else puts "Passage->MIR link NULL" passage . meeting_program_id = meeting_program_id if meeting_program_id . present? passage . swimmer_id = swimmer_id if swimmer_id . present? passage . team_id = team_id if team_id . present? end passage . passage_type_id = passage_type_id if passage_type_id passage . minutes = timing_instance . minutes passage . seconds = timing_instance . seconds passage . hundreds = timing_instance . hundreds passage . reaction_time = reaction_time_instance ? reaction_time_instance . to_hundreds / 100.0 : 0.0 is_delta = PassageUpdater . is_delta? ( passage ) if is_delta == true puts "is_delta? == TRUE" passage . minutes = timing_instance . minutes passage . seconds = timing_instance . seconds passage . hundreds = timing_instance . hundreds timing_instance += Timing . new ( prev_timing_instance . hundreds , prev_timing_instance . seconds , prev_timing_instance . minutes ) if prev_timing_instance passage . minutes_from_start = timing_instance . minutes passage . seconds_from_start = timing_instance . seconds passage . hundreds_from_start = timing_instance . hundreds else puts "is_delta? == FALSE" delta_timing_instance = prev_timing_instance ? timing_instance - prev_timing_instance : timing_instance passage . minutes = delta_timing_instance . minutes passage . seconds = delta_timing_instance . seconds passage . hundreds = delta_timing_instance . hundreds passage . minutes_from_start = timing_instance . minutes passage . seconds_from_start = timing_instance . seconds passage . hundreds_from_start = timing_instance . hundreds end puts "\r\n- prepare_passage_fields(mir: #{mir ? mir.id : 'nil'}): " << passage . inspect passage end
Prepares the required timing fields for the specified passage instance row,
given a parsed timing instance containing the values used to update the Passage.
Prepares the required timing fields for the specified passage instance row given a parsed timing instance containing the values used to update the Passage .
# DEBUG # [Steve, 20180712] passage.get_previous_passage() works only if the Passage # instance has a MIR associated. # DEBUG # DEBUG # Establish whether the passage is "delta" or "incremental": # DEBUG # timing_instance is "delta". # Should calculate time from start: # DEBUG # timing_instance is "incremental". # Should calculate delta time: # DEBUG
passage
<not_specific>
timing_instance
<not_specific>
reaction_time_instance
<not_specific>
mir
<not_specific>
passage_type_id
<not_specific>
meeting_program_id
<not_specific>
swimmer_id
<not_specific>
team_id
<not_specific>