💻 Friday Evening Coding
2025-10-03 22:29
I gave in. My head just can't handle how to convert total time in seconds and total distance in meters to an average pace in minutes per kilometer. My logic is:
- convert seconds to minutes
- convert meters to kilometers
- divide minutes by kilometers
But of course there's remainders and things that muck it all up and causes my head to mush when I try and write it in python. So (is this the part where AI makes me stupider?), I GPT'd it and it gave me:
pace_sec_per_km = moving_time / (distance / 1000)
minutes = int(pace_sec_per_km // 60)
seconds = int(pace_sec_per_km % 60)
pace = f"{minutes}:{seconds:02d} /km"
print("Pace:", pace)
The pieces I didn't know about (but do now, because I asked some follow-up questions):
- The
// 60
returns only the full minutes (ignoring remainders). - The
% 60
returns the remainder after the division (the seconds). {seconds:02d}
means pad with0
if the number is too short, ie at least2
characters wide, and format as ad
ecimal integer. Eg. it will return 6:05 /km instead of 6:05.3 /km, or 6:5 /km.
*Edit - I can drop the d
altogether because I've already declared seconds as an integer with int
.
I find it a nightmare to find those little tidbits through web searching, so GPT it was. I've thoroughly enjoyed coding this week without AI, but I'm also happy it exists for little things like this.
Anyway, I'm getting pretty close now to a script that publishes all my activities to my site like a Strava feed with maps and all.