jovandeginste / workout-tracker

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

Add imperial units #45

Closed atkirtland closed 5 months ago

atkirtland commented 6 months ago

Thanks for the app! Would it be possible to add imperial units like miles instead of kilometers?

iamhyrumharris commented 6 months ago

I would also like this, American user here...

jovandeginste commented 6 months ago

That would also mean feet for elevation, etc?

atkirtland commented 6 months ago

@jovandeginste Yes, I think it would affect elevation, distance, speed, and temperature.

jovandeginste commented 6 months ago

Thank god you use minutes and hours like us :sweat_smile:

jovandeginste commented 6 months ago

I'm trying to find a library for conversion of meters to imperial units...

atkirtland commented 6 months ago

I can't provide any library suggestions, but I did see FitTrackee just wrote their own script for it

jovandeginste commented 6 months ago

Is any of you able to test PR #49 ?

wills106 commented 5 months ago

Would it be possible to release the imperial branch as a pre-release? I'm running this on UNRAID so could easily select another release, but I don't think I can select a branch.

Can mixed unit's be set? Or at least set units independently? In the UK we use a Mixed Imperial / Metric system.

Things like speed and distance tends to be Miles, but elevation is in Meters, temp in Celsius. Although if each parameter could be set in the user interface it might benefit more countries.

mochman commented 5 months ago

I just built this branch and tested it out. I have only a few GPX files to test with, but they seem mostly correct. In one workout, Garmin Connect says I ran 4.00 miles, while your app shows 4.02 miles. In another workout, Garmin shows 3.00 miles, yours shows 3.02 miles. Another Garmin showed 26.2 and yours showed 26.81. Other short runs were the same between the programs. Most of them seem close enough for rounding errors.

Another thing I noticed, on the workout pages. The graph and one of the tables still shows KMs. imp1 imp2

The statistics page also shows metric for the graphs.

Everything else looks good with the imperial data.

Thanks for providing the option for imperial.

jovandeginste commented 5 months ago

I'm reworking the statistics (see the API changes), and will follow up with the per-km breakdown (so you can switch to per-mile or per minute or per-n-km). Then it would be more practical to switch to the user-preferred units.

Regarding the mixed units, I'll look into this. It sounds complex, but indeed most flexible. I suppose a kind of template to set all individual units, and then the possibility to change each; like "use imperial", then change temperature to Celsius.

jovandeginste commented 5 months ago

@wills106 @mochman can you check out the new PR, which adds separate units per user? The same issues remain, namely that the graphs are still using metric units whatever you choose (for now)

jovandeginste commented 5 months ago

The profile page looks like this, now:

image

wills106 commented 5 months ago

Can you release it as a pre-release so I can pull that into my Unraid install?

You can tag a branch as a pre-release

mochman commented 5 months ago

I tested out the new unit selection. It looks like they all work in switching units. I did see a problem though. The Avg Tempo and Avg Temp (No Pause) don't convert to imperial units correctly. km mil

I would love to be able to run 4 minute miles, but I think the conversion went the opposite way. The min/km seem correct with my slowness.

mochman commented 5 months ago

I think the issue is here: https://github.com/jovandeginste/workout-tracker/blob/d152fa209498c07b42e55df51388274031819e6e/pkg/templatehelpers/imperial.go#L32

I think it should be: mpm := (1 / milesPerKM) * 1000 / (60 * mps)

jovandeginste commented 5 months ago

I think the issue is here:

https://github.com/jovandeginste/workout-tracker/blob/d152fa209498c07b42e55df51388274031819e6e/pkg/templatehelpers/imperial.go#L32

I think it should be: mpm := (1 / milesPerKM) * 1000 / (60 * mps)

Yes, I was too hasty... Fixed it in the PR, which I will now merge to master. This will make it easier for more people to test, while I work on the breakdown and the statistics!

jovandeginste commented 5 months ago

@wills106 I will release it now; I'll keep it open until you verified the tempos are correct too

mochman commented 5 months ago

The tempos look good now. Thank you!

wills106 commented 5 months ago

I seem to be getting a bit of discrepancy between FitoTrack and workout-tracker.

image

I seem to gain an elevation of 51.25 meters on both the min and max elevation. image

