Skip to content

Commit 248a4a5

Browse files
Merge pull request #772 from jovandeginste/fix-tcx-swim
feat(distance): Allow TCX files with distance, but without coördinates
2 parents 2464e26 + 54e5365 commit 248a4a5

6 files changed

Lines changed: 38 additions & 7 deletions

File tree

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,3 +178,5 @@ tool (
178178
github.com/mdomke/git-semver/v6
179179
github.com/swaggo/swag/cmd/swag
180180
)
181+
182+
replace github.com/galeone/tcx => github.com/jovandeginste/tcx v0.0.0-20260324124628-5ba45eaf04f3

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,6 @@ github.com/fsnotify/fsnotify v1.9.0 h1:2Ml+OJNzbYCTzsxtv8vKSFD9PbJjmhYF14k/jKC7S
169169
github.com/fsnotify/fsnotify v1.9.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0=
170170
github.com/fsouza/slognil v0.4.3 h1:BozwVsIBrT+DSRKZm7Fmm8Hwpl6OWrRjpaQYKHRzxuA=
171171
github.com/fsouza/slognil v0.4.3/go.mod h1:aeqfcl5mmgmSSQaF7t1ue8AVu7i4VU/fDVdbcjF5u0s=
172-
github.com/galeone/tcx v1.0.1-0.20230114151622-8168e1e47884 h1:aiujMvmLqdGvZftIoDSYmTPtSVPDXC9csDpZJQ8EEkQ=
173-
github.com/galeone/tcx v1.0.1-0.20230114151622-8168e1e47884/go.mod h1:cHrVurc4epPGjwvJt8kDkQgp4hEUhk0UiWPSN6/dykI=
174172
github.com/getkin/kin-openapi v0.133.0 h1:pJdmNohVIJ97r4AUFtEXRXwESr8b0bD721u/Tz6k8PQ=
175173
github.com/getkin/kin-openapi v0.133.0/go.mod h1:boAciF6cXk5FhPqe/NQeBTeenbjqU4LhWBf09ILVvWE=
176174
github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk=
@@ -406,6 +404,8 @@ github.com/jovandeginste/fitbit v0.0.4-0.20250213164811-b0b3b27c3a84 h1:VAPYoqkq
406404
github.com/jovandeginste/fitbit v0.0.4-0.20250213164811-b0b3b27c3a84/go.mod h1:GEs6hK/2Kqjg8VPf30j++3AsmIH8FytcnQlP6kfduII=
407405
github.com/jovandeginste/gpxgo v1.4.1-0.20250629150855-db85929d31f6 h1:RQY3NFjYmkILBkudjoH0aaNPHoO8aqEruAKYKthwmlI=
408406
github.com/jovandeginste/gpxgo v1.4.1-0.20250629150855-db85929d31f6/go.mod h1:BXSMfUAvKiEhMEXAFM2NvNsbjsSvp394mOvdcNjettg=
407+
github.com/jovandeginste/tcx v0.0.0-20260324124628-5ba45eaf04f3 h1:6wfkaP91JXHWq/H9s+8cbTEObB3l+ImTZ8hVChqPLBg=
408+
github.com/jovandeginste/tcx v0.0.0-20260324124628-5ba45eaf04f3/go.mod h1:cHrVurc4epPGjwvJt8kDkQgp4hEUhk0UiWPSN6/dykI=
409409
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
410410
github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk=
411411
github.com/kevinburke/ssh_config v1.2.0 h1:x584FjTGwHzMwvHx18PXxbBVzfnxogHaAReU4gf13a4=

pkg/converters/tcx.go

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ import (
99
"github.com/tkrajina/gpxgo/gpx"
1010
)
1111

12+
type tcxConverter struct {
13+
totalDistance float64
14+
}
15+
1216
func ParseTCX(content []byte) (*gpx.GPX, error) {
1317
var t tcx.TCXDB
1418

@@ -31,10 +35,21 @@ func ParseTCX(content []byte) (*gpx.GPX, error) {
3135
g.Creator = "TCX importer"
3236
}
3337

38+
g.AppendTrack(&gpx.GPXTrack{
39+
Name: t.Acts.Act[0].Id.String(),
40+
Type: t.Acts.Act[0].Sport,
41+
})
42+
43+
tc := tcxConverter{}
44+
3445
for _, a := range t.Acts.Act {
3546
for _, l := range a.Laps {
47+
if l.Trk == nil {
48+
continue
49+
}
50+
3651
for _, p := range l.Trk.Pt {
37-
gpxP := tcxPtToGPXPt(&p)
52+
gpxP := tc.tcxPtToGPXPt(&p)
3853
if gpxP == nil {
3954
continue
4055
}
@@ -47,13 +62,12 @@ func ParseTCX(content []byte) (*gpx.GPX, error) {
4762
return g, nil
4863
}
4964

50-
func tcxPtToGPXPt(t *tcx.Trackpoint) *gpx.GPXPoint {
65+
func (tc *tcxConverter) tcxPtToGPXPt(t *tcx.Trackpoint) *gpx.GPXPoint {
5166
if t == nil {
5267
return nil
5368
}
5469

55-
if t.Time.IsZero() ||
56-
(t.Lat == 0 && t.Long == 0) {
70+
if t.Time.IsZero() {
5771
return nil
5872
}
5973

@@ -72,6 +86,11 @@ func tcxPtToGPXPt(t *tcx.Trackpoint) *gpx.GPXPoint {
7286
setIfNotZero(p, "power", t.Power)
7387
setIfNotZero(p, "speed", t.Speed)
7488

89+
if t.Dist == 0 && t.SwimDistance > 0 {
90+
tc.totalDistance += t.SwimDistance
91+
setIfNotZero(p, "distance", tc.totalDistance)
92+
}
93+
7594
return p
7695
}
7796

pkg/database/workouts.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,10 @@ func autoDetectWorkoutType(data *MapData, gpxContent *gpx.GPX, dataName string)
497497
}
498498
}
499499

500+
if data == nil {
501+
return WorkoutTypeOther
502+
}
503+
500504
if 3.6*data.AverageSpeedNoPause > 15.0 {
501505
return WorkoutTypeCycling
502506
}

vendor/github.com/galeone/tcx/tcxschema.go

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/modules.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ github.com/fsnotify/fsnotify/internal
187187
# github.com/fsouza/slognil v0.4.3
188188
## explicit; go 1.24.0
189189
github.com/fsouza/slognil
190-
# github.com/galeone/tcx v1.0.1-0.20230114151622-8168e1e47884
190+
# github.com/galeone/tcx v1.0.1-0.20230114151622-8168e1e47884 => github.com/jovandeginste/tcx v0.0.0-20260324124628-5ba45eaf04f3
191191
## explicit; go 1.19
192192
github.com/galeone/tcx
193193
# github.com/glebarez/go-sqlite v1.22.0
@@ -868,3 +868,4 @@ resty.dev/v3
868868
# sigs.k8s.io/yaml v1.3.0
869869
## explicit; go 1.12
870870
sigs.k8s.io/yaml
871+
# github.com/galeone/tcx => github.com/jovandeginste/tcx v0.0.0-20260324124628-5ba45eaf04f3

0 commit comments

Comments
 (0)