优化执行
This commit is contained in:
@@ -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.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['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['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)
|
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'])[
|
community_summary_df['relative_price_ranking_std'] = community_summary_df.groupby(by=['city'])[
|
||||||
'relative_price_ranking'].transform(np.std)
|
'relative_price_ranking'].transform(np.std)
|
||||||
|
|
||||||
community_summary_df['avg_cost_mean'] = community_summary_df.groupby(by=['city'])['avg_cost_fixed'].transform(np.mean)
|
try:
|
||||||
community_summary_df['avg_cost_std'] = community_summary_df.groupby(by=['city'])['avg_cost_fixed'].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)
|
||||||
|
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(
|
community_summary_df['total_price_mean'] = community_summary_df.groupby(by=['city'])['total_price_fixed'].transform(
|
||||||
np.mean)
|
np.mean)
|
||||||
@@ -314,9 +322,13 @@ def sync(city=None):
|
|||||||
# 清空缺少因子的老潜力
|
# 清空缺少因子的老潜力
|
||||||
temp_df = es206_client.scan_by_sql_to_data_frame(clear_sql)
|
temp_df = es206_client.scan_by_sql_to_data_frame(clear_sql)
|
||||||
clear_rating(temp_df)
|
clear_rating(temp_df)
|
||||||
|
run = False
|
||||||
for city_now in reasonable_df['city'].unique():
|
for city_now in reasonable_df['city'].unique():
|
||||||
#if pd.isna(reasonable_dict[city_now]):
|
#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:
|
else:
|
||||||
clear_sql += f" and city='{city}' "
|
clear_sql += f" and city='{city}' "
|
||||||
temp_df = es206_client.scan_by_sql_to_data_frame(clear_sql)
|
temp_df = es206_client.scan_by_sql_to_data_frame(clear_sql)
|
||||||
|
|||||||
+26
-26
@@ -84,32 +84,32 @@ def calc(city, year_month):
|
|||||||
log.info(f"{city} {year_month} 商圈均价计算完毕!")
|
log.info(f"{city} {year_month} 商圈均价计算完毕!")
|
||||||
|
|
||||||
|
|
||||||
# yearmonth = sys.argv[1] if len(sys.argv) > 1 else ''
|
yearmonth = sys.argv[1] if len(sys.argv) > 1 else ''
|
||||||
#
|
|
||||||
# if yearmonth == '':
|
if yearmonth == '':
|
||||||
# date = dateutils.add_months(datetime.today(), months=-1)
|
date = dateutils.add_months(datetime.today(), months=-1)
|
||||||
# yearmonth = int(dateutils.format_date(date, '%Y%m'))
|
yearmonth = int(dateutils.format_date(date, '%Y%m'))
|
||||||
# try:
|
try:
|
||||||
# for city in areautils.get_all_cities():
|
for city in areautils.get_all_cities():
|
||||||
# calc(city, yearmonth)
|
calc(city, yearmonth)
|
||||||
# except Exception as e:
|
except Exception as e:
|
||||||
# log.error(e)
|
log.error(e)
|
||||||
|
|
||||||
# # 初始化从2024年9月
|
# # 初始化从2024年9月
|
||||||
# 创建从2024年9月到2024年12月的日期范围
|
# 创建从2024年9月到2024年12月的日期范围
|
||||||
date_range = pd.date_range(start='2024-09-01', end='2025-02-28', freq='M')
|
# date_range = pd.date_range(start='2024-09-01', end='2025-02-28', freq='M')
|
||||||
|
#
|
||||||
# 创建一个包含这些日期的DataFrame
|
# # 创建一个包含这些日期的DataFrame
|
||||||
df = pd.DataFrame({'date': date_range, 'value': range(1, len(date_range) + 1)})
|
# df = pd.DataFrame({'date': date_range, 'value': range(1, len(date_range) + 1)})
|
||||||
|
#
|
||||||
# 将日期设置为索引
|
# # 将日期设置为索引
|
||||||
df.set_index('date', inplace=True)
|
# df.set_index('date', inplace=True)
|
||||||
|
#
|
||||||
# 遍历DataFrame
|
# # 遍历DataFrame
|
||||||
for city in areautils.get_all_cities():
|
# for city in areautils.get_all_cities():
|
||||||
for date, row in df.iterrows():
|
# for date, row in df.iterrows():
|
||||||
try:
|
# try:
|
||||||
date_format = int(dateutils.format_date(date, '%Y%m'))
|
# date_format = int(dateutils.format_date(date, '%Y%m'))
|
||||||
calc(city, date_format)
|
# calc(city, date_format)
|
||||||
except Exception as e:
|
# except Exception as e:
|
||||||
log.error(e)
|
# log.error(e)
|
||||||
|
|||||||
+26
-26
@@ -81,32 +81,32 @@ def calc(city, year_month):
|
|||||||
log.info(f"{city} {year_month} 均价计算完毕!")
|
log.info(f"{city} {year_month} 均价计算完毕!")
|
||||||
|
|
||||||
|
|
||||||
# yearmonth = sys.argv[1] if len(sys.argv) > 1 else ''
|
yearmonth = sys.argv[1] if len(sys.argv) > 1 else ''
|
||||||
#
|
|
||||||
# if yearmonth == '':
|
if yearmonth == '':
|
||||||
# date = dateutils.add_months(datetime.today(), months=-1)
|
date = dateutils.add_months(datetime.today(), months=-1)
|
||||||
# yearmonth = int(dateutils.format_date(date, '%Y%m'))
|
yearmonth = int(dateutils.format_date(date, '%Y%m'))
|
||||||
# try:
|
try:
|
||||||
# for city in areautils.get_all_cities():
|
for city in areautils.get_all_cities():
|
||||||
# calc(city, yearmonth)
|
calc(city, yearmonth)
|
||||||
# except Exception as e:
|
except Exception as e:
|
||||||
# log.error(e)
|
log.error(e)
|
||||||
|
|
||||||
# # 初始化从2024年9月
|
# # 初始化从2024年9月
|
||||||
# 创建从2024年9月到2024年12月的日期范围
|
# 创建从2024年9月到2024年12月的日期范围
|
||||||
date_range = pd.date_range(start='2024-09-01', end='2025-02-28', freq='M')
|
# date_range = pd.date_range(start='2024-09-01', end='2025-02-28', freq='M')
|
||||||
|
#
|
||||||
# 创建一个包含这些日期的DataFrame
|
# # 创建一个包含这些日期的DataFrame
|
||||||
df = pd.DataFrame({'date': date_range, 'value': range(1, len(date_range) + 1)})
|
# df = pd.DataFrame({'date': date_range, 'value': range(1, len(date_range) + 1)})
|
||||||
|
#
|
||||||
# 将日期设置为索引
|
# # 将日期设置为索引
|
||||||
df.set_index('date', inplace=True)
|
# df.set_index('date', inplace=True)
|
||||||
|
#
|
||||||
# 遍历DataFrame
|
# # 遍历DataFrame
|
||||||
for city in areautils.get_all_cities():
|
# for city in areautils.get_all_cities():
|
||||||
for date, row in df.iterrows():
|
# for date, row in df.iterrows():
|
||||||
try:
|
# try:
|
||||||
date_format = int(dateutils.format_date(date, '%Y%m'))
|
# date_format = int(dateutils.format_date(date, '%Y%m'))
|
||||||
calc(city, date_format)
|
# calc(city, date_format)
|
||||||
except Exception as e:
|
# except Exception as e:
|
||||||
log.error(e)
|
# log.error(e)
|
||||||
|
|||||||
Reference in New Issue
Block a user