Hacker News new | ask | show | jobs
by shantnutiwari 847 days ago
nice. How do you track teh distance (walked or running?)
2 comments

Not sure exactly what you are asking about, so I'll be verbose :-)

I use an app called FitoTrack (also FOSS), which records my location while running. It stores my GPS position every few seconds. When I'm done, it auto-exports a GPX file to a folder on my phone, which is synced via syncthing. Then I (manually, for now) upload the file to my self-hosted workout tracker.

The GPX file contains some data per measurement point; this is the second point in some random GPX file:

      <trkpt lat="x" lon="y">
        <ele>56.72105575919558</ele>
        <extensions>
          <speed>1.8200000524520874</speed>
          <wstxns2:TrackPointExtension xmlns:wstxns2="gpxtxp"/>
        </extensions>
        <time>2024-02-28T09:28:26Z</time>
      </trkpt>
So it contains speed (average since previous point), elevation, location and time (offtopic: it took me a while to understand that this elevation is not the actual elevation above sea level; only yesterday I figured that out and fixed it in the code!).

The Go GPX library some of this information, and some extras (like max and min elevation, max speed, total up and down, etc. over the whole track). Then I perform some more calculations (like putting the points in buckets per km and per minute), and calculate the estimated location using a geocoder library.

Then, finally, to estimate the difference between walking, running, or cycling, I take the average speed and guesstimate from there. This may be wrong some times for some people, and could be improved on. Or maybe I should include an AI here? (just kidding)

Without diving in too deeply, it looks like they use a package called `gpxgo` [1], which has some code for calculating the moving distance of a given GPX file [2].

[1] https://github.com/tkrajina/gpxgo

[2] https://github.com/tkrajina/gpxgo/blob/5e7c336e94dac3583a07c...