fix(office): filter abnormal rent sample prices and fix city variable shadowing in base_price

This commit is contained in:
王文艳
2026-10-19 10:46:15 +08:00
parent fb8f6400be
commit 0d65af4be7
3 changed files with 18 additions and 10 deletions
+9 -3
View File
@@ -18,7 +18,7 @@ def calc(city, year_month):
raise Exception('年月格式错误yyyyMM')
office = es_client.scan_by_sql_to_data_frame(
"select * from latest_seawater where cat='office_rent' and city='" + city + "' and p_date>=" + str(
year_month) + "01 and p_date<=" + str(year_month) + "31 ")
year_month) + "01 and p_date<=" + str(year_month) + "31 and avg_price>=30 and avg_price<=450 ")
if len(office) > 0:
office['day_avg_price'] = office['avg_price'] / 30
# 计算总价的Z-score
@@ -42,7 +42,10 @@ def calc(city, year_month):
dateutils.format_date(dateutils.add_months(dateutils.parse_date(str(year_month), '%Y%m'), months=-1), '%Y%m'))
if pd.isna(city_price):
# 处理均价为空情况,用上月均价替代
stat = office_rent_stat_conn.find_one({'city': city, 'cat': 'city', 'date': int(last_month)})
stat = office_rent_stat_conn.find_one(
{'city': city, 'cat': 'city', 'date': {'$lte': int(last_month)}, 'avg_price': {'$lte': 15, '$gt': 0}},
sort=[('date', -1)]
)
if pd.isna(stat):
return False
last_month_city_price = stat['avg_price']
@@ -64,7 +67,10 @@ def calc(city, year_month):
avg_price = region_avg_prices[region]
else:
# 处理均价为空情况,用上月均价替代
district_stat = office_rent_stat_conn.find_one({'city': city, 'cat': 'district', 'date': int(last_month), 'district': region})
district_stat = office_rent_stat_conn.find_one(
{'city': city, 'cat': 'district', 'date': {'$lte': int(last_month)}, 'district': region, 'avg_price': {'$lte': 15, '$gt': 0}},
sort=[('date', -1)]
)
if pd.isna(district_stat):
continue
last_month_region_price = district_stat['avg_price']