From 787380ad9464bd0c912aae7088cedb73e6f599d4 Mon Sep 17 00:00:00 2001 From: "shenjian@fangjia.com" Date: Thu, 11 May 2023 09:32:05 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../community/relative_price_ranking.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/dags/business/business/community/relative_price_ranking.py b/dags/business/business/community/relative_price_ranking.py index b7f270d..4638f91 100644 --- a/dags/business/business/community/relative_price_ranking.py +++ b/dags/business/business/community/relative_price_ranking.py @@ -60,8 +60,11 @@ def find_around_seaweed(city_now, lng, lat): def build_doc(item): doc_dict = dict() - if 'relative_price_ranking' in item and pd.notna(item['relative_price_ranking']): - doc_dict['relative_price_ranking'] = item['relative_price_ranking'] + if 'relative_price_ranking' in item: + if pd.notna(item['relative_price_ranking']): + doc_dict['relative_price_ranking'] = item['relative_price_ranking'] + else: + doc_dict['relative_price_ranking'] = None if 'credit_detail' in item: doc_dict['credit_detail'] = item['credit_detail'] return doc_dict @@ -90,8 +93,11 @@ def find_around_price_item(seaweed): mutex.acquire() if len(around_seaweed_df) > 1: around_seaweed_df['relative_price_ranking'] = around_seaweed_df['avg_price'].rank(pct=True) - seaweed['relative_price_ranking'] = around_seaweed_df[around_seaweed_df['id'] == seaweed['_id']].iloc[0][ - 'relative_price_ranking'] + temp_df = around_seaweed_df[around_seaweed_df['id'] == seaweed['_id']] + if len(temp_df) > 0: + seaweed['relative_price_ranking'] = temp_df.iloc[0]['relative_price_ranking'] + else: + seaweed['relative_price_ranking'] = None elif len(around_seaweed_df) == 1: seaweed['relative_price_ranking'] = 0.5 @@ -128,9 +134,9 @@ def find_around_price_item(seaweed): def sync(city=None): log.info("开始同步相对价格排名数据...") - tmp_sql = f"select * from community_summary where avg_price > 0 " + tmp_sql = f"select * from community_summary " if pd.notna(city): - tmp_sql += f" and city='{city}'" + tmp_sql += f" where city='{city}'" seaweed_df = tmp_ck.read_sql_query(tmp_sql) seaweed_list = list()