优化执行

This commit is contained in:
沈健
2025-04-14 17:57:04 +08:00
parent 80d391b358
commit 390b869d3e
3 changed files with 68 additions and 56 deletions
@@ -95,7 +95,11 @@ def calc_consumption_potential(city):
# 人均消费极大值处理
community_summary_df['avg_cost_fixed'] = np.where(community_summary_df['avg_cost_fixed'] > 250, 250, community_summary_df['avg_cost_fixed'])
community_summary_df['avg_cost_fixed'] = np.log1p(community_summary_df['avg_cost_fixed'])
try:
community_summary_df['avg_cost_fixed'] = np.log1p(community_summary_df['avg_cost_fixed'])
except Exception:
community_summary_df['avg_cost_fixed'] = None
pass
#community_summary_df['avg_cost_fixed'] = 1 - np.log(community_summary_df['avg_cost_fixed'] + 1) / np.log(max_avg_cost_fixed + 1)
community_summary_df['estate_charge_fixed'] = 1 - np.log(community_summary_df['estate_charge_fixed'] + 1) / np.log(max_estate_charge_fixed + 1)
community_summary_df['relative_price_ranking'] = 1 - np.log(community_summary_df['relative_price_ranking'] + 1) / np.log(max_relative_price_ranking + 1)
@@ -110,8 +114,12 @@ def calc_consumption_potential(city):
community_summary_df['relative_price_ranking_std'] = community_summary_df.groupby(by=['city'])[
'relative_price_ranking'].transform(np.std)
community_summary_df['avg_cost_mean'] = community_summary_df.groupby(by=['city'])['avg_cost_fixed'].transform(np.mean)
community_summary_df['avg_cost_std'] = community_summary_df.groupby(by=['city'])['avg_cost_fixed'].transform(np.std)
try:
community_summary_df['avg_cost_mean'] = community_summary_df.groupby(by=['city'])['avg_cost_fixed'].transform(np.mean)
community_summary_df['avg_cost_std'] = community_summary_df.groupby(by=['city'])['avg_cost_fixed'].transform(np.std)
except Exception:
community_summary_df['avg_cost_mean'] = None
community_summary_df['avg_cost_std'] = None
community_summary_df['total_price_mean'] = community_summary_df.groupby(by=['city'])['total_price_fixed'].transform(
np.mean)
@@ -314,9 +322,13 @@ def sync(city=None):
# 清空缺少因子的老潜力
temp_df = es206_client.scan_by_sql_to_data_frame(clear_sql)
clear_rating(temp_df)
run = False
for city_now in reasonable_df['city'].unique():
#if pd.isna(reasonable_dict[city_now]):
sync_by_city(city_now)
if city_now == '昌都':
run = True
if run:
sync_by_city(city_now)
else:
clear_sql += f" and city='{city}' "
temp_df = es206_client.scan_by_sql_to_data_frame(clear_sql)