新增户均总价同步

This commit is contained in:
shenjian@fangjia.com
2022-10-18 14:08:18 +08:00
parent 0d8bb6acbe
commit ff375e1012
+18 -6
View File
@@ -1,5 +1,5 @@
"""
同步挂牌信息至206
同步挂牌信息、户均总价至206
"""
import logging
import pandas as pd
@@ -17,8 +17,10 @@ m_date = dateutils.iso_format()
def build_doc(item):
doc_dict = dict()
if pd.notna(item['three_months_sell_num']):
if 'three_months_sell_num' in item and pd.notna(item['three_months_sell_num']):
doc_dict['three_months_sell_num'] = int(item['three_months_sell_num'])
if 'total_price' in item and pd.notna(item['total_price']):
doc_dict['total_price'] = int(item['total_price'])
return doc_dict
@@ -31,23 +33,33 @@ def sync(city=None):
seaweed_df = pd.DataFrame(
list(seaweed_conn.find(seaweed_query, {'city': 1, 'region': 1, 'name': 1, 'alias': 1}).batch_size(100000)))
# 近三个月
# 加载库中均价数据
community_summary_df = es206_client.scan_by_sql_to_data_frame("SELECT city, region, name, avg_price FROM community_summary")
with ThreadPoolExecutor(30) as pool:
def deal(index, item):
curr_city = item['city']
curr_region = item['region']
curr_name = item['name']
names = list()
names = [curr_name]
if type(item['alias']) == list:
for alias_item in item['alias']:
names.append(alias_item)
names_str = "','".join(names)
names_str = "'" + names_str + "'"
# 近三个月挂牌量
sample_num = commutils.get_sample(curr_city, curr_region, names_str, cat='sell', daysBefore=93)
seaweed_df.loc[index, 'three_months_sell_num'] = sample_num
# 户均总价
avg_price = community_summary_df.loc[(community_summary_df['city'] == curr_city) & (community_summary_df['region'] == curr_region) & (community_summary_df['name'] == curr_name)].reset_index().loc[0, 'avg_price']
if pd.notna(avg_price):
min_avg_price = 0.8 * avg_price
max_avg_rice = 1.2 * avg_price
total_price = commutils.get_total_price(curr_city, curr_region, names, day_before=93, min_avg_price=min_avg_price, max_avg_price=max_avg_rice)
seaweed_df.loc[index, 'total_price'] = total_price
for index, item in seaweed_df.iterrows():
pool.submit(deal, index, item)
@@ -80,4 +92,4 @@ def sync(city=None):
except Exception as e:
print(e)
actions.clear()
log.info(f"完成同步出售信息至206 {index_name}")
log.info(f"完成同步出售信息至206 {index_name}")