#2871 - Initial commit of a show_history() function in AbstractAgent
This commit is contained in:
@@ -4,6 +4,7 @@ from abc import ABC, abstractmethod
|
|||||||
from typing import Any, Dict, List, Optional, Tuple, TYPE_CHECKING
|
from typing import Any, Dict, List, Optional, Tuple, TYPE_CHECKING
|
||||||
|
|
||||||
from gymnasium.core import ActType, ObsType
|
from gymnasium.core import ActType, ObsType
|
||||||
|
from prettytable import PrettyTable
|
||||||
from pydantic import BaseModel, model_validator
|
from pydantic import BaseModel, model_validator
|
||||||
|
|
||||||
from primaite.game.agent.actions import ActionManager
|
from primaite.game.agent.actions import ActionManager
|
||||||
@@ -126,6 +127,27 @@ class AbstractAgent(ABC):
|
|||||||
self.history: List[AgentHistoryItem] = []
|
self.history: List[AgentHistoryItem] = []
|
||||||
self.logger = AgentLog(agent_name)
|
self.logger = AgentLog(agent_name)
|
||||||
|
|
||||||
|
def show_history(self):
|
||||||
|
"""
|
||||||
|
Print an agent action provided it's not the DONOTHING action.
|
||||||
|
|
||||||
|
:param agent_name: Name of agent (str).
|
||||||
|
"""
|
||||||
|
table = PrettyTable()
|
||||||
|
table.field_names = ["Step", "Action", "Node", "Application", "Response"]
|
||||||
|
print(f"Actions for '{self.agent_name}':")
|
||||||
|
for item in self.history:
|
||||||
|
if item.action != "DONOTHING":
|
||||||
|
node, application = "unknown", "unknown"
|
||||||
|
if (node_id := item.parameters.get("node_id")) is not None:
|
||||||
|
node = self.action_manager.node_names[node_id]
|
||||||
|
if (application_id := item.parameters.get("application_id")) is not None:
|
||||||
|
application = self.action_manager.application_names[node_id][application_id]
|
||||||
|
if (application_name := item.parameters.get("application_name")) is not None:
|
||||||
|
application = application_name
|
||||||
|
table.add_row([item.timestep, item.action, node, application, item.response.status])
|
||||||
|
print(table)
|
||||||
|
|
||||||
def update_observation(self, state: Dict) -> ObsType:
|
def update_observation(self, state: Dict) -> ObsType:
|
||||||
"""
|
"""
|
||||||
Convert a state from the simulator into an observation for the agent using the observation space.
|
Convert a state from the simulator into an observation for the agent using the observation space.
|
||||||
|
|||||||
Reference in New Issue
Block a user