本文整理汇总了Python中factual.Factual.multi方法的典型用法代码示例。如果您正苦于以下问题:Python Factual.multi方法的具体用法?Python Factual.multi怎么用?Python Factual.multi使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类factual.Factual
的用法示例。
在下文中一共展示了Factual.multi方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: FactualAPITestSuite
# 需要导入模块: from factual import Factual [as 别名]
# 或者: from factual.Factual import multi [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):
values = {'longitude': 100}
submit = self.factual.submit('t7RSEV', factual_id='bf6547a8-c0f3-4ada-abf8-9b831bbd5eeb', values=values).user('python_driver_tester')
response = submit.write()
if 'new_entity' in response:
self.assertFalse(response['new_entity'])
else:
self.assertIn('status', response)
self.assertEqual('warning', response['status'])
def test_flag(self):
flag = self.factual.flag('t7RSEV', 'bf6547a8-c0f3-4ada-abf8-9b831bbd5eeb').user('python_driver_tester').other().debug(True)
response = flag.write()
self.assertEqual('ok', response['status'])
def test_diffs(self):
diffs = self.factual.diffs('2EH4Pz', 1339123455775, 1339136968687).data()
self.assertGreater(len(diffs), 0)
def test_diffs_streaming(self):
diff_request = self.factual.diffs('2EH4Pz', 1339123455775, 1339136968687)
batch = diff_request.data()
streamed = list(diff_request.stream())
self.assertItemsEqual(batch, streamed)
def test_match(self):
match = self.factual.match({'name':'McDonalds','address':'10451 Santa Monica Blvd','locality':'Los Angeles','region':'CA'})
match_id = match.get_id()
self.assertEqual('bd886f67-9d86-40c5-9217-f7bcd53cfc0e', match_id)
def test_multi(self):
q1 = self.factual.table('places').filters({'postcode':'90067'})
q2 = self.factual.facets('places').filters({'postcode':'90067'}).select('category')
response = self.factual.multi({'query1':q1,'query2':q2})
self.assertTrue('query1' in response and 'query2' in response)
示例2: FactualAPITestSuite
# 需要导入模块: from factual import Factual [as 别名]
# 或者: from factual.Factual import multi [as 别名]
#.........这里部分代码省略.........
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:
self.assertTrue(response['new_entity'])
else:
self.assertIn('status', response)
self.assertEqual('warning', response['status'])
def test_submit_with_id(self):
values = {'longitude': 100}
submit = self.factual.submit('us-sandbox', factual_id='1007462b-dd79-44f5-a69f-e0b6041fa8bd', values=values).user('python_driver_tester')
response = submit.write()
if 'new_entity' in response:
self.assertFalse(response['new_entity'])
else:
self.assertIn('status', response)
self.assertEqual('warning', response['status'])
def test_clear(self):
clear = self.factual.clear('us-sandbox', '1007462b-dd79-44f5-a69f-e0b6041fa8bd', 'latitude,longitude').user('python_driver_tester')
response = clear.write()
self.assertIn('commit_id', response)
self.assertGreater(len(response['commit_id']), 0)
def test_flag(self):
flag = self.factual.flag('us-sandbox', '1007462b-dd79-44f5-a69f-e0b6041fa8bd').user('python_driver_tester').other().debug(True)
response = flag.write()
self.assertEqual('ok', response['status'])
def test_diffs(self):
diffs = self.factual.diffs('2EH4Pz', 1339123455775, 1339136968687).data()
self.assertGreater(len(diffs), 0)
def test_diffs_streaming(self):
diff_request = self.factual.diffs('2EH4Pz', 1339123455775, 1339136968687)
batch = diff_request.data()
streamed = list(diff_request.stream())
self.assertItemsEqual(batch, streamed)
def test_match(self):
match = self.factual.match('places-v3', {'name':'McDonalds','address':'10451 Santa Monica Blvd','locality':'Los Angeles','region':'CA'})
match_id = match.get_id()
self.assertEqual('c730d193-ba4d-4e98-8620-29c672f2f117', match_id)
def test_multi(self):
q1 = self.factual.table('places').filters({'postcode':'90067'})
q2 = self.factual.facets('places').filters({'postcode':'90067'}).select('category_labels')
response = self.factual.multi({'query1':q1,'query2':q2})
self.assertTrue('query1' in response and 'query2' in response)
def test_get_row(self):
row = self.factual.get_row('places', '03c26917-5d66-4de9-96bc-b13066173c65')
self.assertEqual('Factual', row['name'])
示例3: FactualAPITestSuite
# 需要导入模块: from factual import Factual [as 别名]
# 或者: from factual.Factual import multi [as 别名]
#.........这里部分代码省略.........
self.assertEqual(15, payload['response']['included_rows'])
self.assertTrue(all(row['name'] == 'Starbucks' for row in data))
def test_raw_write(self):
uuid = SANDBOX_UUID
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_geocode(self):
geocode = self.factual.geocode(point(34.058744, -118.416937))
result = geocode.data()[0]
self.assertEqual('1999 Avenue Of The Stars', result['address'])
self.assertLess(result['$distance'], 20)
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:
self.assertTrue(response['new_entity'])
else:
self.assertIn('status', response)
self.assertEqual('warning', response['status'])
def test_submit_with_id(self):
values = {'longitude': 100}
submit = self.factual.submit('us-sandbox', factual_id=SANDBOX_UUID, values=values).user('python_driver_tester')
response = submit.write()
if 'new_entity' in response:
self.assertFalse(response['new_entity'])
else:
self.assertIn('status', response)
self.assertEqual('warning', response['status'])
def test_clear(self):
clear = self.factual.clear('us-sandbox', SANDBOX_UUID, 'latitude,longitude').user('python_driver_tester')
response = clear.write()
self.assertIn('commit_id', response)
self.assertGreater(len(response['commit_id']), 0)
def test_flag(self):
flag = self.factual.flag('us-sandbox', SANDBOX_UUID).user('python_driver_tester').other().debug(True)
response = flag.write()
self.assertEqual('ok', response['status'])
def test_flag_preferred(self):
flag = self.factual.flag('us-sandbox', SANDBOX_UUID).duplicate(FACTUAL_UUID).user('python_driver_tester').debug(True)
response = flag.write()
self.assertEqual('ok', response['status'])
def test_diffs(self):
diffs = self.factual.diffs('places-us', 1400788800000, 1400792400000).data()
self.assertGreater(len(diffs), 0)
def test_diffs_streaming(self):
diff_request = self.factual.diffs('places-us', 1400788800000, 1400792400000)
batch = diff_request.data()
streamed = list(diff_request.stream())
self.assertSequenceEqual(batch, streamed)
def test_match(self):
match = self.factual.match('places-us', {'name':'McDonalds','address':'10451 Santa Monica Blvd','locality':'Los Angeles','region':'CA'})
match_id = match.get_id()
self.assertEqual('c730d193-ba4d-4e98-8620-29c672f2f117', match_id)
def test_multi(self):
q1 = self.factual.table('places').filters({'postcode':'90067'})
q2 = self.factual.facets('places').filters({'postcode':'90067'}).select('category_labels')
response = self.factual.multi({'query1':q1,'query2':q2})
self.assertTrue('query1' in response and 'query2' in response)
def test_get_row(self):
row = self.factual.get_row('places', FACTUAL_UUID)
self.assertEqual('Factual', row['name'])
def test_boost(self):
boost = self.factual.boost('us-sandbox', SANDBOX_UUID).user('python_driver_tester')
response = boost.write()
self.assertEqual('ok', response['status'])