Boston Roulette Part 2

Import Python packages


In [1]:
from pymongo import MongoClient

Get a place example


In [2]:
client = MongoClient('localhost:27017')
db = client.bosroul
db.places.find_one()


Out[2]:
{u'_id': ObjectId('54ff308d66a7a58297001f01'),
 u'labels': [u'restaurant'],
 u'lat': u'42.3944389',
 u'lon': u'-71.1209963',
 u'name': u'Out of the Blue'}

Helper function


In [20]:
def aggregate(pipeline):
    return db.places.aggregate(pipeline)

See how many places don't have names


In [22]:
total = db.places.count()

pipeline = {"$match" : {"name" : None}}
results = aggregate(pipeline)

print "Total number of places: {0}".format(total)

print "Number of places without a name: {0}".format(len(results['result']))


Total number of places: 4902
Number of places without a name: 1403

For the no-names, what are the labels?


In [30]:
pipeline = [{"$match" : {"name" : None}},
            {"$unwind" : "$labels"},
            {"$group" : {"_id" : "$labels",
                         "count" : {"$sum" : 1}}},
            {"$sort" : {"count" : -1}}]
results = aggregate(pipeline)
results


Out[30]:
{u'ok': 1.0,
 u'result': [{u'_id': u'bench', u'count': 732},
  {u'_id': u'bicycle_parking', u'count': 202},
  {u'_id': u'post_box', u'count': 63},
  {u'_id': u'parking', u'count': 59},
  {u'_id': u'fountain', u'count': 57},
  {u'_id': u'atm', u'count': 32},
  {u'_id': u'waste_basket', u'count': 31},
  {u'_id': u'drinking_water', u'count': 28},
  {u'_id': u'toilets', u'count': 24},
  {u'_id': u'fuel', u'count': 17},
  {u'_id': u'car_sharing', u'count': 13},
  {u'_id': u'playground', u'count': 13},
  {u'_id': u'fire_hydrant', u'count': 9},
  {u'_id': u'picnic_table', u'count': 8},
  {u'_id': u'telephone', u'count': 7},
  {u'_id': u'recycling', u'count': 7},
  {u'_id': u'emergency_phone', u'count': 7},
  {u'_id': u'pitch', u'count': 6},
  {u'_id': u'bank', u'count': 5},
  {u'_id': u'convenience', u'count': 5},
  {u'_id': u'slipway', u'count': 5},
  {u'_id': u'restaurant', u'count': 4},
  {u'_id': u'taxi', u'count': 4},
  {u'_id': u'magazine_box', u'count': 4},
  {u'_id': u'vending_machine', u'count': 4},
  {u'_id': u'post_office', u'count': 3},
  {u'_id': u'library', u'count': 3},
  {u'_id': u'bicycle_repair_station', u'count': 3},
  {u'_id': u'shower', u'count': 3},
  {u'_id': u'bbq', u'count': 3},
  {u'_id': u'hospital', u'count': 2},
  {u'_id': u'car', u'count': 2},
  {u'_id': u'fire_station', u'count': 2},
  {u'_id': u'fast_food', u'count': 2},
  {u'_id': u'marina', u'count': 2},
  {u'_id': u'parking_entrance', u'count': 2},
  {u'_id': u'pet', u'count': 2},
  {u'_id': u'park', u'count': 2},
  {u'_id': u'cafe', u'count': 2},
  {u'_id': u'supermarket', u'count': 2},
  {u'_id': u'hairdresser', u'count': 2},
  {u'_id': u'pharmacy', u'count': 2},
  {u'_id': u'pizza', u'count': 2},
  {u'_id': u'school', u'count': 2},
  {u'_id': u'bus_station', u'count': 1},
  {u'_id': u'clock', u'count': 1},
  {u'_id': u'vacant', u'count': 1},
  {u'_id': u'police', u'count': 1},
  {u'_id': u'gift', u'count': 1},
  {u'_id': u'ice_cream', u'count': 1},
  {u'_id': u'florist', u'count': 1},
  {u'_id': u'place_of_worship', u'count': 1},
  {u'_id': u'fitness_station', u'count': 1},
  {u'_id': u'minot_rose_garden_study_spot', u'count': 1},
  {u'_id': u'romanza_pizzaria', u'count': 1},
  {u'_id': u'food_court', u'count': 1},
  {u'_id': u'school_library', u'count': 1},
  {u'_id': u'sound-reflection', u'count': 1},
  {u'_id': u'bakery', u'count': 1},
  {u'_id': u'clothes', u'count': 1},
  {u'_id': u'veterinary', u'count': 1},
  {u'_id': u'comedy_club', u'count': 1}]}

Hmm, obvsiously, there are some possible not-so-interesting places in the above list. Post office? I mean, c'mon, right?

However, what if, and just bear with me here, we put something somewhere that said something along the lines of:

"Hey, did a post office come up? Is it kinda far from you? Maybe you should write a letter to someone you haven't seen in a while and then go on an adventure to mail it."

"Was it a fire station? Maybe you could go bring the fellas some 'za, nah mean?"

"We could give you some more suggestions, for example for when ATMs come up, but we figure you get the idea."

OK, I think I've seen enough.

I'm going to Heroku, setting up MongoLab, gonna make a little Node.js app (I've never done that before), and see if this thing makes sense. You're welcome to join me. :)