def setUp(self):
        self.app = create_app('testing')
        self.app_context = self.app.app_context()
        self.app_context.push()
        self.client = self.app.test_client()

        #   An inverted index, mapping UTM (Universal Transverse Mercator) lat/lng
        #   values geolocating each film, to a LIST of films that were filmed
        #   at that location.
        #
        #   IMPORTANT!:  This is a shared data-structure, built only at startup,
        #   that is READ-ONLY by all, and so can be safely shared.
        invertedPointLocationIndex = InvertedPointLocationIndex()
        invertedPointLocationIndex.build_inverted_location_index()

        #   A KD tree, implemented using the scipy package's kdtree implementation
        #   under the hood, to allow for fast O(ln) queries of 2D point data.  The
        #   points that it stores are geocoded locations coded in UTM to allow them
        #   to be treated as 2D points to an approximation.
        #
        #   IMPORTANT!:  This is a shared data-structure, built only at startup,
        #   that is READ-ONLY by all, and so can be safely shared.
        filmLocationsKDTree = LocationsKDTree()
        filmLocationsKDTree.load_point_data()
        filmLocationsKDTree.build_kd_tree()

        self.app_context.g.filmlocationsKDTree = filmLocationsKDTree
        self.app_context.g.invertedPointLocationIndex = invertedPointLocationIndex
Exemple #2
0
#   at that location.
#
#   IMPORTANT!:  This is a shared data-structure, built only at startup,
#   that is READ-ONLY by all, and so can be safely shared.
invertedPointLocationIndex = InvertedPointLocationIndex()
invertedPointLocationIndex.build_inverted_location_index()

#   A KD tree, implemented using the scipy package's kdtree implementation
#   under the hood, to allow for fast O(ln) queries of 2D point data.  The
#   points that it stores are geocoded locations coded in UTM to allow them
#   to be treated as 2D points to an approximation.
#
#   IMPORTANT!:  This is a shared data-structure, built only at startup,
#   that is READ-ONLY by all, and so can be safely shared.
filmLocationsKDTree = LocationsKDTree()
filmLocationsKDTree.load_point_data()
filmLocationsKDTree.build_kd_tree()

#   If the request is for the endpoint 'films_near_me,' which is seeking
#   the 7 films closest to a user's location, only then do we bother to
#   load the request with the globally existing KD tree and inverted
#   index.
@app.before_request
def before_request():
    print "before request ..."
    if request.endpoint == 'films_near_me':
        g.filmlocationsKDTree = filmLocationsKDTree
        g.invertedPointLocationIndex = invertedPointLocationIndex

def make_shell_context():
    return dict(app=app)