周边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
|
||||
import poiutils
|
||||
@@ -18,9 +18,15 @@ administrative_mapping_conn = MAIN_MONGO_CLIENT.get_collection('fangjia_base', '
|
||||
bus_typecode = ["150700"]
|
||||
|
||||
|
||||
def deal(city, lng, lat, distance=1000):
|
||||
location = [lng, lat]
|
||||
return poiutils.find_around_by_location(city, location, bus_typecode, distance)
|
||||
def deal3(item):
|
||||
location = [item['lng'], item['lat']]
|
||||
item['bus'] = poiutils.find_around_by_location(item['city_display'], location, bus_typecode, 3000)
|
||||
return item
|
||||
|
||||
def deal(item):
|
||||
location = [item['lng'], item['lat']]
|
||||
item['bus'] = poiutils.find_around_by_location(item['city_display'], location, bus_typecode, 1000)
|
||||
return item
|
||||
|
||||
def do():
|
||||
sync_new()
|
||||
@@ -28,11 +34,10 @@ def do():
|
||||
|
||||
|
||||
def sync_new(distance=3000):
|
||||
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(
|
||||
@@ -41,10 +46,10 @@ def sync_new(distance=3000):
|
||||
continue
|
||||
seaweed_df['lng'] = seaweed_df['lng'] / 10 ** 10
|
||||
seaweed_df['lat'] = seaweed_df['lat'] / 10 ** 10
|
||||
seaweed_df['bus'] = seaweed_df.apply(lambda x: deal(city_item['city'], x['lng'], x['lat'], distance), axis=1)
|
||||
seaweed_df = process_dataframe_multithread(seaweed_df, deal3, 30)
|
||||
#seaweed_df['bus'] = 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
|
||||
@@ -65,11 +70,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(
|
||||
@@ -78,10 +82,10 @@ def sync1():
|
||||
continue
|
||||
seaweed_df['lng'] = seaweed_df['lng'] / 10 ** 10
|
||||
seaweed_df['lat'] = seaweed_df['lat'] / 10 ** 10
|
||||
seaweed_df['bus'] = seaweed_df.apply(lambda x: deal(city_item['city'], x['lng'], x['lat']), axis=1)
|
||||
seaweed_df = process_dataframe_multithread(seaweed_df, deal, 30)
|
||||
#seaweed_df['bus'] = 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