Esempio n. 1
0
    def disabled_t_estPlacemarkQueries(self):
        """Tests placemark queries."""
        def _QueryAndVerify(episode_ids, barrier_cb, search, matches):
            def _Verify(keys):
                ids = [key.hash_key for key in keys]
                self.assertEqual(len(ids), len(matches))
                [self.assertTrue(episode_ids[m] in ids) for m in matches]
                barrier_cb()

            Episode.IndexQueryKeys(self._client, ('episode.placemark={s}', {
                's': search
            }),
                                   callback=_Verify)

        def _OnCreate(locations, episodes):
            with util.Barrier(self.stop) as b:
                episode_ids = dict([(v.title, v.episode_id) for v in episodes])
                _QueryAndVerify(episode_ids, b.Callback(), 'Broadway',
                                ['kimball ph'])
                _QueryAndVerify(episode_ids, b.Callback(), '682 Broadway',
                                ['kimball ph'])
                _QueryAndVerify(episode_ids, b.Callback(), 'Broadway 682', [])
                _QueryAndVerify(episode_ids, b.Callback(),
                                'new york, ny, united states', [
                                    'kimball ph', 'bond st sushi',
                                    'viewfinder', 'soho house', 'google'
                                ])
                _QueryAndVerify(episode_ids, b.Callback(), 'new york, ny', [
                    'kimball ph', 'bond st sushi', 'viewfinder', 'soho house',
                    'google'
                ])
                _QueryAndVerify(
                    episode_ids, b.Callback(), 'NY, United States', [
                        'kimball ph', 'bond st sushi', 'viewfinder',
                        'soho house', 'google', 'kimball east', 'surf lodge'
                    ])
                _QueryAndVerify(episode_ids, b.Callback(), 'United States', [
                    'kimball ph', 'bond st sushi', 'viewfinder', 'soho house',
                    'google', 'kimball east', 'surf lodge'
                ])
                _QueryAndVerify(episode_ids, b.Callback(), 'Bahamas',
                                ['atlantis'])
                _QueryAndVerify(episode_ids, b.Callback(), 'Dominican',
                                ['casa kimball'])
                _QueryAndVerify(episode_ids, b.Callback(),
                                'Dominican Republic', ['casa kimball'])
                _QueryAndVerify(episode_ids, b.Callback(), 'Cabrera',
                                ['casa kimball'])
                _QueryAndVerify(episode_ids, b.Callback(), 'DR',
                                ['casa kimball'])

        locations = {
            'kimball ph':
            Placemark('US', 'United States', 'NY', 'New York', 'NoHo',
                      'Broadway', '682'),
            'bond st sushi':
            Placemark('US', 'United States', 'NY', 'New York', 'NoHo',
                      'Bond St', '6'),
            'viewfinder':
            Placemark('US', 'United States', 'NY', 'New York', 'SoHo',
                      'Grand St', '154'),
            'soho house':
            Placemark('US', 'United States', 'NY', 'New York',
                      'Meatpacking District', '9th Avenue', '29-35'),
            'google':
            Placemark('US', 'United States', 'NY', 'New York', 'Chelsea',
                      '8th Avenue', '111'),
            'kimball east':
            Placemark('US', 'United States', 'NY', 'East Hampton',
                      'Northwest Harbor', 'Milina', '35'),
            'surf lodge':
            Placemark('US', 'United States', 'NY', 'Montauk', '',
                      'Edgemere St', '183'),
            'casa kimball':
            Placemark('DR', 'Dominican Republic', 'Maria Trinidad Sanchez',
                      'Cabrera', 'Orchid Bay Estates', '', '5-6'),
            'atlantis':
            Placemark('BS', 'Bahamas', '', 'Paradise Island', '', '', '')
        }
        with util.ArrayBarrier(partial(_OnCreate, locations)) as b:
            device_episode_id = 0
            for place, placemark in locations.items():
                device_episode_id += 1
                timestamp = time.time()
                episode_id = Episode.ConstructEpisodeId(
                    timestamp, 1, device_episode_id)
                episode = Episode.CreateFromKeywords(
                    timestamp=timestamp,
                    episode_id=episode_id,
                    user_id=self._user.user_id,
                    viewpoint_id=self._user.private_vp_id,
                    publish_timestamp=timestamp,
                    title=place,
                    placemark=placemark)
                episode.Update(self._client, b.Callback())
