fitbolt

package module
v0.0.0-...-a622dc2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 23, 2018 License: MIT Imports: 12 Imported by: 0

README

fitbolt

Syncs from Fitbit API and stores data into a local Bolt database

Install

go install github.com/sajal/fitbolt/cmd/fitbolt

Usage

$ fitbolt --help
NAME:
   fitbolt - sync and query fitbit data locally

USAGE:
   fitbolt [global options] command [command options] [arguments...]

VERSION:
   0.0.1

COMMANDS:
     sync     Sync with fitbit, needs FITBIT_CLIENT and FITBIT_SECRET to be set
     steps    list steps by day
     help, h  Shows a list of commands or help for one command

GLOBAL OPTIONS:
   --dbpath value   path to bolt database(gets created if not exists) (default: "/home/sajal/fitsyncgo.db")
   --creds value    path to bolt database(gets created if not exists) (default: "/home/sajal/.fitsyncgo")
   --genesis value  The date to start fetching data from (default: "2016-01-01")
   --help, -h       show help
   --version, -v    print the version
sync

Register an app with Fitbit, make sure it is of type Personal

FITBIT_CLIENT="<OAuth 2.0 Client ID>" FITBIT_SECRET="<Client Secret>" fitbolt sync

This should start fetching data from genesis. Due to stringent rate-limits in Fitbit API, you can only fetch ~30 days of data per hour. So to bootstrap the database, you would need to run fitbolt every hour until it catches up.

Query sub commands

TODO

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ActivitiesSteps

type ActivitiesSteps struct {
	Dataset []*StepDataset `json:"dataset"`
}

ActivitiesSteps Stores intra-day steps activity

type BoltDB

type BoltDB struct {
	// contains filtered or unexported fields
}

BoltDB stores/retrieves our data from boltdb

func NewBoltDB

func NewBoltDB(dbpath string) (*BoltDB, error)

NewBoltDB returns a new instance of BoltDB

func (*BoltDB) Close

func (db *BoltDB) Close()

Close the bolt db

func (*BoltDB) GetDayDetail

func (db *BoltDB) GetDayDetail(ts time.Time) (ds *DayDetail, err error)

GetDayDetail retrieves data for a given day represented by ts.

func (*BoltDB) StoreDayDetail

func (db *BoltDB) StoreDayDetail(ts time.Time, ds *DayDetail) error

StoreDayDetail stores a day's data into the db

type DB

type DB interface {
	GetDayDetail(ts time.Time) (*DayDetail, error)
	StoreDayDetail(ts time.Time, ds *DayDetail) error
	Close()
}

DB interface to allow pluggable database backends in future... some day...

type DayDetail

type DayDetail struct {
	Date      time.Time          `json:"date"` //What date is this report about
	Fetched   time.Time          `json:"fetched"`
	Weight    *LogWeight         `json:"weight"`
	Activity  *fitbit.Activities `json:"activity"`
	Sleep     *fitbit.Sleep      `json:"sleep"`
	IsFinal   bool               `json:"isfinal"` //Is this report finalized? to not spam fitbit api again for it...
	Steps     *StepIntra         `json:"steps"`
	HeartRate *Heart             `json:"heart"`
}

DayDetail is all fitbit data we track for a single day

func (*DayDetail) DaySteps

func (ds *DayDetail) DaySteps() (steps uint64)

DaySteps returns total steps taken in a day

type Heart

type Heart struct {
	ActivityZones []*HeartActivityZones `json:"activities-heart"`
	IntraDay      *ActivitiesSteps      `json:"activities-heart-intraday"`
}

Heart Stores details about the heart

type HeartActivityZones

type HeartActivityZones struct {
	HeartRateZones *HeartRateZoneValue `json:"value"`
}

HeartActivityZones Stores heartrate zones

type HeartRateZone

type HeartRateZone struct {
	CaloriesOut float64 `json:"caloriesOut"`
	Max         int     `json:"max"`
	Min         int     `json:"min"`
	Name        string  `json:"name"`
}

HeartRateZone stores heart rate

type HeartRateZoneValue

type HeartRateZoneValue struct {
	HeartRateZone []*HeartRateZone `json:"heartRateZones"`
	Resting       int              `json:"restingHeartRate"`
}

HeartRateZoneValue Stores heartrate values

type LogWeight

type LogWeight struct {
	WeightLog []*fitbit.Weight `json:"weight"`
}

LogWeight stores Weight details. Upstream is broken...

type StepDataset

type StepDataset struct {
	Time  string `json:"time"`
	Value uint64 `json:"value"`
}

StepDataset Stores intra-day steps activity dataset

type StepIntra

type StepIntra struct {
	Steps *ActivitiesSteps `json:"activities-steps-intraday"`
}

StepIntra Stores intra-day steps activity

type Syncer

type Syncer struct {
	// contains filtered or unexported fields
}

Syncer syncs fitbit data to a DB

func NewSyncer

func NewSyncer(fname, fClient, fSecret string, db DB) (*Syncer, error)

NewSyncer creates a new syncer

func (*Syncer) Sync

func (sync *Syncer) Sync(genesis string) (err error)

Sync syncs from fitbit api starting from genisis

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL