#2058 - Fix up log file path
This commit is contained in:
@@ -38,6 +38,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()
|
||||||
|
|
||||||
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()
|
||||||
@@ -105,6 +106,10 @@ 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:
|
||||||
|
"""The PrimAITE app episode step log file path."""
|
||||||
|
return self.app_log_dir_path / "epi_step.json"
|
||||||
|
|
||||||
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()])
|
||||||
return f"{self.__class__.__name__}({properties_str})"
|
return f"{self.__class__.__name__}({properties_str})"
|
||||||
|
|||||||
@@ -1,18 +1,17 @@
|
|||||||
"""PrimAITE game - Encapsulates the simulation and agents."""
|
"""PrimAITE game - Encapsulates the simulation and agents."""
|
||||||
import json
|
import json
|
||||||
from datetime import datetime
|
import os
|
||||||
from ipaddress import IPv4Address
|
from ipaddress import IPv4Address
|
||||||
from typing import Dict, List
|
from typing import Dict, List
|
||||||
|
|
||||||
from pydantic import BaseModel, ConfigDict
|
from pydantic import BaseModel, ConfigDict
|
||||||
|
|
||||||
from primaite import getLogger
|
from primaite import getLogger, PRIMAITE_PATHS
|
||||||
from primaite.game.agent.actions import ActionManager
|
from primaite.game.agent.actions import ActionManager
|
||||||
from primaite.game.agent.data_manipulation_bot import DataManipulationAgent
|
from primaite.game.agent.data_manipulation_bot import DataManipulationAgent
|
||||||
from primaite.game.agent.interface import AbstractAgent, AgentSettings, ProxyAgent, RandomAgent
|
from primaite.game.agent.interface import AbstractAgent, AgentSettings, ProxyAgent, RandomAgent
|
||||||
from primaite.game.agent.observations import ObservationManager
|
from primaite.game.agent.observations import ObservationManager
|
||||||
from primaite.game.agent.rewards import RewardFunction
|
from primaite.game.agent.rewards import RewardFunction
|
||||||
from primaite.session.io import generate_session_path
|
|
||||||
from primaite.simulator.network.hardware.base import NIC, NodeOperatingState
|
from primaite.simulator.network.hardware.base import NIC, NodeOperatingState
|
||||||
from primaite.simulator.network.hardware.nodes.computer import Computer
|
from primaite.simulator.network.hardware.nodes.computer import Computer
|
||||||
from primaite.simulator.network.hardware.nodes.router import ACLAction, Router
|
from primaite.simulator.network.hardware.nodes.router import ACLAction, Router
|
||||||
@@ -112,10 +111,10 @@ class PrimaiteGame:
|
|||||||
|
|
||||||
# Create state suitable for dumping to JSON file.
|
# Create state suitable for dumping to JSON file.
|
||||||
dump_state = {self.episode_counter: {self.step_counter: sim_state}}
|
dump_state = {self.episode_counter: {self.step_counter: sim_state}}
|
||||||
json_path = generate_session_path(datetime.now()) / "describe_state.json"
|
|
||||||
# Dump to file
|
# Dump to file
|
||||||
with open(json_path, "a") as f:
|
if os.path.isfile(PRIMAITE_PATHS.episode_steps_log_file_path):
|
||||||
json.dump(dump_state, f)
|
with open(PRIMAITE_PATHS.episode_steps_log_file_path, "a") as f:
|
||||||
|
json.dump(dump_state, f)
|
||||||
|
|
||||||
# Update agents' observations and rewards based on the current state
|
# Update agents' observations and rewards based on the current state
|
||||||
self.update_agents(sim_state)
|
self.update_agents(sim_state)
|
||||||
|
|||||||
Reference in New Issue
Block a user