当前位置: 首页>>代码示例>>Python>>正文


Python Factual.geopulse方法代码示例

本文整理汇总了Python中factual.Factual.geopulse方法的典型用法代码示例。如果您正苦于以下问题:Python Factual.geopulse方法的具体用法?Python Factual.geopulse怎么用?Python Factual.geopulse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在factual.Factual的用法示例。


在下文中一共展示了Factual.geopulse方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: FactualAPITestSuite

# 需要导入模块: from factual import Factual [as 别名]
# 或者: from factual.Factual import geopulse [as 别名]

#.........这里部分代码省略.........
    def test_raw_read_with_map(self):
        response = self.factual.raw_read('t/places/read', {'limit':15,'filters':{"name":"Starbucks"}})
        payload = json.loads(response)
        data = payload['response']['data']
        self.assertEqual(15, payload['response']['included_rows'])
        self.assertTrue(all(row['name'] == 'Starbucks' for row in data))

    def test_raw_write(self):
        uuid = '1007462b-dd79-44f5-a69f-e0b6041fa8bd'
        params = {'problem':'other','user':'python_driver_tester','debug':True}
        response = self.factual.raw_write('t/us-sandbox/' + uuid + '/flag', params)
        payload = json.loads(response)
        self.assertEqual('ok', payload['status'])

    def test_facets1(self):
        q = self.facets.search("starbucks").select("country")
        results = q.data()['country']
        self.assertTrue(results['us'] > 5000)
        self.assertTrue(results['ca'] > 200)

    def test_facets2(self):
        q = self.facets.search("starbucks").select("locality,region").filters({"country":"US"})
        locality = q.data()['locality']
        region = q.data()['region']
        self.assertTrue(locality['chicago'] > 50)
        self.assertTrue(region['tx'] > 200)

    def test_facets_geo(self):
        q = self.facets.select("locality").geo(circle(34.06018, -118.41835, 1000))
        locality = q.data()['locality']
        self.assertTrue(locality['los angeles'] > 3000)
        self.assertTrue(locality['beverly hills'] > 500)

    def test_geopulse(self):
        geopulse = self.factual.geopulse(point(34.06021, -118.41828))
        income_only = geopulse.select('income')
        all_results = geopulse.data()
        income_results = income_only.data()
        self.assertIn('demographics', all_results)
        demographics = all_results['demographics']
        self.assertIn('area_statistics', demographics)
        area_statistics = demographics['area_statistics']
        self.assertIn('commercial_residential', area_statistics)
        commercial_residential = area_statistics['commercial_residential']
        self.assertTrue(0 <= commercial_residential['business'] <= 100)
        income_demographics = income_results['demographics']
        self.assertEqual(1, len(income_demographics))
        self.assertIn('income', income_demographics)

    def test_geocode(self):
        geocode = self.factual.geocode(point(34.06021, -118.41828))
        result = geocode.data()[0]
        self.assertEqual('1801 Avenue Of The Stars', result['address'])
        self.assertLess(result['$distance'], 20)

    def test_monetize(self):
        monetize = self.factual.monetize().filters({'place_locality':'Los Angeles'})
        result = monetize.data()
        self.assertGreaterEqual(len(result), 1)
        self.assertTrue(all(row['place_locality'] == 'Los Angeles' for row in result))

    def test_submit_without_id(self):
        values = {'longitude': 100}
        submit = self.factual.submit('us-sandbox', values=values).user('python_driver_tester')
        response = submit.write()
        if 'new_entity' in response:
开发者ID:jgraham6,项目名称:factual-python-driver,代码行数:70,代码来源:api_test.py

示例2: FactualAPITestSuite

# 需要导入模块: from factual import Factual [as 别名]
# 或者: from factual.Factual import geopulse [as 别名]

#.........这里部分代码省略.........
        # filters here is url encoded {"name":"Starbucks"}
        response = self.factual.raw_read('t/places/read', 'limit=15&filters=%7B%22name%22%3A%22Starbucks%22%7D')
        payload = json.loads(response)
        data = payload['response']['data']
        self.assertEqual(15, payload['response']['included_rows'])
        self.assertTrue(all(row['name'] == 'Starbucks' for row in data))

    def test_raw_read_with_map(self):
        response = self.factual.raw_read('t/places/read', {'limit':15,'filters':{"name":"Starbucks"}})
        payload = json.loads(response)
        data = payload['response']['data']
        self.assertEqual(15, payload['response']['included_rows'])
        self.assertTrue(all(row['name'] == 'Starbucks' for row in data))

    def test_facets1(self):
        q = self.facets.search("starbucks").select("country")
        results = q.data()['country']
        self.assertTrue(results['us'] > 5000)
        self.assertTrue(results['ca'] > 200)

    def test_facets2(self):
        q = self.facets.search("starbucks").select("locality,region").filters({"country":"US"})
        locality = q.data()['locality']
        region = q.data()['region']
        self.assertTrue(locality['chicago'] > 50)
        self.assertTrue(region['tx'] > 200)

    def test_facets_geo(self):
        q = self.facets.select("category").geo(circle(34.06018, -118.41835, 5000))
        category = q.data()['category']
        self.assertTrue(category['shopping'] > 1000)
        self.assertTrue(category['health & medicine > physicians'] > 1000)

    def test_geopulse(self):
        geopulse = self.factual.geopulse(point(34.06021, -118.41828))
        income_only = geopulse.select('income')
        all_results = geopulse.data()[0]
        income_results = income_only.data()[0]
        self.assertIn('commercial_density', all_results)
        self.assertTrue(0 <= all_results['commercial_density'] <= 1)
        self.assertEqual(1, len(income_results))
        self.assertIn('income', income_results)

    def test_geocode(self):
        geocode = self.factual.geocode(point(34.06021, -118.41828))
        result = geocode.data()[0]
        self.assertEqual('1801 Avenue Of The Stars', result['address'])
        self.assertLess(result['$distance'], 20)

    def test_monetize(self):
        monetize = self.factual.monetize().filters({'place_locality':'Los Angeles'})
        result = monetize.data()
        self.assertGreaterEqual(len(result), 1)
        self.assertTrue(all(row['place_locality'] == 'Los Angeles' for row in result))

    def test_submit_without_id(self):
        values = {'longitude': 100}
        submit = self.factual.submit('t7RSEV', values=values).user('python_driver_tester')
        response = submit.write()
        if 'new_entity' in response:
            self.assertTrue(response['new_entity'])
        else:
            self.assertIn('status', response)
            self.assertEqual('warning', response['status'])

    def test_submit_with_id(self):
开发者ID:mmoutenot,项目名称:factual-python-driver,代码行数:70,代码来源:api_test.py


注:本文中的factual.Factual.geopulse方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。