示例#1
0
    def to_oef_description(cls, desc: Description) -> OEFDescription:
        """From our description to OEF description."""
        oef_data_model = (cls.to_oef_data_model(desc.data_model)
                          if desc.data_model is not None else None)

        new_values = {}
        location_keys = set()
        loggers_by_key = {}
        for key, value in desc.values.items():
            if isinstance(value, Location):
                oef_location = OEFLocation(latitude=value.latitude,
                                           longitude=value.longitude)
                location_keys.add(key)
                new_values[key] = oef_location
            else:
                new_values[key] = value

        # this is a workaround to make OEFLocation objects deep-copyable.
        # Indeed, there is a problem in deep-copying such objects
        # because of the logger object they have attached.
        # Steps:
        # 1) we remove the loggers attached to each Location obj,
        # 2) then we instantiate the description (it runs deepcopy on the values),
        # 3) and then we reattach the loggers.
        for key in location_keys:
            loggers_by_key[key] = new_values[key].log
            # in this way we remove the logger
            new_values[key].log = None

        description = OEFDescription(new_values, oef_data_model)

        for key in location_keys:
            new_values[key].log = loggers_by_key[key]

        return description
示例#2
0
 def to_oef_description(cls, desc: Description) -> OEFDescription:
     """From our description to OEF description."""
     oef_data_model = (
         cls.to_oef_data_model(desc.data_model)
         if desc.data_model is not None
         else None
     )
     return OEFDescription(desc.values, oef_data_model)