From: Florian Forster Date: Tue, 16 Jan 2018 21:35:29 +0000 (+0100) Subject: Package gfit: Calculate "average" heart rate. X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=3313c545eece0a29c49e7e1621e491d88f2f957b;p=kraftakt.git Package gfit: Calculate "average" heart rate. JSON does not support NaN data points. --- diff --git a/gfit/gfit.go b/gfit/gfit.go index fcd88f1..33e5a66 100644 --- a/gfit/gfit.go +++ b/gfit/gfit.go @@ -3,7 +3,6 @@ package gfit import ( "context" "fmt" - "math" "net/http" "strings" "time" @@ -417,13 +416,18 @@ func (c *Client) SetHeartRate(ctx context.Context, totalDurations []fitbit.Heart break } + average := float64(d.Min+d.Max) / 2.0 + if d.Min <= restingHeartRate && restingHeartRate <= d.Max { + average = float64(restingHeartRate) + } + dataPoints = append(dataPoints, &fitness.DataPoint{ DataTypeName: dataSource.DataType.Name, StartTimeNanos: startTime.UnixNano(), EndTimeNanos: endTime.UnixNano(), Value: []*fitness.Value{ &fitness.Value{ - FpVal: math.NaN(), + FpVal: average, }, &fitness.Value{ FpVal: float64(d.Max),