Bodymedia System Wishlist

I bought myself a Body Media On Body Monitoring System. It seems to work really well and I got a good deal on Amazon. It was under a hundred bucks.

This is less about what is great about Body Media and more about what they need to improve.

  1.  My confidence in the step counter. I switched the iOS app to workout mode and walked around my house while it the app and armband were communicating. The updates weren’t realtime, instead it looks like they were batched. It wasn’t clear to me whether it was working properly. You should provide some notification in the UI that explains this. Not something overt like a pop up message but instead integrate the behavior in the UI elements.
  2. The calorie intake. No one does this well, your setup is especially bad. If I can’t easily log what I’ve eaten I’m not likely to use the tool.
    1. In an ideal world, I’d like to be able to take a picture of a nutrition label and the software would OCR the data. These labels are standardized so this doesn’t seem like a hard problem.
    2. In a less than ideal world, take a picture of the label, upload it to you and display your form and label side by side to make data entry easier.
    3. Do you store items that are manually entered by users in your database for public use? It feels like this should be shared pain. It will help improve the database.

Otherwise great product, I am interested to see how well I do with it after the holidays when I’m thinking about what I eat again.


P2 Theme Kill Sites with Many Users

I recently updated my blog theme to use P2. P2 is a free WordPress theme that gives your site more of a Tumblr / Twitter style look.

In general, I liked it. However, I noticed that the performance really sucked. Digging in deeper it turns out the culprit is the P2 variable “mentionData.” I presume it is used to allow the mention feature to work. What it does is preload all of the user profile data onto the page.  This can be bad news for a WordPress instance with a lot of users.

I had over 700 users on the site (that was another problem that I rectified), on each page load it P2 will fill in the mentionData variable with all 700+ account holders.

I’ve since deleted the offending users and my performance is great again. I don’t know enough about the theme to want to dive in and take a look at it. Hopefully the guys at Automattic can fix this.


Software Usability – Find the shortest path to achieve your goals.

I just downloaded the recently release Open Office 3.0 productivity suite. On first launch of the software, I was prompted to register the software in order to help Sun determine the global market share. I didn’t mind doing this so I clicked the Register button. What transpired was a very long process requiring me to fill out a form for the Sun Developer Network, receiving a registration email which I then had to validate. After this registration process was complete, I still had to go back to the original Open Office registration page which, in the end, didn’t actually work. Sun in one stroke ticked me off before I had a chance to even see the software. I’ve given up my time and my email address and our mutual goal (registering the software) wasn’t achieved. Not a great first impression and very poor customer service. However, it is valuable to reflect on this experience when designing your own software.

The point is, determine what the most significant thing that you want your users to do and give them the shortest path to achieving this goal. Goal driven design is nothing new and agile developers tend to already think this way. If Sun’s goal is to determine market share, here is one alternative to the process.

  1. “Do you want to register now and help Sun get a snapshot of the global market share of Open”, Yes / No
  2. Clicking Yes takes you to a simple form that asks for email address and password and a submit button.
  3. Customer fills in email address and password, clicks register.
  4. Sun could then send a single email to me explaining the benefits of the more full fledged program. If I do not choose to opt-in to the full program then Sun still has what they want, a registered user of Open Office, with minimal hassle on my part.

On further thought, Sun could make this simpler:

  1. On first launch, ask the user if they would like to provide feedback to Sun.
  2. If the customer agrees then on each launch, send a ping to Sun’s database with information on who is using the software.

This is a gross example but represents some real world UI lunacy we are often faced with. Make sure you give your customers the easiest path to achieving their goals.


Cleaning your database and starting over in Django

I haven’t posted any django information in a while because I haven’t had any time to mess with it. Today, I dove back in.

I wanted to get a fresh start with the project I’m working on so I thought I’d clear out the database. Why for the life of me I couldn’t find the proper incantation to make this happen I’ll never know.

After searching for about 10 minutes I found it. I’m posting it here so I can reference it the next time I have a brain lapse.

Are you ready? Here it is… flush

This will reset the database to the state immediately after it was created.


Web Framework Django has a new Book

Fans of the excellent Python based web application framework Django will be happy to find out that Christmas has come early this year. Apress has just published The Django Book. Every good framework needs excellent documentation in order to break through. It’s a sign that the software has come into it’s own. Django is no exception.

The Django Book was published by Apress in December 2007. It covers the most current version of Django (as of this writing). It is available in hard copy from your favorite book seller on you can read it free online at the Django Book website. I’ve used this book in BETA form for the last four months. The final version exceeds the beta in quality and depth.


Powered by ScribeFire.


Save Driving Time – Avoid Left Turns

Interested in cutting down on your driving time? It’s easy. Avoid left turns. At least that’s what UPS is doing.

according to Heather Robinson, a U.P.S. spokeswoman, the software helped the company shave 28.5 million miles off its delivery routes, which has resulted in savings of roughly three million gallons of gas and has reduced CO2 emissions by 31,000 metric tons. So what can Brown do for you? We can’t speak to how good or bad they are in the parcel-delivery world, but they won’t be clogging up the left-hand lane while they do their business.

