Graphing OpenMoko community membership by country of residence


A group at the Swiss Federal Institute of Technology recently published the results of their survey of OpenMoko community members.

I’ve graphed their data on survey respondents’ country of origin:

I’ve thresholded the output at 1% i.e. countries whose respondents accounted for less than one percent of the total are omitted from the graph.

This data jives with the webserver traffic logs we saw for Scott’s Doom Port. Greetz to all you German developers!

Why not a map?

In short, I couldn’t find a collection of colors (i.e. a gradient, the `chco` parameter) that looked good for this data set. This is about the best I could do:

Colophon

The script that generated that chart’s parameters is below. It uses BeautifulSoup to dig the data out of HTML. It uses GChartWrapper to generate the chart’s parameters.


#!/usr/bin/env python

from BeautifulSoup import BeautifulSoup
import urllib2
import sys
import re
from GChartWrapper import Map, Pie3D, Pie

# REF http://www.crummy.com/software/BeautifulSoup/documentation.html
# REF http://www.amk.ca/python/howto/regex/
# REF http://www.python.org/doc/2.4.1/lib/string-methods.html
# REF http://code.google.com/p/google-chartwrapper/

def main(argv=None):
page = urllib2.urlopen("http://public.smi.ethz.ch/files/MaemoOpenmoko/"
"PublicDescriptiveStatistics.html")
soup = BeautifulSoup(page)
# the 457th (zero-indexed) table row is the row that contains the first
#  country (e.g. andorra). the 521st row is the last country (e.g. zambia)
j=0
countryCodeList = ""
colorLevelList = ""
for curRow in soup.findAll("tr")[457:521]:
# the first (zero-indexed) paragraph contains the country name.
r = re.compile("\((.*)\)")
m = r.search(curRow.findAll("p")[0].contents[0])
foo = m.group(1)

# the fourth contains the openmoko percentage.
bar = float(curRow.findAll("p")[4].contents[0].replace("%",""))
# let's threshold at 1%
if bar > 1.0:
print foo, ",", bar
colorLevelList += str(bar)
colorLevelList += ","
countryCodeList += "'" + foo + "'"
countryCodeList += ","
#print "qqq", j, curRow.contents
j=j+1

# PUZZLE: can i avoid this annoying step somehow?
colorLevelList = colorLevelList.rstrip(",")
countryCodeList = countryCodeList.rstrip(",")

# print some debugging info
print colorLevelList, "----", countryCodeList

# let's make a chart of type "map"
myChart = Map(colorLevelList, encoding='text')
myChart.color( 'f5f5f5','91b86c','6c9642','365e24','13390a')
myChart.fill('bg','s','eaf7fe') # f37b00 is 'openmoko orange'
myChart.size(440,220) # default is 300x150
myChart.map('world', countryCodeList)
print myChart

# let's make a chart of type "pie". mmm.
herChart = Pie(colorLevelList, encoding='text')
herChart.size(300, 220)
# PUZZLE: can one, at runtime, use a list for a method call's arguments?
eval( "herChart.label(" + countryCodeList + ")")
print herChart

if __name__ == '__main__':
sys.exit(main())

Potential improvements

See also


Write a Comment

Take a moment to comment and tell us what you think. Some basic HTML is allowed for formatting.

Reader Comments

Be the first to leave a comment!