#2871 - Updated the show_history() function to receive a list of actions to ignore when printing the history. Defaults to ignoring DONOTHING actions

This commit is contained in:
Charlie Crane
2024-09-13 15:47:59 +01:00
parent f2a0eeaca2
commit 5006e41546

View File

@@ -139,22 +139,23 @@ class AbstractAgent(ABC):
table.add_row([item.timestep, item.action, node, application, item.response.status]) table.add_row([item.timestep, item.action, node, application, item.response.status])
return table return table
def show_history(self, include_nothing: bool = False): def show_history(self, ignored_actions: Optional[list] = None):
""" """
Print an agent action provided it's not the DONOTHING action. Print an agent action provided it's not the DONOTHING action.
:param include_nothing: boolean for including DONOTHING actions. Default False. :param ignored_actions: OPTIONAL: List of actions to be ignored when displaying the history.
If not provided, defaults to ignore DONOTHING actions.
""" """
if not ignored_actions:
ignored_actions = ["DONOTHING"]
table = PrettyTable() table = PrettyTable()
table.field_names = ["Step", "Action", "Node", "Application", "Response"] table.field_names = ["Step", "Action", "Node", "Application", "Response"]
print(f"Actions for '{self.agent_name}':") print(f"Actions for '{self.agent_name}':")
for item in self.history: for item in self.history:
if item.action == "DONOTHING": if item.action in ignored_actions:
if include_nothing: pass
table = self.add_agent_action(item=item, table=table) else:
else: table = self.add_agent_action(item=item, table=table)
pass
self.add_agent_action(item=item, table=table)
print(table) print(table)
def update_observation(self, state: Dict) -> ObsType: def update_observation(self, state: Dict) -> ObsType: