修改库

This commit is contained in:
沈健
2025-04-23 14:00:08 +08:00
parent 7f91150550
commit f1a8e3e001
7 changed files with 16 additions and 51 deletions
-35
View File
@@ -1,35 +0,0 @@
# airflow_local_settings.py
import json
from airflow.operators.http_operator import SimpleHttpOperator
def send_dingding_notification(context):
task_instance = context.get('task_instance')
message = {
"msgtype": "markdown",
"markdown": {
"title": "Airflow任务错误告警",
"text": f"""### ⚠️ Airflow任务错误告警 ⚠️
**DAG**: {task_instance.dag_id}
**任务**: {task_instance.task_id}
**执行时间**: {context.get('execution_date')}
**重试次数**: {task_instance.try_number - 1}/{task_instance.max_tries}
**日志链接**: [{task_instance.log_url}]({task_instance.log_url})
"""
},
"at": {
"isAtAll": True
}
}
alert = SimpleHttpOperator(
task_id='dingding_alert',
http_conn_id='dingding_webhook',
endpoint='robot/send',
method='POST',
data=json.dumps(message),
headers={"Content-Type": "application/json"},
)
alert.execute(context)
+3 -3
View File
@@ -12,9 +12,9 @@ if not os.path.exists(path):
year_month = int(sys.argv[1]) if len(sys.argv) > 1 else int(dateutils.format_date(datetime.utcnow(), "%Y%m"))
log.info(f"测试月份:{year_month}")
avm_df = pgsql.scan_by_sql_to_data_frame(f"select urbn_id,urbn_nm,gujia_bds_comm_num,gujiabdsvalmnycommnum from t_app_p9pha_plda.avm_evaluation_gj_h where gujia_bds_yrmo={year_month} ")
comm_df = pgsql.scan_by_sql_to_data_frame(f"select urbn_id,gujia_admndiv_nm,gujia_comm_id,comm_nm from base.t0831_bigdata_community_gj_h where gujia_bds_bds_st=0 ")
price_df = pgsql.scan_by_sql_to_data_frame(f"select gujia_bds_id as gujia_comm_id,gujia_comm_basic_prc from t_app_p9pha_plda.avm_community_base_price_gj_h where gujiabds_clc_yrmo_val={year_month} ")
avm_df = pgsql.scan_by_sql_to_data_frame(f"select urbn_id,urbn_nm,gujia_bds_comm_num,gujiabdsvalmnycommnum from price_stat.avm_evaluation_gj_h where gujia_bds_yrmo={year_month} ")
comm_df = pgsql.scan_by_sql_to_data_frame(f"select urbn_id,gujia_admndiv_nm,gujia_comm_id,comm_nm from base.bigdata_community where gujia_bds_bds_st=0 ")
price_df = pgsql.scan_by_sql_to_data_frame(f"select gujia_bds_id as gujia_comm_id,gujia_comm_basic_prc from price_stat.avm_community_base_price where gujiabds_clc_yrmo_val={year_month} ")
comm_df = comm_df.merge(avm_df, on="urbn_id", how="left")
comm_df = comm_df.merge(price_df, on="gujia_comm_id", how="left")
no_price_comm_df = comm_df[comm_df.gujia_comm_basic_prc.isna()][['urbn_id','urbn_nm','gujia_admndiv_nm','gujia_comm_id','comm_nm']]
+5 -5
View File
@@ -10,7 +10,7 @@ def get_community_base_price(cityid,yearmonth):
:param cr:
:return:
"""
sql = f"select gujia_admndiv_nm,gujia_bds_id,urbn_nm,comm_nm,gujiabds_clc_yrmo_val,gujia_comm_basic_prc,gujia_bds_clmtd from t_app_p9pha_plda.avm_community_base_price_gj_h where urbn_id='{cityid}' and gujiabds_clc_yrmo_val={yearmonth}"
sql = f"select gujia_admndiv_nm,gujia_bds_id,urbn_nm,comm_nm,gujiabds_clc_yrmo_val,gujia_comm_basic_prc,gujia_bds_clmtd from price_stat.avm_community_base_price where urbn_id='{cityid}' and gujiabds_clc_yrmo_val={yearmonth}"
data_df = pgdb.read(sql)
data_df = data_df.rename(columns={'gujia_admndiv_nm':'district','gujia_bds_id': '_id','urbn_nm':'city','comm_nm':'name','gujiabds_clc_yrmo_val':'yearmonth','gujia_comm_basic_prc':'price','gujia_bds_clmtd':'type'})
return data_df
@@ -41,7 +41,7 @@ def get_district_polyline(cityid=None,cr=None):
data_df = pd.DataFrame(rs,columns=columns)
return data_df
def get_community_ccb(cityid):
sql = f"select gujia_comm_id,gujia_admndiv_nm,comm_nm from base.t0831_bigdata_community_gj_h where urbn_id='{cityid}' and gujia_bds_bds_st=0"
sql = f"select gujia_comm_id,gujia_admndiv_nm,comm_nm from base.bigdata_community where urbn_id='{cityid}' and gujia_bds_bds_st=0"
data_df = pgdb.read(sql)
data_df = data_df.rename(columns={'gujia_comm_id': '_id','gujia_admndiv_nm':'region','comm_nm':'name'})
return data_df
@@ -59,7 +59,7 @@ def get_bak_community(cityid,cr):
data_df = pd.DataFrame(rs,columns=columns)
return data_df
def avm_price_copy(cityid,yearmonth):
sql = f"insert into t_app_p9pha_plda.avm_community_base_price_gj_h_copy select * from t_app_p9pha_plda.avm_community_base_price_gj_h where urbn_id='{cityid}' and gujiabds_clc_yrmo_val={yearmonth}"
sql = f"insert into price_stat.avm_community_base_price_gj_h_copy select * from price_stat.avm_community_base_price where urbn_id='{cityid}' and gujiabds_clc_yrmo_val={yearmonth}"
pgdb.sql_execute(sql)
def get_sample(cityid):
@@ -79,12 +79,12 @@ def get_deal_data(cityid):
return data_df
def get_region_price(cityid,yearmonth):
sql = f"select urbn_id,gujia_admndiv_id,gxda_admndiv_nm,gujia_bds_urbn_avprc from t_app_p9pha_plda.avm_district_price_gj_h where urbn_id='{cityid}' and gujiabds_clc_yrmo_val={yearmonth}"
sql = f"select urbn_id,gujia_admndiv_id,gxda_admndiv_nm,gujia_bds_urbn_avprc from price_stat.avm_district_price_gj_h where urbn_id='{cityid}' and gujiabds_clc_yrmo_val={yearmonth}"
data_df = pgdb.read(sql)
data_df = data_df.rename(columns={'urbn_id': 'cityid','gujia_admndiv_id': 'district_id','gxda_admndiv_nm': 'district_name', 'gujia_bds_urbn_avprc': 'district_price'})
return data_df
def get_evaluation_third_price(cityid,yearmonth,type='第三方'):
sql = f"select urbn_id,gujia_comm_id,gujiabds_to_mkprc_mny from t_app_p9pha_plda.avm_evaluation_item_gj_h where urbn_id='{cityid}' and gujiabds_clc_yrmo_val={yearmonth} and gujia_data_tp='{type}' "
sql = f"select urbn_id,gujia_comm_id,gujiabds_to_mkprc_mny from price_stat.avm_evaluation_item_gj_h where urbn_id='{cityid}' and gujiabds_clc_yrmo_val={yearmonth} and gujia_data_tp='{type}' "
data_df = pgdb.read(sql)
data_df = data_df.rename(columns={'urbn_id': 'cityid','gujiabds_to_mkprc_mny': 'third_price','gujia_comm_id':'_id'})
return data_df
+1 -1
View File
@@ -23,7 +23,7 @@ if type == month_last:
month_last = month_before
log.info(f"测试月份:{month_now}")
price_df = pgsql.scan_by_sql_to_data_frame(f"select urbn_id,urbn_nm,gujia_admndiv_nm,gujia_bds_id as gujia_comm_id,comm_nm,gujia_bds_clmtd,gujia_comm_basic_prc from t_app_p9pha_plda.avm_community_base_price_gj_h where gujiabds_clc_yrmo_val={month_now} ")
price_df = pgsql.scan_by_sql_to_data_frame(f"select urbn_id,urbn_nm,gujia_admndiv_nm,gujia_bds_id as gujia_comm_id,comm_nm,gujia_bds_clmtd,gujia_comm_basic_prc from price_stat.avm_community_base_price where gujiabds_clc_yrmo_val={month_now} ")
deal_df = pgsql.scan_by_sql_to_data_frame(f"select gujia_bds_mdl_id,gujia_comm_id,gujia_bds_trdtckt_prc from base.t0831_bigdata_deal_gj_h where to_char(txn_dt,'yyyyMM')='{month_last}' ")
deal_price_df = deal_df.merge(price_df, on="gujia_comm_id", how="left")
deal_price_df["ppe"] = round((deal_price_df["gujia_comm_basic_prc"] - deal_price_df['gujia_bds_trdtckt_prc']) / deal_price_df['gujia_bds_trdtckt_prc'], 4)
+5 -5
View File
@@ -51,14 +51,14 @@ year_month = int(sys.argv[1]) if len(sys.argv) > 1 else int(dateutils.format_dat
log.info(f"测试月份:{year_month}")
avm_evaluation_column_map = {'gujia_fsid': 'id', 'urbn_id': 'cityid', 'urbn_nm': 'cityname', 'gujia_bds_yrmo': 'year_month', 'gujia_bds_comm_num': 'community_num', 'gujiabdsvalmnycommnum': 'has_price_community_num', 'gujia_prc_cvr_rate': 'price_coverage', 'gujiabdsmnldpccommnum': 'artificial_calc_num', 'gujia_mnl_drc_prc_pct': 'artificial_calc_coverage', 'gujiabdssamp_comm_num': 'sample_calc_num', 'gujiaext_samp_clc_pct': 'sample_calc_coverage', 'gujiabdsnervetncomnum': 'ann_calc_num', 'gujianervethrunclcpct': 'ann_calc_coverage', 'gujiabds_tst_case_num': 'test_num', 'gujiabdsmdltstcommnum': 'deal_test_comm_num', 'gujiatst_comm_num_pct': 'test_comm_coverage', 'gujia_ppe15_cvr_rate': 'ppe15_coverage', 'gujia_rto_mdn': 'rate_median', 'gujia_rto_lv_san_ceft': 'coefficient', 'gujiabdsmdltstcasenum': 'deal_test_case_num', 'gujiamdltstcommnumpct': 'deal_test_comm_coverage', 'gujiamdltst_ppe15_pct': 'deal_ppe15_coverage', 'gujiamdlrtolvsan_ceft': 'deal_coefficient', 'gujia_mdl_md_bit_rto': 'deal_rate_median', 'gujiabdstrdpttcasenum': 'third_test_case_num', 'gujiabdstrdpttcommnum': 'third_test_comm_num', 'gujiatrdpttcommnumpct': 'third_test_comm_coverage', 'gujiatrdpttstppe15pct': 'third_ppe15_coverage', 'gujiatrdptrolvsanceft': 'third_coefficient', 'gujiatrdpt_md_bit_rto': 'third_rate_median', 'data_crt_tm': 'createtime', 'data_udt_tm': 'updatetime', 'gujia_src_co': 'sourcecode'}
avm_evaluation_item_column_map = {'gujia_fsid': 'id', 'urbn_id': 'cityid', 'urbn_nm': 'cityname', 'gujia_rgon_id': 'distid', 'gujia_rgon_nm': 'distname', 'gujia_comm_id': 'commid', 'gujia_comm_nm': 'commname', 'gujiabds_clc_yrmo_val': 'year_month', 'gujia_bds_clc_avprc': 'calc_avg_price', 'gujia_bds_avprc': 'avg_price', 'gujia_bds_clc_tp': 'calc_type', 'gujia_bds_rlb': 'confidence', 'gujiabds_to_mkprc_mny': 'target_avg_price', 'mdl_dt': 'dealdate', 'gujiabds_valt_unitprc': 'unit_price', 'gujia_area': 'buildarea', 'gujia_dcrt_val': 'fitment', 'gujia_twrd_val': 'houseaspect', 'gujia_bds_floor_num': 'floornum', 'gujiabdstot_floor_num': 'floorcnt', 'gujia_data_tp': 'data_type', 'gujia_rto': 'rate', 'gujia_mns_rto': 'pe', 'data_crt_tm': 'createtime'}
avm_evaluation = pgsql.scan_by_sql_to_data_frame(f"SELECT * FROM t_app_p9pha_plda.avm_evaluation_gj_h where gujia_bds_yrmo={year_month}")
avm_evaluation_item = pgsql.scan_by_sql_to_data_frame(f"SELECT * FROM t_app_p9pha_plda.avm_evaluation_item_gj_h where gujiabds_clc_yrmo_val={year_month}")
avm_evaluation = pgsql.scan_by_sql_to_data_frame(f"SELECT * FROM price_stat.avm_evaluation_gj_h where gujia_bds_yrmo={year_month}")
avm_evaluation_item = pgsql.scan_by_sql_to_data_frame(f"SELECT * FROM price_stat.avm_evaluation_item_gj_h where gujiabds_clc_yrmo_val={year_month}")
avm_evaluation.rename(columns=avm_evaluation_column_map, inplace=True)
avm_evaluation_item.rename(columns=avm_evaluation_item_column_map, inplace=True)
community_base_price = pgsql.scan_by_sql_to_data_frame(f'''SELECT gujia_bds_id as commid,urbn_nm as cityname,gujia_admndiv_nm as distname,comm_nm as commname,
gujia_comm_basic_prc as comm_avg_price,gujia_bds_cfdc_dgr as confidence,gujia_bds_clmtd as calc_type from t_app_p9pha_plda.avm_community_base_price_gj_h where gujiabds_clc_yrmo_val={year_month}'''
gujia_comm_basic_prc as comm_avg_price,gujia_bds_cfdc_dgr as confidence,gujia_bds_clmtd as calc_type from price_stat.avm_community_base_price where gujiabds_clc_yrmo_val={year_month}'''
)
communities = pgsql.scan_by_sql_to_data_frame(f"select gujia_comm_id as COMMID from base.t0831_bigdata_community_gj_h")
communities = pgsql.scan_by_sql_to_data_frame(f"select gujia_comm_id as COMMID from base.bigdata_community")
community_base_price = community_base_price[community_base_price.commid.isin(communities["commid"])]
avm_evaluation_item["fitment"] = avm_evaluation_item["fitment"].map(convert_fitment_code)
@@ -91,7 +91,7 @@ import_avm_evaluation_item_third.sort_values(by="cityrank", inplace=True)
file_name = f"{year_month}估值模型测试.xlsx"
aim_file_name = path + '/' + file_name
with pd.ExcelWriter(aim_file_name) as writer:
avm_evaluation.to_excel(writer, sheet_name="92个城市估值概况", columns=["cityname","community_num","price_coverage","sample_calc_coverage","ann_calc_coverage","artificial_calc_coverage","deal_test_case_num","deal_ppe15_coverage","deal_test_comm_num","deal_test_comm_coverage","deal_rate_median","deal_coefficient","third_test_comm_num","third_test_comm_coverage","third_ppe15_coverage","third_rate_median","third_coefficient"], header=["城市名称","小区量","可输出均价小区占比","样本计算占比","神经网络计算占比","人工指导价占比","成交测试案例总量","成交测试PPE15占比","成交测试小区量","成交测试小区量占比","成交比率中位数","成交比率离散系数","第三方均价测试小区量","第三方均价测试小区量占比","第三方均价测试PPE15占比","第三方比率中位数","第三方比率离散系数"], index=False)
avm_evaluation.to_excel(writer, encoding="UTF-8", sheet_name="92个城市估值概况", columns=["cityname","community_num","price_coverage","sample_calc_coverage","ann_calc_coverage","artificial_calc_coverage","deal_test_case_num","deal_ppe15_coverage","deal_test_comm_num","deal_test_comm_coverage","deal_rate_median","deal_coefficient","third_test_comm_num","third_test_comm_coverage","third_ppe15_coverage","third_rate_median","third_coefficient"], header=["城市名称","小区量","可输出均价小区占比","样本计算占比","神经网络计算占比","人工指导价占比","成交测试案例总量","成交测试PPE15占比","成交测试小区量","成交测试小区量占比","成交比率中位数","成交比率离散系数","第三方均价测试小区量","第三方均价测试小区量占比","第三方均价测试PPE15占比","第三方比率中位数","第三方比率离散系数"], index=False)
import_community_base_price.to_excel(writer, sheet_name="测试10个城市估值数据", columns=["cityname","distname","commname","comm_avg_price","confidence","calc_type"], header=["城市","区域","小区名","估值小区均价","置信度","估值方式"],index=False)
import_avm_evaluation_item_deal.to_excel(writer, sheet_name="10个城市成交测试案例", columns=['cityname','distname', 'commname', 'unit_price', 'confidence', 'calc_type','total_price', 'deal_total_price', 'target_avg_price','pe',"dealdate","fitment","houseaspect","floornum","floorcnt","buildarea"], header=["城市","区域","小区名","修正均价","置信度","估值方式","小区估价","对标成交价","对标均价","PPE","dealdate","fitment","houseaspect","floornum","floorcnt","buildarea"], index=False)
import_avm_evaluation_item_third.to_excel(writer, sheet_name="10个城市第三方均价测试", columns=["cityname","distname","commname","avg_price","confidence","calc_type","target_avg_price","pe"], header=["城市","区域","小区名","小区均价","置信度","估值方式","对标第三方均价","PPE"],index=False)
+1 -1
View File
@@ -91,7 +91,7 @@ if type == month_last:
month_now = month_last
month_last = month_before
df = pgsql.scan_by_sql_to_data_frame("SELECT gujia_bss_prc_id as id, urbn_nm as cityname, gujia_admndiv_nm as distname, gujia_bds_id as commid, comm_nm as commname, gujia_bds_clmtd as calc_type, gujia_bds_cfdc_dgr as confidence, gujia_comm_basic_prc as avg_price, gujiabds_clc_yrmo_val as year_month FROM t_app_p9pha_plda.avm_community_base_price_gj_h WHERE gujiabds_clc_yrmo_val IN('"+month_now+"', '"+month_last+"') " +
df = pgsql.scan_by_sql_to_data_frame("SELECT gujia_bss_prc_id as id, urbn_nm as cityname, gujia_admndiv_nm as distname, gujia_bds_id as commid, comm_nm as commname, gujia_bds_clmtd as calc_type, gujia_bds_cfdc_dgr as confidence, gujia_comm_basic_prc as avg_price, gujiabds_clc_yrmo_val as year_month FROM price_stat.avm_community_base_price WHERE gujiabds_clc_yrmo_val IN('"+month_now+"', '"+month_last+"') " +
" ORDER BY urbn_nm, gujia_admndiv_nm, gujia_bds_id, comm_nm, gujia_bds_clmtd")
six_map = dict()
+1 -1
View File
@@ -87,7 +87,7 @@ monthly_data = monthly_data.sort_values(by=["city", "region", "name"])
# community_base_price = oracle.scan_by_sql_to_data_frame(f"select commid, year_month, avg_price, calc_type,confidence, cityname from community_base_price_gj where year_month > {before_year_month}")
community_base_price = pgsql.scan_by_sql_to_data_frame(f"select gujia_bds_id as commid,gujiabds_clc_yrmo_val as year_month, gujia_comm_basic_prc as avg_price, urbn_nm as cityname,gujia_bds_clmtd as calc_type, gujia_bds_cfdrg as confidence from t_app_p9pha_plda.avm_community_base_price_gj_h where gujiabds_clc_yrmo_val>{before_year_month} ")
community_base_price = pgsql.scan_by_sql_to_data_frame(f"select gujia_bds_id as commid,gujiabds_clc_yrmo_val as year_month, gujia_comm_basic_prc as avg_price, urbn_nm as cityname,gujia_bds_clmtd as calc_type, gujia_bds_cfdrg as confidence from price_stat.avm_community_base_price where gujiabds_clc_yrmo_val>{before_year_month} ")
community_base_price = community_base_price.sort_values(by=['commid', 'year_month'], ascending=[True, True])
# In[15]: