teich-hrmparser 0.3.1 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.txt +5 -1
- data/VERSION.yml +2 -2
- data/lib/hrmparser/importer/polar.rb +0 -2
- data/lib/hrmparser/importer/suunto.rb +78 -0
- data/lib/hrmparser/importer.rb +21 -16
- data/spec/hrmparser_spec.rb +23 -4
- metadata +3 -2
data/CHANGELOG.txt
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
|
+
0.4.0 - May 8th, 2009
|
|
2
|
+
Added initial support for Suunto T6. Just grabs HRs for now.
|
|
3
|
+
|
|
1
4
|
0.3.1 - May 6th, 2009
|
|
2
5
|
Handles missing data in a trackpoint now, including no lat and lng.
|
|
3
6
|
|
|
4
7
|
0.2.3
|
|
5
|
-
Now should keep lat and lng set to nil when they don't exist in garmin files.
|
|
8
|
+
Now should keep lat and lng set to nil when they don't exist in garmin files.
|
|
9
|
+
|
data/VERSION.yml
CHANGED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
module Importer
|
|
2
|
+
class Suunto
|
|
3
|
+
attr_reader :time_zone
|
|
4
|
+
|
|
5
|
+
def initialize(opts = {:data => nil, :time_zone => "UTC"})
|
|
6
|
+
@data = opts[:data]
|
|
7
|
+
@time_zone = opts[:time_zone]
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def restore
|
|
11
|
+
workout = HRMParser::Workout.new(:duration => 0)
|
|
12
|
+
|
|
13
|
+
params = parse_params("HEADER")
|
|
14
|
+
dt = DateTime.strptime(params["STARTTIME"] + " " + @time_zone, "%d.%m.%Y %H:%M.%S %Z")
|
|
15
|
+
workout.time = Time.parse(dt.to_s)
|
|
16
|
+
workout.duration = params["DURATION"].to_f
|
|
17
|
+
|
|
18
|
+
workout.trackpoints = get_trackpoints
|
|
19
|
+
|
|
20
|
+
workout.calc_average_hr!
|
|
21
|
+
return workout
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
private
|
|
25
|
+
|
|
26
|
+
def parse_params(string)
|
|
27
|
+
hash = {}
|
|
28
|
+
param_block = find_block(string)
|
|
29
|
+
param_block.each do |param|
|
|
30
|
+
# /=/ in case that doesn't work
|
|
31
|
+
key, value = param.split("=", 2)
|
|
32
|
+
key = key.strip unless key.nil?
|
|
33
|
+
value = value.strip unless value.nil?
|
|
34
|
+
hash[key] = value unless key.nil?
|
|
35
|
+
end
|
|
36
|
+
return hash
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def find_block(header)
|
|
40
|
+
found = false
|
|
41
|
+
block = []
|
|
42
|
+
@data.each do |line|
|
|
43
|
+
line.chomp!
|
|
44
|
+
found = false if line =~ /^\[.*\]$/
|
|
45
|
+
block << line if found
|
|
46
|
+
found = true if line =~ /\[#{header}\]/
|
|
47
|
+
end
|
|
48
|
+
return block
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def parse_data(string)
|
|
52
|
+
data = []
|
|
53
|
+
block_text = find_block(string)
|
|
54
|
+
block_text.each do |block_line|
|
|
55
|
+
data << block_line.chomp
|
|
56
|
+
end
|
|
57
|
+
return data
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def get_trackpoints
|
|
61
|
+
trackpoints = []
|
|
62
|
+
logs = parse_data("POINTS")
|
|
63
|
+
for line in logs do
|
|
64
|
+
type, date, time, altitude, blank, blank, hr, epoc, respiration, ventilation, vo2, kcal, blank, blank, blank, blank, blank, temp = line.split(/,/)
|
|
65
|
+
next if type == "\"T6LAP\""
|
|
66
|
+
|
|
67
|
+
trackpoint = HRMParser::TrackPoint.new
|
|
68
|
+
|
|
69
|
+
dt = DateTime.strptime(date + " " + time + " " + @time_zone, "%d.%m.%Y %H:%M.%S %Z")
|
|
70
|
+
trackpoint.time = Time.parse(dt.to_s)
|
|
71
|
+
trackpoint.hr = hr.to_i
|
|
72
|
+
|
|
73
|
+
trackpoints << trackpoint
|
|
74
|
+
end
|
|
75
|
+
return trackpoints
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
data/lib/hrmparser/importer.rb
CHANGED
|
@@ -1,20 +1,25 @@
|
|
|
1
1
|
require 'importer/garmin'
|
|
2
2
|
require 'importer/polar'
|
|
3
|
+
require 'importer/suunto'
|
|
3
4
|
|
|
4
5
|
module Importer
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
6
|
+
def Importer.file_type(name)
|
|
7
|
+
case name
|
|
8
|
+
when /\.tcx$/i
|
|
9
|
+
return "GARMIN_XML"
|
|
10
|
+
when /\.hrm$/i
|
|
11
|
+
return "POLAR_HRM"
|
|
12
|
+
when /\.sdf$/i
|
|
13
|
+
return "SUUNTO"
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def Importer.read_in_file(name)
|
|
18
|
+
if File.readable?(name)
|
|
19
|
+
return open(name, "r")
|
|
20
|
+
else
|
|
21
|
+
puts "FILE ERROR, can't read #{name}"
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
data/spec/hrmparser_spec.rb
CHANGED
|
@@ -78,7 +78,7 @@ module HRMParser
|
|
|
78
78
|
workout.altitude_gain.should be_nil
|
|
79
79
|
workout.trackpoints.should == {}
|
|
80
80
|
end
|
|
81
|
-
|
|
81
|
+
|
|
82
82
|
# Parsing the full XML is just slow. Commenting out for now.
|
|
83
83
|
it "gets workout level settings for outdoor workout" do
|
|
84
84
|
filename = "spec/samples/outdoor-garmin-405.TCX"
|
|
@@ -90,7 +90,7 @@ module HRMParser
|
|
|
90
90
|
workout.average_speed.should be_close(1.5, 0.2)
|
|
91
91
|
workout.altitude_gain.should be_close(583, 1.0)
|
|
92
92
|
end
|
|
93
|
-
|
|
93
|
+
|
|
94
94
|
it "gets workout level settings for weird distance workout" do
|
|
95
95
|
filename = "spec/samples/garmin-405-dies-distance.TCX"
|
|
96
96
|
data = File.read(filename)
|
|
@@ -101,7 +101,7 @@ module HRMParser
|
|
|
101
101
|
workout.average_speed.should be_close(6.7, 0.2)
|
|
102
102
|
workout.altitude_gain.should be_close(40, 1.0)
|
|
103
103
|
end
|
|
104
|
-
|
|
104
|
+
|
|
105
105
|
it "doesn't have any 0 in latitude" do
|
|
106
106
|
filename = "spec/samples/garmin-405-with-0-0.TCX"
|
|
107
107
|
data = File.read(filename)
|
|
@@ -111,7 +111,7 @@ module HRMParser
|
|
|
111
111
|
workout.trackpoints.map {|tp| tp.lat.should_not == "undefined"}
|
|
112
112
|
end
|
|
113
113
|
end
|
|
114
|
-
|
|
114
|
+
|
|
115
115
|
context "Parse polar RS200 file" do
|
|
116
116
|
it "finds the duration and time" do
|
|
117
117
|
filename ="spec/samples/polarRS200.hrm"
|
|
@@ -140,5 +140,24 @@ module HRMParser
|
|
|
140
140
|
workout.average_speed.should == nil
|
|
141
141
|
end
|
|
142
142
|
end
|
|
143
|
+
|
|
144
|
+
context "Parse a Suunto T6C RR file" do
|
|
145
|
+
it "finds the duration and time" do
|
|
146
|
+
filename = "spec/samples/suunto-t6-RR-stops.sdf"
|
|
147
|
+
data = File.read(filename)
|
|
148
|
+
importer = Importer::Suunto.new(:data => data, :time_zone => "-0700")
|
|
149
|
+
workout = importer.restore
|
|
150
|
+
workout.duration.should be_close(4781,1)
|
|
151
|
+
workout.time.should == Time.parse("Thu May 07 14:16:07 -0700 2009")
|
|
152
|
+
end
|
|
153
|
+
it "calculates the average HR" do
|
|
154
|
+
filename = "spec/samples/suunto-t6-RR-stops.sdf"
|
|
155
|
+
data = File.read(filename)
|
|
156
|
+
importer = Importer::Suunto.new(:data => data, :time_zone => "-0700")
|
|
157
|
+
workout = importer.restore
|
|
158
|
+
workout.average_hr.should be_close(152,1)
|
|
159
|
+
workout.average_speed.should == nil
|
|
160
|
+
end
|
|
161
|
+
end
|
|
143
162
|
end
|
|
144
163
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: teich-hrmparser
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.4.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Oren Teich
|
|
@@ -9,7 +9,7 @@ autorequire:
|
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
11
|
|
|
12
|
-
date: 2009-05-
|
|
12
|
+
date: 2009-05-08 00:00:00 -07:00
|
|
13
13
|
default_executable:
|
|
14
14
|
dependencies: []
|
|
15
15
|
|
|
@@ -31,6 +31,7 @@ files:
|
|
|
31
31
|
- lib/hrmparser/importer.rb
|
|
32
32
|
- lib/hrmparser/importer/garmin.rb
|
|
33
33
|
- lib/hrmparser/importer/polar.rb
|
|
34
|
+
- lib/hrmparser/importer/suunto.rb
|
|
34
35
|
- lib/hrmparser/trackpoint.rb
|
|
35
36
|
- lib/hrmparser/workout.rb
|
|
36
37
|
- spec/arraymath_spec.rb
|