summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/postrunner/ActivitySummary.rb5
-rw-r--r--lib/postrunner/Main.rb1
-rw-r--r--lib/postrunner/MonitoringDB.rb39
-rw-r--r--postrunner.gemspec3
-rw-r--r--spec/spec_helper.rb1
5 files changed, 45 insertions, 4 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
diff --git a/postrunner.gemspec b/postrunner.gemspec
index 530f6bb..7497ba3 100644
--- a/postrunner.gemspec
+++ b/postrunner.gemspec
@@ -19,7 +19,8 @@ Gem::Specification.new do |spec|
spec.require_paths = ["lib"]
spec.required_ruby_version = '>=2.0'
- spec.add_dependency 'fit4ruby', '~> 0.0.6'
+ spec.add_dependency 'fit4ruby', '~> 0.0.7'
+ spec.add_dependency 'perobs', '~> 1.0.0'
spec.add_dependency 'nokogiri', '~> 1.6'
spec.add_development_dependency 'bundler', '~> 1.6'
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 691f097..3b7ea85 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -15,7 +15,6 @@
%w( postrunner fit4ruby perobs ).each do |lib_dir|
$:.unshift(File.join(File.dirname(__FILE__), '..', '..', lib_dir, 'lib'))
end
-puts $:
def create_fit_file(name, date, duration_minutes = 30)
Fit4Ruby.write(name, create_fit_activity(date, duration_minutes))