@@ -9,6 +9,10 @@ import (
99 "github.com/tkrajina/gpxgo/gpx"
1010)
1111
12+ type tcxConverter struct {
13+ totalDistance float64
14+ }
15+
1216func 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
0 commit comments