class PostRunner::FFS_Activity
The FFS_Activity
objects can store a reference to the FIT file data and caches some frequently used values. In some cases the cached values can be used to overwrite the data from the FIT file.
Attributes
fit_activity[R]
Public Class Methods
new(p, device, fit_file_name, fit_entity)
click to toggle source
Create a new FFS_Activity
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_Activity.rb, line 56 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 self.norecord = false if (@fit_activity = fit_entity) self.timestamp = fit_entity.timestamp self.total_timer_time = fit_entity.total_timer_time self.sport = fit_entity.sport self.sub_sport = fit_entity.sub_sport self.total_distance = fit_entity.total_distance self.avg_speed = fit_entity.avg_speed end end
Public Instance Methods
<=>(a)
click to toggle source
FFS_Activity
objects are sorted by their timestamp values and then by their device long_uids.
# File lib/postrunner/FFS_Activity.rb, line 92 def <=>(a) @timestamp == a.timestamp ? a.device.long_uid <=> self.device.long_uid : a.timestamp <=> @timestamp end
activity_sub_type()
click to toggle source
# File lib/postrunner/FFS_Activity.rb, line 201 def activity_sub_type Activity::ActivitySubTypes[@sub_sport] || "Undefined #{@sub_sport}" end
activity_type()
click to toggle source
# File lib/postrunner/FFS_Activity.rb, line 197 def activity_type Activity::ActivityTypes[@sport] || 'Undefined' end
check()
click to toggle source
# File lib/postrunner/FFS_Activity.rb, line 97 def check generate_html_report Log.info "FIT file #{@fit_file_name} is OK" end
distance(timestamp, unit_system)
click to toggle source
# File lib/postrunner/FFS_Activity.rb, line 205 def distance(timestamp, unit_system) load_fit_file @fit_activity.records.each do |record| if record.timestamp >= timestamp unit = { :metric => 'km', :statute => 'mi'}[unit_system] value = record.get_as('distance', unit) return '-' unless value return "#{'%.2f %s' % [value, unit]}" end end '-' end
dump(filter)
click to toggle source
# File lib/postrunner/FFS_Activity.rb, line 102 def dump(filter) load_fit_file(filter) end
events()
click to toggle source
# File lib/postrunner/FFS_Activity.rb, line 125 def events load_fit_file puts EventList.new(self, @store['config']['unit_system'].to_sym).to_s end
generate_html_report()
click to toggle source
# File lib/postrunner/FFS_Activity.rb, line 192 def generate_html_report load_fit_file ActivityView.new(self, @store['config']['unit_system'].to_sym) end
has_records?()
click to toggle source
Return true if this activity generated any personal records.
# File lib/postrunner/FFS_Activity.rb, line 183 def has_records? !@store['records'].activity_records(self).empty? end
html_file_name(full_path = true)
click to toggle source
# File lib/postrunner/FFS_Activity.rb, line 187 def html_file_name(full_path = true) fn = "#{@device.short_uid}_#{@fit_file_name[0..-5]}.html" full_path ? File.join(@store['config']['html_dir'], fn) : fn end
load_fit_file(filter = nil)
click to toggle source
# File lib/postrunner/FFS_Activity.rb, line 220 def load_fit_file(filter = nil) return if @fit_activity dir = @store['file_store'].fit_file_dir(@fit_file_name, @device.long_uid, 'activity') fit_file = File.join(dir, @fit_file_name) begin @fit_activity = Fit4Ruby.read(fit_file, filter) rescue Fit4Ruby::Error Log.fatal "#{@fit_file_name} corrupted: #{$!}" end unless @fit_activity Log.fatal "#{fit_file} does not contain any activity records" end end
purge_fit_file()
click to toggle source
# File lib/postrunner/FFS_Activity.rb, line 237 def purge_fit_file @fit_activity = nil end
query(key)
click to toggle source
# File lib/postrunner/FFS_Activity.rb, line 106 def query(key) unless @@Schemata.include?(key) raise ArgumentError, "Unknown key '#{key}' requested in query" end schema = @@Schemata[key] if schema.func value = send(schema.func) else unless instance_variable_defined?(key) raise ArgumentError, "Don't know how to query '#{key}'" end value = instance_variable_get(key) end QueryResult.new(value, schema) end
set(attribute, value)
click to toggle source
# File lib/postrunner/FFS_Activity.rb, line 151 def set(attribute, value) case attribute when 'name' self.name = value when 'note' self.note = value when 'type' load_fit_file unless Activity::ActivityTypes.values.include?(value) Log.fatal "Unknown activity type '#{value}'. Must be one of " + Activity::ActivityTypes.values.join(', ') end self.sport = Activity::ActivityTypes.invert[value] when 'subtype' unless Activity::ActivitySubTypes.values.include?(value) Log.fatal "Unknown activity subtype '#{value}'. Must be one of " + Activity::ActivitySubTypes.values.join(', ') end self.sub_sport = Activity::ActivitySubTypes.invert[value] when 'norecord' unless %w( true false).include?(value) Log.fatal "norecord must either be 'true' or 'false'" end self.norecord = value == 'true' else Log.fatal "Unknown activity attribute '#{attribute}'. Must be one of " + 'name, type or subtype' end generate_html_report end
show()
click to toggle source
# File lib/postrunner/FFS_Activity.rb, line 130 def show html_file = html_file_name generate_html_report #unless File.exist?(html_file) @store['file_store'].show_in_browser(html_file) end
sources()
click to toggle source
# File lib/postrunner/FFS_Activity.rb, line 138 def sources load_fit_file puts DataSources.new(self, @store['config']['unit_system'].to_sym).to_s 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_Activity.rb, line 75 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, 'activity') # Create the necessary directories if they don't exist yet. create_directory(dir, 'Device activity 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
summary()
click to toggle source
# File lib/postrunner/FFS_Activity.rb, line 143 def summary load_fit_file puts ActivitySummary.new(self, @store['config']['unit_system'].to_sym, { :name => @name, :type => activity_type, :sub_type => activity_sub_type }).to_s end