添加API启动支持

This commit is contained in:
2025-12-11 16:02:17 +08:00
parent 94f509725a
commit 54012fc635
+6 -4
View File
@@ -164,8 +164,8 @@ def update_office(city, office, sample, year_month):
office['estate_type2'] = None office['estate_type2'] = None
if 'alias' not in office.columns: if 'alias' not in office.columns:
office['alias'] = None office['alias'] = None
if sample.empty: merge_df = None
return if not sample.empty:
sample_new = sample sample_new = sample
if 'alias' not in sample_new.columns: if 'alias' not in sample_new.columns:
sample_new['alias'] = None sample_new['alias'] = None
@@ -221,6 +221,8 @@ def update_office(city, office, sample, year_month):
# 第二步 取周边3公里内同等级、同类型的最近10个有样本写字楼的基准价的平均值 # 第二步 取周边3公里内同等级、同类型的最近10个有样本写字楼的基准价的平均值
office_info = office[['city', 'region', 'name', 'lng', 'lat', 'estate_type2', 'bed_kind']].drop_duplicates( office_info = office[['city', 'region', 'name', 'lng', 'lat', 'estate_type2', 'bed_kind']].drop_duplicates(
keep='first') keep='first')
combined = office_info
if merge_df is not None and not merge_df.empty:
combined = pd.concat([office_info, merge_df]) combined = pd.concat([office_info, merge_df])
diff_df = combined.drop_duplicates(subset=['city', 'region', 'name'], keep=False) diff_df = combined.drop_duplicates(subset=['city', 'region', 'name'], keep=False)
actions = list() actions = list()
@@ -464,7 +466,7 @@ def getOffice(city, district=None, name=None):
query['city'] = city query['city'] = city
if pd.notna(district): if pd.notna(district):
query['region'] = district query['region'] = district
if pd.notna(city): if pd.notna(name):
query['name'] = name query['name'] = name
office = pd.DataFrame(list(seaweed_df.find(query).batch_size(10000))) office = pd.DataFrame(list(seaweed_df.find(query).batch_size(10000)))
for col in ['city', 'region', 'name', 'alias', 'estate_type2', 'bed_kind', 'lng', 'lat']: for col in ['city', 'region', 'name', 'alias', 'estate_type2', 'bed_kind', 'lng', 'lat']:
@@ -477,4 +479,4 @@ def getOffice(city, district=None, name=None):
if __name__ == "__main__": if __name__ == "__main__":
# 测试脚本:直接运行时模拟 Airflow 的上下文 # 测试脚本:直接运行时模拟 Airflow 的上下文
calc(dag_run=type('DagRun', (), {'conf': {'city': '上海', 'district': '静安', 'name': '凯迪克大厦'}})) calc(dag_run=type('DagRun', (), {'conf': {'city': '西安'}}))