From 623ec1dee30c307e6912ac45c73a8c67165b5e49 Mon Sep 17 00:00:00 2001 From: Metalnem Date: Mon, 26 Dec 2016 18:36:45 +0100 Subject: [PATCH] Start exporting heart rate data again --- api/api.go | 4 ++-- main.go | 23 +++++++++++++++++------ 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/api/api.go b/api/api.go index ea574bd..70605ae 100644 --- a/api/api.go +++ b/api/api.go @@ -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 } } diff --git a/main.go b/main.go index c14b775..0a37330 100644 --- a/main.go +++ b/main.go @@ -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 { @@ -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{