拆开挂牌与户均(特慢)

This commit is contained in:
shenjian@fangjia.com
2022-10-18 18:09:05 +08:00
parent 1dd123d9b0
commit 2451f5099f
2 changed files with 97 additions and 13 deletions
-13
View File
@@ -19,8 +19,6 @@ def build_doc(item):
doc_dict = dict()
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
@@ -33,9 +31,6 @@ 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(50) as pool:
def deal(index, item):
if index % 1000 == 0:
@@ -54,14 +49,6 @@ def sync(city=None):
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)