diff --git a/dags/business/business/community/estate_charge_complete.py b/dags/business/business/community/estate_charge_complete.py index c836c45..74ba860 100644 --- a/dags/business/business/community/estate_charge_complete.py +++ b/dags/business/business/community/estate_charge_complete.py @@ -34,7 +34,7 @@ def save_fix(community_summary_df): if 'estate_charge_fix' not in community_summary_df.columns: log.info("该城市无调整物业费") return - df = community_summary_df[['_id', 'city', 'estate_charge_fix']] + df = community_summary_df[['_id', 'city', 'estate_charge_fix', 'estate_charge_score']] df = df.dropna(subset=['estate_charge_fix']) actions = list() count = 0 @@ -45,6 +45,7 @@ def save_fix(community_summary_df): row = dict() _id = str(item["_id"]) row['estate_charge_fix'] = item['estate_charge_fix'] + row['credit_detail'] = {'estate_charge_score': int(item['estate_charge_score'])} row['m_date'] = m_date action = {'_op_type': 'update', @@ -72,7 +73,7 @@ def save_fill(community_summary_df): if 'estate_charge' not in community_summary_df.columns: log.info("该城市无补充物业费") return - df = community_summary_df[['_id', 'city', 'estate_charge']] + df = community_summary_df[['_id', 'city', 'estate_charge', 'estate_charge_score']] df = df.dropna(subset=['estate_charge']) actions = list() count = 0 @@ -83,6 +84,7 @@ def save_fill(community_summary_df): row = dict() _id = str(item["_id"]) row['estate_charge'] = item['estate_charge'] + row['credit_detail'] = {'estate_charge_score': int(item['estate_charge_score'])} # 1 表示为物业费补充的,在实际应用中不输出 row['estate_charge_flag'] = 1 row['m_date'] = m_date @@ -188,10 +190,11 @@ def deal_adjust(community): max_now = estate_charge_city_region_dict[city_short]['max'] if community['estate_charge'] > max_now: - estate_charge = find_estate_charge_for_adjust(community, max_now) + estate_charge, score = find_estate_charge_for_adjust(community, max_now) if pd.notna(estate_charge): mutex.acquire(timeout=60) community['estate_charge_fix'] = estate_charge + community['estate_charge_score'] = score mutex.release() def adjust_estate_charge(city_now): @@ -223,16 +226,21 @@ def find_estate_charge_for_adjust(community, max_now): docs = find_nearest_by_location(community['city'], location) if len(docs) <= 0 or 'estate_charge' not in docs.columns: return estate_charge + # 记录打分 + score = None if pd.notna(community['finish_building_date']) and 'finish_building_date' in docs.columns: # 根据相近建筑年代赋值 estate_charge = get_estate_charge_for_adjust(community['finish_building_date'], docs) + score = 9 if pd.isna(estate_charge) or estate_charge > max_now: # 取周边均值 estate_charge = docs['estate_charge'].mean() + score = 8 # 如果查找的还大于分位值,不调整 if estate_charge > max_now: estate_charge = None - return estate_charge + score = None + return estate_charge, score def find_estate_charge(community, max_now): """ @@ -249,15 +257,19 @@ def find_estate_charge(community, max_now): docs['estate_charge_fix'] = None # 用修正后的物业费补充 docs['estate_charge_fix'].fillna(docs['estate_charge'], inplace=True) + score = None if pd.notna(community['finish_building_date']) and 'finish_building_date' in docs.columns: # 根据相近建筑年代赋值 estate_charge = get_estate_charge(community['finish_building_date'], docs) + score = 7 if pd.isna(estate_charge) or estate_charge > max_now: # 取周边均值 estate_charge = docs['estate_charge_fix'].mean() + score = 6 if estate_charge > max_now: estate_charge = None - return estate_charge + score = None + return estate_charge, score find_count = 0 def deal_fill(community): @@ -276,10 +288,11 @@ def deal_fill(community): if community['estate_type'] == '别墅': # 别墅不限制物业费最大值 max_now = 99 - estate_charge = find_estate_charge(community, max_now) + estate_charge, score = find_estate_charge(community, max_now) if pd.notna(estate_charge): mutex.acquire(timeout=60) community["estate_charge"] = estate_charge + community["estate_charge_score"] = score mutex.release() def fill_estate_charge(city_now):