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
+6 -5
View File
@@ -69,7 +69,7 @@ def calcByOffice(city, district, office_name):
# 只查询该小区的样本
year_time = dateutils.format_date(dateutils.datetime.datetime.now())
one_year_time = dateutils.format_date(dateutils.add_months(dateutils.datetime.datetime.now(), days=-365))
sql = f"select * from latest_seawater where cat='office_rent' and city='{city}' and region='{district}' and district_name in ({names_str}) and p_date > {one_year_time}"
sql = f"select * from latest_seawater where cat='office_rent' and city='{city}' and region='{district}' and district_name in ({names_str}) and p_date > {one_year_time} and avg_price>=30 and avg_price<=450"
sample = es.scan_by_sql_to_data_frame(sql)
location = {
@@ -114,7 +114,7 @@ def calcByOffice(city, district, office_name):
new_avg_price = round(average_price, 2)
elif len(sample) > 0:
# 取样本的平均值
new_avg_price = round(sample['avg_price'].mean(), 2)
new_avg_price = round((sample['avg_price'] / 30).mean(), 2)
if pd.notna(new_avg_price):
action = UpdateOne(
{'cat': 'office', 'city': city, 'district': district, 'name': office_name, 'date': curr_date},
@@ -190,7 +190,7 @@ def calcByCity(city, year_month):
"""
写字楼基准价
"""
sql = "select * from latest_seawater where cat='office_rent' "
sql = "select * from latest_seawater where cat='office_rent' and avg_price>=30 and avg_price<=450 "
if pd.notna(city):
sql += "and city='" + city + "' "
if pd.notna(year_month):
@@ -215,6 +215,7 @@ def calcByCity(city, year_month):
def update_office(city, office, sample, year_month):
target_city = city
if 'bed_kind' not in office.columns:
office['bed_kind'] = None
if 'estate_type2' not in office.columns:
@@ -443,8 +444,8 @@ def update_office(city, office, sample, year_month):
actions.clear()
# 第五步
query = {'cat': 'office', 'date': year_month, 'calc_type': {'$in': [1, 2, 3]}}
if pd.notna(city):
query['city'] = city
if pd.notna(target_city) and target_city != '':
query['city'] = target_city
db_df = pd.DataFrame(list(office_rent_stat_conn.find(query)))
office_info = office[['city', 'region', 'name', 'lng', 'lat', 'estate_type2', 'bed_kind']].drop_duplicates(
keep='first')