def match_reporting_entities(
            *, proposed_entities: DeserializedFile,
            solution_entities: DeserializedFile) -> List[CloudDeviceId]:
        """
      Matches reporting entities by `cloud_device_id`

      Args:
        proposed_entities: Dictionary of proposed entity names
          and `EntityInstance`s
        solution_entities: Dictionary of solution entity names
          and `EntityInstance`s

      Returns:
        List of `cloud_device_id`s which have corresponding
        proposed and solution entities
    """
        matches = []
        for solution_entity in solution_entities.values():
            if solution_entity.cloud_device_id is None:
                continue  # as this is not a reporting device
            for proposed_entity in proposed_entities.values():
                if proposed_entity.cloud_device_id == solution_entity.cloud_device_id:
                    matches.append(proposed_entity.cloud_device_id)

        return matches
Esempio n. 2
0
 def _isolate_entities_virtual(
         self, *, file: DeserializedFile,
         exclude_noncanonical: bool) -> Set[EntityInstance]:
     virtual_entities = filter(self.is_entity_virtual, file.values())
     return set(
         filter(self.is_entity_canonical, virtual_entities
                ) if exclude_noncanonical else virtual_entities)
Esempio n. 3
0
 def _isolate_entities_reporting(
         self, *, file: DeserializedFile,
         exclude_noncanonical: bool) -> Set[EntityInstance]:
     reporting_entities = filter(self.is_entity_reporting, file.values())
     return set(
         filter(self.is_entity_canonical, reporting_entities
                ) if exclude_noncanonical else reporting_entities)
Esempio n. 4
0
 def _list_ids_reporting(self, *, file: DeserializedFile,
                         exclude_noncanonical: bool) -> List[CloudDeviceId]:
     """Generates list of `cloud_device_id`s representing reporting entities."""
     reporting_entities = filter(self.is_entity_reporting, file.values())
     filtered = filter(
         self.is_entity_canonical,
         reporting_entities) if exclude_noncanonical else reporting_entities
     return [entity.cloud_device_id for entity in filtered]
Esempio n. 5
0
 def _isolate_connections(self, file: DeserializedFile):
   """Distill individual connections from each entity
   prior to inclusion in sets for global comparison."""
   return [
       tup for tup in (((cloud_device_id, connection)
                        for connection in entity.connections)
                       for cloud_device_id, entity in file.items()
                       if entity.connections is not None) for tup in tup
   ]
 def _list_ids_reporting(self,
                         file: DeserializedFile) -> List[CloudDeviceId]:
     """Generates list of `cloud_device_id`s representing
 reporting entities with canonical types."""
     return [
         entity.cloud_device_id for entity in filter(
             self.is_entity_canonical,
             filter(self.is_entity_reporting, file.values()))
     ]
 def _list_ids_virtual(self, file: DeserializedFile) -> List[CloudDeviceId]:
     """Generates list of `cloud_device_id`s representing
 reporting entities with canonical types that
 are linked to by virtual entities."""
     return [
         cloud_device_id for source_list in ((
             file[link.source].cloud_device_id
             for link in entity.links) for entity in filter(
                 self.is_entity_canonical,
                 filter(self.is_entity_virtual, file.values())))
         for cloud_device_id in source_list
     ]
Esempio n. 8
0
 def _list_ids_virtual(self, *, file: DeserializedFile,
                       exclude_noncanonical: bool) -> List[CloudDeviceId]:
     """Generates list of `cloud_device_id`s representing
 reporting entities that are linked to by virtual entities."""
     virtual_entities = filter(self.is_entity_virtual, file.values())
     filtered = filter(
         self.is_entity_canonical,
         virtual_entities) if exclude_noncanonical else virtual_entities
     ids = []
     for entity in filtered:
         for link in entity.links:
             ids.append(file[link.source].cloud_device_id)
     return ids
 def _isolate_entities_reporting(
         self, file: DeserializedFile) -> Set[EntityInstance]:
     return set(
         filter(self.is_entity_canonical,
                filter(self.is_entity_reporting, file.values())))
Esempio n. 10
0
    def retrieve_reporting_translations(
            *, proposed_entities: DeserializedFile,
            solution_entities: DeserializedFile) -> TranslationsDict:
        """
      Retrieves proposed and solution translations
      for all matched reporting entities.

      Args:
        matches: List of `cloud_device_id`s which have corresponding
          proposed and solution entities
        proposed_entities: Dictionary of proposed entity names
          and `EntityInstance`s
        solution_entities: Dictionary of solution entity names
          and `EntityInstance`s

      Returns:
        Dictionary with `cloud_device_id`s as keys
        and values which are dictionaries containing lists
        of translations for the device, keyed under the file type
    """

        translations = {}
        for solution_entity in solution_entities.values():
            if solution_entity.cloud_device_id is None:
                continue  # as this is not a reporting device
            if not Dimension.is_entity_canonical(solution_entity):
                continue  # as noncanonical entities are skipped

            cloud_device_id = solution_entity.cloud_device_id

            def find_matches(cdid: str) -> List[Any]:
                """Find the matching proposal via cloud_device_id comparison.

        Args:
          cdid: cloud device id string.

        Returns:
          List of matching entities.
        """
                matches = [
                    proposed_entity
                    for proposed_entity in proposed_entities.values()
                    if proposed_entity.cloud_device_id == cdid
                ]
                return matches

            proposed_entity = find_matches(cloud_device_id)[0] if find_matches(
                cloud_device_id) else {}

            def aggregate_translations(entity) -> List[Any]:
                """Isolate translation of an entity pairing."""
                if getattr(entity, 'translation', None):
                    return list(entity.translation.items())
                return []

            translations[cloud_device_id] = {
                f'{PROPOSED}': aggregate_translations(proposed_entity),
                f'{SOLUTION}': aggregate_translations(solution_entity)
            }

        return translations