class PostRunner::EventList
The EventList
objects can generate a table that lists all the recorded FIT file events in chronological order.
Public Class Methods
new(activity, unit_system)
click to toggle source
Create a DataSources
object. @param activity [Activity] The activity to analyze. @param unit_system [Symbol] The unit system to use (:metric or
:imperial )
# File lib/postrunner/EventList.rb, line 31 def initialize(activity, unit_system) @activity = activity @fit_activity = activity.fit_activity @unit_system = unit_system end
Public Instance Methods
to_html(doc)
click to toggle source
Add the list as HTML table to the specified doc. @param doc [HTMLBuilder] HTML document
# File lib/postrunner/EventList.rb, line 44 def to_html(doc) ViewFrame.new('events', 'Events', 600, list, true).to_html(doc) end
to_s()
click to toggle source
Return the list as ASCII table
# File lib/postrunner/EventList.rb, line 38 def to_s list.to_s end
Private Instance Methods
event_name_and_value(table, event)
click to toggle source
# File lib/postrunner/EventList.rb, line 74 def event_name_and_value(table, event) case event.event when 'timer' name = "Timer (#{event.event_type.gsub(/_/, ' ')})" value = '-' when 'course_point' name = 'Course Point' value = event.message_index when 'battery' name = 'Battery Level' value = "#{event.battery_level} V" when 'hr_high_alert' name = 'HR high alert' value = "#{event.hr_high_alert} bpm" when 'hr_low_alert' name = 'HR low alert' value = "#{event.hr_low_alert} bpm" when 'speed_high_alert' name = 'Speed high alert' value = event.speed_high_alert when 'speed_low_alert' name = 'Speed low alert' value = event.speed_low_alert when 'cad_high_alert' name = 'Cadence high alert' value = "#{2 * event.cad_high_alert} spm" when 'cad_low_alert' name = 'Cadence low alert' value = "#{2 * event.cad_low_alert} spm" when 'power_high_alert' name = 'Power high alert' value = event.power_high_alert when 'power_low_alert' name = 'Power low alert' value = event.power_low_alert when 'time_duration_alert' name = 'Time duration alert' value = event.time_duration_alert when 'calorie_duration_alert' name = 'Calorie duration alert' value = event.calorie_duration_alert when 'fitness_equipment' name = 'Fitness equipment state' value = event.fitness_equipment_state when 'rider_position' name 'Rider position changed' value = event.rider_position when 'comm_timeout' name 'Communication timeout' value = event.comm_timeout when 'off_course' name = 'Off Course' value = '-' when 'recovery_hr' name = 'Recovery heart rate' value = "#{event.recovery_hr} bpm" when 'recovery_time' name = 'Recovery time' if event.recovery_time value = "#{secsToDHMS(event.recovery_time * 60)}" else value = '-' end when 'recovery_info' name = 'Recovery info' mins = event.recovery_info value = "#{secsToDHMS(mins * 60)} (#{mins < 24 * 60 ? 'Good' : 'Poor'})" when 'vo2max' name = 'VO2Max' value = event.vo2max when 'lactate_threshold_heart_rate' name = 'Lactate Threshold Heart Rate' value = "#{event.lactate_threshold_heart_rate} bpm" when 'lactate_threshold_speed' name = 'Lactate Threshold Pace' value = pace(event, 'lactate_threshold_speed') when 'functional_threshold_power' name = 'Functional Threshold Power' value = "#{event.functional_threshold_power} W" else name = event.event value = event.data end table.cell(name) table.cell(value) end
list()
click to toggle source
# File lib/postrunner/EventList.rb, line 50 def list session = @fit_activity.sessions[0] t = FlexiTable.new t.enable_frame(false) t.body t.row([ 'Time', 'Distance', 'Description', 'Value' ]) t.set_column_attributes([ { :halign => :right }, { :halign => :right }, { :halign => :left }, { :halign => :right } ]) start_time = session.start_time @fit_activity.events.each do |event| t.cell(secsToHMS(event.timestamp - start_time)) t.cell(@activity.distance(event.timestamp, @unit_system)) event_name_and_value(t, event) t.new_row end t end
pace(fdr, field, show_unit = true)
click to toggle source
# File lib/postrunner/EventList.rb, line 162 def pace(fdr, field, show_unit = true) speed = fdr.get(field) case @unit_system when :metric "#{speedToPace(speed)}#{show_unit ? ' min/km' : ''}" when :statute "#{speedToPace(speed, 1609.34)}#{show_unit ? ' min/mi' : ''}" else Log.fatal "Unknown unit system #{@unit_system}" end end