fitdata

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2024 License: MIT Imports: 16 Imported by: 0

README

fitdata

A library to access some data that is uploaded to fitness sites I use

Documentation

Index

Constants

View Source
const STRAVA_API_BASE_URL = "https://www.strava.com/api/v3"

Variables

This section is empty.

Functions

func StravaCreateActivity

func StravaCreateActivity(strava StravaClient, activity StravaNewActivity) error

func WriteStravaClientToFile added in v0.3.0

func WriteStravaClientToFile(client StravaClient, path string) error

Types

type Athlete

type Athlete struct {
	ID                    int64         `json:"id"`
	Username              string        `json:"username"`
	ResourceState         int64         `json:"resource_state"`
	Firstname             string        `json:"firstname"`
	Lastname              string        `json:"lastname"`
	City                  string        `json:"city"`
	State                 string        `json:"state"`
	Country               string        `json:"country"`
	Sex                   string        `json:"sex"`
	Premium               bool          `json:"premium"`
	CreatedAt             string        `json:"created_at"`
	UpdatedAt             string        `json:"updated_at"`
	BadgeTypeID           int64         `json:"badge_type_id"`
	ProfileMedium         string        `json:"profile_medium"`
	Profile               string        `json:"profile"`
	Friend                interface{}   `json:"friend"`
	Follower              interface{}   `json:"follower"`
	FollowerCount         int64         `json:"follower_count"`
	FriendCount           int64         `json:"friend_count"`
	MutualFriendCount     int64         `json:"mutual_friend_count"`
	AthleteType           int64         `json:"athlete_type"`
	DatePreference        string        `json:"date_preference"`
	MeasurementPreference string        `json:"measurement_preference"`
	Clubs                 []interface{} `json:"clubs"`
	FTP                   interface{}   `json:"ftp"`
	Weight                float64       `json:"weight"`
	Bikes                 []Bike        `json:"bikes"`
	Shoes                 []Bike        `json:"shoes"`
}

type Bike

type Bike struct {
	ID            string `json:"id"`
	Primary       bool   `json:"primary"`
	Name          string `json:"name"`
	ResourceState int64  `json:"resource_state"`
	Distance      int64  `json:"distance"`
}

type DetailedSegmentEffort added in v0.2.0

type DetailedSegmentEffort struct {
	ID            int64  `json:"id"`
	ResourceState int    `json:"resource_state"`
	Name          string `json:"name"`
	Activity      struct {
		ID            int64 `json:"id"`
		ResourceState int   `json:"resource_state"`
	} `json:"activity"`
	Athlete        Athlete   `json:"athlete"`
	ElapsedTime    int       `json:"elapsed_time"`
	MovingTime     int       `json:"moving_time"`
	StartDate      time.Time `json:"start_date"`
	StartDateLocal time.Time `json:"start_date_local"`
	Distance       float64   `json:"distance"`
	StartIndex     int       `json:"start_index"`
	EndIndex       int       `json:"end_index"`
	AverageCadence float64   `json:"average_cadence"`
	DeviceWatts    bool      `json:"device_watts"`
	AverageWatts   float64   `json:"average_watts"`
	Segment        struct {
		ID            int       `json:"id"`
		ResourceState int       `json:"resource_state"`
		Name          string    `json:"name"`
		ActivityType  string    `json:"activity_type"`
		Distance      float64   `json:"distance"`
		AverageGrade  float64   `json:"average_grade"`
		MaximumGrade  float64   `json:"maximum_grade"`
		ElevationHigh float64   `json:"elevation_high"`
		ElevationLow  float64   `json:"elevation_low"`
		StartLatlng   []float64 `json:"start_latlng"`
		EndLatlng     []float64 `json:"end_latlng"`
		ClimbCategory int       `json:"climb_category"`
		City          string    `json:"city"`
		State         string    `json:"state"`
		Country       string    `json:"country"`
		Private       bool      `json:"private"`
		Hazardous     bool      `json:"hazardous"`
		Starred       bool      `json:"starred"`
	} `json:"segment"`
	KomRank      any   `json:"kom_rank"`
	PrRank       any   `json:"pr_rank"`
	Achievements []any `json:"achievements"`
	Hidden       bool  `json:"hidden"`
}

type FitbitActivity

