# Parkrun Calculator

The Parkrun is a 5K timed run that happens every Saturday morning at 9AM. There are Parkrun's all over the country. The Cambridge Parkrun takes place on Milton Country Park. I have a Garmin Forerunner 410 GPS watch, which I use on Linux with ant-downloader. The watch tends to underread the distance, so I wrote a calculator in Python that lets me input the distance my watch thinks I ran, as well as the time I ran it in, and recalculates the pace for the correct distance.

Here's the code:

```#!/usr/bin/env python2

import re
from datetime import datetime, timedelta

garmin_miles_str = raw_input("Garmin Miles: ")
garmin_time_str = raw_input("Garmin Time: ")

garmin_miles = float(garmin_miles_str)

# Split time into min and second components
time_regex = re.search("(\d+):(\d+)", garmin_time_str)
garmin_time_c_mins = int(time_regex.group(1))
garmin_time_c_secs = int(time_regex.group(2))

garmin_time_seconds = int((garmin_time_c_mins * 60) + garmin_time_c_secs)

full_miles = float(5 * 0.621371192)

corrected_time_seconds = garmin_time_seconds / full_miles

# Convert the seconds back to minutes and seconds
sec = timedelta(seconds=corrected_time_seconds)
d = datetime(1,1,1) + sec

print("Corrected pace:")
print("%d:%02d Min/Mi" % (d.minute, d.second))
```

Usage:

```[liam@liam-laptop Scripts]\$ ./parkrun-calculator
Garmin Miles: 2.98
Garmin Time: 28:07
Corrected pace:
9:02 Min/Mi
```