示例#1
0
 def __check_alive(self, event):
     """
     Iterates over all registered specifications and sends an error if no package is received but was expected.
     """
     for seuid in self.__specification_handler.loaded_specifications():
         if seuid not in self.__alive_timers.keys():
             spec = self.__specification_handler.get(seuid)
             alive_timer = spec.get("alive_timer")
             if not alive_timer:
                 alive_timer = rospy.get_param("~alive_timer", 10)
             else:
                 alive_timer = alive_timer[1]
             self.__alive_timers[seuid] = rospy.Duration(alive_timer)
         if seuid not in self.__alive_countdown.keys():
             self.__alive_countdown[seuid] = rospy.Time.now()
         if rospy.Time.now(
         ) >= self.__alive_countdown[seuid] + self.__alive_timers[seuid]:
             r = RatedStatisticsContainer(seuid)
             r.add_value("alive", ["False"], ["True"], [1])
             r.add_value("window_start", self.__alive_countdown[seuid],
                         None, None)
             r.add_value("window_stop", rospy.Time.now(), None, None)
             msg = r.to_msg_type()
             self.__publish_data(msg)
示例#2
0
 def __check_alive(self, event):
     """
     Iterates over all registered specifications and sends an error if no package is received but was expected.
     """
     for seuid in self.__specification_handler.loaded_specifications():
         if seuid not in self.__alive_timers.keys():
             spec = self.__specification_handler.get(seuid)
             alive_timer = spec.get("alive_timer")
             if not alive_timer:
                 alive_timer = rospy.get_param("~alive_timer", 10)
             else:
                 alive_timer = alive_timer[1]
             self.__alive_timers[seuid] = rospy.Duration(alive_timer)
         if seuid not in self.__alive_countdown.keys():
             self.__alive_countdown[seuid] = rospy.Time.now()
         if rospy.Time.now() >= self.__alive_countdown[seuid] + self.__alive_timers[seuid]:
             r = RatedStatisticsContainer(seuid)
             r.add_value("alive", ["False"], ["True"], [1])
             r.add_value("window_start", self.__alive_countdown[seuid], None, None)
             r.add_value("window_stop", rospy.Time.now(), None, None)
             msg = r.to_msg_type()
             self.__publish_data(msg)
示例#3
0
    def compare(self, data, identifier, specification=None):
        """
        Compares a Message object with a Specification object regarding all available matching fields.

        :param data: The actual data.
        :type data: object.
        :param identifier: The identifier of the metadata package.
        :type identifier: str
        :param specification: The Specification object, alternatively a string identifying it.
        :type specification: Specification or str.
        :returns: A RatedStatisticsContainer object representing the result.
        """
        if identifier is None:
            rospy.logdebug("[SpecificationHandler][compare] No identifier given.")
            return None
        if not SEUID().is_valid(identifier):
            rospy.logdebug("[SpecificationHandler][compare] Given identifier is invalid.")
            return None
        if data is None:
            rospy.logdebug("[SpecificationHandler][compare] No data given.")
            return None
        result = RatedStatisticsContainer(identifier)
        if identifier[0] == "n":
            result.host = data.host
        if specification is None:
            specification = self.get(identifier)
        window_len = data.window_stop - data.window_start
        if window_len.to_sec() == 0:
            window_len = rospy.Duration(1)
        fields = dir(data)
        exclude = ("delivered_msgs", "traffic")
        for x in exclude:
            if x in fields:
                fields.remove(x)
        if identifier[0] == "c":
            fields.append("bandwidth")
            fields.append("frequency")
        for field in fields:
            value = None
            if field[0] == "_" or "serialize" in field:
                continue
            current_obj = {}
            if field == "bandwidth":
                value = data.traffic / window_len.to_sec()
            elif field == "frequency":
                value = data.delivered_msgs / window_len.to_sec()
            else:
                value = getattr(data, field)
            if value is not None:
                limits = self.__get_limits(specification, field)
                if isinstance(value, (list, tuple)):
                    current_obj["state"] = []
                    current_obj["actual"] = []
                    current_obj["expected"] = []
                    for i, v in enumerate(value):
                        limits = self.__get_limits(specification, field, i)
                        current_obj["actual"].append(v)
                        current_obj["state"].append(self.__compare(v, limits))
                        current_obj["expected"].append(limits)
                else:
                    status = self.__compare(value, limits)
                    current_obj["state"] = status
                    current_obj["actual"] = value
                    current_obj["expected"] = limits
                result.add_value(field, current_obj["actual"], current_obj["expected"], current_obj["state"])
        result.add_value("alive", ["True"], ["True"], [2])
        return result
示例#4
0
    def compare(self, data, identifier, specification=None):
        """
        Compares a Message object with a Specification object regarding all available matching fields.

        :param data: The actual data.
        :type data: object.
        :param identifier: The identifier of the metadata package.
        :type identifier: str
        :param specification: The Specification object, alternatively a string identifying it.
        :type specification: Specification or str.
        :returns: A RatedStatisticsContainer object representing the result.
        """
        if identifier is None:
            rospy.logdebug("[SpecificationHandler][compare] No identifier given.")
            return None
        if not SEUID().is_valid(identifier):
            rospy.logdebug("[SpecificationHandler][compare] Given identifier is invalid.")
            return None
        if data is None:
            rospy.logdebug("[SpecificationHandler][compare] No data given.")
            return None
        result = RatedStatisticsContainer(identifier)
        if identifier[0] == "n":
            result.host = data.host
        if specification is None:
            specification = self.get(identifier)
        window_len = data.window_stop - data.window_start
        if window_len.to_sec() == 0:
            window_len = rospy.Duration(1)
        fields = dir(data)
        exclude = ("delivered_msgs", "traffic")
        for x in exclude:
            if x in fields:
                fields.remove(x)
        if identifier[0] == "c":
            fields.append("bandwidth")
            fields.append("frequency")
        for field in fields:
            value = None
            if field[0] == "_" or "serialize" in field:
                continue
            current_obj = {}
            if field == "bandwidth":
                value = data.traffic / window_len.to_sec()
            elif field == "frequency":
               value = data.delivered_msgs / window_len.to_sec()
            else:
                value = getattr(data, field)
            if value is not None:
                limits = self.__get_limits(specification, field)
                if isinstance(value, (list, tuple)):
                    current_obj["state"] = []
                    current_obj["actual"] = []
                    current_obj["expected"] = []
                    for i, v in enumerate(value):
                        limits = self.__get_limits(specification, field, i)
                        current_obj["actual"].append(v)
                        current_obj["state"].append(self.__compare(v, limits))
                        current_obj["expected"].append(limits)
                else:
                    status = self.__compare(value, limits)
                    current_obj["state"] = status
                    current_obj["actual"] = value
                    current_obj["expected"] = limits
                result.add_value(field, current_obj["actual"], current_obj["expected"], current_obj["state"])
        result.add_value("alive", ["True"], ["True"], [2])
        return result