summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorChris Schlaeger <chris@linux.com>2015-10-11 20:29:15 +0200
committerChris Schlaeger <chris@linux.com>2015-10-11 20:29:15 +0200
commitf5b6672822058a1bd236adb49bcfa019e533e6a8 (patch)
treec4cbd4ee9d74f4ffef09e76b4917e78afa75fdb5 /lib
parent199717d21cda2b4d230ce0cc14054ffc1a8ea80b (diff)
downloadpostrunner-f5b6672822058a1bd236adb49bcfa019e533e6a8.zip
Include purely GPS coordinate based distances as well
Diffstat (limited to 'lib')
-rw-r--r--lib/postrunner/ActivitySummary.rb5
-rw-r--r--lib/postrunner/Main.rb1
-rw-r--r--lib/postrunner/MonitoringDB.rb39
3 files changed, 43 insertions, 2 deletions
diff --git a/lib/postrunner/ActivitySummary.rb b/lib/postrunner/ActivitySummary.rb
index c1c1464..bf13fb7 100644
--- a/lib/postrunner/ActivitySummary.rb
+++ b/lib/postrunner/ActivitySummary.rb
@@ -54,6 +54,11 @@ module PostRunner
t.row([ 'Distance:',
local_value(session, 'total_distance', '%.2f %s',
{ :metric => 'km', :statute => 'mi'}) ])
+ if session.has_geo_data?
+ t.row([ 'GPS Data based Distance:',
+ local_value(@fit_activity, 'total_gps_distance', '%.2f %s',
+ { :metric => 'km', :statute => 'mi'}) ])
+ end
t.row([ 'Time:', secsToHMS(session.total_timer_time) ])
if @activity.sport == 'running' || @activity.sport == 'multisport'
t.row([ 'Avg. Pace:', pace(session, 'avg_speed') ])
diff --git a/lib/postrunner/Main.rb b/lib/postrunner/Main.rb
index 71bda49..2605fe4 100644
--- a/lib/postrunner/Main.rb
+++ b/lib/postrunner/Main.rb
@@ -337,6 +337,7 @@ EOT
if fit_entity.is_a?(Fit4Ruby::Activity)
return @activities.add(fit_file_name, fit_entity)
elsif fit_entity.is_a?(Fit4Ruby::Monitoring_B)
+ return @monitoring.add(fit_file_name, fit_entity)
else
Log.error "#{fit_file_name} is not a recognized FIT file"
return false
diff --git a/lib/postrunner/MonitoringDB.rb b/lib/postrunner/MonitoringDB.rb
index 28d8322..cc500bf 100644
--- a/lib/postrunner/MonitoringDB.rb
+++ b/lib/postrunner/MonitoringDB.rb
@@ -10,12 +10,47 @@
# published by the Free Software Foundation.
#
+require 'postrunner/TimestampedObjectList'
+require 'postrunner/MonitoringData'
+
module PostRunner
class MonitoringDB
- def initialize(db, cfg)
- db.sync
+ def initialize(store, cfg)
+ @store = store
+ @tol = TimestampedObjectList.new(@store, 'monitoring')
+ end
+
+ def add(fit_file_name, fit_monitoring_b)
+ start_time = fit_monitoring_b.monitoring_infos[0].timestamp
+ data = MonitoringData.new(@store)
+ @tol.add_object(start_time, data)
+
+ fit_monitoring_b.monitorings.each do |monitoring|
+ if (cati = monitoring.current_activity_type_intensity)
+ data = MonitoringData.new(@store)
+ @tol.add_object(monitoring.timestamp, data)
+ data.activity_type = decode_activity_type(cati & 0x1F)
+ data.intensity = (cati >> 5) & 0x7
+ #puts "#{monitoring.timestamp}: #{decode_activity_type(cati & 0x1F)}" +
+ # " #{(cati >> 5) & 0x7}"
+ end
+ end
+ end
+
+ private
+
+ 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
end