优化全量统计
This commit is contained in:
@@ -22,20 +22,7 @@ if not os.path.exists(save_png_path):
|
|||||||
nextcloud_aim_file_path = '财力评级/财力评级/财力评级统计报表'
|
nextcloud_aim_file_path = '财力评级/财力评级/财力评级统计报表'
|
||||||
|
|
||||||
|
|
||||||
def calculate_confidence(row):
|
|
||||||
"""计算置信度等级"""
|
|
||||||
diff = abs(row["consumption_rating"] - row["price_rating"])
|
|
||||||
if diff == 0:
|
|
||||||
return "高"
|
|
||||||
elif diff == 1:
|
|
||||||
return "中"
|
|
||||||
else:
|
|
||||||
return "低"
|
|
||||||
|
|
||||||
|
|
||||||
def stat(community_summary_df):
|
def stat(community_summary_df):
|
||||||
# 计算置信度
|
|
||||||
community_summary_df["置信度"] = community_summary_df.apply(calculate_confidence, axis=1)
|
|
||||||
grouped = community_summary_df.groupby(["city", "region"])
|
grouped = community_summary_df.groupby(["city", "region"])
|
||||||
|
|
||||||
results = []
|
results = []
|
||||||
@@ -58,7 +45,7 @@ def stat(community_summary_df):
|
|||||||
rating_6_scores = group[group["consumption_rating"] == 6]["consumption_score"]
|
rating_6_scores = group[group["consumption_rating"] == 6]["consumption_score"]
|
||||||
|
|
||||||
# 计算置信度占比
|
# 计算置信度占比
|
||||||
confidence_counts = group["置信度"].value_counts(normalize=True)
|
confidence_counts = group["credit"].value_counts(normalize=True)
|
||||||
|
|
||||||
results.append({
|
results.append({
|
||||||
"城市": city,
|
"城市": city,
|
||||||
@@ -132,6 +119,7 @@ def detail(city):
|
|||||||
"consumption_score",
|
"consumption_score",
|
||||||
"sub_factor.total_price_rating"
|
"sub_factor.total_price_rating"
|
||||||
], index="community_summary")
|
], index="community_summary")
|
||||||
|
# 减少重复查询
|
||||||
community_summary_df = data_utils.flatten_json(community_summary_df, 'sub_factor')
|
community_summary_df = data_utils.flatten_json(community_summary_df, 'sub_factor')
|
||||||
community_summary_df = data_utils.flatten_json(community_summary_df, 'credit_detail')
|
community_summary_df = data_utils.flatten_json(community_summary_df, 'credit_detail')
|
||||||
community_summary_df['diff'] = np.abs(community_summary_df['consumption_rating'] - community_summary_df['price_rating'])
|
community_summary_df['diff'] = np.abs(community_summary_df['consumption_rating'] - community_summary_df['price_rating'])
|
||||||
@@ -139,6 +127,7 @@ def detail(city):
|
|||||||
community_summary_df['estate_charge_type'] = np.where(community_summary_df['estate_charge_flag'] == 1,'周边','自有')
|
community_summary_df['estate_charge_type'] = np.where(community_summary_df['estate_charge_flag'] == 1,'周边','自有')
|
||||||
|
|
||||||
community_summary_df['credit'] = np.where(community_summary_df['total_price_diff'] == 0, '高', np.where(community_summary_df['total_price_diff'] == 1, '中', np.where(community_summary_df['total_price_diff'] >= 2, '低', '-')))
|
community_summary_df['credit'] = np.where(community_summary_df['total_price_diff'] == 0, '高', np.where(community_summary_df['total_price_diff'] == 1, '中', np.where(community_summary_df['total_price_diff'] >= 2, '低', '-')))
|
||||||
|
stat(community_summary_df)
|
||||||
community_summary_df = community_summary_df.rename(columns={'city': '城市', 'region': '区域', 'name': '小区名称', 'consumption_score': '财力分数', 'consumption_rating': '财力评级',
|
community_summary_df = community_summary_df.rename(columns={'city': '城市', 'region': '区域', 'name': '小区名称', 'consumption_score': '财力分数', 'consumption_rating': '财力评级',
|
||||||
'total_price_rating': '户均总价评级', 'total_price_diff': '差值',
|
'total_price_rating': '户均总价评级', 'total_price_diff': '差值',
|
||||||
'total_price': '户均总价', 'avg_price': '小区均价', 'main_house_area': '典型面积', 'relative_price_ranking': '相对价格排名',
|
'total_price': '户均总价', 'avg_price': '小区均价', 'main_house_area': '典型面积', 'relative_price_ranking': '相对价格排名',
|
||||||
@@ -152,8 +141,7 @@ def detail(city):
|
|||||||
community_summary_df.to_csv(save_png_path + '/' + aim_file, index=False, columns=["城市", "区域", "小区名称", "财力分数", "财力评级", "户均总价评级", "差值", "户均总价", "小区均价", "计算方式", "典型面积",
|
community_summary_df.to_csv(save_png_path + '/' + aim_file, index=False, columns=["城市", "区域", "小区名称", "财力分数", "财力评级", "户均总价评级", "差值", "户均总价", "小区均价", "计算方式", "典型面积",
|
||||||
"获取方式", "相对价格排名", "人均消费", "物业费", "物业费获取方式", '置信度'])
|
"获取方式", "相对价格排名", "人均消费", "物业费", "物业费获取方式", '置信度'])
|
||||||
nextcloudutils.up_to_nextcloud(save_png_path + "/" + aim_file, nextcloud_aim_file_path + "/" + aim_file)
|
nextcloudutils.up_to_nextcloud(save_png_path + "/" + aim_file, nextcloud_aim_file_path + "/" + aim_file)
|
||||||
# 减少重复查询
|
|
||||||
stat(community_summary_df)
|
|
||||||
dingutils.send_text("【统计】财力评级统计完毕,请点击 https://nextcloud.fangjia.com/s/nMbzk6ZKJDimapf 查看", "32400b949005817550937f82a82c064fe5be65c23204306442c15e8b485d7ef2")
|
dingutils.send_text("【统计】财力评级统计完毕,请点击 https://nextcloud.fangjia.com/s/nMbzk6ZKJDimapf 查看", "32400b949005817550937f82a82c064fe5be65c23204306442c15e8b485d7ef2")
|
||||||
|
|
||||||
|
|
||||||
@@ -163,5 +151,4 @@ if pd.notna(sys_city) and "," in sys_city:
|
|||||||
for city in cities:
|
for city in cities:
|
||||||
detail(city)
|
detail(city)
|
||||||
else:
|
else:
|
||||||
stat(sys_city)
|
|
||||||
detail(sys_city)
|
detail(sys_city)
|
||||||
Reference in New Issue
Block a user