From 68e154d3900ff4b664dd6e19160bb3820f646a94 Mon Sep 17 00:00:00 2001 From: "shenjian@fangjia.com" Date: Thu, 9 Mar 2023 13:27:44 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BA=BA=E5=9D=87=E6=B6=88=E8=B4=B9=E4=BB=B7?= =?UTF-8?q?=E6=A0=BC=E9=80=89=E5=8F=96=E7=AD=96=E7=95=A5=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dags/business/business/community/avg_cost.py | 53 +++++++++++--------- 1 file changed, 29 insertions(+), 24 deletions(-) diff --git a/dags/business/business/community/avg_cost.py b/dags/business/business/community/avg_cost.py index 52a376d..e73be89 100644 --- a/dags/business/business/community/avg_cost.py +++ b/dags/business/business/community/avg_cost.py @@ -17,45 +17,48 @@ m_date = dateutils.iso_format() path = "/home/airflow/data/community" -def find_around_price(lng, lat): +def find_around_price(city_now, lng, lat): """ 查找周边均价 + 返回取值为10~300,为所有有价格的1-99百分位 """ if pd.isna(lng): return None - ret_es = es206_client.elastic_client.search({ - "query": { - "bool": { - "filter": [ - { + filter = [] + if pd.notna(city_now): + filter.append({ "term": { - "status": { - "value": 0 + "city": { + "value": city_now } } - }, - { - "range": { - "price": { - "gt": 0 - } - } - }, - { + }) + filter.append({ "terms": { "tag": [ "美食;中餐厅", "美食;外国餐厅" ] } - }, - { + }) + filter.append({ + "range": { + "price": { + "gte": 10, + "lte": 300 + } + } + }) + filter.append({ "geo_distance": { "distance": 1000, "location": [lng, lat] } - } - ] + }) + ret_es = es206_client.elastic_client.search({ + "query": { + "bool": { + "filter": filter } }, "size": 0, @@ -74,7 +77,7 @@ def build_doc(item): doc_dict = dict() if 'avg_cost' in item: if pd.notna(item['avg_cost']): - doc_dict['avg_cost'] = item['avg_cost'] + doc_dict['avg_cost'] = int(item['avg_cost']) else: doc_dict['avg_cost'] = None return doc_dict @@ -104,7 +107,7 @@ def update_status(new_df): def sync(city=None): log.info("开始同步消费数据...") - # 暂时注释 + # 【过期,无需状态】 # query_sql = "select id, city, tag, type, price from bd_poi where price > 0 and tag in('美食;中餐厅', '美食;外国餐厅') " # if pd.notna(city): # query_sql += " and city='" + areautils.get_city_display(city) + "'" @@ -121,6 +124,7 @@ def sync(city=None): # # # 按最新的百分位更新库中价格状态 # update_status(new_df) + ### 人均消费大于500的,按500 seaweed_df = pd.read_csv(path + '/seaweed.csv', sep='@', encoding='UTF-8') if pd.notna(city): @@ -134,7 +138,8 @@ def sync(city=None): return lng = commutils.format_lat_lng(item['lng']) lat = commutils.format_lat_lng(item['lat']) - price = find_around_price(lng, lat) + city_now = areautils.get_city_display(item['city']) + price = find_around_price(city_now, lng, lat) if pd.notna(price): seaweed_df.loc[index, 'avg_cost'] = price else: