jovandeginste / workout-tracker

A workout tracking web application for personal use (or family, friends), geared towards running and other GPX-based activities
Other
958 stars 30 forks source link

Issue with GPX exported from Workoutdoors #4

Closed pixelspark closed 8 months ago

pixelspark commented 8 months ago

Great project!

When importing a GPX generated by the Workoutdoors iOS app, I get this error: constraint failed: NOT NULL constraint failed: workouts.date (1299).

Importing a GPX generated by Strava from the same workout works. The difference appears to be that the Workoutdoors file does not have a <time> element under <metadata> in the GPX, whereas the Strava one has it. The Workoutdoors file does have <time> items under each track point:

<gpx version="1.1" ...>
<metadata><name>Wednesday Evening Run</name></metadata>
<trk><name>Wednesday Evening Run</name><type>running</type>
<trkseg>
<trkpt lat="xxx" lon="xxx">
<ele>-30</ele><time>2024-02-28T17:26:34.000Z</time>

Perhaps the importer could use the earliest date in the file in case a date under metadata is missing.

I can have a go at implementing this myself if such feature would be desirable. If so any guidance on where to start would be appreciated (i.e. which part of the code to look)!

jovandeginste commented 8 months ago

I'll be verbose - skip as you please :)

The error comes from this line:

type Workout struct {
    [...]
    Date     *time.Time `gorm:"not null"`
    [...]
}

The Date field is indeed mandatory. It is set at this point when parsing a new file:

w := Workout{
    [...]
    Name:     gpxName(gpxContent),
    [...]
    Date:     gpxContent.Time,
    [...]
}

I left the Name line too, because this would be the way I would fix it:

Can you work with this? Thanks in advance! If it works with some tools, feel free to create a PR to the README compatibility section!

pixelspark commented 8 months ago

Thanks for the elaborate explanation, will have a look this weekend! (Also: groeten uit Nederland :-))