优化
This commit is contained in:
@@ -23,10 +23,18 @@ 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(city, year_month):
|
||||
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', '')
|
||||
|
||||
|
||||
sql = "select * from latest_seawater where cat='office_sell' "
|
||||
if pd.notna(city):
|
||||
sql += "and city='" + city + "' "
|
||||
@@ -49,6 +57,10 @@ def calc(city, year_month):
|
||||
query = {'cat': 'office', 'status': 0}
|
||||
if pd.notna(city):
|
||||
query['city'] = city
|
||||
if pd.notna(district):
|
||||
query['region'] = district
|
||||
if pd.notna(office_name):
|
||||
query['name'] = office_name
|
||||
office = pd.DataFrame(list(seaweed_df.find(query).batch_size(10000)))
|
||||
office = office[['city', 'region', 'name', 'alias', 'estate_type2', 'bed_kind', 'lng', 'lat']]
|
||||
office = office.explode('alias')
|
||||
@@ -353,5 +365,6 @@ def calc(city, year_month):
|
||||
print("已计算" + str(count) + "条数据")
|
||||
actions.clear()
|
||||
|
||||
yearmonth = sys.argv[1] if len(sys.argv) > 1 else None
|
||||
calc(None, yearmonth)
|
||||
if __name__ == "__main__":
|
||||
# 测试脚本:直接运行时模拟 Airflow 的上下文
|
||||
calc(dag_run=type('DagRun', (), {'conf': {'city': '上海', 'district': '静安', 'name': '凯迪克大厦'}}))
|
||||
@@ -83,16 +83,16 @@ def calc(city, year_month):
|
||||
print("已处理{}条数据".format(count))
|
||||
print("处理完毕")
|
||||
|
||||
if __name__ == '__main__':
|
||||
yearmonth = sys.argv[1] if len(sys.argv) > 1 else ''
|
||||
|
||||
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)
|
||||
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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user