Package gfit: Change Activity.Type to be a string.
[kraftakt.git] / gfit / gfit.go
index 4993725..36e5d5f 100644 (file)
@@ -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},
                        },
                })
        }