Tuesday, June 28, 2011

The Long Road to Electric: part 3

My shoulder had not recovered sufficiently to allow me to ride the motorcycle to Portland for MWWW (Mozilla Webdev Work Week) and OS Bridge.  Saturday's test ride was a fail.

I turned my trip  into a different adventure. I drove the electric car to Portland. It was my own case study in range anxiety and actual range.  Not expecting to be able to do the whole trip on one charge, I knew I'd have to stop halfway for a recharge.
This is the route that I took to Salem.  It is entirely on back roads with lots of up and down hills and little traffic.  I used about four bars of charge to get to the Level 2 charging station at the Salem Nissan dealership.  I left the car there for two hours bringing the battery back to just under a full charge.  I killed time by walking two miles to the Salem Harley Dealership.
Going on to Portland, I wasn't as concerned about my range because I had a nearly full charge.  I didn't take the freeway, but chose 99E a two lane highway to Wilsonville just south of Portland.  At Wilsonville, I switched over to I5 and drove the rest of the way to the Level 3 charger in downtown Portland.
The Level 3 charger in the PGE parking garage is free, but it cost six bucks to get into the garage. I thought this was rather high for about 20 minutes of parking.  The charger itself was simple enough to use.  It took about 20 minutes to get the charge up to eighty percent.  I wondered what it would take to get up to one hundred percent, would I have to go to another charger to get that last twenty percent?
The car spent the rest of the week in the parking garage at the hotel.  I got fifty percent off on the parking fee because the car was electric.  I walked or used public transportation during my stay.
On the last day, I checked out of the hotel and moved over to a friend's house near Mt Tabor.  I plugged the car into a long extension cord and charged up to one hundred percent.
On my return trip home, I eschewed the freeway for back roads, taking a route through Lake Oswego to Wilsonville and then on 99E to Salem.  I used six bars of charge to get there.  That was interesting, because if I could use only four bars of charge to get home to Corvallis, I could do the whole trip on one charge. I opted for caution and recharged for an hour in Salem.
On arriving in Corvallis, I had just over twenty miles of range left and had used an additional five bars leaving me only one white and two red bars.
What is a bar?  There are ten white bars and two red bars in the battery charge indicator.  That isn't very good resolution over the range of possible charges.  It could be in my initial run from Corvallis to Salem that I really used 4.9 bars, but since I didn't use that last one tenth of a bar, it only displayed 4 bars of usage. I suspect that is true, because I used 5 bars on that leg of the return trip.
It is really complicated to get real information from the bars and miles left indicators.  These are all just estimates. Road conditions, elevation changes, speed, traffic and my mood all seem to affect the range.  As time goes by, I'll get more of an intuitive handle on it.
Soon, I hope to try to do the trip without the recharge in Salem.

Monday, June 20, 2011

Configuration - part 4

We've seen how to dynamically load class with the ConfigurationManager in my previous posting. The configuration manager interrogates the loaded class to find any further configuration requirements it may have. These additional parameters are added to the configuration requirements for the whole application.

There is a potential conflict though. For example, let's say we've got an application that copies data from a source to a destination. Further, we've a hierarchy of classes that define potential sources and destinations.

We could specify a PostgreSQL source and an HBase destination. A database wants a hostname, port number, username and password. HBase wants only the hostname and port number. If both classes define the configuration parameter 'hostname', we've got a conflict. A valid hostname for the database isn't likely to be the valid name for HBase.

Namespaces can resolve this issue by prefixing and isolating any symbols within them.

    top_level = cm.Namespace()
    top_level.source = cm.Namespace(doc='the input source')
                 doc='the classname for the source',
    top_level.destination = cm.Namespace(doc='the output destination')
                 doc='the classname for the destination',

When finally using these definitions in an application, you'll find that the requirements of the two loaded classes are prefixed with 'source' and 'destination':

    print config.source.hostname
    print config.source.port
    print config.destination.hostname
    print config.destination.port

The conflicts are resolved.

How does this work for the command line? here's how you'd specify HBase as both a source and a destination:

    python sample.py   
        --source.hostname=hbase1 --source.port=9090 

This has a direct analog in the flat conf file and the ini files. in the conf files, we've got the same dot separated structure:


In the ini files, the namespaces translate into the sections in the ini file.


As noted in part 1 of this series. you can get the whatever app employs the ConfigurationManager to write these config files for you with the --_write=ini or --_write=conf command line options.

Next, we'll see how to make the entire guts of an application configurable.