class PostRunner::FFS_Monitoring

The FFS_Monitoring objects can store a reference to the FIT file data and caches some frequently used values.

Public Class Methods

new(p, device, fit_file_name, fit_entity) click to toggle source

Create a new FFS_Monitoring object. @param p [PEROBS::Handle] PEROBS handle @param fit_file_name [String] The fully qualified file name of the FIT

file to add

@param fit_entity [Fit4Ruby::FitEntity] The content of the loaded FIT

file
Calls superclass method
# File lib/postrunner/FFS_Monitoring.rb, line 32
def initialize(p, device, fit_file_name, fit_entity)
  super(p)

  self.device = device
  self.fit_file_name = fit_file_name ? File.basename(fit_file_name) : nil
  self.name = fit_file_name ? File.basename(fit_file_name) : nil

  extract_summary_values(fit_entity)
end

Public Instance Methods

<=>(a) click to toggle source

FFS_Monitoring objects are sorted by their start time values and then by their device long_uids.

# File lib/postrunner/FFS_Monitoring.rb, line 61
def <=>(a)
  @period_start == a.period_start ?
    a.device.long_uid <=> self.device.long_uid :
    a.period_start <=> @period_start
end
store_fit_file(fit_file_name) click to toggle source

Store a copy of the given FIT file in the corresponding directory. @param fit_file_name [String] Fully qualified name of the FIT file.

# File lib/postrunner/FFS_Monitoring.rb, line 44
def store_fit_file(fit_file_name)
  # Get the right target directory for this particular FIT file.
  dir = @store['file_store'].fit_file_dir(File.basename(fit_file_name),
                                          @device.long_uid, 'monitor')
  # Create the necessary directories if they don't exist yet.
  create_directory(dir, 'Device monitoring diretory')

  # Copy the file into the target directory.
  begin
    FileUtils.cp(fit_file_name, dir)
  rescue StandardError
    Log.fatal "Cannot copy #{fit_file_name} into #{dir}: #{$!}"
  end
end

Private Instance Methods

decode_activity_type(activity_type) click to toggle source
# File lib/postrunner/FFS_Monitoring.rb, line 79
def decode_activity_type(activity_type)
  types = [ :generic, :running, :cycling, :transition,
            :fitness_equipment, :swimming, :walking, :unknown7,
            :resting, :unknown9 ]
  if (decoded_type = types[activity_type])
    decoded_type
  else
    Log.error "Unknown activity type #{activity_type}"
    :generic
  end
end
extract_summary_values(fit_entity) click to toggle source
# File lib/postrunner/FFS_Monitoring.rb, line 69
def extract_summary_values(fit_entity)
  self.period_start = fit_entity.monitoring_infos[0].timestamp

  period_end = @period_start
  fit_entity.monitorings.each do |monitoring|
    period_end = monitoring.timestamp if monitoring.timestamp
  end
  self.period_end = period_end
end