Automating the Bunkplan

Posted on March 6, 2012 by Jack Kelly
Tags: windeward_bound, coding

One of the things we have to do before we go to sea is have a bunkplan and watchbill: each person is assigned one and only one bunk (except when hotbunking) and are assigned jobs and watches (red, white and blue watch rotate through keeping watch so everyone gets to sleep).

Currently, the watchbill is an excel spreadsheet and each cabin has a word document detailing its occupants and their watches. The watchbill is the canonical source for bunk assignments and watches, and the cabin sheets can be derived from the watchbill. Preparing them also takes a lot of time, meaning they don’t arrive until a day or so before we leave. What’s a lazy and impatient programmer to do?

Automate it, of course! I decided it was time to shake out the cobwebs from my OCaml knowledge and the result was bunkplan.ml. The output isn’t pretty: the machine that prints the bunkplans is still running IE 6, so I went straight to legacy HTML output (<font> and so on). The code’s probably not that idiomatic, either. But it only took a few hours, and it works.

OCaml’s an interesting language to write. The last time I played with it was before I’d completed COMP3610 and that experience made OCaml’s syntax feel less repulsive. I found that I needed to think a lot more before I could write anything, but what I did was a lot more correct. The only major bug I found turned out to be an error in the sample input data: garbage in, garbage out.

I originally attempted this program in C, using Lua to describe the ship’s bunk layout and wrote a Gtk+ GUI to enter the watchbill. I planned on using Cairo to generate PDF output for the watchbill and cabin sheets. This time, I avoided writing an interface by reading CSV (it helps that the watchbill was prepared in Excel, anyway) and I avoided writing a rendering engine by generating HTML and palming it off to a browser. It’s not reading text on stdin and writing to stdout, but it’s a lot closer to the Unix Philosophy. The result was faster and simpler to write, and easier to debug.

If you’re one of my coding friends, you might want to take a minute to read bunkplan.ml. It’s only 305 lines long.

Previous Post
All Posts | RSS | Atom
Next Post
Copyright © 2024 Jack Kelly
Site generated by Hakyll (source)