Esempio n. 2
0
    def disabled_t_estLocationQueries(self):
        """Tests location queries."""
        def _QueryAndVerify(episode_ids, barrier_cb, loc_search, matches):
            def _Verify(keys):
                ids = [key.hash_key for key in keys]
                self.assertEqual(len(ids), len(matches))
                [self.assertTrue(episode_ids[m] in ids) for m in matches]
                barrier_cb()

            Episode.IndexQueryKeys(self._client, 'episode.location="%f,%f,%f"' % \
                                   (loc_search[0], loc_search[1], loc_search[2]), callback=_Verify)

        def _OnCreate(locations, episodes):
            with util.Barrier(self.stop) as b:
                episode_ids = dict([(v.title, v.episode_id) for v in episodes])
                # Exact search.
                _QueryAndVerify(episode_ids, b.Callback(),
                                Location(40.727657, -73.994583, 30),
                                ['kimball ph'])
                _QueryAndVerify(episode_ids, b.Callback(),
                                Location(41.044048, -71.950622, 100),
                                ['surf lodge'])
                # A super-small search area, centered in middle of Great Jones Alley.
                _QueryAndVerify(episode_ids, b.Callback(),
                                Location(40.727267, -73.994443, 10), [])
                # Widen the search area to 50m, centered in middle of Great Jones Alley.
                _QueryAndVerify(episode_ids, b.Callback(),
                                Location(40.727267, -73.994443, 50),
                                ['kimball ph', 'bond st sushi'])
                # Union square with a 2km radius.
                _QueryAndVerify(episode_ids, b.Callback(),
                                Location(40.736462, -73.990517, 2000), [
                                    'kimball ph', 'bond st sushi',
                                    'viewfinder', 'soho house', 'google'
                                ])
                # The Dominican Republic.
                _QueryAndVerify(episode_ids, b.Callback(),
                                Location(19.041349, -70.427856, 75000),
                                ['casa kimball'])
                # The Caribbean.
                _QueryAndVerify(episode_ids, b.Callback(),
                                Location(22.593726, -76.662598, 800000),
                                ['casa kimball', 'atlantis'])
                # Long Island.
                _QueryAndVerify(episode_ids, b.Callback(),
                                Location(40.989228, -72.144470, 40000),
                                ['kimball east', 'surf lodge'])

        locations = {
            'kimball ph': Location(40.727657, -73.994583, 50.0),
            'bond st sushi': Location(40.726901, -73.994358, 50.0),
            'viewfinder': Location(40.720169, -73.998756, 200.0),
            'soho house': Location(40.740616, -74.005880, 200.0),
            'google': Location(40.740974, -74.002115, 500.0),
            'kimball east': Location(41.034184, -72.210603, 50.0),
            'surf lodge': Location(41.044048, -71.950622, 100.0),
            'casa kimball': Location(19.636848, -69.896602, 100.0),
            'atlantis': Location(25.086104, -77.323065, 1000.0)
        }
        with util.ArrayBarrier(partial(_OnCreate, locations)) as b:
            device_episode_id = 0
            for place, location in locations.items():
                device_episode_id += 1
                timestamp = time.time()
                episode_id = Episode.ConstructEpisodeId(
                    timestamp, 1, device_episode_id)
                episode = Episode.CreateFromKeywords(
                    timestamp=timestamp,
                    episode_id=episode_id,
                    user_id=self._user.user_id,
                    viewpoint_id=self._user.private_vp_id,
                    publish_timestamp=timestamp,
                    title=place,
                    location=location)
                episode.Update(self._client, b.Callback())