space_packet_parser.comparisons =============================== .. py:module:: space_packet_parser.comparisons .. autoapi-nested-parse:: Matching logical objects Attributes ---------- .. autoapisummary:: space_packet_parser.comparisons.Anded space_packet_parser.comparisons.Ored Classes ------- .. autoapisummary:: space_packet_parser.comparisons.AttrComparable space_packet_parser.comparisons.MatchCriteria space_packet_parser.comparisons.Comparison space_packet_parser.comparisons.Condition space_packet_parser.comparisons.BooleanExpression space_packet_parser.comparisons.DiscreteLookup Module Contents --------------- .. py:class:: AttrComparable Generic class that provides a notion of equality based on all non-callable, non-dunder attributes .. py:method:: __eq__(other) .. py:class:: MatchCriteria Bases: :py:obj:`AttrComparable` This class stores criteria for performing logical operations based on parameter values Classes that inherit from this ABC include those that represent , , (not supported), and (not supported) .. py:attribute:: _valid_operators .. py:method:: from_match_criteria_xml_element(element: lxml.etree.Element, ns: dict) :classmethod: :abstractmethod: Abstract classmethod to create a match criteria object from an XML element. :param element: XML element :type element: ElementTree.Element :param ns: XML namespace dict :type ns: dict :rtype: cls .. py:method:: evaluate(packet: space_packet_parser.packets.CCSDSPacket, current_parsed_value: Optional[Union[int, float]] = None) -> bool :abstractmethod: Evaluate match criteria down to a boolean. :param packet: Packet data used to evaluate truthyness of the match criteria. :type packet: packets.CCSDSPacket :param current_parsed_value: Uncalibrated value that is currently being matched (e.g. as a candidate for calibration). Used to resolve comparisons that reference their own raw value as a condition. :type current_parsed_value: any, Optional :returns: Truthyness of this match criteria based on previously parsed values. :rtype: bool .. py:class:: Comparison(required_value: any, referenced_parameter: str, operator: str = '==', use_calibrated_value: bool = True) Bases: :py:obj:`MatchCriteria` .. py:attribute:: required_value .. py:attribute:: referenced_parameter .. py:attribute:: operator .. py:attribute:: use_calibrated_value .. py:method:: __repr__() .. py:method:: _validate() Validate state as logically consistent. :rtype: None .. py:method:: from_match_criteria_xml_element(element: lxml.etree.Element, ns: dict) -> Comparison :classmethod: Create :param element: XML element :type element: ElementTree.Element :param ns: XML namespace dict :type ns: dict :rtype: Comparison .. py:method:: evaluate(packet: space_packet_parser.packets.CCSDSPacket, current_parsed_value: Optional[Union[int, float]] = None) -> bool Evaluate comparison down to a boolean. If the parameter to compare is not present in the parsed_data dict, we assume that we are comparing against the current raw value in current_parsed_value. :param packet: Packet data used to evaluate truthyness of the match criteria. :type packet: packets.CCSDSPacket :param current_parsed_value: Optional. Uncalibrated value that is currently a candidate for calibration and so has not yet been added to the packet. Used to resolve calibrator conditions that reference their own raw value as a comparate. :type current_parsed_value: Union[int, float] :returns: Truthyness of this match criteria based on previously parsed values. :rtype: bool .. py:class:: Condition(left_param: str, operator: str, *, right_param: Optional[str] = None, right_value: Optional[Any] = None, left_use_calibrated_value: bool = True, right_use_calibrated_value: bool = True) Bases: :py:obj:`MatchCriteria` Note: This xtce model doesn't actually inherit from MatchCriteria in the UML model but it's functionally close enough that we inherit the class here. .. py:attribute:: left_param .. py:attribute:: right_param .. py:attribute:: right_value .. py:attribute:: operator .. py:attribute:: right_use_calibrated_value .. py:attribute:: left_use_calibrated_value .. py:method:: _validate() Check that the instantiated object actually makes logical sense. :rtype: None .. py:method:: _parse_parameter_instance_ref(element: lxml.etree.Element) :staticmethod: Parse an xtce:ParameterInstanceRef element :param element: xtce:ParameterInstanceRef element :type element: ElementTree.Element :returns: * **parameter_name** (*str*) -- Name of referenced parameter * **use_calibrated_value** (*bool*) -- Whether to use the calibrated form of the referenced parameter .. py:method:: from_match_criteria_xml_element(element: lxml.etree.Element, ns: dict) :classmethod: Classmethod to create a Condition object from an XML element. :param element: XML element :type element: ElementTree.Element :param ns: XML namespace dict :type ns: dict :rtype: cls .. py:method:: evaluate(packet: space_packet_parser.packets.CCSDSPacket, current_parsed_value: Optional[Union[int, float]] = None) -> bool Evaluate match criteria down to a boolean. :param packet: Packet data used to evaluate truthyness of the match criteria. :type packet: packets.CCSDSPacket :param current_parsed_value: Current value being parsed. NOTE: This is currently ignored. See the TODO item below. :type current_parsed_value: Optional[Union[int, float]] :returns: Truthyness of this match criteria based on previously parsed values. :rtype: bool .. py:data:: Anded .. py:data:: Ored .. py:class:: BooleanExpression(expression: Union[Condition, Anded, Ored]) Bases: :py:obj:`MatchCriteria` .. py:attribute:: expression .. py:method:: from_match_criteria_xml_element(element: lxml.etree.Element, ns: dict) -> BooleanExpression :classmethod: Abstract classmethod to create a match criteria object from an XML element. :param element: XML element :type element: ElementTree.Element :param ns: XML namespace dict :type ns: dict :rtype: BooleanExpression .. py:method:: evaluate(packet: space_packet_parser.packets.CCSDSPacket, current_parsed_value: Optional[Union[int, float]] = None) -> bool Evaluate the criteria in the BooleanExpression down to a single boolean. :param packet: Packet data used to evaluate truthyness of the match criteria. :type packet: packets.CCSDSPacket :param current_parsed_value: Current value being parsed. :type current_parsed_value: Optional[Union[int, float]] :returns: Truthyness of this match criteria based on previously parsed values. :rtype: bool .. py:class:: DiscreteLookup(match_criteria: list, lookup_value: Union[int, float]) Bases: :py:obj:`AttrComparable` .. py:attribute:: match_criteria .. py:attribute:: lookup_value .. py:method:: from_discrete_lookup_xml_element(element: lxml.etree.Element, ns: dict) -> DiscreteLookup :classmethod: Create a DiscreteLookup object from an XML element :param element: XML element from which to parse the DiscreteLookup object. :type element: ElementTree.Element :param ns: Namespace dict for XML parsing :type ns: dict :rtype: DiscreteLookup .. py:method:: evaluate(packet: space_packet_parser.packets.CCSDSPacket, current_parsed_value: Optional[Union[int, float]] = None) -> Any Evaluate the lookup to determine if it is valid. :param packet: Packet data used to evaluate truthyness of the match criteria. :type packet: packets.CCSDSPacket :param current_parsed_value: If referenced parameter in criterion isn't in the packet, we assume we are comparing against this currently parsed value. :type current_parsed_value: Optional[Union[int, float]] :returns: Return the lookup value if the match criteria evaluate true. Return None otherwise. :rtype: any