Skip to content
This repository has been archived by the owner on Nov 24, 2022. It is now read-only.

Commit

Permalink
Add support for activities with heart rate data only
Browse files Browse the repository at this point in the history
  • Loading branch information
Metalnem committed Dec 27, 2016
1 parent 729a45a commit 3811671
Showing 1 changed file with 27 additions and 17 deletions.
44 changes: 27 additions & 17 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ type activitiesResponse struct {
MoreItemsAvailable jsonBool `json:"moreItemsAvailable"`
Sessions []struct {
ID ActivityID `json:"id"`
DeletedAt string `json:"deletedAt"`
GPSTraceAvailable jsonBool `json:"gpsTraceAvailable"`
HeartRateAvailable jsonBool `json:"heartRateAvailable"`
} `json:"sessions"`
Expand All @@ -130,6 +131,22 @@ type activityResponse struct {
} `json:"runSessions"`
}

func (gps gpsPoint) DataPoint() DataPoint {
return DataPoint{
Longitude: gps.Longitude,
Latitude: gps.Latitude,
Elevation: gps.Elevation,
Time: gps.Time,
}
}

func (heartRate heartRatePoint) DataPoint() DataPoint {
return DataPoint{
Time: heartRate.Time,
HeartRate: heartRate.HeartRate,
}
}

func setHeaders(header http.Header) {
t := time.Now().Format("2006-01-02 15:04:05")
s := fmt.Sprintf("--%s--%s--%s--", appKey, appSecret, t)
Expand Down Expand Up @@ -264,17 +281,7 @@ func GetActivityIDs(ctx context.Context, session *Session) ([]ActivityID, error)
}

for _, session := range data.Sessions {
var hasGPSTrace bool
hasGPSTrace, err = session.GPSTraceAvailable.Bool()

if err != nil {
return err
}

var hasHeartRate bool
hasHeartRate, _ = session.HeartRateAvailable.Bool()

if hasGPSTrace || hasHeartRate {
if session.DeletedAt == "" {
l := len(activities)
id := ActivityID(session.ID)

Expand Down Expand Up @@ -444,16 +451,19 @@ func parseHeartRateData(trace string) ([]heartRatePoint, error) {
func merge(gpsData []gpsPoint, heartRateData []heartRatePoint) []DataPoint {
var data []DataPoint

if len(gpsData) == 0 {
for _, heartRate := range heartRateData {
data = append(data, heartRate.DataPoint())
}

return data
}

l := len(heartRateData)
diff := 5 * time.Second

for _, gps := range gpsData {
point := DataPoint{
Longitude: gps.Longitude,
Latitude: gps.Latitude,
Elevation: gps.Elevation,
Time: gps.Time,
}
point := gps.DataPoint()

if l > 0 {
index := sort.Search(l, func(i int) bool {
Expand Down

0 comments on commit 3811671

Please sign in to comment.