コード例 #1
0
ファイル: testGeodis.py プロジェクト: e42s/geodis
    def test_city(self):

        self.assertTrue(City.exist(["san francisco"], self.redis))
        self.assertFalse(City.exist(["ban hranbisco"], self.redis))

        locs = City.getByName("san francisco", self.redis)
        self.assertEquals(1, len(locs))
        city = locs[0]

        score1 = city.score(37.7833, -122.4167)
        self.assertGreater(score1, 0)

        # we need a second instance of the city to get a different score because scores are cached
        city2 = City.getByName("san francisco", self.redis)[0]
        score2 = city2.score(38.7833, -102.4167)
        self.assertGreater(score2, 0)
        self.assertGreater(score1, score2)

        # test converting to country only info
        city.toCountry()
        for k in City.__cityspec__:
            self.assertEquals(getattr(city, k), None)

        # test get by radius
        locs = City.getByRadius(37.7833, -122.4167, 4, self.redis, None, 5)
        self.assertEqual(5, len(locs))
        self.assertEqual(locs[0].name, "San Francisco")
コード例 #2
0
    def test_city(self):

        self.assertTrue(City.exist(['san francisco'], self.redis))
        self.assertFalse(City.exist(['ban hranbisco'], self.redis))

        locs = City.getByName('san francisco', self.redis)
        self.assertEquals(1, len(locs))
        city = locs[0]

        score1 = city.score(37.7833, -122.4167)
        self.assertGreater(score1, 0)

        # we need a second instance of the city to get a different score because scores are cached
        city2 = City.getByName('san francisco', self.redis)[0]
        score2 = city2.score(38.7833, -102.4167)
        self.assertGreater(score2, 0)
        self.assertGreater(score1, score2)


        #test converting to country only info
        city.toCountry()
        for k in City.__cityspec__:
            self.assertEquals(getattr(city,k), None)


        #test get by radius
        locs = City.getByRadius(37.7833, -122.4167, 4, self.redis, None, 5)
        self.assertEqual(5, len(locs))
        self.assertEqual(locs[0].name, 'San Francisco')
コード例 #3
0
ファイル: testGeodis.py プロジェクト: e42s/geodis
    def test5_resolve_by_textual_search(self):
        locs = City.getByName("san francisco", self.redis, 44.0462, -123.022, "united states")

        self.assertGreater(len(locs), 0)
        self.assertEqual(locs[0].country, "United States")
        self.assertEqual(locs[0].name, "San Francisco")
        self.assertEqual(locs[0].state, "California")

        locs = City.getByName("san francisco", self.redis)

        self.assertGreater(len(locs), 0)
        self.assertEqual(locs[0].country, "United States")
        self.assertEqual(locs[0].name, "San Francisco")
        self.assertEqual(locs[0].state, "California")
コード例 #4
0
    def test5_resolve_by_textual_search(self):
        locs = City.getByName('san francisco', self.redis, 44.0462, -123.022, 'united states')

        self.assertGreater(len(locs), 0)
        self.assertEqual(locs[0].country, 'United States')
        self.assertEqual(locs[0].name, 'San Francisco')
        self.assertEqual(locs[0].state, 'California')

        locs = City.getByName('san francisco', self.redis)

        self.assertGreater(len(locs), 0)
        self.assertEqual(locs[0].country, 'United States')
        self.assertEqual(locs[0].name, 'San Francisco')
        self.assertEqual(locs[0].state, 'California')
コード例 #5
0
ファイル: testGeodis.py プロジェクト: e42s/geodis
    def test4_resolve_by_coords(self):
        loc = City.getByLatLon(34.05223, -118.24368, self.redis)

        self.assertIsNotNone(loc)

        self.assertEqual(loc.country, "United States")
        self.assertIn(loc.state, ("CA", "California"))
コード例 #6
0
    def test4_resolve_by_coords(self):
        loc = City.getByLatLon(34.05223, -118.24368, self.redis)

        self.assertIsNotNone(loc)

        self.assertEqual(loc.country, 'United States')
        self.assertIn(loc.state, ('CA', 'California'))
コード例 #7
0
ファイル: benchmark.py プロジェクト: eliranmoyal/geodis
def benchResolveCoords(num):

    coords = [(-3.03333, 53.47778), (40.7226, -74.66544), (31.78199, 35.2196),
              (0, 0), (45, 45)]
    r = redis.Redis()
    ncoords = len(coords)
    for i in range(num):
        lat, lon = coords[i % ncoords]
        loc = City.getByLatLon(lat, lon, r)

    return num