#2085: generate time based log files
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
# © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK
|
# © Crown-owned copyright 2023, Defence Science and Technology Laboratory UK
|
||||||
|
import datetime as datetime
|
||||||
import logging
|
import logging
|
||||||
import logging.config
|
import logging.config
|
||||||
import shutil
|
import shutil
|
||||||
@@ -38,7 +39,7 @@ class _PrimaitePaths:
|
|||||||
self.app_config_file_path = self.generate_app_config_file_path()
|
self.app_config_file_path = self.generate_app_config_file_path()
|
||||||
self.app_log_dir_path = self.generate_app_log_dir_path()
|
self.app_log_dir_path = self.generate_app_log_dir_path()
|
||||||
self.app_log_file_path = self.generate_app_log_file_path()
|
self.app_log_file_path = self.generate_app_log_file_path()
|
||||||
self.episode_steps_log_file_path = self.generate_episode_step_log_file_path()
|
self.episode_log_file_path = self.generate_episode_log_file_path()
|
||||||
|
|
||||||
def _get_dirs_properties(self) -> List[str]:
|
def _get_dirs_properties(self) -> List[str]:
|
||||||
class_items = self.__class__.__dict__.items()
|
class_items = self.__class__.__dict__.items()
|
||||||
@@ -106,9 +107,12 @@ class _PrimaitePaths:
|
|||||||
"""The PrimAITE app log file path."""
|
"""The PrimAITE app log file path."""
|
||||||
return self.app_log_dir_path / "primaite.log"
|
return self.app_log_dir_path / "primaite.log"
|
||||||
|
|
||||||
def generate_episode_step_log_file_path(self) -> Path:
|
def generate_episode_log_file_path(self) -> Path:
|
||||||
"""The PrimAITE app episode step log file path."""
|
"""The PrimAITE app episode step log file path."""
|
||||||
return self.app_log_dir_path / "epi_step.log"
|
date_string = datetime.datetime.now().strftime("%Y-%m-%dT%H-%M-%S")
|
||||||
|
self.episode_log_dir_path = self.app_log_dir_path / date_string
|
||||||
|
self.episode_log_dir_path.mkdir(exist_ok=True, parents=True)
|
||||||
|
return self.episode_log_dir_path / "episode.log"
|
||||||
|
|
||||||
def __repr__(self) -> str:
|
def __repr__(self) -> str:
|
||||||
properties_str = ", ".join([f"{p}='{getattr(self, p)}'" for p in self._get_dirs_properties()])
|
properties_str = ", ".join([f"{p}='{getattr(self, p)}'" for p in self._get_dirs_properties()])
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import os
|
# import os
|
||||||
from typing import Any, Dict, Final, Optional, SupportsFloat, Tuple
|
from typing import Any, Dict, Final, Optional, SupportsFloat, Tuple
|
||||||
|
|
||||||
import gymnasium
|
import gymnasium
|
||||||
@@ -37,11 +37,11 @@ class PrimaiteGymEnv(gymnasium.Env):
|
|||||||
dump_state = {self.game.episode_counter: {self.game.step_counter: state}}
|
dump_state = {self.game.episode_counter: {self.game.step_counter: state}}
|
||||||
|
|
||||||
# Dump to file
|
# Dump to file
|
||||||
if os.path.isfile(PRIMAITE_PATHS.episode_steps_log_file_path):
|
# if os.path.isfile(PRIMAITE_PATHS.episode_steps_log_file_path):
|
||||||
with open(PRIMAITE_PATHS.episode_steps_log_file_path, "a", encoding="utf-8") as f:
|
with open(PRIMAITE_PATHS.episode_log_file_path, "a", encoding="utf-8") as f:
|
||||||
f.write(str(dump_state))
|
f.write(str(dump_state))
|
||||||
f.write("\n=================\n")
|
f.write("\n=================\n")
|
||||||
f.flush()
|
f.flush()
|
||||||
|
|
||||||
self.game.update_agents(state)
|
self.game.update_agents(state)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user