Skip to content

Instantly share code, notes, and snippets.

@danesherbs
Created August 22, 2023 02:38
Show Gist options
  • Save danesherbs/8668bc5355656c1c2f47ffe8d2d31c8f to your computer and use it in GitHub Desktop.
Save danesherbs/8668bc5355656c1c2f47ffe8d2d31c8f to your computer and use it in GitHub Desktop.
Generates a marathon training plan
import csv
from datetime import datetime, timedelta
START_DATE = datetime.today()
WEEKS = 15
INITIAL_DISTANCE = 35
MAX_INCREASE_RATE = 0.10
PARK_RUN_DISTANCE = 8
INCREASE_RATE = 0.05
headers = [
"date",
"monday",
"tuesday",
"wednesday",
"thursday",
"friday",
"saturday",
"sunday",
]
file_path = "training-plan.csv"
with open(file_path, mode="w", newline="") as file:
writer = csv.writer(file)
writer.writerow(headers)
weekly_distance = INITIAL_DISTANCE
distance_before_recovery = 0
for week in range(WEEKS):
if (week + 1) % 4 == 0:
distance_before_recovery = weekly_distance
weekly_distance *= 0.50
elif distance_before_recovery > 0:
weekly_distance = distance_before_recovery
distance_before_recovery = 0
interval_distance = weekly_distance * 0.20
tempo_distance = weekly_distance * 0.20
long_run_distance = weekly_distance - (
interval_distance + tempo_distance + PARK_RUN_DISTANCE
)
if long_run_distance > 28:
excess_distance = long_run_distance - 28
long_run_distance = 28
interval_distance += excess_distance / 2
tempo_distance += excess_distance / 2
current_date = START_DATE + timedelta(weeks=week)
row = [
current_date.strftime("%Y-%m-%d"),
"", # Monday
int(interval_distance), # Tuesday
"", # Wednesday
int(tempo_distance), # Thursday
"", # Friday
int(PARK_RUN_DISTANCE), # Saturday
int(long_run_distance), # Sunday
]
writer.writerow(row)
if (distance_before_recovery == 0):
next_week_distance = weekly_distance * (1 + INCREASE_RATE)
if next_week_distance > weekly_distance * (1 + MAX_INCREASE_RATE):
next_week_distance = weekly_distance * (1 + MAX_INCREASE_RATE)
weekly_distance = next_week_distance
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment