6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/broutes/formats/fit_file.rb', line 6
def load(file, route)
fit_file = Fit::File.read(file)
Broutes.logger.info {"Started fit processing"}
i = 0
fit_file.records.select {|r| r.content && r.content.record_type == :record }.each do |r|
begin
pr = r.content
data = { time: record_time(r) }
data[:lat] = convert_position(pr.position_lat) if pr.respond_to?(:position_lat)
data[:lon] = convert_position(pr.position_long) if pr.respond_to?(:position_long)
data[:elevation] = pr.altitude if pr.respond_to?(:altitude)
[:distance, :heart_rate, :power, :speed, :cadence, :temperature].each do |m|
data[m] = pr.send(m) if pr.respond_to?(m)
end
route.add_point(data)
i += 1
rescue => e
Broutes.logger.debug {"#{e.message} for #{r}"}
end
end
Broutes.logger.info {"Loaded #{i} data points"}
end
|