Exemple #1
0
 def _set_stopping_conditions(conditions):
     if conditions:
         return [
             Fact(trait, value) for sc in conditions
             for trait, value in sc.items()
         ]
     return []
Exemple #2
0
 async def _save_fact(self, operation, trait):
     if all(trait) and not any(f.trait == trait[0] and f.value == trait[1]
                               for f in operation.all_facts()):
         self.facts.append(
             Fact(trait=trait[0],
                  value=trait[1],
                  score=1,
                  collected_by=self.paw))
Exemple #3
0
 async def _load_sources(self, directory):
     for filename in glob.iglob('%s/*.yml' % directory, recursive=False):
         for src in self.strip_yml(filename):
             source = Source(
                 name=src['name'],
                 facts=[Fact(trait=f['trait'], value=str(f['value'])) for f in src.get('facts')]
             )
             await self.store(source)
Exemple #4
0
 async def _load_sources(self, directory):
     for filename in glob.iglob('%s/*.yml' % directory, recursive=False):
         for src in self.strip_yml(filename):
             source = Source(
                 identifier=src['id'],
                 name=src['name'],
                 facts=[
                     Fact(trait=f['trait'], value=str(f['value']))
                     for f in src.get('facts')
                 ],
                 adjustments=await
                 self._create_adjustments(src.get('adjustments')),
                 rules=[Rule(**r) for r in src.get('rules', [])])
             await self.store(source)
Exemple #5
0
 async def update_planner(self, data):
     """
     Update a new planner from either the GUI or REST API with new stopping conditions.
     This overwrites the existing YML file.
     :param data:
     :return: the ID of the created adversary
     """
     planner = (await self.get_service('data_svc').locate('planners', dict(name=data['name'])))[0]
     planner_id = planner.planner_id
     file_path = await self._get_file_path(planner_id)
     planner_dict = await self._read_from_yaml(file_path)
     planner_dict['stopping_conditions'] = self._get_stopping_conditions(data)
     await self._write_to_yaml(file_path, planner_dict)
     planner.stopping_conditions = [Fact(trait=f.get('trait'), value=f.get('value'))
                                    for f in data['stopping_conditions']]
     await self.get_service('data_svc').store(planner)