优化保存图片,无需多次查库
This commit is contained in:
@@ -10,7 +10,6 @@ from elasticsearch import helpers
|
|||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
|
|
||||||
from sklearn.mixture import GaussianMixture
|
from sklearn.mixture import GaussianMixture
|
||||||
from concurrent.futures import ThreadPoolExecutor
|
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
@@ -102,16 +101,15 @@ def calc_consumption_rating(community_summary_df):
|
|||||||
"""
|
"""
|
||||||
计算消费等级
|
计算消费等级
|
||||||
"""
|
"""
|
||||||
consumption_aim_df = community_summary_df[['_id', 'city', 'consumption_potential']]
|
df = community_summary_df[['_id', 'city', 'consumption_potential']]
|
||||||
consumption_aim_df = consumption_aim_df.dropna(subset=['consumption_potential'])
|
df = df.dropna(subset=['consumption_potential'])
|
||||||
source = "consumption_potential"
|
source = "consumption_potential"
|
||||||
target = "consumption_rating"
|
target = "consumption_rating"
|
||||||
actions = list()
|
actions = list()
|
||||||
count = 0
|
count = 0
|
||||||
|
|
||||||
df = consumption_aim_df.copy()
|
|
||||||
if len(df) < 5:
|
if len(df) < 5:
|
||||||
return
|
return []
|
||||||
df = gmm_train(5, df, source, target)
|
df = gmm_train(5, df, source, target)
|
||||||
# 批量更新
|
# 批量更新
|
||||||
for index, item in df.iterrows():
|
for index, item in df.iterrows():
|
||||||
@@ -138,6 +136,7 @@ def calc_consumption_rating(community_summary_df):
|
|||||||
count += len(actions)
|
count += len(actions)
|
||||||
actions.clear()
|
actions.clear()
|
||||||
log.info("评级完成,共更新: {}".format(count))
|
log.info("评级完成,共更新: {}".format(count))
|
||||||
|
return df
|
||||||
|
|
||||||
|
|
||||||
def sync_by_city(city_now):
|
def sync_by_city(city_now):
|
||||||
@@ -146,8 +145,11 @@ def sync_by_city(city_now):
|
|||||||
if len(community_summary_df) == 0:
|
if len(community_summary_df) == 0:
|
||||||
log.warning(f"{city_now}无法评级,缺少因子")
|
log.warning(f"{city_now}无法评级,缺少因子")
|
||||||
return
|
return
|
||||||
calc_consumption_rating(community_summary_df)
|
community_summary_df = calc_consumption_rating(community_summary_df)
|
||||||
save_png(city_now)
|
if len(community_summary_df) == 0:
|
||||||
|
log.warning(f"{city_now}无法评级,数量低于5")
|
||||||
|
return
|
||||||
|
save_png(community_summary_df)
|
||||||
nextcloudutils.up_to_nextcloud(save_png_path + "/" + city_now + ".png", nextcloud_aim_file_path + "/" + city_now + ".png")
|
nextcloudutils.up_to_nextcloud(save_png_path + "/" + city_now + ".png", nextcloud_aim_file_path + "/" + city_now + ".png")
|
||||||
|
|
||||||
|
|
||||||
@@ -183,16 +185,10 @@ def filter_min_max(city, community_summary_df):
|
|||||||
return community_summary_df
|
return community_summary_df
|
||||||
|
|
||||||
|
|
||||||
def save_png(city):
|
def save_png(community_city):
|
||||||
"""
|
"""
|
||||||
生成财力评级图表
|
生成财力评级图表
|
||||||
"""
|
"""
|
||||||
sql = "select id, city, region, name, total_price, estate_charge, avg_cost, relative_price_ranking, consumption_rating from community_summary where city='" + city + "'"
|
|
||||||
community_summary_df = es206_client.scan_by_sql_to_data_frame(sql)
|
|
||||||
community_summary_df['total_price'] = community_summary_df['total_price'] / 10000
|
|
||||||
|
|
||||||
community_city = filter_min_max(city, community_summary_df).copy()
|
|
||||||
|
|
||||||
plt.subplot(3, 1, 1)
|
plt.subplot(3, 1, 1)
|
||||||
community_city['consumption_rating'].hist(bins=100)
|
community_city['consumption_rating'].hist(bins=100)
|
||||||
plt.xlabel('consumption_rating')
|
plt.xlabel('consumption_rating')
|
||||||
@@ -218,7 +214,7 @@ def save_png(city):
|
|||||||
plt.xlabel('relative_price_ranking')
|
plt.xlabel('relative_price_ranking')
|
||||||
plt.tight_layout()
|
plt.tight_layout()
|
||||||
|
|
||||||
plt.savefig(save_png_path + "/" + city + ".png")
|
plt.savefig(save_png_path + "/" + community_city['city'].unique()[0] + ".png")
|
||||||
# 清图
|
# 清图
|
||||||
plt.clf()
|
plt.clf()
|
||||||
# 清坐标轴
|
# 清坐标轴
|
||||||
|
|||||||
Reference in New Issue
Block a user