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
class testLocationsKDTree(unittest.TestCase):

    def setUp(self):
        self.test = InvertedPointLocationIndex()
        self.point_data = self.test.build_inverted_location_index()

    def test_lookup_location_single_entry(self):
        """ TESTING IF the inverted index returns a single location in an
            array if only a single location exists

            COMPARING WITH the known 1 points manually selected

            Retrieved from MySQL via:

            select Locations from Locations group by Locations having count = 1
        """
        found_location = self.test.lookup_locations((547809.3901228452, 4180255.2775678867))
        self.assertEqual(found_location, [{u'Fun Facts': u"Golden Gate Park is similar in shape but 20% larger than New York's Central Park.", u'Actor 2': u'Jayden C. Smith', u'Title': u'The Pursuit of Happyness', u'Production Company': u'Columbia Pictures Corporation', u'Writer': u'Gabriele Muccino', u'Locations': u"Golden Gate Park Children's Playground ", u'Director': u'Steven Conrad', u'filmid': 941, u'Actor 1': u'Will Smith', u'location_mercator': {u'y': 4180255.2775678867, u'x': 547809.3901228452}, u'Actor 3': u'', u'Distributor': u'Columbia Pictures', u'Release Year': u'2006', u'location': {u'lat': 37.7683778, u'lng': -122.4571623}}])

        found_location = self.test.lookup_locations((548452.309670817, 4184076.543236543))
        self.assertEqual(found_location, [{u'Fun Facts': u'Suppsedly, the Cow Palace\'s name derives from a newspaper editorial in which the writer wonders whether the soon-to-be-built structure for livestock was a "palace for cows". ', u'Actor 2': u'Ed Harris', u'Title': u'The Right Stuff', u'Production Company': u'The Ladd Company', u'Writer': u'Philip Kaufman', u'Locations': u'Cow Palace', u'Director': u'Philip Kaufman', u'filmid': 943, u'Actor 1': u'Sam Shepard', u'location_mercator': {u'y': 4184076.543236543, u'x': 548452.309670817}, u'Actor 3': u'', u'Distributor': u'The Ladd Company', u'Release Year': u'1983', u'location': {u'lat': 37.8027843, u'lng': -122.4496074}}])

    def test_lookup_location_multiple_entry(self):
        """ TESTING IF the inverted index returns a multiple filmlocations in an
            array if for multiple films at a single location

            COMPARING WITH the known 1 points manually selected

            Retrieved from MySQL via:

            select Locations from Locations group by Locations having count > 1
        """
        found_location = self.test.lookup_locations((551392.6450425778, 4181595.6111473767))
        self.assertEqual(found_location, [{u'Fun Facts': u'The Dalai Lama opened an exhibition on Wisdom and Compassion at the museum in 1991.', u'Actor 2': u'Chevy Chase', u'Title': u'Foul Play', u'Production Company': u'Paramount Pictures', u'Writer': u'Colin Higgins', u'Locations': u'Asian Art Museum (200 Larkin Street, Civic Center)', u'Director': u'Colin Higgins', u'filmid': 313, u'Actor 1': u'Goldie Hawn', u'location_mercator': {u'y': 4181595.6111473767, u'x': 551392.6450425778}, u'Actor 3': u'', u'Distributor': u'Paramount Pictures', u'Release Year': u'1978', u'location': {u'lat': 37.7802635, u'lng': -122.4163842}}, {u'Fun Facts': u'The Dalai Lama opened an exhibition on Wisdom and Compassion at the museum in 1991.', u'Actor 2': u'Mandy Patinkin', u'Title': u'Maxie', u'Production Company': u'Elsboy Entertainment', u'Writer': u'Patricia Resnick', u'Locations': u'Asian Art Museum (200 Larkin Street, Civic Center)', u'Director': u'Paul Aaron', u'filmid': 541, u'Actor 1': u'Glenn Close', u'location_mercator': {u'y': 4181595.6111473767, u'x': 551392.6450425778}, u'Actor 3': u'Gary Oldman', u'Distributor': u'Orion Pictures Corporation', u'Release Year': u'1985', u'location': {u'lat': 37.7802635, u'lng': -122.4163842}}])

    def test_lookup_location_errors(self):
        self.assertRaises(LookupException, self.test.lookup_locations, (1,2))
示例#3
0
app = create_app(env_configuration)

print "Running the " + env_configuration + " configuration ..."
setup_app(env_configuration)
print "Finished running the " + env_configuration + " configuration ..."

#   Manager to manage large-scale Flask apps
manager = Manager(app)

#   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()

#   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
 def setUp(self):
     self.test = InvertedPointLocationIndex()
     self.point_data = self.test.build_inverted_location_index()