From 428a91c3d1adc71f21d761bf9e96e7157b9d51c1 Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Thu, 1 Feb 2018 10:18:01 +0100 Subject: [PATCH] Package gfit: Change Activity.Type to be a string. This simplifies producing nice debug messages. --- gfit/gfit.go | 9 +++++---- kraftakt.go | 10 +++++----- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/gfit/gfit.go b/gfit/gfit.go index 4993725..36e5d5f 100644 --- a/gfit/gfit.go +++ b/gfit/gfit.go @@ -272,11 +272,11 @@ func (c *Client) SetCalories(ctx context.Context, totalCalories float64, startOf type Activity struct { Start time.Time End time.Time - Type int64 + Type string } func (a Activity) String() string { - return fmt.Sprintf("%s-%s %d", a.Start.Format("15:04:05"), a.End.Format("15:04:05"), a.Type) + return fmt.Sprintf("%s-%s %q", a.Start.Format("15:04:05"), a.End.Format("15:04:05"), a.Type) } func (c *Client) SetActivities(ctx context.Context, activities []Activity, startOfDay time.Time) error { @@ -313,9 +313,10 @@ Next: for _, a := range activities { startTimeNanos := a.Start.UnixNano() endTimeNanos := a.End.UnixNano() + activityType := ParseFitbitActivity(a.Type) for _, p := range dataset.Point { - if p.StartTimeNanos == startTimeNanos && p.EndTimeNanos == endTimeNanos && p.Value[0].IntVal == a.Type { + if p.StartTimeNanos == startTimeNanos && p.EndTimeNanos == endTimeNanos && p.Value[0].IntVal == activityType { log.Debugf(ctx, "activity %s already stored in Google Fit", a) continue Next } @@ -327,7 +328,7 @@ Next: StartTimeNanos: startTimeNanos, EndTimeNanos: endTimeNanos, Value: []*fitness.Value{ - &fitness.Value{IntVal: a.Type}, + &fitness.Value{IntVal: activityType}, }, }) } diff --git a/kraftakt.go b/kraftakt.go index 53d1764..a2b8b13 100644 --- a/kraftakt.go +++ b/kraftakt.go @@ -437,7 +437,7 @@ func activitiesNotification(ctx context.Context, s *fitbit.Subscription) error { activities = append(activities, gfit.Activity{ Start: startTime, End: endTime, - Type: gfit.ParseFitbitActivity(a.Name), + Type: a.Name, }) } if err := gfitClient.SetActivities(ctx, activities, tm); err != nil { @@ -500,13 +500,13 @@ func sleepNotification(ctx context.Context, s *fitbit.Subscription) error { } switch stg.Level { case fitbit.SleepLevelDeep: - a.Type = 110 // Deep sleep + a.Type = "Deep sleep" case fitbit.SleepLevelLight: - a.Type = 109 // Light sleep + a.Type = "Light sleep" case fitbit.SleepLevelREM: - a.Type = 111 // REM sleep + a.Type = "REM sleep" case fitbit.SleepLevelWake: - a.Type = 112 // Awake (during sleep cycle) + a.Type = "Awake (during sleep cycle)" default: log.Warningf(ctx, "unexpected sleep level %v", stg.Level) continue -- 2.11.0