周边配套计算库修改
This commit is contained in:
@@ -9,7 +9,6 @@ import poiutils
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
elastic_client = ElasticSearchClient(host='192.168.0.206')
|
||||
district_facilitys_conn = MAIN_MONGO_CLIENT.get_collection('fangjia', 'district_facilitys')
|
||||
surrounding_facilities_conn = MAIN_MONGO_CLIENT.get_collection('fangjia_base', 'surrounding_facilities')
|
||||
seaweed_conn = MAIN_MONGO_CLIENT.get_collection('fangjia', 'seaweed')
|
||||
@@ -17,44 +16,52 @@ administrative_mapping_conn = MAIN_MONGO_CLIENT.get_collection('fangjia_base', '
|
||||
|
||||
# 地铁code
|
||||
subway_typecode = ["150500"]
|
||||
small_type = ["地铁站"]
|
||||
|
||||
|
||||
def deal3(item):
|
||||
location = [item['lng'], item['lat']]
|
||||
item['subway'] = poiutils.find_around_by_location(item['city_display'], location, subway_typecode, 3000)
|
||||
item['subway'] = poiutils.find_around_by_location_for_bus(item['city_display'], location, small_type, 3000)
|
||||
return item
|
||||
|
||||
|
||||
def deal(item):
|
||||
location = [item['lng'], item['lat']]
|
||||
item['subway'] = poiutils.find_around_by_location(item['city_display'], location, subway_typecode, 1000)
|
||||
item['subway'] = poiutils.find_around_by_location_for_bus(item['city_display'], location, small_type, 1000)
|
||||
return item
|
||||
|
||||
|
||||
def do():
|
||||
sync_new()
|
||||
sync1()
|
||||
|
||||
|
||||
def sync_new(distance=3000):
|
||||
city_dict = list(administrative_mapping_conn.find({'type': '城市'}))
|
||||
for city_item in city_dict:
|
||||
city = city_item['city_short']
|
||||
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)))
|
||||
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['city_display'] = city_display
|
||||
seaweed_df = process_dataframe_multithread(seaweed_df, deal3, 30)
|
||||
#seaweed_df['subway'] = seaweed_df.apply(lambda x: deal(city_item['city'], x['lng'], x['lat'], distance), axis=1)
|
||||
# seaweed_df['subway'] = seaweed_df.apply(lambda x: deal(city_item['city'], x['lng'], x['lat'], distance), axis=1)
|
||||
|
||||
actions = list()
|
||||
for index, item in seaweed_df.iterrows():
|
||||
try:
|
||||
# 周边配套库中历史原因,id可能不为小区id
|
||||
action = UpdateOne({'city': item['city'], 'region': item['region'],
|
||||
'district_name': item['name']}, {'$set': {'subway': item['subway'], 'city': item['city'], 'region': item['region'],
|
||||
'district_name': item['name'], 'lng': item['lng'], 'lat': item['lat'], 'distance': distance}}, upsert=True)
|
||||
'district_name': item['name']},
|
||||
{'$set': {'subway': item['subway'], 'city': item['city'], 'region': item['region'],
|
||||
'district_name': item['name'], 'lng': item['lng'], 'lat': item['lat'],
|
||||
'distance': distance}}, upsert=True)
|
||||
actions.append(action)
|
||||
except Exception as e:
|
||||
print(e)
|
||||
@@ -62,33 +69,37 @@ def sync_new(distance=3000):
|
||||
surrounding_facilities_conn.bulk_write(actions)
|
||||
actions.clear()
|
||||
if len(actions) > 0:
|
||||
surrounding_facilities_conn.bulk_write(actions)
|
||||
actions.clear()
|
||||
surrounding_facilities_conn.bulk_write(actions)
|
||||
actions.clear()
|
||||
log.info(city + '周边地铁入库完毕')
|
||||
|
||||
|
||||
def sync1():
|
||||
city_dict = list(administrative_mapping_conn.find({'type': '城市'}))
|
||||
for city_item in city_dict:
|
||||
city = city_item['city_short']
|
||||
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)))
|
||||
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['city_display'] = city_display
|
||||
seaweed_df = process_dataframe_multithread(seaweed_df, deal, 30)
|
||||
#seaweed_df['subway'] = seaweed_df.apply(lambda x: deal(city_item['city'], x['lng'], x['lat']), axis=1)
|
||||
# seaweed_df['subway'] = seaweed_df.apply(lambda x: deal(city_item['city'], x['lng'], x['lat']), axis=1)
|
||||
|
||||
actions = list()
|
||||
for index, item in seaweed_df.iterrows():
|
||||
try:
|
||||
# 周边配套库中历史原因,id可能不为小区id
|
||||
action = UpdateOne({'city': item['city'], 'region': item['region'],
|
||||
'district_name': item['name']}, {'$set': {'subway': item['subway'], 'city': item['city'], 'region': item['region'],
|
||||
'district_name': item['name'], 'lng': item['lng'], 'lat': item['lat']}}, upsert=True)
|
||||
'district_name': item['name']},
|
||||
{'$set': {'subway': item['subway'], 'city': item['city'], 'region': item['region'],
|
||||
'district_name': item['name'], 'lng': item['lng'], 'lat': item['lat']}},
|
||||
upsert=True)
|
||||
actions.append(action)
|
||||
except Exception as e:
|
||||
print(e)
|
||||
@@ -96,6 +107,8 @@ def sync1():
|
||||
district_facilitys_conn.bulk_write(actions)
|
||||
actions.clear()
|
||||
if len(actions) > 0:
|
||||
district_facilitys_conn.bulk_write(actions)
|
||||
actions.clear()
|
||||
district_facilitys_conn.bulk_write(actions)
|
||||
actions.clear()
|
||||
log.info(city + '周边地铁入库完毕')
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user