From 6ba24850fcb0130f8160ee3168f593805dcaf3b5 Mon Sep 17 00:00:00 2001 From: wangwenyan Date: Mon, 9 Jun 2025 13:26:27 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BB=B7=E6=A0=BC=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E4=B8=BA=E7=A9=BAbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dags/stat/community/community_rate.py | 32 ++++++++++++++++----------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/dags/stat/community/community_rate.py b/dags/stat/community/community_rate.py index 1ea99bc..3928d5b 100644 --- a/dags/stat/community/community_rate.py +++ b/dags/stat/community/community_rate.py @@ -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}") \ No newline at end of file + 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}") \ No newline at end of file