X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=gfit%2Fgfit.go;h=69308a79d5e3dd9837b8534015d5ccd9316c64f7;hb=304308a757d192b9b80455017bda1cb82889d346;hp=d1aacb6895bd923c9238c76a923a07e968b670ae;hpb=87ea973ac5c3cb92de4847717f556ec9b30f2cbc;p=kraftakt.git diff --git a/gfit/gfit.go b/gfit/gfit.go index d1aacb6..69308a7 100644 --- a/gfit/gfit.go +++ b/gfit/gfit.go @@ -7,8 +7,8 @@ import ( "strings" "time" - "github.com/octo/gfitsync/app" - "github.com/octo/gfitsync/fitbit" + "github.com/octo/kraftakt/app" + "github.com/octo/kraftakt/fitbit" "golang.org/x/oauth2" oauth2google "golang.org/x/oauth2/google" fitness "google.golang.org/api/fitness/v1" @@ -120,7 +120,7 @@ func (c *Client) DataSourceCreate(ctx context.Context, dataSource *fitness.DataS } return DataStreamID(dataSource), nil } - log.Errorf(ctx, "c.Service.Users.DataSources.Create() = (%+v, %v)", res, err) + log.Errorf(ctx, "c.Service.Users.DataSources.Create(%q) = (%+v, %v)", dataSource, res, err) return "", err } return res.DataStreamId, nil @@ -234,12 +234,22 @@ func (c *Client) SetActivities(ctx context.Context, activities []Activity, start return nil } - dataStreamID := DataStreamID(&fitness.DataSource{ + dataStreamID, err := c.DataSourceCreate(ctx, &fitness.DataSource{ + Application: Application(ctx), DataType: &fitness.DataType{ + Field: []*fitness.DataTypeField{ + &fitness.DataTypeField{ + Name: "activity", + Format: "integer", + }, + }, Name: dataTypeNameActivitySegment, }, Type: "raw", }) + if err != nil { + return err + } endOfDay := startOfDay.Add(24 * time.Hour).Add(-1 * time.Nanosecond) @@ -332,7 +342,7 @@ func (c *Client) updateCumulative(ctx context.Context, dataSource *fitness.DataS if now := time.Now().In(startOfDay.Location()); now.Before(endOfDay) { endTime = now } - log.Debugf(ctx, "adding cumulative data point: %v-%v %+v", startTime, endTime, diffValue) + log.Debugf(ctx, "add cumulative data %s until %v: %+v", dataSource.DataStreamId, endTime, diffValue) return c.DataSetPatch(ctx, dataSource.DataStreamId, []*fitness.DataPoint{ &fitness.DataPoint{ @@ -354,6 +364,7 @@ func (c *Client) readCumulative(ctx context.Context, dataSource *fitness.DataSou } if len(res.Point) == 0 { + log.Debugf(ctx, "read cumulative data %s until %v: []", dataSource.DataStreamId, endTime) return &fitness.Value{}, startTime, nil }