summaryrefslogtreecommitdiff
path: root/spec/spec_helper.rb
diff options
context:
space:
mode:
authorChris Schlaeger <chris@linux.com>2015-10-26 19:15:47 +0100
committerChris Schlaeger <chris@linux.com>2015-10-26 19:15:47 +0100
commit5590faccc2c96f5038463685407ea4e468c056c8 (patch)
tree3b1a43c9d99300463aeaf13f5f4523a10a5b190a /spec/spec_helper.rb
parent23f180afce6c6089b9c671974611130b999a817f (diff)
downloadpostrunner-5590faccc2c96f5038463685407ea4e468c056c8.zip
Add data sources table to activity view.
Diffstat (limited to 'spec/spec_helper.rb')
-rw-r--r--spec/spec_helper.rb38
1 files changed, 34 insertions, 4 deletions
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index e91cffd..dbb1e0e 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -10,20 +10,44 @@
# published by the Free Software Foundation.
#
+require 'tmpdir'
+require 'fileutils'
+
# Some dependencies may not be installed as Ruby Gems but as local sources.
# Add them and the postrunner dir to the LOAD_PATH.
%w( postrunner fit4ruby perobs ).each do |lib_dir|
$:.unshift(File.join(File.dirname(__FILE__), '..', '..', lib_dir, 'lib'))
end
+def tmp_dir_name(caller_file)
+ begin
+ dir_name = File.join(Dir.tmpdir,
+ "#{File.basename(caller_file)}.#{rand(2**32)}")
+ end while File.exists?(dir_name)
+
+ dir_name
+end
+
def create_fit_file(name, date, duration_minutes = 30)
- Fit4Ruby.write(name, create_fit_activity(date, duration_minutes))
+ Fit4Ruby.write(name, create_fit_activity(
+ { :t => date, :duration => duration_minutes }))
+end
+
+def create_fit_activity_file(dir, config)
+ activity = create_fit_activity(config)
+ end_time = activity.sessions[-1].start_time +
+ activity.sessions[-1].total_elapsed_time
+ fit_file_name = File.join(dir, Fit4Ruby::FileNameCoder.encode(end_time))
+ Fit4Ruby.write(fit_file_name, activity)
+
+ fit_file_name
end
-def create_fit_activity(date, duration_minutes)
- ts = Time.parse(date)
+def create_fit_activity(config)
+ ts = Time.parse(config[:t])
+ serial = config[:serial] || 12345890
a = Fit4Ruby::Activity.new({ :timestamp => ts })
- a.total_timer_time = duration_minutes * 60
+ a.total_timer_time = (config[:duration] || 10) * 60
a.new_user_profile({ :timestamp => ts,
:age => 33, :height => 1.78, :weight => 73.0,
:gender => 'male', :activity_class => 7.0,
@@ -32,8 +56,11 @@ def create_fit_activity(date, duration_minutes)
a.new_event({ :timestamp => ts, :event => 'timer',
:event_type => 'start_time' })
a.new_device_info({ :timestamp => ts, :manufacturer => 'garmin',
+ :garmin_product => 'fenix3',
+ :serial_number => serial,
:device_index => 0 })
a.new_device_info({ :timestamp => ts, :manufacturer => 'garmin',
+ :garmin_product => 'sdm4',
:device_index => 1, :battery_status => 'ok' })
laps = 0
0.upto((a.total_timer_time / 60) - 1) do |mins|
@@ -69,9 +96,12 @@ def create_fit_activity(date, duration_minutes)
a.new_event({ :timestamp => ts, :event => 'timer',
:event_type => 'stop_all' })
a.new_device_info({ :timestamp => ts, :manufacturer => 'garmin',
+ :garmin_product => 'fenix3',
+ :serial_number => serial,
:device_index => 0 })
ts += 1
a.new_device_info({ :timestamp => ts, :manufacturer => 'garmin',
+ :garmin_product => 'sdm4',
:device_index => 1, :battery_status => 'low' })
ts += 120
a.new_event({ :timestamp => ts, :event => 'recovery_hr',