Skip to content
This repository has been archived by the owner on Nov 24, 2022. It is now read-only.

Commit

Permalink
Start exporting heart rate data again
Browse files Browse the repository at this point in the history
  • Loading branch information
Metalnem committed Dec 26, 2016
1 parent c735708 commit 623ec1d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
4 changes: 2 additions & 2 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -466,9 +466,9 @@ func merge(gpsData []gpsPoint, heartRateData []heartRatePoint) []DataPoint {
diff1 := gps.Time.Sub(hr1.Time)
diff2 := hr2.Time.Sub(gps.Time)

if diff1 <= diff2 && diff1 <= diff {
if diff1 <= diff2 && diff1 <= diff && hr1.HeartRate > 0 {
point.HeartRate = hr1.HeartRate
} else if diff2 <= diff1 && diff2 <= diff {
} else if diff2 <= diff1 && diff2 <= diff && hr2.HeartRate > 0 {
point.HeartRate = hr2.HeartRate
}
}
Expand Down
23 changes: 17 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,15 @@ type rfc3339Time struct {
}

type trackPoint struct {
Longitude float32 `xml:"lon,attr"`
Latitude float32 `xml:"lat,attr"`
Elevation float32 `xml:"ele,omitempty"`
Time rfc3339Time `xml:"time,omitempty"`
Longitude float32 `xml:"lon,attr"`
Latitude float32 `xml:"lat,attr"`
Elevation float32 `xml:"ele,omitempty"`
Time rfc3339Time `xml:"time,omitempty"`
Extensions *extensions `xml:"extensions,omitempty"`
}

type extensions struct {
HeartRate uint8 `xml:"gpxtpx:TrackPointExtension>gpxtpx:hr"`
}

type gpx struct {
Expand Down Expand Up @@ -115,12 +120,18 @@ func archive(filename string, activities []api.Activity) (err error) {
var points []trackPoint

for _, point := range activity.Data {
points = append(points, trackPoint{
tp := trackPoint{
Longitude: point.Longitude,
Latitude: point.Latitude,
Elevation: point.Elevation,
Time: rfc3339Time{point.Time},
})
}

if point.HeartRate > 0 {
tp.Extensions = &extensions{HeartRate: point.HeartRate}
}

points = append(points, tp)
}

data := gpx{
Expand Down

0 comments on commit 623ec1d

Please sign in to comment.