周边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,10 +18,15 @@ administrative_mapping_conn = MAIN_MONGO_CLIENT.get_collection('fangjia_base', '
|
||||
school_typecode = ["141200", "141201", "141202", "141203", "141204"]
|
||||
|
||||
|
||||
def deal(city, lng, lat, distance=1000):
|
||||
location = [lng, lat]
|
||||
school_df = poiutils.find_around_by_location(city, location, school_typecode, distance)
|
||||
return school_df
|
||||
def deal3(item):
|
||||
location = [item['lng'], item['lat']]
|
||||
item['school'] = poiutils.find_around_by_location(item['city_display'], location, school_typecode, 3000)
|
||||
return item
|
||||
|
||||
def deal(item):
|
||||
location = [item['lng'], item['lat']]
|
||||
item['school'] = poiutils.find_around_by_location(item['city_display'], location, school_typecode, 1000)
|
||||
return item
|
||||
|
||||
|
||||
def do():
|
||||
@@ -29,21 +34,20 @@ def do():
|
||||
sync1()
|
||||
|
||||
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(10000)))
|
||||
if len(seaweed_df) <= 0:
|
||||
continue
|
||||
seaweed_df['lng'] = seaweed_df['lng'] / 10 ** 10
|
||||
seaweed_df['lat'] = seaweed_df['lat'] / 10 ** 10
|
||||
seaweed_df['school'] = 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['school'] = 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
|
||||
@@ -62,21 +66,20 @@ 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)))
|
||||
if len(seaweed_df) <= 0:
|
||||
continue
|
||||
seaweed_df['lng'] = seaweed_df['lng'] / 10 ** 10
|
||||
seaweed_df['lat'] = seaweed_df['lat'] / 10 ** 10
|
||||
seaweed_df['school'] = 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['school'] = 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