#!/usr/bin/env python # # Copyright (C) 2007 Mark McLoughlin # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. # # # Run with your 10k time, halfway time, 30k time and finish time e.g.: # # $> ./marathon.py 00:58:20 02:00:23 02:55:55 04:24:18 # import sys import string START_TIME = "00:00:00" MARATHON_IN_KM = 42.195 if len(sys.argv) != 5: sys.stderr.write("usage: %s <10k time> <30k time> \n" % sys.argv[0]) sys.exit(1) (tenk, halfway, thirtyk, finish) = sys.argv[1:] def tm_to_secs(tm): (hours, minutes, seconds) = map(lambda s: float(s), string.split(tm, ":")) return (hours * 3600) + (minutes * 60) + seconds def pace(start, end, len_in_km): p = (tm_to_secs(end) - tm_to_secs(start)) / len_in_km return "%.2d:%.2d" % (p / 60, p % 60) print "Pace (time per km) at which each segment was run:" print " From start to 10k: %s" % pace(START_TIME, tenk, 10) print " From 10k to halfway: %s" % pace(tenk, halfway, (MARATHON_IN_KM / 2) - 10) print " From halfway to 30k: %s" % pace(halfway, thirtyk, 30 - (MARATHON_IN_KM / 2)) print " From 30k to finish: %s" % pace(thirtyk, finish, MARATHON_IN_KM - 30)