What's It Going to be then, Eh?
Thu 10 Apr 2008
Not Found
Weight: 217
Workout: 30 Minutes Treadmill

Seems like maybe two days in a row is a bit much for me right now. I'll hit it again tomorrow.

Hoping for a quiet day at work today. Planning to keep my head down.

Wed 09 Apr 2008
If I Should Fall From Grace With God
Weight: 216
Workout: 20 Minute Run

Stepped down to 5.5 on the treadmill and it made quite a difference. Ran for 20 Minutes. I should have stuck it out for the extra 2 minutes but I slacked off. Oh well I seemed to drop 2 lbs. So there's that.

Tue 08 Apr 2008
The Last Letter Home
Weight: 218
Workout: 20 Minutes Bike

Had trouble getting up today so I got to the gym pretty late and just did 20 on the Bike. Happy to see the weight still went down. Maybe watching Jennifer run in the 5K had a good effect on me.

pretty happy with the nightly job.

Fri 04 Apr 2008
White City
Weight: 219
Workout: 1 Mile Run

Man running was hard this morning. I was only able to get 1 mile in. But I'm pretty happy I was able to do that. I was also pleased that I could maintain the 10 Min/Mile pace. I think I may try slowing it down a bit on monday and see if I can stretch the distance a bit. I'll see how I feel this weekend after the run. I stretched pretty well and walked to cool down afterward so I should be ok.

Thu 03 Apr 2008
Dancing Queen [1976]
Weight: 220
Workout: 30 Minutes Eliptical

Well it worked! I had to edit the previous post though because it was skewing the graph. Not much else to report right now.

Wed 02 Apr 2008
Not Found
Weight: 220
Workout: 30 Minutes Treadmill

Well today will be the first test of the nightly script. Tomorrow the graph should have todays date and weight at the very end. How exciting! Not much else to report.

Thu 27 Mar 2008
Google Graphs - Detail

So here is a little more detail on how I did the weight graph for the footer of the blog.

At Google Code They describe the API for generating a .png image of a graph. This is done by sending a request with the proper parameters in the url. the url I'm using is:

"http://chart.apis.google.com/chart?cht=lc&chxt=x,y&chxl=0:" { A bunch of dates here } "1:|185|200|250|275& chd=t:{ A bunch of weights here }& chds=185,275& chs=600x100& chco=224499& chm=B,dcdcdc,0,0,0& chtt=Weight+Graph"

Easy as pie right? The url is a bit cumbersome but in short this is what it brakes down to:

http://char.apis.google.com/chart
This is the address where the chart application lives
cht
This is the Chart type. lc = line chart
chxt is the axis types
I have given the chart an X & Y axis (weight over time)
chxl is the access lables
for the x axis I'm going to use dates that are pulled from the blog and for the y axis I'm giving a static weight range from 185 to 275. Which I think are reasonable extremes in weight for me.
chd is the chart data. the t: means I'm passing the data as text
The data I'm passing is the weights pulled from my blog
chds is the data scale
The data scale is the range for the data points. By default the api expects all points to be between 0 and 100. I change that to 185 and 275.
chs is chart size
This allows you to set the dimensions of the .png image returned
chco is chart color
This sets the color of the line
chm is fill area
This sets area for the data plotted the capital B means fill everything under the line with the color specified
chtt is the chart title
This allows you to specify the Title to appear on the chart using '+' for spaces

Now where to get the data from? Well I use the blosxom blog engine for my blog. It uses a simple text file for each entry. For each daily entry I add my weight to the top. In fact I have written an emacs mode just for blogging that asks my weight and auto populates that info for me when I start the entry. So that makes grep an excellent tool for pulling out the data in those files. Originally I considered perl but that seemed a bit heavy handed. So to pull the data form the text files I used the following grep command

grep -o -P "[w|W]eight:?.?[0-9]{1,3}" *.txt
That says print out the file name and any text matching the pattern specified. The pattern says to Look for the word "weight"(case insensitive) with an optional colon and space afterward, and at least 1 digit but up to 3. So the out put looks like this: UPDATE: had to remove ths as it skewed the graph Now that is starting to look like something we can work with.

