postrunner 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +74 -11
- data/Rakefile +10 -0
- data/lib/postrunner/ActivitiesDB.rb +120 -32
- data/lib/postrunner/Activity.rb +34 -11
- data/lib/postrunner/ActivityListView.rb +195 -0
- data/lib/postrunner/ActivitySummary.rb +141 -0
- data/lib/postrunner/ActivityView.rb +41 -71
- data/lib/postrunner/ChartView.rb +72 -33
- data/lib/postrunner/DeviceList.rb +104 -0
- data/lib/postrunner/FlexiTable.rb +42 -7
- data/lib/postrunner/HTMLBuilder.rb +12 -0
- data/lib/postrunner/Main.rb +68 -9
- data/lib/postrunner/PersonalRecords.rb +12 -0
- data/lib/postrunner/RuntimeConfig.rb +80 -0
- data/lib/postrunner/TrackView.rb +25 -8
- data/lib/postrunner/UserProfileView.rb +70 -0
- data/lib/postrunner/ViewWidgets.rb +107 -0
- data/lib/postrunner/version.rb +13 -1
- data/lib/postrunner.rb +12 -0
- data/misc/icons/back.png +0 -0
- data/misc/icons/back.svg +68 -0
- data/misc/icons/first.png +0 -0
- data/misc/icons/first.svg +64 -0
- data/misc/icons/forward.png +0 -0
- data/misc/icons/forward.svg +64 -0
- data/misc/icons/home.png +0 -0
- data/misc/icons/home.svg +64 -0
- data/misc/icons/last.png +0 -0
- data/misc/icons/last.svg +64 -0
- data/misc/icons/lgpl-3.0.txt +165 -0
- data/postrunner.gemspec +1 -1
- data/spec/ActivitySummary_spec.rb +28 -0
- data/spec/FlexiTable_spec.rb +19 -1
- data/spec/PostRunner_spec.rb +25 -21
- data/spec/spec_helper.rb +62 -0
- metadata +26 -8
- data/LICENSE.txt +0 -22
- data/lib/postrunner/ActivityReport.rb +0 -102
data/spec/PostRunner_spec.rb
CHANGED
@@ -1,6 +1,19 @@
|
|
1
|
+
#!/usr/bin/env ruby -w
|
2
|
+
# encoding: UTF-8
|
3
|
+
#
|
4
|
+
# = PostRunner_spec.rb -- PostRunner - Manage the data from your Garmin sport devices.
|
5
|
+
#
|
6
|
+
# Copyright (c) 2014 by Chris Schlaeger <cs@taskjuggler.org>
|
7
|
+
#
|
8
|
+
# This program is free software; you can redistribute it and/or modify
|
9
|
+
# it under the terms of version 2 of the GNU General Public License as
|
10
|
+
# published by the Free Software Foundation.
|
11
|
+
#
|
12
|
+
|
1
13
|
require 'fileutils'
|
2
14
|
|
3
15
|
require 'postrunner/Main'
|
16
|
+
require 'spec_helper'
|
4
17
|
|
5
18
|
describe PostRunner::Main do
|
6
19
|
|
@@ -13,25 +26,6 @@ describe PostRunner::Main do
|
|
13
26
|
stdout.string
|
14
27
|
end
|
15
28
|
|
16
|
-
def create_fit_file(name, date)
|
17
|
-
a = Fit4Ruby::Activity.new
|
18
|
-
a.timestamp = Time.parse(date)
|
19
|
-
a.total_timer_time = 30 * 60
|
20
|
-
0.upto(30) do |mins|
|
21
|
-
r = a.new_record('record')
|
22
|
-
r.timestamp = a.timestamp + mins * 60
|
23
|
-
r.distance = 200.0 * mins
|
24
|
-
r.cadence = 75
|
25
|
-
|
26
|
-
if mins > 0 && mins % 5 == 0
|
27
|
-
s = a.new_record('laps')
|
28
|
-
end
|
29
|
-
end
|
30
|
-
a.new_record('session')
|
31
|
-
a.aggregate
|
32
|
-
Fit4Ruby.write(name, a)
|
33
|
-
end
|
34
|
-
|
35
29
|
before(:all) do
|
36
30
|
@db_dir = File.join(File.dirname(__FILE__), '.postrunner')
|
37
31
|
FileUtils.rm_rf(@db_dir)
|
@@ -82,11 +76,13 @@ describe PostRunner::Main do
|
|
82
76
|
postrunner(%w( list )).index('FILE1.FIT').should be_a(Fixnum)
|
83
77
|
end
|
84
78
|
|
85
|
-
it 'should import
|
86
|
-
postrunner(
|
79
|
+
it 'should import the other FIT file' do
|
80
|
+
postrunner([ 'import', '.' ])
|
87
81
|
list = postrunner(%w( list ))
|
88
82
|
list.index('FILE1.FIT').should be_a(Fixnum)
|
89
83
|
list.index('FILE2.FIT').should be_a(Fixnum)
|
84
|
+
rc = YAML::load_file(File.join(@db_dir, 'config.yml'))
|
85
|
+
rc[:import_dir].should == '.'
|
90
86
|
end
|
91
87
|
|
92
88
|
it 'should delete the first file' do
|
@@ -118,5 +114,13 @@ describe PostRunner::Main do
|
|
118
114
|
postrunner(%w( dump FILE1.FIT ))
|
119
115
|
end
|
120
116
|
|
117
|
+
it 'should switch to statute units' do
|
118
|
+
postrunner(%w( units statute ))
|
119
|
+
end
|
120
|
+
|
121
|
+
it 'should switch back to metric units' do
|
122
|
+
postrunner(%w( units metric ))
|
123
|
+
end
|
124
|
+
|
121
125
|
end
|
122
126
|
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
def create_fit_file(name, date, duration_minutes = 30)
|
2
|
+
Fit4Ruby.write(name, create_fit_activity(date, duration_minutes))
|
3
|
+
end
|
4
|
+
|
5
|
+
def create_fit_activity(date, duration_minutes)
|
6
|
+
ts = Time.parse(date)
|
7
|
+
a = Fit4Ruby::Activity.new({ :timestamp => ts })
|
8
|
+
a.total_timer_time = duration_minutes * 60
|
9
|
+
a.new_user_profile({ :timestamp => ts,
|
10
|
+
:age => 33, :height => 1.78, :weight => 73.0,
|
11
|
+
:gender => 'male', :activity_class => 7.0,
|
12
|
+
:max_hr => 178 })
|
13
|
+
|
14
|
+
a.new_event({ :timestamp => ts, :event => 'timer',
|
15
|
+
:event_type => 'start_time' })
|
16
|
+
a.new_device_info({ :timestamp => ts, :device_index => 0 })
|
17
|
+
a.new_device_info({ :timestamp => ts, :device_index => 1,
|
18
|
+
:battery_status => 'ok' })
|
19
|
+
0.upto((a.total_timer_time / 60) - 1) do |mins|
|
20
|
+
a.new_record({
|
21
|
+
:timestamp => ts,
|
22
|
+
:position_lat => 51.5512 - mins * 0.0008,
|
23
|
+
:position_long => 11.647 + mins * 0.002,
|
24
|
+
:distance => 200.0 * mins,
|
25
|
+
:altitude => 100 + mins * 3,
|
26
|
+
:speed => 3.1,
|
27
|
+
:vertical_oscillation => 90 + mins * 0.2,
|
28
|
+
:stance_time => 235.0 * mins * 0.01,
|
29
|
+
:stance_time_percent => 32.0,
|
30
|
+
:heart_rate => 140 + mins,
|
31
|
+
:cadence => 75,
|
32
|
+
:activity_type => 'running',
|
33
|
+
:fractional_cadence => (mins % 2) / 2.0
|
34
|
+
})
|
35
|
+
|
36
|
+
if mins > 0 && mins % 5 == 0
|
37
|
+
a.new_lap({ :timestamp => ts })
|
38
|
+
end
|
39
|
+
ts += 60
|
40
|
+
end
|
41
|
+
a.new_session({ :timestamp => ts })
|
42
|
+
a.new_event({ :timestamp => ts, :event => 'recovery_time',
|
43
|
+
:event_type => 'marker',
|
44
|
+
:data => 2160 })
|
45
|
+
a.new_event({ :timestamp => ts, :event => 'vo2max',
|
46
|
+
:event_type => 'marker', :data => 52 })
|
47
|
+
a.new_event({ :timestamp => ts, :event => 'timer',
|
48
|
+
:event_type => 'stop_all' })
|
49
|
+
a.new_device_info({ :timestamp => ts, :device_index => 0 })
|
50
|
+
ts += 1
|
51
|
+
a.new_device_info({ :timestamp => ts, :device_index => 1,
|
52
|
+
:battery_status => 'low' })
|
53
|
+
ts += 120
|
54
|
+
a.new_event({ :timestamp => ts, :event => 'recovery_hr',
|
55
|
+
:event_type => 'marker', :data => 132 })
|
56
|
+
|
57
|
+
a.aggregate
|
58
|
+
|
59
|
+
a
|
60
|
+
end
|
61
|
+
|
62
|
+
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: postrunner
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Schlaeger
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-08-
|
11
|
+
date: 2014-08-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fit4ruby
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ~>
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 0.0.3
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ~>
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 0.0.3
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: nokogiri
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -108,21 +108,24 @@ files:
|
|
108
108
|
- .gitignore
|
109
109
|
- COPYING
|
110
110
|
- Gemfile
|
111
|
-
- LICENSE.txt
|
112
111
|
- README.md
|
113
112
|
- Rakefile
|
114
113
|
- bin/postrunner
|
115
114
|
- lib/postrunner.rb
|
116
115
|
- lib/postrunner/ActivitiesDB.rb
|
117
116
|
- lib/postrunner/Activity.rb
|
118
|
-
- lib/postrunner/
|
117
|
+
- lib/postrunner/ActivityListView.rb
|
118
|
+
- lib/postrunner/ActivitySummary.rb
|
119
119
|
- lib/postrunner/ActivityView.rb
|
120
120
|
- lib/postrunner/ChartView.rb
|
121
|
+
- lib/postrunner/DeviceList.rb
|
121
122
|
- lib/postrunner/FlexiTable.rb
|
122
123
|
- lib/postrunner/HTMLBuilder.rb
|
123
124
|
- lib/postrunner/Main.rb
|
124
125
|
- lib/postrunner/PersonalRecords.rb
|
126
|
+
- lib/postrunner/RuntimeConfig.rb
|
125
127
|
- lib/postrunner/TrackView.rb
|
128
|
+
- lib/postrunner/UserProfileView.rb
|
126
129
|
- lib/postrunner/ViewWidgets.rb
|
127
130
|
- lib/postrunner/version.rb
|
128
131
|
- misc/flot/API.md
|
@@ -235,6 +238,17 @@ files:
|
|
235
238
|
- misc/flot/jquery.flot.time.min.js
|
236
239
|
- misc/flot/jquery.js
|
237
240
|
- misc/flot/jquery.min.js
|
241
|
+
- misc/icons/back.png
|
242
|
+
- misc/icons/back.svg
|
243
|
+
- misc/icons/first.png
|
244
|
+
- misc/icons/first.svg
|
245
|
+
- misc/icons/forward.png
|
246
|
+
- misc/icons/forward.svg
|
247
|
+
- misc/icons/home.png
|
248
|
+
- misc/icons/home.svg
|
249
|
+
- misc/icons/last.png
|
250
|
+
- misc/icons/last.svg
|
251
|
+
- misc/icons/lgpl-3.0.txt
|
238
252
|
- misc/jquery/jquery-2.1.1.min.js
|
239
253
|
- misc/openlayers/.gitignore
|
240
254
|
- misc/openlayers/OpenLayers.debug.js
|
@@ -1444,8 +1458,10 @@ files:
|
|
1444
1458
|
- misc/openlayers/tools/uglify_js.py
|
1445
1459
|
- misc/openlayers/tools/update_dev_dir.sh
|
1446
1460
|
- postrunner.gemspec
|
1461
|
+
- spec/ActivitySummary_spec.rb
|
1447
1462
|
- spec/FlexiTable_spec.rb
|
1448
1463
|
- spec/PostRunner_spec.rb
|
1464
|
+
- spec/spec_helper.rb
|
1449
1465
|
homepage: https://github.com/scrapper/postrunner
|
1450
1466
|
licenses:
|
1451
1467
|
- GNU GPL version 2
|
@@ -1471,6 +1487,8 @@ signing_key:
|
|
1471
1487
|
specification_version: 4
|
1472
1488
|
summary: Application to manage and analyze Garmin FIT files.
|
1473
1489
|
test_files:
|
1490
|
+
- spec/ActivitySummary_spec.rb
|
1474
1491
|
- spec/FlexiTable_spec.rb
|
1475
1492
|
- spec/PostRunner_spec.rb
|
1493
|
+
- spec/spec_helper.rb
|
1476
1494
|
has_rdoc:
|
data/LICENSE.txt
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
Copyright (c) 2014 Chris Schlaeger
|
2
|
-
|
3
|
-
MIT License
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
-
a copy of this software and associated documentation files (the
|
7
|
-
"Software"), to deal in the Software without restriction, including
|
8
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
-
permit persons to whom the Software is furnished to do so, subject to
|
11
|
-
the following conditions:
|
12
|
-
|
13
|
-
The above copyright notice and this permission notice shall be
|
14
|
-
included in all copies or substantial portions of the Software.
|
15
|
-
|
16
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -1,102 +0,0 @@
|
|
1
|
-
require 'fit4ruby'
|
2
|
-
|
3
|
-
require 'postrunner/FlexiTable'
|
4
|
-
require 'postrunner/ViewWidgets'
|
5
|
-
|
6
|
-
module PostRunner
|
7
|
-
|
8
|
-
class ActivityReport
|
9
|
-
|
10
|
-
include Fit4Ruby::Converters
|
11
|
-
include ViewWidgets
|
12
|
-
|
13
|
-
def initialize(activity)
|
14
|
-
@activity = activity
|
15
|
-
end
|
16
|
-
|
17
|
-
def to_s
|
18
|
-
session = @activity.sessions[0]
|
19
|
-
|
20
|
-
summary(session).to_s + "\n" + laps.to_s
|
21
|
-
end
|
22
|
-
|
23
|
-
def to_html(doc)
|
24
|
-
session = @activity.sessions[0]
|
25
|
-
|
26
|
-
frame(doc, 'Summary') {
|
27
|
-
summary(session).to_html(doc)
|
28
|
-
}
|
29
|
-
frame(doc, 'Laps') {
|
30
|
-
laps.to_html(doc)
|
31
|
-
}
|
32
|
-
end
|
33
|
-
|
34
|
-
private
|
35
|
-
|
36
|
-
def summary(session)
|
37
|
-
t = FlexiTable.new
|
38
|
-
t.enable_frame(false)
|
39
|
-
t.body
|
40
|
-
t.row([ 'Date:', session.timestamp])
|
41
|
-
t.row([ 'Distance:', "#{'%.2f' % (session.total_distance / 1000.0)} km" ])
|
42
|
-
t.row([ 'Time:', secsToHMS(session.total_timer_time) ])
|
43
|
-
t.row([ 'Avg. Pace:',
|
44
|
-
"#{speedToPace(session.avg_speed)} min/km" ])
|
45
|
-
t.row([ 'Total Ascend:', "#{session.total_ascend} m" ])
|
46
|
-
t.row([ 'Total Descend:', "#{session.total_descent} m" ])
|
47
|
-
t.row([ 'Calories:', "#{session.total_calories} kCal" ])
|
48
|
-
t.row([ 'Avg. HR:', session.avg_heart_rate ?
|
49
|
-
"#{session.avg_heart_rate} bpm" : '-' ])
|
50
|
-
t.row([ 'Max. HR:', session.max_heart_rate ?
|
51
|
-
"#{session.max_heart_rate} bpm" : '-' ])
|
52
|
-
t.row([ 'Training Effect:', session.total_training_effect ?
|
53
|
-
session.total_training_effect : '-' ])
|
54
|
-
t.row([ 'Avg. Run Cadence:',
|
55
|
-
session.avg_running_cadence ?
|
56
|
-
"#{session.avg_running_cadence.round} spm" : '-' ])
|
57
|
-
t.row([ 'Avg. Vertical Oscillation:',
|
58
|
-
session.avg_vertical_oscillation ?
|
59
|
-
"#{'%.1f' % (session.avg_vertical_oscillation / 10)} cm" : '-' ])
|
60
|
-
t.row([ 'Avg. Ground Contact Time:',
|
61
|
-
session.avg_stance_time ?
|
62
|
-
"#{session.avg_stance_time.round} ms" : '-' ])
|
63
|
-
t.row([ 'Avg. Stride Length:',
|
64
|
-
session.avg_stride_length ?
|
65
|
-
"#{'%.2f' % (session.avg_stride_length / 2)} m" : '-' ])
|
66
|
-
rec_time = @activity.recovery_time
|
67
|
-
t.row([ 'Recovery Time:', rec_time ? secsToHMS(rec_time * 60) : '-' ])
|
68
|
-
vo2max = @activity.vo2max
|
69
|
-
t.row([ 'VO2max:', vo2max ? vo2max : '-' ])
|
70
|
-
|
71
|
-
t
|
72
|
-
end
|
73
|
-
|
74
|
-
def laps
|
75
|
-
t = FlexiTable.new
|
76
|
-
t.head
|
77
|
-
t.row([ 'Lap', 'Duration', 'Distance', 'Avg. Pace', 'Stride', 'Cadence',
|
78
|
-
'Avg. HR', 'Max. HR' ])
|
79
|
-
t.set_column_attributes(Array.new(8, { :halign => :right }))
|
80
|
-
t.body
|
81
|
-
@activity.sessions[0].laps.each.with_index do |lap, index|
|
82
|
-
t.cell(index + 1)
|
83
|
-
t.cell(secsToHMS(lap.total_timer_time))
|
84
|
-
t.cell('%.2f' % (lap.total_distance / 1000.0))
|
85
|
-
t.cell(speedToPace(lap.avg_speed))
|
86
|
-
t.cell(lap.total_strides ?
|
87
|
-
'%.2f' % (lap.total_distance / (2 * lap.total_strides)) : '')
|
88
|
-
t.cell(lap.avg_running_cadence && lap.avg_fractional_cadence ?
|
89
|
-
'%.1f' % (2 * lap.avg_running_cadence +
|
90
|
-
(2 * lap.avg_fractional_cadence) / 100.0) : '')
|
91
|
-
t.cell(lap.avg_heart_rate.to_s)
|
92
|
-
t.cell(lap.max_heart_rate.to_s)
|
93
|
-
t.new_row
|
94
|
-
end
|
95
|
-
|
96
|
-
t
|
97
|
-
end
|
98
|
-
|
99
|
-
end
|
100
|
-
|
101
|
-
end
|
102
|
-
|