周边POI改为多线程
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
小区周边1公里银行入库业务逻辑
|
||||
"""
|
||||
import logging
|
||||
from goojia_utils import MAIN_MONGO_CLIENT
|
||||
from goojia_utils import MAIN_MONGO_CLIENT, process_dataframe_multithread
|
||||
import pandas as pd
|
||||
from pymongo import UpdateOne
|
||||
|
||||
@@ -26,10 +26,15 @@ bank_typecode = ["160100", "160101", "160102", "160103", "160104", "160105", "16
|
||||
"160144",
|
||||
"160145", "160146", "160147", "160148", "160149", "160150", "160151", "160152", "160200"]
|
||||
|
||||
def deal3(item):
|
||||
location = [item['lng'], item['lat']]
|
||||
item['bank'] = poiutils.find_around_by_location(item['city_display'], location, bank_typecode, 3000)
|
||||
return item
|
||||
|
||||
def deal(city, lng, lat, distance=1000):
|
||||
location = [lng, lat]
|
||||
return poiutils.find_around_by_location(city, location, bank_typecode, distance)
|
||||
def deal(item):
|
||||
location = [item['lng'], item['lat']]
|
||||
item['bank'] = poiutils.find_around_by_location(item['city_display'], location, bank_typecode, 1000)
|
||||
return item
|
||||
|
||||
def do():
|
||||
sync_new()
|
||||
@@ -39,11 +44,10 @@ def sync_new(distance=3000):
|
||||
"""
|
||||
周边3公里POI入库
|
||||
"""
|
||||
log.info("开始执行周边银行配套入库")
|
||||
city_dict = list(administrative_mapping_conn.find({'type': '城市'}))
|
||||
for city_item in city_dict:
|
||||
city = city_item['city_short']
|
||||
log.info('开始查找' + city + '周边银行')
|
||||
city_display = city_item['city']
|
||||
seaweed_df = pd.DataFrame(
|
||||
list(seaweed_conn.find({'city': city, 'cat': 'district', 'status': 0, 'lng': {'$ne': None}},
|
||||
{'city': 1, 'region': 1, 'name': 1, 'lng': 1, 'lat': 1}).batch_size(10000)))
|
||||
@@ -51,10 +55,11 @@ def sync_new(distance=3000):
|
||||
continue
|
||||
seaweed_df['lng'] = seaweed_df['lng'] / 10 ** 10
|
||||
seaweed_df['lat'] = seaweed_df['lat'] / 10 ** 10
|
||||
seaweed_df['bank'] = seaweed_df.apply(lambda x: deal(city_item['city'], x['lng'], x['lat'], distance), axis=1)
|
||||
seaweed_df['city_display'] = city_display
|
||||
seaweed_df = process_dataframe_multithread(seaweed_df, deal3, 30)
|
||||
#seaweed_df['bank'] = seaweed_df.apply(lambda x: deal(city_item['city'], x['lng'], x['lat'], distance), axis=1)
|
||||
|
||||
actions = list()
|
||||
log.info(city + '周边银行开始入库')
|
||||
for index, item in seaweed_df.iterrows():
|
||||
try:
|
||||
# 周边配套库中历史原因,id可能不为小区id
|
||||
@@ -75,11 +80,10 @@ def sync_new(distance=3000):
|
||||
log.info(city + '周边银行入库完毕')
|
||||
|
||||
def sync1():
|
||||
log.info("开始执行周边银行配套入库")
|
||||
city_dict = list(administrative_mapping_conn.find({'type': '城市'}))
|
||||
for city_item in city_dict:
|
||||
city = city_item['city_short']
|
||||
log.info('开始查找' + city + '周边银行')
|
||||
city_display = city_item['city']
|
||||
seaweed_df = pd.DataFrame(
|
||||
list(seaweed_conn.find({'city': city, 'cat': 'district', 'status': 0, 'lng': {'$ne': None}},
|
||||
{'city': 1, 'region': 1, 'name': 1, 'lng': 1, 'lat': 1}).batch_size(10000)))
|
||||
@@ -87,10 +91,11 @@ def sync1():
|
||||
continue
|
||||
seaweed_df['lng'] = seaweed_df['lng'] / 10 ** 10
|
||||
seaweed_df['lat'] = seaweed_df['lat'] / 10 ** 10
|
||||
seaweed_df['bank'] = seaweed_df.apply(lambda x: deal(city_item['city'], x['lng'], x['lat']), axis=1)
|
||||
seaweed_df['city_display'] = city_display
|
||||
seaweed_df = process_dataframe_multithread(seaweed_df, deal, 30)
|
||||
#seaweed_df['bank'] = seaweed_df.apply(lambda x: deal(city_item['city'], x['lng'], x['lat']), axis=1)
|
||||
|
||||
actions = list()
|
||||
log.info(city + '周边银行开始入库')
|
||||
for index, item in seaweed_df.iterrows():
|
||||
try:
|
||||
# 周边配套库中历史原因,id可能不为小区id
|
||||
|
||||
Reference in New Issue
Block a user