type FitbitActivity struct {
	ActiveDuration        int64                       `json:"activeDuration"`
	ActivityLevel         []FitbitActivityLevel       `json:"activityLevel"`
	ActivityName          string                      `json:"activityName"`
	ActivityTypeID        int64                       `json:"activityTypeId"`
	Calories              int64                       `json:"calories"`
	CaloriesLink          string                      `json:"caloriesLink"`
	Duration              int64                       `json:"duration"`
	ElevationGain         float64                     `json:"elevationGain"`
	LastModified          string                      `json:"lastModified"`
	LogID                 int64                       `json:"logId"`
	LogType               string                      `json:"logType"`
	ManualValuesSpecified FitbitManualValuesSpecified `json:"manualValuesSpecified"`
	OriginalDuration      int64                       `json:"originalDuration"`
	OriginalStartTime     string                      `json:"originalStartTime"`
	StartTime             string                      `json:"startTime"`
	Steps                 int64                       `json:"steps"`
	TcxLink               string                      `json:"tcxLink"`
}

func FitbitGetActivities

func FitbitGetActivities(fitbit FitbitClient, after time.Time) ([]FitbitActivity, error)

func (FitbitActivity) ActivityTypeName

func (a FitbitActivity) ActivityTypeName(fitbit FitbitClient) string

type FitbitActivityLevel

type FitbitActivityLevel struct {
	Minutes int64  `json:"minutes"`
	Name    string `json:"name"`
}

type FitbitClient

type FitbitClient struct {
	Token fitbitAuthToken
	// contains filtered or unexported fields
}

func NewFitbitClient

func NewFitbitClient(clientID, clientSecret string) (FitbitClient, error)

type FitbitManualValuesSpecified

type FitbitManualValuesSpecified struct {
	Calories bool `json:"calories"`
	Distance bool `json:"distance"`
	Steps    bool `json:"steps"`
}

type Map

type Map struct {
	ID              string      `json:"id"`
	SummaryPolyline interface{} `json:"summary_polyline"`
	ResourceState   int64       `json:"resource_state"`
}

type Photos

type Photos struct {
	Primary struct {
		ID       any    `json:"id"`
		UniqueID string `json:"unique_id"`
		Urls     struct {
			Num100 string `json:"100"`
			Num600 string `json:"600"`
		} `json:"urls"`
		Source int `json:"source"`
	} `json:"primary"`
	UsePrimaryPhoto bool  `json:"use_primary_photo"`
	Count           int64 `json:"count"`
}

type StatsVisibility

type StatsVisibility struct {
	Type       string `json:"type"`
	Visibility string `json:"visibility"`
}

type StravaActivity

type StravaActivity struct {
	ResourceState              int64                   `json:"resource_state"`
	Athlete                    Athlete                 `json:"athlete"`
	Name                       string                  `json:"name"`
	Distance                   float64                 `json:"distance"`
	MovingTime                 int64                   `json:"moving_time"`
	ElapsedTime                int64                   `json:"elapsed_time"`
	TotalElevationGain         float64                 `json:"total_elevation_gain"`
	Type                       string                  `json:"type"`
	WorkoutType                int64                   `json:"workout_type,omitempty"`
	ID                         int64                   `json:"id"`
	ExternalID                 string                  `json:"external_id,omitempty"`
	UploadID                   int64                   `json:"upload_id,omitempty"`
	StartDate                  string                  `json:"start_date"`
	StartDateLocal             string                  `json:"start_date_local"`
	Timezone                   string                  `json:"timezone"`
	UTCOffset                  float64                 `json:"utc_offset"`
	StartLatlng                interface{}             `json:"start_latlng"`
	EndLatlng                  interface{}             `json:"end_latlng"`
	LocationCity               interface{}             `json:"location_city"`
	LocationState              interface{}             `json:"location_state"`
	LocationCountry            string                  `json:"location_country"`
	AchievementCount           int64                   `json:"achievement_count"`
	KudosCount                 int64                   `json:"kudos_count"`
	CommentCount               int64                   `json:"comment_count"`
	AthleteCount               int64                   `json:"athlete_count"`
	PhotoCount                 int64                   `json:"photo_count"`
	Map                        Map                     `json:"map"`
	Trainer                    bool                    `json:"trainer"`
	Commute                    bool                    `json:"commute"`
	Manual                     bool                    `json:"manual"`
	Private                    bool                    `json:"private"`
	Visibility                 string                  `json:"visibility"`
	Flagged                    bool                    `json:"flagged"`
	GearID                     interface{}             `json:"gear_id"`
	StartLatitude              interface{}             `json:"start_latitude"`
	StartLongitude             interface{}             `json:"start_longitude"`
	AverageSpeed               float64                 `json:"average_speed"`
	MaxSpeed                   float64                 `json:"max_speed"`
	AverageCadence             float64                 `json:"average_cadence,omitempty"`
	AverageWatts               float64                 `json:"average_watts,omitempty"`
	WeightedAverageWatts       int64                   `json:"weighted_average_watts,omitempty"`
	Kilojoules                 float64                 `json:"kilojoules,omitempty"`
	DeviceWatts                bool                    `json:"device_watts,omitempty"`
	HasHeartrate               bool                    `json:"has_heartrate"`
	AverageHeartrate           float64                 `json:"average_heartrate,omitempty"`
	MaxHeartrate               float64                 `json:"max_heartrate,omitempty"`
	MaxWatts                   int64                   `json:"max_watts,omitempty"`
	HeartrateOptOut            bool                    `json:"heartrate_opt_out"`
	DisplayHideHeartrateOption bool                    `json:"display_hide_heartrate_option"`
	FromAcceptedTag            bool                    `json:"from_accepted_tag"`
	PRCount                    int64                   `json:"pr_count"`
	TotalPhotoCount            int64                   `json:"total_photo_count"`
	HasKudoed                  bool                    `json:"has_kudoed"`
	SufferScore                int64                   `json:"suffer_score,omitempty"`
	Description                string                  `json:"description"`
	Calories                   float64                 `json:"calories"`
	PerceivedExertion          interface{}             `json:"perceived_exertion"`
	PreferPerceivedExertion    interface{}             `json:"prefer_perceived_exertion"`
	SegmentEfforts             []DetailedSegmentEffort `json:"segment_efforts"`
	BestEfforts                []DetailedSegmentEffort `json:"best_efforts"`
	Photos                     Photos                  `json:"photos"`
	StatsVisibility            []StatsVisibility       `json:"stats_visibility"`
	HideFromHome               bool                    `json:"hide_from_home"`
	EmbedToken                 string                  `json:"embed_token"`
	PrivateNote                interface{}             `json:"private_note"`
	AvailableZones             []interface{}           `json:"available_zones"`
}

