Fixup: Pass RestingHeartRate to SetHeartRate().
[kraftakt.git] / gfit / gfit.go
index fcd88f1..ea41b95 100644 (file)
@@ -3,7 +3,6 @@ package gfit
 import (
        "context"
        "fmt"
-       "math"
        "net/http"
        "strings"
        "time"
@@ -344,7 +343,7 @@ func (c *Client) heartRate(ctx context.Context, dataSource *fitness.DataSource,
        return results, maxEndTime, nil
 }
 
-func (c *Client) SetHeartRate(ctx context.Context, totalDurations []fitbit.HeartRateZone, startOfDay time.Time) error {
+func (c *Client) SetHeartRate(ctx context.Context, totalDurations []fitbit.HeartRateZone, restingHeartRate int, startOfDay time.Time) error {
        dataSource := &fitness.DataSource{
                Application: Application(ctx),
                DataType: &fitness.DataType{
@@ -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),