Class: Joule::IBike::Parser

Inherits:
CSV::Parser show all
Defined in:
lib/joule/ibike/parser.rb

Constant Summary collapse

IBIKE =
'.csv'
SPEED =
0
WINDSPEED =
1
POWER =
2
DISTANCE =
3
CADENCE =
4
HEARTRATE =
5
ELEVATION =
6
SLOPE =
7
DFPM_POWER =
11
LATITUDE =
12
LONGITUDE =
13
TIMESTAMP =
14

Instance Attribute Summary

Attributes inherited from Base::Parser

#workout

Instance Method Summary collapse

Methods inherited from CSV::Parser

#parse_workout

Methods included from UnitsConversion

#convert_distance, #convert_speed, #kilometers_per_hour_to_millimeters_per_second, #kilometers_to_millimeters, #miles_per_hour_to_millimeters_per_second, #miles_to_millimeters, #millimeters_per_second_to_kilometers_per_hour, #millimeters_per_second_to_miles_per_hour, #millimeters_to_kilometers, #millimeters_to_miles

Methods inherited from Base::Parser

#initialize, #parse, #parse_workout

Methods included from Calculator::PeakPowerCalculator

#calculate_peak_power_value, #calculate_peak_power_values

Methods included from Calculator::MarkerCalculator

#calculate_marker_averages, #calculate_marker_maximums, #calculate_marker_totals, #calculate_marker_training_metrics, #calculate_marker_values

Constructor Details

This class inherits a constructor from Joule::Base::Parser

Instance Method Details

#parse_data_pointsObject



45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/joule/ibike/parser.rb', line 45

def parse_data_points()
  records = FasterCSV.parse(@data).slice(5..-1)
  records.each_with_index { |record, index|
    data_point  = DataPoint.new
    data_point.time  = index * @workout.properties.record_interval
    data_point.speed = convert_speed(record[SPEED].to_f)
    data_point.power = record[POWER].to_f
    data_point.distance = convert_distance(record[DISTANCE].to_f)
    data_point.cadence = record[CADENCE].to_i
    data_point.heartrate = record[HEARTRATE].to_i
    @workout.data_points << data_point 
  }
end

#parse_markersObject



59
60
61
62
# File 'lib/joule/ibike/parser.rb', line 59

def parse_markers
  records = FasterCSV.parse(@data).slice(5..-1)
  @workout.markers << create_workout_marker(records)
end

#parse_propertiesObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/joule/ibike/parser.rb', line 18

def parse_properties()
  records = FasterCSV.parse(@data)
  header = records.shift

  @workout.properties = Joule::IBike::Properties.new
  @workout.properties.version=header[1]
  @workout.properties.units=header[2]
  header = records.shift
  @workout.properties.date_time = Time.mktime(header[0].to_i, header[1].to_i, header[2].to_i, header[3].to_i, header[4].to_i, header[5].to_i)
  records.shift
  header = records.shift
  @workout.properties.total_weight = header[0]
  @workout.properties.energy = header[1]
  @workout.properties.record_interval = header[4].to_i
  @workout.properties.starting_elevation = header[5]
  @workout.properties.total_climbing = header[6]
  @workout.properties.wheel_size = header[7]
  @workout.properties.temperature = header[8]
  @workout.properties.starting_pressure = header[9]
  @workout.properties.wind_scaling = header[10]
  @workout.properties.riding_tilt = header[11]
  @workout.properties.calibration_weight = header[12]
  @workout.properties.cm = header[13]
  @workout.properties.cda = header[14]
  @workout.properties.crr = header[15]
end