def print_log(logger: Stack, n=20): print('') print('logs>') len_log = len(logger) if len_log < 2 * n: for log in logger.getTotal(): log_msg = gen_log_msg(log) print(log_msg) elif len_log >= 2 * n: for log in logger.getTotal(n): log_msg = gen_log_msg(log) print(log_msg) print('\n\n') print('A Few Moments Later...') print('\n\n') for log in logger.getTotal(-n): log_msg = gen_log_msg(log) print(log_msg) return
def save_log(logger: Stack, id, goal_position, state_id, cnt): t = time.strftime('%Y%m%d_%H-%M-%S', time.localtime(time.time())) gx = int(goal_position[0]) gz = int(goal_position[2]) g_pos = f'x{gx}z{gz}' path = f'logs/env{id}_gpos{g_pos}/' if not os.path.exists(path): os.makedirs(path) filename = path + f'{state_id}{cnt}_{t}.log' with open(f'{filename}', 'w') as f: for log in logger.getTotal(): log_msg = gen_log_msg(log) f.write(log_msg) return