iPod+Nikeplus+, plans implemented in Perl

jonasbn on 2008-11-09T20:19:50

So I sat down with the training plans I (somewhat) followed preparing for last years Copenhagen Marathon and attempted to layout a plan, but lazyness got me so I wrote a script.

The date for next years Copenhagen Marathon in 24th. of May 2009 (the argument to the script).

Here is the output (the training plan):

hoarfrost /Users/jonasbn/Desktop ; perl marathon-training.pl 24052009 Week: 01 Week number: 50 Distance: 35 Week: 02 Week number: 51 Distance: 30 Week: 03 Week number: 52 Distance: 40 Week: 04 Week number: 1 Distance: 40 Week: 05 Week number: 2 Distance: 40 Week: 06 Week number: 3 Distance: 35 Week: 07 Week number: 4 Distance: 45 Week: 08 Week number: 5 Distance: 45 Week: 09 Week number: 6 Distance: 45 Week: 10 Week number: 7 Distance: 40 Week: 11 Week number: 8 Distance: 50 Week: 12 Week number: 9 Distance: 50 Week: 13 Week number: 10 Distance: 50 Week: 14 Week number: 11 Distance: 45 Week: 15 Week number: 12 Distance: 55 Week: 16 Week number: 13 Distance: 55 Week: 17 Week number: 14 Distance: 55 Week: 18 Week number: 15 Distance: 50 Week: 19 Week number: 16 Distance: 60 Week: 20 Week number: 17 Distance: 65 Week: 21 Week number: 18 Distance: 65 Week: 22 Week number: 19 Distance: 50 Week: 23 Week number: 20 Distance: 45 Week: 24 Week number: 21 Distance: 20

And here is the script:

	#!/usr/bin/perl 

# $Id$

use strict; use warnings; use DateTime;

use constant DAYS_IN_WEEK => 7; our $VERSION = '0.01';

my @distances = qw(20 45 50 65 65 60 50 55 55 55 45 50 50 50 40 45 45 45 35 40 40 40 30 35);

if ( !$ARGV[0] ) { die 'Usage: marathon-training.pl '; }

#parsing argument my ( $day, $month, $year ) = $ARGV[0] =~ m{ (\d{2}) #day (two digits) (\d{2}) #month (two digits) (\d{4}) #year (four digits) }mx;

#DT does it own dying my $dt = new DateTime( year => $year, month => $month, day => $day, time_zone => 'UTC', );

#Using DateTime (machine) to go back the number of weeks scheduled in distances #minus one of be of by one week when we get to the marathon, eventhough an #extra week of preparation might not hurt $dt = $dt->subtract( DateTime::Duration->new( days => ( DAYS_IN_WEEK * scalar @distances ) - DAYS_IN_WEEK ) );

#Print the plan from the beginning and on... my $i = 0; while (@distances) { printf 'Week: %02d', ++$i; print "\tWeek number: " . $dt->week_number(); $dt = $dt->add( DateTime::Duration->new( days => DAYS_IN_WEEK ) ); print "\tDistance: " . pop @distances; print "\n"; }

exit 0;


Of course the scripts TODO list would be long, things like localization etc. should be taken into consideration.