Skip to content
Permalink
Browse files

Added __slots__ to objects to save memory. This allows dogWalkScore t…

…o run on a t2.micro!

Fixed string format
Removed unnecessary spaces
  • Loading branch information...
jeffseif committed Nov 23, 2014
1 parent 76649d6 commit e8022525a47635508d5fffc751ed4b12a0c1acbc
Showing with 55 additions and 4 deletions.
  1. +55 −4 static/py/dogWalkScore.py
@@ -43,13 +43,28 @@
# Classes

class Address:

__slots__ = [
'address',
'latitude',
'longitude',
]

def __init__(self, *args):
self.address, self.latitude, self.longitude = args

return

class Tree:
'''https://data.sfgov.org/Public-Works/Street-Tree-List/tkzw-k3nq'''

__slots__ = [
'id',
'variety',
'latitude',
'longitude',
]

def __init__(self, *args):
if 4 == len(args):

@@ -70,6 +85,22 @@ def __init__(self, *args):

class POI:
'''http://www.yelp.com/developers/documentation/v2/search_api#rValue'''

__slots__ = [
'id',
'poiType',
'name',
'nodeIds',
'offsets',
'latitude',
'longitude',
'address',
'city',
'state',
'imageUrl',
'yelpUrl',
]

def __init__(self, *args):
if 4 == len(args):
json, poiType, nodeIds, offsets = args
@@ -119,6 +150,18 @@ def __hash__(self):

class Node:
'''http://wiki.openstreetmap.org/wiki/Node'''

__slots__ = [
'id',
'isIntersection',
'latitude',
'longitude',
'nodeIds',
'edgeIds',
'lengths',
'poiIds',
]

def __init__(self, *args):
if 1 == len(args):
nodeXml, = args
@@ -163,6 +206,14 @@ def Count(self):

class Edge:
'''http://wiki.openstreetmap.org/wiki/Way'''

__slots__ = [
'id',
'name',
'nodeIds',
'treeCount',
]

def __init__(self, *args):
if 2 == len(args):
xml, id2Node = args
@@ -1131,7 +1182,7 @@ def Dijkstra(start, finishes, id2Node, id2Edge):
return path, id2Distance.get(nearest)

def Route(startId, finishIds, nodeIds, id2Node, id2Edge):
PrintNow('Routing a path from {:d} to {:s} ... '.format(startId, finishIds), end = '')
PrintNow('Routing a path from {:d} to {} ... '.format(startId, len(finishIds)), end = '')
subGraph = {nodeId : id2Node.get(nodeId) for nodeId in nodeIds}
pathIds, distance = Dijkstra(startId, finishIds, subGraph, id2Edge)
PrintNow('{:d} edges take {:G}km'.format(len(pathIds) - 1, distance / 1e3))
@@ -1273,9 +1324,9 @@ def DebugPlot(pathIds, nodeIds, id2Node, id2Edge, pdfFileName = 'debug.pdf'):

# Filenames

datDirectory = './static/dat'
osmFileName = 'neighborhood.osm'
osmFileName = 'sf-city.osm'
datDirectory = './static/dat'
osmFileName = 'neighborhood.osm'
osmFileName = 'sf-city.osm'
treeFileName = 'sfTrees'
mySqlDataBase = 'dogWalkScore6'
pickleFileName = '{}.pkl'.format(mySqlDataBase)

0 comments on commit e802252

Please sign in to comment.
You can’t perform that action at this time.