Skip to content

Commit

Permalink
add helper method for updating ignored links; use chain data to provi…
Browse files Browse the repository at this point in the history
…de list of potential skipped abilities
  • Loading branch information
bleepbop committed Sep 22, 2023
1 parent e7b2d8c commit 8092725
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
2 changes: 2 additions & 0 deletions app/api/v2/managers/operation_api_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ async def update_operation_link(self, operation_id: str, link_id: str, link_data
if not link.is_valid_status(link_status):
raise JsonHttpBadRequest(f'Cannot update link {link_id} due to invalid link status.')
link.status = link_status
if link.can_ignore():
operation.add_ignored_link(link.id)
return link.display

async def create_potential_link(self, operation_id: str, data: dict, access: BaseWorld.Access):
Expand Down
15 changes: 10 additions & 5 deletions app/objects/c_operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ async def wait_for_links_completion(self, link_ids):
for link_id in link_ids:
link = [link for link in self.chain if link.id == link_id][0]
if link.can_ignore():
self.ignored_links.add(link.id)
self.add_ignored_link(link.id)
member = [member for member in self.agents if member.paw == link.paw][0]
while not (link.finish or link.can_ignore()):
await asyncio.sleep(5)
Expand All @@ -256,6 +256,9 @@ async def is_finished(self):
def link_status(self):
return -3 if self.autonomous else -1

def add_ignored_link(self, link_id):
self.ignored_links.add(link_id)

async def active_agents(self):
active = []
for agent in self.agents:
Expand All @@ -272,7 +275,7 @@ async def get_skipped_abilities_by_agent(self, data_svc):
for agent in self.agents:
agent_skipped = defaultdict(dict)
agent_executors = agent.executors
agent_ran = set([link.ability.ability_id for link in self.chain if link.paw == agent.paw])
agent_ran = set([link.ability.ability_id for link in self.chain if link.paw == agent.paw and link.finish])
for ab in abilities_by_agent[agent.paw]['all_abilities']:
skipped = self._check_reason_skipped(agent=agent, ability=ab, agent_executors=agent_executors,
op_facts=[f.trait for f in await self.all_facts()],
Expand Down Expand Up @@ -437,9 +440,11 @@ async def _unfinished_links_for_agent(self, paw):
return [link for link in self.chain if link.paw == paw and not link.finish and not link.can_ignore()]

async def _get_all_possible_abilities_by_agent(self, data_svc):
abilities = {'all_abilities': [ab for ab_id in self.adversary.atomic_ordering
for ab in await data_svc.locate('abilities', match=dict(ability_id=ab_id))]}
return {a.paw: abilities for a in self.agents}
abilities_by_agent = {a.paw: {'all_abilities': []} for a in self.agents}
for link in self.chain:
matching_abilities = await data_svc.locate('abilities', match=dict(ability_id=link.ability.ability_id))
abilities_by_agent[link.paw]['all_abilities'].extend(matching_abilities)
return abilities_by_agent

def _check_reason_skipped(self, agent, ability, op_facts, state, agent_executors, agent_ran):
if ability.ability_id in agent_ran:
Expand Down

0 comments on commit 8092725

Please sign in to comment.