https://developers.strava.com/docs/reference/#api-models-DetailedActivity

func StravaGetActivities

func StravaGetActivities(strava StravaClient, after time.Time) ([]StravaActivity, error)

func StravaGetActivityByID

func StravaGetActivityByID(strava StravaClient, id int64) (StravaActivity, error)

type StravaClient

type StravaClient struct {
	ClientID     string          `json:"client_id"`
	ClientSecret string          `json:"client_secret"`
	Token        stravaAuthToken `json:"token"`
}

func NewStravaClient

func NewStravaClient(clientID, clientSecret string) (StravaClient, error)

func ReadStravaClientFromFile added in v0.3.0

func ReadStravaClientFromFile(path string) (StravaClient, error)

func RefreshStravaClient added in v0.3.0

func RefreshStravaClient(client StravaClient) (StravaClient, error)

func (*StravaClient) IsExpired added in v0.3.0

func (c *StravaClient) IsExpired() bool

type StravaDetailedActivity added in v0.2.0

type StravaDetailedActivity struct {
	ID                   int64                   `json:"id"`
	ResourceState        int                     `json:"resource_state"`
	ExternalID           string                  `json:"external_id"`
	UploadID             int64                   `json:"upload_id"`
	Athlete              Athlete                 `json:"athlete"`
	Name                 string                  `json:"name"`
	Distance             int                     `json:"distance"`
	MovingTime           int                     `json:"moving_time"`
	ElapsedTime          int                     `json:"elapsed_time"`
	TotalElevationGain   int                     `json:"total_elevation_gain"`
	Type                 string                  `json:"type"`
	SportType            string                  `json:"sport_type"`
	StartDate            time.Time               `json:"start_date"`
	StartDateLocal       time.Time               `json:"start_date_local"`
	Timezone             string                  `json:"timezone"`
	UtcOffset            int                     `json:"utc_offset"`
	StartLatlng          []float64               `json:"start_latlng"`
	EndLatlng            []float64               `json:"end_latlng"`
	AchievementCount     int                     `json:"achievement_count"`
	KudosCount           int                     `json:"kudos_count"`
	CommentCount         int                     `json:"comment_count"`
	AthleteCount         int                     `json:"athlete_count"`
	PhotoCount           int                     `json:"photo_count"`
	Map                  Map                     `json:"map"`
	Trainer              bool                    `json:"trainer"`
	Commute              bool                    `json:"commute"`
	Manual               bool                    `json:"manual"`
	Private              bool                    `json:"private"`
	Flagged              bool                    `json:"flagged"`
	GearID               string                  `json:"gear_id"`
	FromAcceptedTag      bool                    `json:"from_accepted_tag"`
	AverageSpeed         float64                 `json:"average_speed"`
	MaxSpeed             float64                 `json:"max_speed"`
	AverageCadence       float64                 `json:"average_cadence"`
	AverageTemp          int                     `json:"average_temp"`
	AverageWatts         float64                 `json:"average_watts"`
	WeightedAverageWatts int                     `json:"weighted_average_watts"`
	Kilojoules           float64                 `json:"kilojoules"`
	DeviceWatts          bool                    `json:"device_watts"`
	HasHeartrate         bool                    `json:"has_heartrate"`
	MaxWatts             int                     `json:"max_watts"`
	ElevHigh             float64                 `json:"elev_high"`
	ElevLow              float64                 `json:"elev_low"`
	PrCount              int                     `json:"pr_count"`
	TotalPhotoCount      int                     `json:"total_photo_count"`
	HasKudoed            bool                    `json:"has_kudoed"`
	WorkoutType          int                     `json:"workout_type"`
	SufferScore          any                     `json:"suffer_score"`
	Description          string                  `json:"description"`
	Calories             float64                 `json:"calories"`
	SegmentEfforts       []DetailedSegmentEffort `json:"segment_efforts"`
	SplitsMetric         []struct {
		Distance            float64 `json:"distance"`
		ElapsedTime         int     `json:"elapsed_time"`
		ElevationDifference float64 `json:"elevation_difference"`
		MovingTime          int     `json:"moving_time"`
		Split               int     `json:"split"`
		AverageSpeed        float64 `json:"average_speed"`
		PaceZone            int     `json:"pace_zone"`
	} `json:"splits_metric"`
	Laps []struct {
		ID            int64  `json:"id"`
		ResourceState int    `json:"resource_state"`
		Name          string `json:"name"`
		Activity      struct {
			ID            int `json:"id"`
			ResourceState int `json:"resource_state"`
		} `json:"activity"`
		Athlete struct {
			ID            int `json:"id"`
			ResourceState int `json:"resource_state"`
		} `json:"athlete"`
		ElapsedTime        int       `json:"elapsed_time"`
		MovingTime         int       `json:"moving_time"`
		StartDate          time.Time `json:"start_date"`
		StartDateLocal     time.Time `json:"start_date_local"`
		Distance           float64   `json:"distance"`
		StartIndex         int       `json:"start_index"`
		EndIndex           int       `json:"end_index"`
		TotalElevationGain int       `json:"total_elevation_gain"`
		AverageSpeed       float64   `json:"average_speed"`
		MaxSpeed           float64   `json:"max_speed"`
		AverageCadence     float64   `json:"average_cadence"`
		DeviceWatts        bool      `json:"device_watts"`
		AverageWatts       float64   `json:"average_watts"`
		LapIndex           int       `json:"lap_index"`
		Split              int       `json:"split"`
	} `json:"laps"`
	Gear struct {
		ID            string `json:"id"`
		Primary       bool   `json:"primary"`
		Name          string `json:"name"`
		ResourceState int    `json:"resource_state"`
		Distance      int    `json:"distance"`
	} `json:"gear"`
	PartnerBrandTag     any    `json:"partner_brand_tag"`
	Photos              Photos `json:"photos"`
	HighlightedKudosers []struct {
		DestinationURL string `json:"destination_url"`
		DisplayName    string `json:"display_name"`
		AvatarURL      string `json:"avatar_url"`
		ShowName       bool   `json:"show_name"`
	} `json:"highlighted_kudosers"`
	HideFromHome             bool   `json:"hide_from_home"`
	DeviceName               string `json:"device_name"`
	EmbedToken               string `json:"embed_token"`
	SegmentLeaderboardOptOut bool   `json:"segment_leaderboard_opt_out"`
	LeaderboardOptOut        bool   `json:"leaderboard_opt_out"`
}

type StravaNewActivity

type StravaNewActivity struct {
	Name, Type, Description string
	StartDate               time.Time
	ElapsedSeconds          int64
}

name required String, in form The name of the activity. type required String, in form Type of activity. For example - Run, Ride etc. start_date_local required Date, in form ISO 8601 formatted date time. elapsed_time required Integer, in form In seconds. description String, in form Description of the activity. distance Float, in form In meters.

Jump to

Keyboard shortcuts

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