修复价格数据为空bug
This commit is contained in:
@@ -244,6 +244,8 @@ def load_comm_stat(city):
|
||||
{"city": 1, "region": 1, "district_name": 1, "avg_price_2b": 1, "_id": 0})))
|
||||
half_on_year_stat = half_on_year_stat.rename(
|
||||
columns={"district_name": "name", "avg_price_2b": "half_on_year_avg_price"})
|
||||
if half_on_year_stat.empty:
|
||||
return pd.DataFrame()
|
||||
stat = stat.merge(half_on_year_stat, on=['city', 'region', 'name'], how="left")
|
||||
stat['half_on_year'] = (stat['avg_price'] - stat['half_on_year_avg_price']) * 100 / stat['half_on_year_avg_price']
|
||||
stat['half_on_year'] = stat['yoy'].fillna(0)
|
||||
@@ -439,17 +441,21 @@ if __name__ == '__main__':
|
||||
cities = areautils.get_all_cities()
|
||||
else:
|
||||
cities = [city for city in args.city.split(',')]
|
||||
|
||||
db_fields = ["comm_id", "city", "region", "name", "total_score", "community_quality_score", "community_price_score",
|
||||
"location_advantage_score", "flowability_score", "living_facilities_score", "education_score",
|
||||
"hospital_score", "total_score_level", "community_quality_score_level", "community_price_score_level",
|
||||
"location_advantage_score_level", "flowability_score_level", "living_facilities_score_level",
|
||||
"education_score_level", "hospital_score_level"]
|
||||
for city in cities:
|
||||
logger.info(f"开始计算楼盘评级:{city}")
|
||||
data = load_data_by_city(city)
|
||||
data = comms_rating(data)
|
||||
data["comm_id"] = data['_id']
|
||||
db_fields = ["comm_id", "city", "region", "name", "total_score", "community_quality_score", "community_price_score",
|
||||
"location_advantage_score", "flowability_score", "living_facilities_score", "education_score",
|
||||
"hospital_score", "total_score_level", "community_quality_score_level", "community_price_score_level",
|
||||
"location_advantage_score_level", "flowability_score_level", "living_facilities_score_level",
|
||||
"education_score_level", "hospital_score_level"]
|
||||
db_df = data[db_fields]
|
||||
updater = MongoDataFrameUpdater(community_rate_client)
|
||||
updater.bulk_insert_or_update_by_id(db_df, id_fields=['comm_id'])
|
||||
logger.info(f"楼盘评级计算结束:{city}")
|
||||
try:
|
||||
logger.info(f"开始计算楼盘评级:{city}")
|
||||
data = load_data_by_city(city)
|
||||
data = comms_rating(data)
|
||||
data["comm_id"] = data['_id']
|
||||
db_df = data[db_fields]
|
||||
updater = MongoDataFrameUpdater(community_rate_client)
|
||||
updater.bulk_insert_or_update_by_id(db_df, id_fields=['comm_id'])
|
||||
logger.info(f"楼盘评级计算结束:{city}")
|
||||
except Exception as e:
|
||||
logging.error(f"{city}楼盘评级计算失败;{e}")
|
||||
Reference in New Issue
Block a user