X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=gfit%2Fgfit.go;h=ea41b95df86fcce6357b3624908e93084e44813e;hb=4b89d270e3125a5184896db627520b915ffec635;hp=fcd88f12cdf488bdfc49647515b5c5a703084507;hpb=2eac6c527c6997568372a3f3e3d7c09d86aec78e;p=kraftakt.git diff --git a/gfit/gfit.go b/gfit/gfit.go index fcd88f1..ea41b95 100644 --- a/gfit/gfit.go +++ b/gfit/gfit.go @@ -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),