From 7aa60a620ca62017fe741d7d0a0cb9cafd1282bb Mon Sep 17 00:00:00 2001 From: "shenjian@fangjia.com" Date: Tue, 15 Nov 2022 17:32:35 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=94=AE=E7=A7=9F=E6=AF=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../{estate_charge_ranking.py => other.py} | 29 ++++++++++++------- dags/business/community_summary_dag.py | 4 +-- 2 files changed, 20 insertions(+), 13 deletions(-) rename dags/business/business/community/{estate_charge_ranking.py => other.py} (71%) diff --git a/dags/business/business/community/estate_charge_ranking.py b/dags/business/business/community/other.py similarity index 71% rename from dags/business/business/community/estate_charge_ranking.py rename to dags/business/business/community/other.py index ec693de..d336fcf 100644 --- a/dags/business/business/community/estate_charge_ranking.py +++ b/dags/business/business/community/other.py @@ -30,18 +30,18 @@ def get_old_or_new(finish_building_date): def deal(actions, x): global count - estate_charge_ranking = '' + estate_charge_ranking = None if pd.notna(x['estate_charge']): estate_charge = float(x['estate_charge']) if estate_charge >= 1: estate_charge_ranking = "一级" - if estate_charge >= 0.75: + elif estate_charge >= 0.75: estate_charge_ranking = "二级" - if estate_charge >= 0.50: + elif estate_charge >= 0.50: estate_charge_ranking = "三级" - if estate_charge >= 0.35: + elif estate_charge >= 0.35: estate_charge_ranking = "四级" - if estate_charge < 0.35: + elif estate_charge < 0.35: estate_charge_ranking = "五级" else: old_or_new = get_old_or_new(x['finish_building_date']) @@ -53,24 +53,31 @@ def deal(actions, x): elif old_or_new == '旧': estate_charge_ranking = '五级' + doc_info = dict() + if pd.notna(estate_charge_ranking): + doc_info['estate_charge_ranking'] = estate_charge_ranking + if pd.notna(x['avg_price']) and pd.notna(x['rent_price']): + doc_info['sell_to_rent'] = int(x['avg_price'] / x['rent_price']) + action_doc = { "_op_type": "update", "_index": index_name, "_id": x['_id'], - "doc": {'estate_charge_ranking': estate_charge_ranking} + "doc": doc_info } - actions.append(action_doc) + if len(doc_info) > 0: + actions.append(action_doc) if len(actions) == 5000: helpers.bulk(es206_client.elastic_client, actions) count += len(actions) - log.info(f"物业费等级已更新{count}") + log.info(f"物业费等级、售租比已更新{count}") actions.clear() def sync(city=None): - log.info(f"开始同步物业费等级至206 {index_name}") + log.info(f"开始同步物业费等级、售租比至206 {index_name}") - sql = "select city, region, name, estate_charge, finish_building_date, build_type from community_summary " + sql = "select city, region, name, estate_charge, finish_building_date, build_type, avg_price, rent_price from community_summary" if pd.notna(city): sql += " where city='" + city + "'" community_summary_df = es206_client.scan_by_sql_to_data_frame(sql) @@ -82,7 +89,7 @@ def sync(city=None): helpers.bulk(es206_client.elastic_client, actions) actions.clear() - log.info(f"完成同步物业费等级至206 {index_name}") + log.info(f"完成同步物业费等级、售租比至206 {index_name}") sync() \ No newline at end of file diff --git a/dags/business/community_summary_dag.py b/dags/business/community_summary_dag.py index 83d5c34..2670f58 100644 --- a/dags/business/community_summary_dag.py +++ b/dags/business/community_summary_dag.py @@ -75,7 +75,7 @@ with DAG( # bash_command='python /opt/airflow/dags/repo/dags/business/business/community/extra.py {{dag_run.conf["type"] if "type" in dag_run.conf}}', # ) t16 = BashOperator( - task_id='estate_charge_ranking_dag', - bash_command='python /opt/airflow/dags/repo/dags/business/business/community/estate_charge_ranking.py {{dag_run.conf["type"] if "type" in dag_run.conf}}', + task_id='other_dag', + bash_command='python /opt/airflow/dags/repo/dags/business/business/community/other.py {{dag_run.conf["type"] if "type" in dag_run.conf}}', ) # t1 >> t2 >> t3 >> t4 >> t5 >> t6 >> t6_1 >> t7 >> t8 >> t9 >> t10 >> t11 >> t12 >> t13 >> t14 >> t15 >> t16