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

Commit

Permalink
Fixes #3
Browse files Browse the repository at this point in the history
Garmin Connect treats activity type as case sensitive, so I had
to change first letter to uppercase. Also, Runtastic has dozens
of activity types, but none of them are recognized by either
Garmin or Strava, so now I only support Running, Walking, Biking
and Swimming.
  • Loading branch information
Metalnem committed Apr 29, 2017
1 parent 7dafcd9 commit a2b6847
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 99 deletions.
23 changes: 17 additions & 6 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ type Session struct {
// Metadata represents high-level overview of the single activity.
type Metadata struct {
ID ActivityID
Type ActivityType
Type string
StartTime time.Time
EndTime time.Time
Calories int32
Expand Down Expand Up @@ -269,6 +269,21 @@ func Login(ctx context.Context, email, password string) (*Session, error) {
return &session, nil
}

func getActivityType(id int64) string {
switch id {
case 1, 14:
return "Running"
case 3, 4, 15, 22:
return "Biking"
case 18:
return "Swimming"
case 2, 7, 19:
return "Walking"
default:
return "Other"
}
}

func convert(m metadata) (Metadata, error) {
t, err := m.Type.Int64()

Expand All @@ -284,7 +299,7 @@ func convert(m metadata) (Metadata, error) {

metadata := Metadata{
ID: m.ID,
Type: types[t],
Type: getActivityType(t),
StartTime: time.Time(m.StartTime),
EndTime: time.Time(m.EndTime),
Calories: int32(calories),
Expand Down Expand Up @@ -621,10 +636,6 @@ func (session *Session) GetActivity(ctx context.Context, id ActivityID) (*Activi
Data: merge(ctx, gpsData, heartRateData, session.Options.Tolerance),
}

if activity.Type.ID == 0 {
activity.Type = types[5] // Default to "Other"
}

return &activity, nil
}

Expand Down
6 changes: 3 additions & 3 deletions api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func TestGetActivityGPS(t *testing.T) {
expected := &Activity{
Metadata: Metadata{
ID: id,
Type: ActivityType{1, "Running", "running"},
Type: "Running",
StartTime: time.Unix(1480085018, 0).UTC(),
EndTime: time.Unix(1480085041, 0).UTC(),
},
Expand Down Expand Up @@ -143,7 +143,7 @@ func TestGetActivityHeartRate(t *testing.T) {
expected := &Activity{
Metadata: Metadata{
ID: id,
Type: ActivityType{3, "Cycling", "cycling"},
Type: "Biking",
StartTime: time.Unix(1482135300, 0).UTC(),
EndTime: time.Unix(1482135324, 0).UTC(),
AvgHeartRate: 76,
Expand All @@ -166,7 +166,7 @@ func TestGetActivityManual(t *testing.T) {
expected := &Activity{
Metadata: Metadata{
ID: id,
Type: ActivityType{5, "Other", "other"},
Type: "Other",
StartTime: time.Unix(1483025750, 0).UTC(),
EndTime: time.Unix(1483031015, 0).UTC(),
Calories: 1183,
Expand Down
82 changes: 0 additions & 82 deletions api/types.go

This file was deleted.

2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func export(activities []api.Activity, exp func(io.Writer) exporter, ext string)
defer checkedClose(zw, &err)

for _, activity := range activities {
filename := fmt.Sprintf("Runtastic %s %s.%s", formatTime(activity.EndTime), activity.Type.DisplayName, ext)
filename := fmt.Sprintf("Runtastic %s %s.%s", formatTime(activity.EndTime), activity.Type, ext)

header := zip.FileHeader{
Name: filename,
Expand Down
2 changes: 1 addition & 1 deletion static/tcx/empty.tcx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<TrainingCenterDatabase xmlns="http://www.garmin.com/xmlschemas/TrainingCenterDatabase/v2" version="1.0" creator="Runtastic Archiver, https://github.com/Metalnem/runtastic" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.garmin.com/xmlschemas/TrainingCenterDatabase/v2 http://www.garmin.com/xmlschemas/TrainingCenterDatabasev2.xsd" xmlns:ns2="http://www.garmin.com/xmlschemas/UserProfile/v2" xmlns:ns3="http://www.garmin.com/xmlschemas/ActivityExtension/v2" xmlns:ns4="http://www.garmin.com/xmlschemas/ProfileExtension/v1" xmlns:ns5="http://www.garmin.com/xmlschemas/ActivityGoals/v1">
<Activities>
<Activity Sport="other">
<Activity Sport="Other">
<Id>2010-11-25T18:35:20Z</Id>
<Lap StartTime="2010-11-25T18:35:20Z">
<TotalTimeSeconds>0</TotalTimeSeconds>
Expand Down
2 changes: 1 addition & 1 deletion static/tcx/gps.tcx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<TrainingCenterDatabase xmlns="http://www.garmin.com/xmlschemas/TrainingCenterDatabase/v2" version="1.0" creator="Runtastic Archiver, https://github.com/Metalnem/runtastic" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.garmin.com/xmlschemas/TrainingCenterDatabase/v2 http://www.garmin.com/xmlschemas/TrainingCenterDatabasev2.xsd" xmlns:ns2="http://www.garmin.com/xmlschemas/UserProfile/v2" xmlns:ns3="http://www.garmin.com/xmlschemas/ActivityExtension/v2" xmlns:ns4="http://www.garmin.com/xmlschemas/ProfileExtension/v1" xmlns:ns5="http://www.garmin.com/xmlschemas/ActivityGoals/v1">
<Activities>
<Activity Sport="other">
<Activity Sport="Other">
<Id>2012-10-15T09:30:45Z</Id>
<Lap StartTime="2012-10-15T09:30:45Z">
<TotalTimeSeconds>10</TotalTimeSeconds>
Expand Down
2 changes: 1 addition & 1 deletion static/tcx/heartRate.tcx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<TrainingCenterDatabase xmlns="http://www.garmin.com/xmlschemas/TrainingCenterDatabase/v2" version="1.0" creator="Runtastic Archiver, https://github.com/Metalnem/runtastic" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.garmin.com/xmlschemas/TrainingCenterDatabase/v2 http://www.garmin.com/xmlschemas/TrainingCenterDatabasev2.xsd" xmlns:ns2="http://www.garmin.com/xmlschemas/UserProfile/v2" xmlns:ns3="http://www.garmin.com/xmlschemas/ActivityExtension/v2" xmlns:ns4="http://www.garmin.com/xmlschemas/ProfileExtension/v1" xmlns:ns5="http://www.garmin.com/xmlschemas/ActivityGoals/v1">
<Activities>
<Activity Sport="other">
<Activity Sport="Other">
<Id>2012-10-15T09:30:45Z</Id>
<Lap StartTime="2012-10-15T09:30:45Z">
<TotalTimeSeconds>1234</TotalTimeSeconds>
Expand Down
2 changes: 1 addition & 1 deletion static/tcx/manual.tcx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<TrainingCenterDatabase xmlns="http://www.garmin.com/xmlschemas/TrainingCenterDatabase/v2" version="1.0" creator="Runtastic Archiver, https://github.com/Metalnem/runtastic" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.garmin.com/xmlschemas/TrainingCenterDatabase/v2 http://www.garmin.com/xmlschemas/TrainingCenterDatabasev2.xsd" xmlns:ns2="http://www.garmin.com/xmlschemas/UserProfile/v2" xmlns:ns3="http://www.garmin.com/xmlschemas/ActivityExtension/v2" xmlns:ns4="http://www.garmin.com/xmlschemas/ProfileExtension/v1" xmlns:ns5="http://www.garmin.com/xmlschemas/ActivityGoals/v1">
<Activities>
<Activity Sport="running">
<Activity Sport="Running">
<Id>2016-12-10T17:32:40Z</Id>
<Lap StartTime="2016-12-10T17:32:40Z">
<TotalTimeSeconds>4250</TotalTimeSeconds>
Expand Down
4 changes: 2 additions & 2 deletions tcx/tcx.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,10 @@ func (exp *Exporter) Export(a api.Activity) error {
lap.MaxHeartReate = &a.MaxHeartReate
}

activity := activity{Sport: a.Type.ExportName, ID: startTime, Lap: lap}
activity := activity{Sport: a.Type, ID: startTime, Lap: lap}

if activity.Sport == "" {
activity.Sport = "other"
activity.Sport = "Other"
}

data := tcx{
Expand Down
2 changes: 1 addition & 1 deletion tcx/tcx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func TestManual(t *testing.T) {
activity := api.Activity{
Metadata: api.Metadata{
ID: "1485608013",
Type: api.ActivityType{ID: 1, DisplayName: "Running", ExportName: "running"},
Type: "Running",
StartTime: mustParse("2016-12-10T17:32:40Z"),
Calories: 1250,
Distance: 9458,
Expand Down

0 comments on commit a2b6847

Please sign in to comment.