From ff375e10121654d0a3186740e8a14cf168cff4e6 Mon Sep 17 00:00:00 2001 From: "shenjian@fangjia.com" Date: Tue, 18 Oct 2022 14:08:18 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=88=B7=E5=9D=87=E6=80=BB?= =?UTF-8?q?=E4=BB=B7=E5=90=8C=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dags/business/business/community/sell.py | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/dags/business/business/community/sell.py b/dags/business/business/community/sell.py index 123c7f1..cf7e87e 100644 --- a/dags/business/business/community/sell.py +++ b/dags/business/business/community/sell.py @@ -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}") \ No newline at end of file + log.info(f"完成同步出售信息至206 {index_name}")