优化成交挂牌价系数

This commit is contained in:
2024-08-16 10:33:54 +08:00
parent 6fe480ee66
commit 4c55387790
+14 -12
View File
@@ -1,9 +1,8 @@
from goojia_utils import MAIN_MONGO_CLIENT,dateutils
from datetime import datetime,date
from goojia_utils import MAIN_MONGO_CLIENT, dateutils
from datetime import datetime, date
import pandas as pd
from dateutil.relativedelta import relativedelta
deal_price_conn = MAIN_MONGO_CLIENT.get_collection('fangjia', 'deal_price')
district_sell_stat_conn = MAIN_MONGO_CLIENT.get_collection('fangjia_stat', 'district_sell_stat')
evaluate_ratio_conn = MAIN_MONGO_CLIENT.get_collection('business', 'evaluate_ratio')
@@ -21,6 +20,7 @@ year = datetimeNow.year
month = datetimeNow.month
day = datetimeNow.day
def sync():
# 查询2年内成交价格
dear_price_r = deal_price_conn.find({
@@ -28,14 +28,15 @@ def sync():
{
"$gte": datetime(ago_year, ago_month, ago_day, 0, 0),
"$lt": datetime(year, month, day, 0, 0)
},
'area': {"$gt": 20},
'type': {'$ne': '车位'},
'match_id': {'$exists': 'true'},
'avg_price': {'$lte': 500000}
}, {'city': 1, 'region': 1, 'district_name': 1, 'avg_price': 1, 'area': 1, 'trade_date': 1, 'match_id': 1})
}
}, {'city': 1, 'region': 1, 'district_name': 1, 'avg_price': 1, 'area': 1, 'trade_date': 1, 'match_id': 1,
'type': 1}).batch_size(10000)
df1 = pd.DataFrame(list(dear_price_r))
df1 = df1[df1.type != "车位"]
df1 = df1[df1.area > 20]
df1 = df1[df1.avg_price > 500000]
df1 = df1[~df1.match_id.isna()]
if df1.empty:
return
# 去重
@@ -64,7 +65,7 @@ def sync():
"$gte": 202106,
"$lt": 202306
}
},{'city': 1, 'region': 1, 'district_name': 1, 'avg_price': 1, 'date': 1})
}, {'city': 1, 'region': 1, 'district_name': 1, 'avg_price': 1, 'date': 1})
df2 = pd.DataFrame(list(district_stat_r))
@@ -91,7 +92,7 @@ def sync():
df = pd.merge(deal_price_city_avgprice, district_stat_city_avgprice, how='inner', on=['city'])
df['ratio'] = round((df['avg_price_x'] - df['avg_price_y']) / df['avg_price_y'], 2)
#df.to_excel('data/city_ratio.xlsx', index=False)
# df.to_excel('data/city_ratio.xlsx', index=False)
for index in df.index:
city = df['city'].get(index)
@@ -143,4 +144,5 @@ def sync():
"$set": {"ratio": ratio, "m_date": m_date}}
update_result = evaluate_ratio_conn.update_one(query, update, upsert=True)
sync()
sync()