I wrote a small Perl script to help out Athletes with lap times (splits.) The script is based on knowing a time you want to do for a particular distance first - it shows you how many laps the distance is (sometimes it is easy to forget), what average lap time you would need to do and what times you would clock for other distances if you were averaging that lap time.
#!/usr/bin/perl
use strict;
use warnings;
use Getopt::Std;
use POSIX qw(floor);
my %args;
sub Usage {
print "Usage:\n\t$0 -d distance -m mins -s secs [ -t track length ]\n";
}
getopt('dmst', \%args);
for (['d', 'distance'], ['m', 'minutes'], ['s', 'seconds']) {
my ($short, $long) = ($_->[0], $_->[1]);
if (! defined($args{$short}) or $args{$short} !~ /^\d+$/) {
Usage && die "\tPlease ensure ${long} is an integer.\n"
}
}
Usage && die "\tSeconds must be between 0 and 59." if ($args{'s'} > 59);
if (defined($args{'t'}) && $args{'t'} !~ /^\d+$/) {
Usage && die "\tPlease ensure track length is an integer.\n"
}
my $track_distance = $args{'t'} || 400;
my $laps = $args{'d'} / $track_distance;
printf("%dm is %.2f laps.\n", $args{'d'}, $laps);
my $time_in_seconds = ($args{'m'} * 60) + $args{'s'};
my $lap_time = $time_in_seconds / $laps;
printf("Average lap time is %.1f seconds.\n", $lap_time);
print "\n";
print "At this speed,\n";
for my $distance (400, 800, 1500, 3000, 5000, 10000) {
my $new_time = $lap_time * ($distance / $track_distance);
my $new_minutes = floor($new_time / 60);
my $new_seconds = sprintf("%0.2d", $new_time % 60);
printf("\t%5dm -> %2dm %.2ds\n", $distance, $new_minutes, $new_seconds);
}
Usage example for figuring out average lap time of a 5km race if you wanted to run it in 16 minutes:
$ ./tracktime -d 5000 -m 16 -s 00
5000m is 12.5 laps.
Average lap time is 76.8 seconds.
At this speed,
400m -> 1m 16s
800m -> 2m 33s
1500m -> 4m 48s
3000m -> 9m 36s
5000m -> 16m 00s
10000m -> 32m 00s
Django Python 960.gs Git Vim NetBSD Nginx
The author is a software engineer living in Australia. He sux at guitar, loves camping, doesn't like cake, does like coffee and is a lazy home brewer.
Help
Latest entries
*BSD Agile Apache Apple Athletics Beer Best-Practice Censorship Comedy Cool Crosswords Deployment Django English Exim Firefox Git Hardcore Health Interface irssi Javascript Jira Languages Linux Makefile Markdown Mathematics Mobile Broadband MySQL NetBSD nginx Nokia OSX Perl Photo Privacy Python Rant Requirements rsync Ruby Shell Slackware SQL SQLite SSH Standards Subversion Testing ThisBlog Vim VMWare (Fusion) VPN WDTEM X Yum zsh
Perldoc Output
Yum
Possum
Git's Index
Jira Project Keys
The Coffee Shop
Git GUI
It is more important...
Questioning Unix (and Other) File Times
The Frog King Photo
Rain Cloud Photo
rsync
Timezone
utf8 in your Perl
Theatre Ceiling Photo
Some problems are so complex...
Colours in your PAGER
zsh vared
zsh magic-equals and double-star
Funny Tweets
ChoppingBoard, Project365, RageQuit