Town-Wide Garage Sale Web App

The Borough of Madison, NJ organized a town-wide garage sale to benefit Union Beach, a community hit hard by Hurricane Sandy. I added a feature to their website, so residents can register their sale and (pending a quick review by a website administrator) have it placed on a map of Madison. Check out the map here!

Madison Garage Sale Map

Screenshot of Madison’s town-wide garage sale map mashup

I built the town’s extensible content management system starting in 2008, working closely with Jim Sanderson, Madison’s technology directory. The history of “RoseNet” (named for Madison’s “Rose City” moniker), one of the first community websites, dates back to 1997. It has gradually grown to include more and more content and interactive features. I haven’t seen any other municipal websites that come close in terms of quantity and quality of data. For example, Jim has invited all local businesses and non-profit organizations to have a self-maintained presence on the website, and this cool business map is a fun way to promote Madison’s downtown merchants. The local business listings provide a helpful service to residents and help boost revenue by promoting the business district in the face of competition from internet and big box retailers. There is, of course, room for improvement (we’re constantly debating the home page and navigation), but the site has proven to be a very effective communication medium for the town.

The garage sale registration process highlights a flexible workflow capability that will help the municipal government streamline many forms and processes. Plus, thanks to years of careful design and execution, Jim and I were able to deploy this feature with minimal cost and lead time.

I think we’ve really stumbled onto a great architecture for a civic website. I’d love to turn the design into an open source project. Recently, I’ve heard a lot about civic code volunteering and startups (like the Code for America project), and I think that’s really great. Even though Madison is a small town, I think we’re out in front in terms of designing an effective municipal content management system. Drop me a line [Twitter, Google Plus, or just leave a comment below] if you’re interested in collaborating.

Battery Life and Charge Cycles

There are two camps on how to best protect the capacity of your cell phone battery: charge it when it’s dead, or charge it every night.

I’ve heard older NiCd battery technology should be deep cycled to avoid the old “memory effect”, but our phones, tablets and laptops all have newer lithium-based batteries. The conventional knowledge seems to be that completely discharging a lithium battery permanently degrades its lifespan. But I haven’t found a definitive source on how to best care for my battery.

As an iPhone user, I thought I’d check with Apple first. For maximizing battery lifespan, their website suggests keeping your phone at the right temperature and adjusting your settings to use your battery less. They don’t offer any specific recommendation on deep vs. shallow charge cycling, but they do suggest going through at least one complete charge cycle (charging the battery to 100% and then completely running it down) per month. That seemed like an oddly specific recommendation with no data to back it up.

Checking the Literature

I decided to see what the scientific literature had to say about this. Here’s what I learned:

Measuring Battery Performance: When evaluating any kind of performance, engineers need a metric. The standard lifespan metric seems to be “number of charging cycles through which the battery can retain 80% of its original capacity”. For example, Apple promises 400 charging cycles for your iPhone battery.

Temperature: I found an interesting paper (behind a paywall, unfortunately) on the aging mechanisms of lithium ion batteries. Sure enough, there’s good science verifying that temperature plays a big role in battery lifespan. Most batteries are designed to operate at room temperature, and both hot and cold temperatures accelerate aging. They also note that battery capacity will fade over time regardless of your usage habits because the chemicals simply break down.

Shallow cycling: The best research I could find comparing deep and shallow cycling was Nicholas Williard’s master’s thesis from the University of Maryland. He experimented with a particular make and model of lithium ion batteries. He preconditioned a fraction of these batteries by shallow cycling them 900 times (draining just 7% of charge before recharging). Amazingly, he found the preconditioned (i.e., shallow-cycled) batteries were able to withstand about the same number of deep cycles as brand new batteries. In other words, shallow cycling didn’t seem to degrade battery capacity at all!

My conclusions:

  • Keep your battery cool (but not cold).
  • Shallow cycling is OK (go ahead and charge every night… or even more often).
  • I couldn’t find any research backing up Apple’s “monthly deep cycle” recommendation.

Curiosity at 120 Volts

Have you ever wondered what would happen if you plug an old iPhone charger half-way into the wall and then short the power prongs with the 30-pin connector? My seven year-old nephew did.

shorted iPhone charger

Not surprisingly, iPhone chargers don’t handle 15-amp short circuits very well.

The metal shielding of the 30-pin connector completed shorted the 120 V A/C power prongs. My nephew reports seeing a large spark, hearing a pop, and then witnessing a bit of smoke and funny smell. Fortunately, the 15-amp circuit breaker tripped almost immediately, preventing him from getting shocked and probably stopping a house fire.

