Package gfit: Calculate "average" heart rate.
authorFlorian Forster <ff@octo.it>
Tue, 16 Jan 2018 21:35:29 +0000 (22:35 +0100)
committerFlorian Forster <ff@octo.it>
Tue, 16 Jan 2018 21:36:01 +0000 (22:36 +0100)
JSON does not support NaN data points.

gfit/gfit.go

index fcd88f1..33e5a66 100644 (file)
@@ -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),