From cb938f81f02b4f678419aafff954071b0f3faa20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B2=88=E5=81=A5?= Date: Tue, 10 Jun 2025 15:12:44 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BF=98=E5=8E=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dags/office/sell/base_price.py | 28 +++++++++++++--------------- dags/office/sell/fill_price.py | 1 - 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/dags/office/sell/base_price.py b/dags/office/sell/base_price.py index b455270..f354259 100644 --- a/dags/office/sell/base_price.py +++ b/dags/office/sell/base_price.py @@ -23,18 +23,7 @@ seaweed_df = MAIN_MONGO_CLIENT.get_collection('fangjia', 'seaweed') office_sell_stat_conn = MAIN_MONGO_CLIENT.get_collection('fangjia_stat', 'office_sell_stat') # 计算有样本写字楼的基准价 1. 取近一年,最近100个样本的中位值 -def calc(**kwargs): - """ - 写字楼基准价 - """ - # 从 Airflow 的 dag_run.conf 获取参数 - conf = kwargs.get('dag_run').conf if kwargs.get('dag_run') else {} - city = conf.get('city', '') - year_month = conf.get('year_month', '') - district = conf.get('district', '') - office_name = conf.get('name', '') - - +def calc(city, year_month): sql = "select * from latest_seawater where cat='office_sell' " if pd.notna(city): sql += "and city='" + city + "' " @@ -365,6 +354,15 @@ def calc(**kwargs): print("已计算" + str(count) + "条数据") actions.clear() -if __name__ == "__main__": - # 测试脚本:直接运行时模拟 Airflow 的上下文 - calc(dag_run=type('DagRun', (), {'conf': {'city': '上海', 'district': '静安', 'name': '凯迪克大厦'}})) \ No newline at end of file +if __name__ == '__main__': + yearmonth = sys.argv[1] if len(sys.argv) > 1 else '' + + if yearmonth == '': + date = dateutils.add_months(datetime.today(), months=-1) + yearmonth = int(dateutils.format_date(date, '%Y%m')) + try: + if type(yearmonth) is str: + yearmonth = int(yearmonth) + calc(None, yearmonth) + except Exception as e: + print(e) \ No newline at end of file diff --git a/dags/office/sell/fill_price.py b/dags/office/sell/fill_price.py index 1187d07..e6484ed 100644 --- a/dags/office/sell/fill_price.py +++ b/dags/office/sell/fill_price.py @@ -13,7 +13,6 @@ es_client = ElasticSearchClient(host='192.168.0.206') office_sell_stat_conn = MAIN_MONGO_CLIENT.get_collection('fangjia_stat', 'office_sell_stat') office_rent_stat_conn = MAIN_MONGO_CLIENT.get_collection('fangjia_stat', 'office_rent_stat') - def calc(city, year_month): print(f"开始处理{city}, {year_month}") query = {'date': year_month, 'cat': 'office'}