Eat It, Blog It: Week 9 Update

It's been a little over two months since I started logging my food intake and activity. It's been an interesting behavioral experiment. I definitely have noticed that I am more aware of how much am I eating.

For example, if I have a particularly gluttonous day, I will significantly reduce my calorie intake for the next day or two. Or when I look back on the week and notice that I haven't been consuming as many greens or vegetables as I might like, I try to self-correct.

I've also noticed that logging my food has also helped cut down on haphazard snacking. Often when I'm bored and pass the snacks in my kitchen at work I now think: "I could get a snack, but then I'd have to log it". My laziness seems to be a good counterweight to my urge to snack when I'm bored.

Working Out

In the last week, I've started working out at the gym again. I believe this has contributed to an increase in my calorie intake. I'll probably need to make some adjustments to address this issue, such as eating a small snack after working out to prevent getting crazy hungry later in the day.

As with any effort to get back in the gym, it's often easier to do it when somebody tells you what to do. I've been following a 30 day workout program called "30 Days of Change". I'm doing the beginner track, which has been a decent challenge thus far. It's only been a week, but I definitely feel like I'm getting a good workout.

By the Numbers

Now for some results. The graph below shows my weight over the past nine weeks. The maximum weight loss over this period of time was 12.5 lbs. The average weight loss over the period has been 0.975 lbs per week.

The graph above was generated using matplotlib. I wrote the following python code to grab and parse the HTML and plot the graph.

#!  /usr/bin/env python
 
from HTMLParser import HTMLParser
import urllib2
 
from pylab import *
import numpy
 
class MyParser(HTMLParser):
    """ Custom HTML Parser for parsing weight data from eat blog"""
    def __init__(self, *args, **kwargs):
        """Constructor initializes state and data array"""
        HTMLParser.__init__(self, *args, **kwargs)
        # States: IDLE, EAT_TABLE, EAT_TD, EAT_WEIGHT, EAT_WEIGHT_DATA
        self.m_state = "IDLE"
        self.m_data = []
    def handle_starttag(self, tag, attrs):
        """Handler for start of tag"""
        # EAT_TABLE -> EAT_TD
        if (self.m_state=="EAT_TABLE") and (tag=='td'):
            self.m_state = "EAT_TD"
        # IDLE -> EAT_TABLE
        if (self.m_state=="IDLE") and (tag=='table'):
            is_eat_table = False
            for k,v in attrs:
                if (k=='class') and (v=='eat-blog-table sticky-enabled'):
                    is_eat_table = True
            if (is_eat_table):
                self.m_state = "EAT_TABLE"
        # EAT_WEIGHT -> EAT_WEIGHT_DATA
        if (self.m_state=="EAT_WEIGHT") and (tag=='td'):
            self.m_state = "EAT_WEIGHT_DATA"
    def handle_endtag(self, tag):
        """Handler for end of tag"""
        # EAT_TABLE -> IDLE
        if (self.m_state=="EAT_TABLE") and (tag=='table'):
            self.m_state = "IDLE"
        # EAT_TD -> IDLE
        if (self.m_state=="EAT_TD") and (tag=='td'):
            self.m_state=="EAT_TABLE"
    def handle_data(self, data):
        """Handler for data in a tag"""
        # EAT_TD -> EAT_WEIGHT
        if (self.m_state=="EAT_TD") and (data=="Weight"):
            self.m_state = "EAT_WEIGHT"
        # EAT_WEIGHT_DATA -> EAT_TD
        if (self.m_state=="EAT_WEIGHT_DATA"):
            sarr = data.split()
            w = float(sarr[0])
            self.m_data.append(w)
            self.m_state = "EAT_TD"
    def get_data(self):
        """Get data array"""
        return self.m_data
 
def main():
    # Open URL and parse eat blog pages
    url = "http://mandke.com/blog/week-*-eat-blog"
    week_range = range(1,10)
 
    # Initialize parser
    parser = MyParser()
 
    for w in week_range:
        site = url.replace('*', "%d"%(w))
        f = urllib2.urlopen(site)
        s = f.read()
        parser.feed(s)
 
    # Plot weight data
    wdata = parser.get_data()
    plot(np.arange(len(wdata))+1, wdata)
    xlabel("Day Number")
    ylabel("Weight (lbs.)")
    grid(True)
    show()
 
if __name__=='__main__':
    main()
Tags: