Running the marathon running planning script

I am almost back in a regular running schedule.

So looking ahead at the Copenhagen Marathon 2010, I sat down and adjusted a script I wrote at an earlier occasion.

  1. #!/usr/bin/perl
  2. # $Id$
  3. use strict;
  4. use warnings;
  5. use DateTime;
  6. use constant DAYS_IN_WEEK => 7;
  7. our $VERSION = ‘0.02’;
  8. my @distances
  9. = 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);
  10. if ( !$ARGV[0] ) {
  11.   die ‘Usage: marathon-training.pl <date of marathon ddmmyyyy>’;
  12. }
  13. #parsing argument
  14. my ( $day, $month, $year ) = $ARGV[0] =~ m{
  15.   (\d{2}) #day (two digits)
  16. (\d{2}) #month (two digits)
  17. (\d{4}) #year (four digits)
  18. }mx;
  19. #DT does it own dying
  20. my $dt = new DateTime(
  21. year => $year,
  22. month => $month,
  23. day => $day,
  24. time_zone => ‘UTC’,
  25. );
  26. #Using DateTime (machine) to go back the number of weeks scheduled in distances
  27. #minus one of be of by one week when we get to the marathon, eventhough an
  28. #extra week of preparation might not hurt
  29. $dt = $dt->subtract(
  30. DateTime::Duration->new(
  31. days => ( DAYS_IN_WEEK * scalar @distances ) - DAYS_IN_WEEK
  32. )
  33. );
  34. my $dt_now = DateTime->now(time_zone => ‘UTC’,);
  35. #Print the plan from the beginning and on...
  36. my $i = 0;
  37. while (@distances) {
  38.   printf ‘Week: %02d’, ++$i;
  39.   print “\tWeek number: “ . $dt->week_number();
  40.   $dt = $dt->add(DateTime::Duration->new( days => DAYS_IN_WEEK ));
  41. my $this_week;
  42. if ($dt->week_number() == $dt_now->week_number()) {
  43. $this_week++;
  44. }
  45. print “\tDistance: “ . pop @distances;
  46. if ($this_week) {
  47. print “ <-- this week\n”;
  48. } else {
  49.   print “\n”;
  50. }
  51. }
  52. exit 0;

So running it with the date: 23rd. of May 2010 gives the following output:

Output   
; perl ~/develop/stuff/marathon-training.pl 23052010
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: 53 Distance: 40
Week: 05        Week number: 1  Distance: 40
Week: 06        Week number: 2  Distance: 35 <-- this week
Week: 07        Week number: 3  Distance: 45
Week: 08        Week number: 4  Distance: 45
Week: 09        Week number: 5  Distance: 45
Week: 10        Week number: 6  Distance: 40
Week: 11        Week number: 7  Distance: 50
Week: 12        Week number: 8  Distance: 50
Week: 13        Week number: 9  Distance: 50
Week: 14        Week number: 10 Distance: 45
Week: 15        Week number: 11 Distance: 55
Week: 16        Week number: 12 Distance: 55
Week: 17        Week number: 13 Distance: 55
Week: 18        Week number: 14 Distance: 50
Week: 19        Week number: 15 Distance: 60
Week: 20        Week number: 16 Distance: 65
Week: 21        Week number: 17 Distance: 65
Week: 22        Week number: 18 Distance: 50
Week: 23        Week number: 19 Distance: 45
Week: 24        Week number: 20 Distance: 20

If you compare to the output of the referred blog entry, this is of course another marathon, so the dates are different, but I have just added an indicator of the current week.

Leave a Comment


NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>