So now I want to strip away just the file name and date. awk is just the thing there.

awk -F: '{print $1 "," $3}'
This tells awk that the field separator is a colon and to print out fields 1 and 3. easy poesy!

Next I want to sort the data coming out to give it a bit of order in the graph. To accomplish this I pipe through sort. Next I pipe that output to a perl script I wrote to collect the data and craft the url.

so the final cron job looks like this:

#!/bin/bash
cd /home/abturet/blog/;
grep -o -P "[w|W]eight:?.?[0-9]{1,3}" *.txt |awk -F: '{print $1 "," $3}' \
| sort | ./weightgraph.pl;

So what is it that the perl script does???? Well, I'll tell you. But first I'll show you

#!/usr/bin/perl
use strict;
use warnings;
use POSIX qw(strftime);
my ($url,$img_location,$dates,$weights,$weight_counter,$date_counter,@data,$date,$weight);
$weight_counter = 40;
$date_counter = 100;
$dates .= "|";
$img_location = "/home/abturet/public_html/images/weightgraph.png";
while(<>) {
($date,$weight) = m/(.*), ?(\d+)\n/;
$date= strftime "%Y-%m-%d", (localtime((stat($date))[9]));
s/^\s+/$2/;
if($weight_counter == 40){
$weights .= "$weight,";
$weight_counter = 0
}
if($date_counter == 100){
$dates .= "$date|";
$date_counter = 0
}
$weight_counter++;
$date_counter++;
}
$dates.= "$date|";
$weights .= $weight;
$weights =~ s/,$//;
$url = "\"http://chart.apis.google.com/chart?cht=lc&chxt=x,y&chxl=0:".$dates.
"1:|185|200|250|275&chd=t:$weights
&chds=185,275&chs=600x100&chco=224499&chm=B,dcdcdc,0,0,0&chtt=Weight+Graph\""
;
`curl -o $img_location -s $url `;

That's quite a mouthfull. What I do is as each line comes through I capture the two parts. The date and the weight. The date is actually the file name. So I call stat on the file and use the ninth element(the create date). I format that with strftime. Then I strip any white space from the weight.

The next to blocks make sure I don't send too much data. The api documentation says there is a url size limit of 3600 characters so I only grab every 40th weight and every 100th date. I have initialized them to the max value so that I have the first values from 2004 in the data set. After I've handled every date in the blog I tack on the last date and width so that the full range is represented.

Then I use those big strings of dates and weights to fill in the url and use curl to send the http request and save my nifty png file.

Sometimes it's fun to put your documentation out there in the public view. And now that it's here I can always find it if I want to make a change.

Wed 26 Mar 2008
Take It and Run
Weight: 219
Workout: 20 Minute Walk/Run

Ran a little and walked a little. Will Run more tomorrow

There was an issue yesterday at lunch with a UPS in our Computing center at work. The server that hosts many of my applications died during the event. Today I can't to comb the memory banks of everything I've done for the last 7 years to bring some of those apps back on line. Today is going to present many opportunities i am sure

Tue 25 Mar 2008
Google Graph Api

Played with the google graph api today. Since I did the weight graph a few months ago I have wanted to add it to cron to update everyday. However the old way was a bit of work and there was one manual step because of data cleaning. That was something that had been bothering me for a bit. I am supposed to be a programmer and have tools that will get me around these types of issues. I have been reading "Mastering Regular Expressions" this week and learned a way to fix that issue. Then Josh at work showed me the google graph api's yesterday and I thought Hey! that's just what I need. So this morning I took a minute and played around and now I have a nice graph of weight loss(and gain) over the life of this blog.

it will show up at the bottom of the page and be refreshed every day now thanks to cron

080371: NPR: 03
Weight: 220
Workout: 20 Minutes Treadmil

Was up a little late last night watching "Walk Hard: The Dewey Cox story." So I was a little tired at the gym this morning. I ran a little but not really enough. I'll try again in the morning.

« older | newer »

Home
Weight graph, 793 weigh-ins