I imported the same walk into Garmin Connect and I am getting the same elevation as FitoTrack, but I have a speed spike at the end of the file. image With the gained and lost on Garmin I'm guessing it's adding together each time I got up and down and not just the highest point and lowest point of the walk.

jovandeginste commented 5 months ago

My impression is that the elevations are very off - they never add up for my runs, and while my runs start and end at the same spot (my front door), the elevations are sometimes off by several meters...

jovandeginste commented 5 months ago

FYI, latest release also converts statistics (per-workout and general). Please test :)

wills106 commented 5 months ago

The breakdown per mile top right looks correct.

image

The bottom graphs are working again. But speed is still km/h

Still think it's a bit odd with the elevation always being out by about 50m in workout-tracker compared to Fito / Garmin display I'm not sure if they are doing the rounding different compared to your HumanElevation bit?

I'm recording the walk using FitoTrack and exporting the gpx into both workout-tracker and Garmin Connect.

wills106 commented 5 months ago

Just had a look at the file and workout-tracker is reading what's in the file.

So there must be something in FitoTrack / Garmin viewer to compensate the elevation by around 50 meters?

jovandeginste commented 5 months ago

There are two ways of parsing elevation; if you look at the source code, you can find an exception for Garmin etc. Some take elevation from sea level, others from a virtual sphere inside earth...

jovandeginste commented 5 months ago

The thing is, I use fitotrack too, so I'm curious why your results could be different from mine....

jovandeginste commented 5 months ago

About the bottom graphs: master has them in mph (if you choose that unit):

image

jovandeginste commented 5 months ago

(v0.12.1 should also have the graphs in mph, btw)

jovandeginste commented 5 months ago

Check these lines for the correction:

https://github.com/jovandeginste/workout-tracker/blob/master/pkg/database/workouts_map.go#L16-L18

You can calculate online, maybe you find that to be the 50m discrepancy: https://geographiclib.sourceforge.io/cgi-bin/GeoidEval

wills106 commented 5 months ago

Speed Graph looks correct to me.

I have put my starting coordinates into that Calculator and got: EGM2008 = 51.5874 EGM96 = 51.1969 EGM84 = 52.1547

My starting Elevation in the GPX is 262.5665345760264 and I know it should be around 210m 262.57 minus one of the EGM does bring it to around 210m.

So far I have logged a route with FitoTrack with Imperial and Imperial + Meters. I'll try pure metric to ensure I get the same reading.

Also I'm using FitoTrack 15.4

wills106 commented 5 months ago

It does look like FitoTrack records and displays elevation differently. https://codeberg.org/jannis/FitoTrack/issues/334#issuecomment-291097 So I'm surprised your elevations matches in FitoTrack and workout-tracker.

jovandeginste commented 5 months ago

It does look like FitoTrack records and displays elevation differently. https://codeberg.org/jannis/FitoTrack/issues/334#issuecomment-291097 So I'm surprised you elevations matches in FitoTrack and workout-tracker.

No, it's exactly what I was seeing: the GPX values were not what FitoTrack showed in the app. Then I found out about the WGS84 stuff, and added code to account for this. So, I'm surprised your GPX files have elevation at sea level?

wills106 commented 5 months ago

workout-2024-01-25_10-15-Walk_Puerto_Mazarron.zip This is a seafront walk I did earlier this year. It shows an elevation of 45.14 m to 57.82 m in workout-tracker but -5 to 7m in FitoTrack

This is with a Pixel 7. I can try on an iPhone 14 to see if I get 210m at home, or the 262m as per my Pixel 7

jovandeginste commented 5 months ago

I found the cause: https://go.dev/play/p/iTL_cpUHZtG

panic: requested longitude -1.26 lies outside of EGM96 longitude range 0.0 to 360.0

jovandeginste commented 5 months ago

Fixed in 3c7727d54bf1fd73c76dc83dc827a2bbf68c1e55

jovandeginste commented 5 months ago

And now released as v0.12.2 (build in progress)

wills106 commented 5 months ago

All seems good to me now.

Speeds look correct and calculates into the tempo and laps seem correct. Also elevation matches as close as it can be from a GPS signal.

jovandeginste commented 5 months ago

Can I consider this issue closed?

wills106 commented 5 months ago

As far as I am concerned it's complete. Also adds in the extra functionality of mixed units.

jovandeginste commented 5 months ago

Thanks everyone for testing!