fix(office): filter abnormal rent sample prices and fix city variable shadowing in base_price
This commit is contained in:
@@ -69,7 +69,7 @@ def calcByOffice(city, district, office_name):
|
|||||||
# 只查询该小区的样本
|
# 只查询该小区的样本
|
||||||
year_time = dateutils.format_date(dateutils.datetime.datetime.now())
|
year_time = dateutils.format_date(dateutils.datetime.datetime.now())
|
||||||
one_year_time = dateutils.format_date(dateutils.add_months(dateutils.datetime.datetime.now(), days=-365))
|
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)
|
sample = es.scan_by_sql_to_data_frame(sql)
|
||||||
|
|
||||||
location = {
|
location = {
|
||||||
@@ -114,7 +114,7 @@ def calcByOffice(city, district, office_name):
|
|||||||
new_avg_price = round(average_price, 2)
|
new_avg_price = round(average_price, 2)
|
||||||
elif len(sample) > 0:
|
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):
|
if pd.notna(new_avg_price):
|
||||||
action = UpdateOne(
|
action = UpdateOne(
|
||||||
{'cat': 'office', 'city': city, 'district': district, 'name': office_name, 'date': curr_date},
|
{'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):
|
if pd.notna(city):
|
||||||
sql += "and city='" + city + "' "
|
sql += "and city='" + city + "' "
|
||||||
if pd.notna(year_month):
|
if pd.notna(year_month):
|
||||||
@@ -215,6 +215,7 @@ def calcByCity(city, year_month):
|
|||||||
|
|
||||||
|
|
||||||
def update_office(city, office, sample, year_month):
|
def update_office(city, office, sample, year_month):
|
||||||
|
target_city = city
|
||||||
if 'bed_kind' not in office.columns:
|
if 'bed_kind' not in office.columns:
|
||||||
office['bed_kind'] = None
|
office['bed_kind'] = None
|
||||||
if 'estate_type2' not in office.columns:
|
if 'estate_type2' not in office.columns:
|
||||||
@@ -443,8 +444,8 @@ def update_office(city, office, sample, year_month):
|
|||||||
actions.clear()
|
actions.clear()
|
||||||
# 第五步
|
# 第五步
|
||||||
query = {'cat': 'office', 'date': year_month, 'calc_type': {'$in': [1, 2, 3]}}
|
query = {'cat': 'office', 'date': year_month, 'calc_type': {'$in': [1, 2, 3]}}
|
||||||
if pd.notna(city):
|
if pd.notna(target_city) and target_city != '':
|
||||||
query['city'] = city
|
query['city'] = target_city
|
||||||
db_df = pd.DataFrame(list(office_rent_stat_conn.find(query)))
|
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(
|
office_info = office[['city', 'region', 'name', 'lng', 'lat', 'estate_type2', 'bed_kind']].drop_duplicates(
|
||||||
keep='first')
|
keep='first')
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ def calc(city, year_month):
|
|||||||
raise Exception('年月格式错误yyyyMM')
|
raise Exception('年月格式错误yyyyMM')
|
||||||
office = es_client.scan_by_sql_to_data_frame(
|
office = es_client.scan_by_sql_to_data_frame(
|
||||||
"select * from latest_seawater where cat='office_rent' and city='" + city + "' and p_date>=" + str(
|
"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:
|
if len(office) > 0:
|
||||||
office['day_avg_price'] = office['avg_price'] / 30
|
office['day_avg_price'] = office['avg_price'] / 30
|
||||||
# 计算总价的Z-score
|
# 计算总价的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'))
|
dateutils.format_date(dateutils.add_months(dateutils.parse_date(str(year_month), '%Y%m'), months=-1), '%Y%m'))
|
||||||
if pd.isna(city_price):
|
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):
|
if pd.isna(stat):
|
||||||
return False
|
return False
|
||||||
last_month_city_price = stat['avg_price']
|
last_month_city_price = stat['avg_price']
|
||||||
@@ -64,7 +67,10 @@ def calc(city, year_month):
|
|||||||
avg_price = region_avg_prices[region]
|
avg_price = region_avg_prices[region]
|
||||||
else:
|
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):
|
if pd.isna(district_stat):
|
||||||
continue
|
continue
|
||||||
last_month_region_price = district_stat['avg_price']
|
last_month_region_price = district_stat['avg_price']
|
||||||
|
|||||||
@@ -217,6 +217,7 @@ def calcByCity(city, year_month):
|
|||||||
|
|
||||||
|
|
||||||
def update_office(city, office, sample, year_month):
|
def update_office(city, office, sample, year_month):
|
||||||
|
target_city = city
|
||||||
if 'bed_kind' not in office.columns:
|
if 'bed_kind' not in office.columns:
|
||||||
office['bed_kind'] = None
|
office['bed_kind'] = None
|
||||||
if 'estate_type2' not in office.columns:
|
if 'estate_type2' not in office.columns:
|
||||||
@@ -446,8 +447,8 @@ def update_office(city, office, sample, year_month):
|
|||||||
actions.clear()
|
actions.clear()
|
||||||
# 第五步
|
# 第五步
|
||||||
query = {'cat': 'office', 'date': year_month, 'calc_type': {'$in': [1, 2, 3]}}
|
query = {'cat': 'office', 'date': year_month, 'calc_type': {'$in': [1, 2, 3]}}
|
||||||
if pd.notna(city):
|
if pd.notna(target_city) and target_city != '':
|
||||||
query['city'] = city
|
query['city'] = target_city
|
||||||
db_df = pd.DataFrame(list(office_sell_stat_conn.find(query)))
|
db_df = pd.DataFrame(list(office_sell_stat_conn.find(query)))
|
||||||
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')
|
||||||
|
|||||||
Reference in New Issue
Block a user