Day: March 15, 2005

Weight Table – Perl

The Perl Version

I really liked the Tcl version, but at some point I didn’t want to stick to an application any more. A web interface would have been much better for my needs.

This change by itself would not have prompted a new implementation, but I realized that there would be no GUI interface, and that hence the tables and graphs would have to be built on the fly. Tcl’s sluggish response and the need for external software made me wonder whether that was the right approach.

I saw the GD package, and was surprised how easy it actually was to create graphs given knowledge of the data. Further along, I found GD::Graph, which actually went all the way to displaying a graph from data input. I had to do without comments, but as soon as I get hotspots to work, they’ll be there again.

As a result of the conversion, the code went down from 20k for the Tcl version to 8.5k for Perl. Of course, the Tcl version could be optimized considerably (especially the computation of coordinate transformation, which is not centralized), there is no GUI in the Perl version, and the latter benefits from a sizeable library. All in all, though, I think I’ll stick with Perl for future programming tasks, and will switch to PyQT for GUIs.

All the Perl that's Practical to Extract and Report

Weight Table – TCL

Weight – The Tcl Version

Ok, the real name of the program is gewicht.tcl, and it is correctly TCL, since it’s an acronym. Now that we’ve got the FAQ done, let’s move on to greater things…

The only external package used is TkTable. The weight input is a table, so that you can see past dates and modify the data there, or even input many days at the same time. If TkTable is not available, don’t despair – you’ll still be able to input today’s weight (but not the bodyfat) very conveniently.

All you need to run the program is Tcl, more precisely a currentish Tcl/Tk wish application. gewicht.tcl expects the file gewicht.txt to be present in the startup directory. It will read the file and figure out the current weight chart from there, asking for additional data if there is no information for the current day.

The format of the file is fairly simple. In human-readable terms it’s a sequence of lines, each of which contains the data for one particular day. Each day is made up of the date, the weight, the bodyfat percentage and a comment, each separated by semicolons.

Example:    16.03.2003;170.4;20.1;Back from Maui

Of course I didn’t choose the example to rub it in! 🙂

Everything after the weight is optional. The code knows how to work around missing data, and it doesn’t expect the dates to be sequential.

Once input is complete, a chart pops up. Dots mean single day data, lines denote averages. Big black dots mean data with comments, and if you hover above the dot, a popup will show the comment. An unruly status display at the bottom will show the current pointer pixel’s date and weight.

By default, it shows dates on the x-axis and weight in pounds on the y-axis. A ‘complicated’ system of keyboard shortcuts allows you to get to additional data:

  • l for ‘lbs’, displays the weight in pounds
  • k for ‘kilos’, displays the weight in kilograms
  • b for ‘bodyfat’, displays weight and bodyfat (y axis displays bodyfat units)
  • f for ‘fat’, displays weight and total fat (y axis displays pounds)
  • t for ‘total’, displays weight and non-fat total (y axis displays pounds)
  • q for ‘quit’
  • right, left, control right, control left, home, end navigate if you need to scroll
  • alt f, shift alt f save the current canvas as postscript file

Weight Table – The Table

This is the current chart of Marco’s body fat. (Click on picture to see other views)

If you want to input new data for a particular day, please do so here:

User Name: