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
This is the blog of Brad Willis, a software engineer living in Brisbane.
Help
Latest entries
*BSD Agile Apache Apple apt Athletics Best-Practice Censorship Comedy Cool Crosswords Deployment Django English Exim Firefox Git Hardcore Health irssi Javascript Jira Languages Linux Makefile Mathematics Mobile Broadband Mutt MySQL NetBSD nginx Nokia OpenVZ OSX Perl Privacy Python Rant Requirements rsync Ruby Shell Slackware SQL SQLite SSH Standards Subversion Television Testing ThisBlog Vim VMWare (Fusion) VPN X zsh
Checking for exceptions in doctests
Homer's Curling Speech
retry in Python
Vim Makefile tabs
Centos (or RH) IPTables
Converting ssh2 public keys to openssh
Vim comment hints
Context managers in Perl
Dish rotation
Git - fixing commit user
apt stuff
Using shell variables in AWK
Linux - Too many open files
Tell gvim to save and quit... remotely
Vim - automatically remove whitespace at EOL
Python - relative paths from within modules
TV Aspect Ratios
Git - Which commits are in your branch only?
Subversion setup cheat sheet
Force detach a screen session
Modify sudo's use of environment variables
Install all Perl modules
Mutt - delete old messages
OpenVZ VPS and swap space
fail2ban on NetBSD for ssh
NetBSD - Using sup
Python - testing for a sys.exit
Python Best Practice Link Dump
Python script names
Perl - Using an expensive module
Speed of git clone
Perl Modules with Custom Prefix
Perl: tr vs. s
Brilliant sysadmin Reference
Why is GRUB better than LILO?
Why is swap space important?
Perldoc Output
Git's Index
Jira Project Keys
Git GUI