In the picture below, you can see the power prongs melted a bit, and there’s a coating of black soot all over the charger (the wall was dirty, too, I’m told).

another look at the fried iPhone charger

Lesson learned? We sure hope so!

How to Analyze the Play-by-Play Data

Interested in analyzing the play-by-play football stats? I pushed some code to GitHub to help you parse the plays and output them to your choice of CSV (for use in a spreadsheet), JSON, or a SQL database. You can check out the code (and a brief README) here. The repository also contains all the source code of my play-by-play effectiveness webapp.

How to Parse Plays to CSV

If you don’t need the data in a SQL database, you can quickly parse the plays to a CSV file (comma-separated values). You could then open this file in a spreadsheet application or read it into the scripting environment of your choice (R, MATLAB, Python, etc.).

I created a specific branch of the repository that will parse the plays without any dependencies on database libraries (i.e. SQLAlchemy). Assuming you’re on Linux and have Git installed, just clone the “nodatabase” branch of the repository to get started like this:

$ git clone --branch=nodatabase https://github.com/10flow/playbyplay.git

Then you can run the parser script:

$ cd playbyplay/play-parser/
$ ./play_parser.py

After a minute or two of processing, you’ll have a “output.csv” ready to play with.

How to Ingest Plays into a Database

If you want to use a SQL database, I’ll assume you have one installed. If not, I’ll refer you here for Ubuntu’s guide to MySQL.

My ingest script requires SQLAlchemy, a popular database library for Python. This is easy to install with the “easy_install” package manager. If you don’t have easy install, you can install it on Ubuntu as follows: “sudo apt-get install python-setuptools”. Next, get SQLAlchemy like this:

$ sudo easy_install SQLAlchemy

Now you’re ready to download the code from GitHub. Grab the master branch if you’re planning on using a database:

$ git clone https://github.com/10flow/playbyplay.git

Before you run the parser script, there’s a few things to do. First, specify your database information in “play_parser.py” on line 28. And next, you’ll need to create the database before you can insert the data. For example, if your database connection string (line 28) looks like this:

database_engine = create_engine('mysql+mysqldb://root:password@localhost/playtest', echo=False)

Then create the database like this:

$ mysql -u root -p
mysql> create database playtest;
Query OK, 1 row affected (0.06 sec)
mysql> exit

Now you’re ready to run the script:

$ cd playbyplay/play-parser/
$ ./play_parser.py

Inserting the plays will take a long time. But once it’s done, you can issue queries this:

$ mysql -u root -p
mysql> use playtest;

Database changed
mysql> select result,count(result) from plays where season=2012 and result!='play' group by result;
+--------+---------------+
| result | count(result) |
+--------+---------------+
| downs  |           209 |
| fg     |           855 |
| fumble |           184 |
| half   |           185 |
| int    |           378 |
| loss   |            61 |
| miss   |           193 |
| ot     |            14 |
| other  |           154 |
| punt   |          2480 |
| td     |          1269 |
| tie    |             2 |
| win    |           148 |
+--------+---------------+
13 rows in set (0.02 sec)

And now you’re ready to analyze.

Let me know if you come with any interesting stats in time for the big game!

Play-by-Play Effectiveness

Check out this web app I put together to measure the effectiveness of plays and drives:
http://football.10flow.com/

Here are some interesting stats I’ve found so far:

The stats show Andy Reid’s Eagles performed poorly when down a score in the final 2 minutes. The biggest problem seems to be the terrible 34% pass success rate and a below average plays-per-drive (4.4 compared to 4.7). Two-minute drill drives ended in 11 picks (21.2%), 12 turnovers on downs (23.1%), and 10 TDs (19.2%). They ran out of the clock 9 times. Their scoring percentage was 25% compared to a league average of 33.4%. Good luck Kansas City!

The 2012 Jets stand out as a weak offense. There was a big drop in touchdowns, pass play effectiveness, and interestingly, pass play selection. The Jets passed on 57.1% of plays in 2011, compared to 52.1% this year. The loss of CB Darrelle Revis also had an impact. Opposing team’s pass success rate went from 40.8% (with 15 picks) in 2011 to 42.8% (with 9 picks) in 2012.

Finally, the Pats offense was scary-effective this year. Their touchdown rate stands out the most — 32.4% compared to league average 21.0%.

Leave a reply below or Tweet at me if you find something interesting in the stats!