优化楼盘评级
This commit is contained in:
@@ -201,7 +201,7 @@ def gmm_train(total_rate, data, source, target):
|
|||||||
def load_comms(city):
|
def load_comms(city):
|
||||||
query = {"cat": "district", "status": 0, "city": city}
|
query = {"cat": "district", "status": 0, "city": city}
|
||||||
fields = {"city": 1, "region": 1, "name": 1, "address": 1, "lng": 1, "lat": 1, "estate_type2": 1, "create_year": 1,
|
fields = {"city": 1, "region": 1, "name": 1, "address": 1, "lng": 1, "lat": 1, "estate_type2": 1, "create_year": 1,
|
||||||
"cubage_percent": 1, "virescence_percent": 1, "estate_charge": 1, "business_quarter": 1}
|
"cubage_percent": 1, "virescence_percent": 1, "estate_charge": 1, "business_quarter": 1, "business_quarter": 1}
|
||||||
seaweed = pd.DataFrame(list(seaweed_client.find(query, fields)))
|
seaweed = pd.DataFrame(list(seaweed_client.find(query, fields)))
|
||||||
seaweed = seaweed.dropna(subset=['lng', 'lat'])
|
seaweed = seaweed.dropna(subset=['lng', 'lat'])
|
||||||
seaweed['_id'] = seaweed['_id'].apply(lambda x: str(x))
|
seaweed['_id'] = seaweed['_id'].apply(lambda x: str(x))
|
||||||
@@ -403,7 +403,7 @@ def comms_rating(data):
|
|||||||
data[f'{score_factor}_level'] = data[f'{score_factor}_level'].map(COMM_RATING_LEVEL_NAMES)
|
data[f'{score_factor}_level'] = data[f'{score_factor}_level'].map(COMM_RATING_LEVEL_NAMES)
|
||||||
for score_factor in ['total_score', 'community_quality_score', 'community_price_score', 'location_advantage_score',
|
for score_factor in ['total_score', 'community_quality_score', 'community_price_score', 'location_advantage_score',
|
||||||
'flowability_score', 'living_facilities_score', 'education_score', 'hospital_score']:
|
'flowability_score', 'living_facilities_score', 'education_score', 'hospital_score']:
|
||||||
data[f'{score_factor}'] = data[f'{score_factor}'].apply(lambda x: int(x * 100))
|
data[f'{score_factor}'] = data[f'{score_factor}'].apply(lambda x: round(x * 100, 6))
|
||||||
return data
|
return data
|
||||||
|
|
||||||
# ## 按照城市加载楼盘评级数据宽表
|
# ## 按照城市加载楼盘评级数据宽表
|
||||||
@@ -442,7 +442,7 @@ if __name__ == '__main__':
|
|||||||
else:
|
else:
|
||||||
cities = [city for city in args.city.split(',')]
|
cities = [city for city in args.city.split(',')]
|
||||||
|
|
||||||
db_fields = ["comm_id", "city", "region", "name", "total_score", "community_quality_score", "community_price_score",
|
db_fields = ["comm_id", "city", "region", 'business_quarter', "name", "total_score", "community_quality_score", "community_price_score",
|
||||||
"location_advantage_score", "flowability_score", "living_facilities_score", "education_score",
|
"location_advantage_score", "flowability_score", "living_facilities_score", "education_score",
|
||||||
"hospital_score", "total_score_level", "community_quality_score_level", "community_price_score_level",
|
"hospital_score", "total_score_level", "community_quality_score_level", "community_price_score_level",
|
||||||
"location_advantage_score_level", "flowability_score_level", "living_facilities_score_level",
|
"location_advantage_score_level", "flowability_score_level", "living_facilities_score_level",
|
||||||
@@ -454,6 +454,37 @@ if __name__ == '__main__':
|
|||||||
data = comms_rating(data)
|
data = comms_rating(data)
|
||||||
data["comm_id"] = data['_id']
|
data["comm_id"] = data['_id']
|
||||||
db_df = data[db_fields]
|
db_df = data[db_fields]
|
||||||
|
df_simple = db_df.copy()
|
||||||
|
for factor_score_field in ['total_score', 'community_quality_score', 'community_price_score',
|
||||||
|
'location_advantage_score', 'flowability_score', 'living_facilities_score',
|
||||||
|
'education_score', 'hospital_score']:
|
||||||
|
key = "_"
|
||||||
|
if factor_score_field != "total_score":
|
||||||
|
key = f"_{factor_score_field.replace('_score', '')}"
|
||||||
|
|
||||||
|
df_simple[f'city{key}rank'] = df_simple.groupby('city')[factor_score_field].rank(method='dense',
|
||||||
|
ascending=False).astype(
|
||||||
|
int)
|
||||||
|
df_simple[f'city{key}total_rank'] = df_simple[f'city{key}rank'].max()
|
||||||
|
df_simple[f'region{key}rank'] = df_simple.groupby(['city', 'region'])[factor_score_field].rank(
|
||||||
|
method='dense', ascending=False).astype(int)
|
||||||
|
df_simple[f'region{key}total_rank'] = df_simple[f'region{key}rank'].max()
|
||||||
|
# 处理bis为None的情况 - 只对非空bis值计算排名
|
||||||
|
df_simple[f'business_quarter{key}_total_rank'] = None
|
||||||
|
df_simple[f'business_quarter{key}_rank'] = None
|
||||||
|
# 对bis不为None的记录计算商圈排名
|
||||||
|
bis_not_null = df_simple['business_quarter'].notna()
|
||||||
|
if bis_not_null.any():
|
||||||
|
df_simple.loc[bis_not_null, f'business_quarter{key}_rank'] = \
|
||||||
|
df_simple.loc[bis_not_null].groupby(['city', 'region', 'business_quarter'])[
|
||||||
|
factor_score_field].rank(method='dense', ascending=False).astype(int)
|
||||||
|
df_simple.loc[bis_not_null, f'business_quarter{key}_total_rank'] = df_simple.loc[bis_not_null][
|
||||||
|
f'business_quarter{key}_rank'].max()
|
||||||
|
for score_factor in ['total_score', 'community_quality_score', 'community_price_score',
|
||||||
|
'location_advantage_score', 'flowability_score', 'living_facilities_score',
|
||||||
|
'education_score', 'hospital_score']:
|
||||||
|
df_simple[f'{score_factor}'] = df_simple[f'{score_factor}'].apply(lambda x: round(x * 100, 2))
|
||||||
|
|
||||||
updater = MongoDataFrameUpdater(community_rate_client)
|
updater = MongoDataFrameUpdater(community_rate_client)
|
||||||
updater.bulk_insert_or_update_by_id(db_df, id_fields=['comm_id'])
|
updater.bulk_insert_or_update_by_id(db_df, id_fields=['comm_id'])
|
||||||
logger.info(f"楼盘评级计算结束:{city}")
|
logger.info(f"楼盘评级计算结束:{city}")
|
||||||
|
|||||||
Reference in New Issue
Block a user