[tags]economics, environment,software development[/tags]


Adding Model Field Validation to the Django Admin Page

Django, the hot Python web application framework, provides an excellent administration user interface out of the box. Django originated in the newsroom and it’s reflected throughout the code. The idea behind including an admin interface is that reporters can work on easily submitting their content while the code jockeys work on the fun stuff – namely presenting that content to their readers.

The admin interface provides a great experience out of the box but is also extensible so you can add features not present in the original interface.

I was working on a Model that was meant to be manipulated inside the admin interface. I wanted to provide constraints on some Integers Fields in that that model in order to limit the range of possible entered values.

The first way I tried to solve this was to add a choices parameter for my IntegerFields. While this technique worked, it caused my admin interface to add a drop down box displaying my choices. This was not what I was looking for.

The final way I solved it came from a suggestion on the Django IRC channel. Use validators. It took some digging through the documentation but I figured out how to do what I want. I will explain by way of an example.

from django.core import validators
from django.db import models

range_validator = validators.NumberIsInRange(0,4)

class Test (models.Model):
    valid_int = models.IntegerField(null=True, blank=True, validator_list=[range_validator])

The validation framework is defined in the validators module. Import that if you need to perform any validation on your data.

Django includes a number of built-in validators. I lucked out and they had a validator that suited my purposes. The first step creates a validator instance of NumberIsInRange with the appropriate range. This returns a callable that I use later.

Model fields take a parameter of type validator_list which is a “list of extra validators to apply to the field. Each should be a callable that takes the parameters field_data, all_data and raises django.core.validators.ValidationError for errors. (See the validator docs.)”

A quick test in the admin interface and the code works.

The Django documentation contains everything you need to get the job done. Some careful searching and a great support community has helped make Django one of the best web frameworks available.



Django Tip – Don’t use hard coded urls in templates

Django, the Python based web framework has a template system which allows you to separate business logic from presentation. It provides a method of substituting variables inside the template using the {% var %} syntax.

One of the things you will often need to do is provide links to various views inside your application. However, the worst possible way to do this is to hard code pages inside your template. Developers of the Django framework are proponents of the DRY philosophy. This is evident in the URL mapping mechanism.

When you need to link to other views in your application, open your file. Copy the full to your view. Then, inside your template in an anchor tag insert the following.

<a href="{% url %}">
Link location

Django will then substitute the view name with the proper link relative to where your application lives.

The obvious advantage to doing this is if you ever publish your Django application to a different location you don’t have to update your links.



Running external scripts against Django Models

Django, the Python based web application framework, is an excellent Model/View/Controller application framework for rich website design.

A Django application runs under a web server. However, often it is necessary to develop external scripts that need to interact with you web application data models. This brief tutorial will walk through an example. This may not necessarily be the _best_ way to do this, but merely a way. I struggled for a few hours on this last night and thought it would be useful to others to document my results.

Let’s look at an example. Feel free to take this and modify it as needed. It’s a bit contrived but will suit our purposes.

Suppose you have written a blog application and you want to periodically purge old entries. In your Model, you have written code to to all of the heavy lifting. Now, you want to make sure that these updates happen at a scheduled interval.

Assume your project lives in c:\project\blogprj

import sys,os
from datetime import *
os.environ['DJANGO_SETTINGS_MODULE'] ='blogprj.settings'

from import setup_environ
from blogprj import settings

from import Entry


blogs = BlogEntry.objects.all()

for entry in blogs:

Let’s take a closer look at this.


This line appends your project directory to the python module search search path so that it can find the your packages. Remember, when django creates your template, it creates an file in each directory of your project and apps. These files tell python to treat the entire directory as a python package. If you set your module path to c:\\project\\blog then python will not be able to find the root of your packages (blog)

os.environ['DJANGO_SETTINGS_MODULE'] ='blogprj.settings'
The DJANGO_SETTINGS_MODULE variable tells your django application the name of the settings module. It uses the Python path syntax.

from import setup_environ
from blogprj import settings

Since you are using Django libraries, you must tell it where to find your file. This is done through the function setup_environ and your project settings, imported here.

from import Entry

We are going to be working with the Entry model, so we need to import it.


As stated previously, we must tell Django to use our project settings. This is necessary so Django can know what database we use, our installed apps, etc. This is handled by the setup_environ() method which takes a Settings object as a parameter.

Once this is done, the rest of the application merely performs the work against the model.

Save this script and you can run it inside your favorite scheduler, on Windows, we use Task Scheduler.

I hope this small tutorial has given you a little insight in how to call Django from external scripts. I welcome your comments.
[tags]Django, Development, Python, tutorial[/tags]


Quote of the Day

“Programming  languages are like girlfriends: the new one is better because *you* are better” – Derek Silvers

Found that one in a blog post, from the owner of CD Baby, on why he dumped the Ruby Rails framework and went back to plain old PHP.