Skip to content

Commit

Permalink
Merge pull request #29 from Enraged-Dun-Cookie-Development-Team/auto-…
Browse files Browse the repository at this point in the history
…scheduler-v0.1

减小batch;强行短暂休息;后处理环节补充log
  • Loading branch information
YoungHector authored Oct 13, 2024
2 parents 4c688e6 + 2af36c4 commit 7844eaf
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
15 changes: 12 additions & 3 deletions src/_data_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ def limit_cpu(interval):
info_dict={'info': '{} '.format(datetime.datetime.now()) +
str({'cpu使用率:': cpu_usage})})

if cpu_usage > 30: # 如果CPU使用率超过40%
if cpu_usage > 20: # 如果CPU使用率超过40%
time.sleep(interval) # 暂停一小段时间
stop_counts += 1
else:
Expand All @@ -335,11 +335,12 @@ def limit_cpu(interval):
start_time = time.time()
# 在预测过程中定期调用此函数
predictions = []
batch_size = 100000
interval = 5e-5
batch_size = 10000
interval = 0.005
messager.send_to_bot_shortcut('开始预测')

for i in range(0, len(X_list), batch_size):
time.sleep(0.005)
batch = X_list[i:i + batch_size]
batch_predictions = self.model.predict(batch)
predictions.extend(batch_predictions)
Expand All @@ -361,6 +362,7 @@ def limit_cpu(interval):
self._set_model_predicted_result_pool(X_list, predicted_result)
except Exception as e:
# 打印报错
messager.send_to_bot_shortcut('出现报错,详细信息为:')
messager.send_to_bot_shortcut(str(e))

def get_post_data_list(self, pending_datasources_id_list, maintainer:Maintainer):
Expand Down Expand Up @@ -461,14 +463,21 @@ def _set_model_predicted_result_pool(self, X_list, predicted_result):
把预测结果和原始输入,整合成方便查找蹲饼时间和对应数据源的形式。
"""
X_list['predicted_y'] = np.array(predicted_result) > 0.99999
messager.send_to_bot_shortcut('将预测结果与特征完成拼接,完整形状为:')
messager.send_to_bot_shortcut(X_list.shape)

X_list.columns = ['datasource', '1', '2', '3', '4', 'year', 'month', 'day', 'hour', 'minute', 'second', '11', 'predicted_y']

X_list['datetime'] = pd.to_datetime(X_list[['year', 'month', 'day', 'hour', 'minute', 'second']])
messager.send_to_bot_shortcut('完成时间戳转换')

# 使用.dt.strftime()将日期时间对象格式化为字符串
X_list['datetime_str'] = X_list['datetime'].dt.strftime('%Y-%m-%d %H:%M:%S')

messager.send_to_bot_shortcut('完成时间戳字符串化')

X_list = X_list[X_list['datasource'] < 33].reset_index(drop=True)
messager.send_to_bot_shortcut('完成datasource筛选')

# debug
print('未来一天的预测结果')
Expand Down
10 changes: 9 additions & 1 deletion src/auto_sche/model_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,15 @@ def feature_combine(self):

time_points = self.feature_of_time()
messager.send_to_bot_shortcut('梳理时间相关的特征完成')
for t in tqdm(time_points):

time_points_nums = len(time_points)

for t_idx, t in tqdm(enumerate(time_points)):

# 打印10次中间过程。
if t_idx % (time_points_nums // 10) == 0:
messager.send_to_bot_shortcut('合成最终特征中,进度{}/{}'.format(t_idx, time_points_nums))

cur_feature = np.zeros([datasource_num, feature_num], dtype=int)

# datasource_encoded
Expand Down

0 comments on commit 7844eaf

Please sign in to comment.