Also subscribe to the "sleep" Fitbit collection.
[kraftakt.git] / gfit / gfit.go
index eca961c..d1aacb6 100644 (file)
@@ -225,7 +225,15 @@ type Activity struct {
        Type  int64
 }
 
+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)
+}
+
 func (c *Client) SetActivities(ctx context.Context, activities []Activity, startOfDay time.Time) error {
+       if len(activities) == 0 {
+               return nil
+       }
+
        dataStreamID := DataStreamID(&fitness.DataSource{
                DataType: &fitness.DataType{
                        Name: dataTypeNameActivitySegment,
@@ -249,13 +257,13 @@ Next:
                endTimeNanos := a.End.UnixNano()
 
                for _, p := range res.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 == a.Type {
+                               log.Debugf(ctx, "activity %s already stored in Google Fit", a)
                                continue Next
                        }
                }
 
+               log.Debugf(ctx, "activity %s will be added to Google Fit", a)
                dataPoints = append(dataPoints, &fitness.DataPoint{
                        DataTypeName:   dataTypeNameActivitySegment,
                        StartTimeNanos: startTimeNanos,