def __init__(self, for_log, source, normal_ranges=check_range.AllInclusiveRange(), warning_ranges=check_range.AllInclusiveRange()): self._source = source super(BaseSeptentrioCheck, self).__init__(for_log, normal_ranges, warning_ranges)
def __init__(self, for_log, gps_type_per_source, normal_ranges=check_range.AllInclusiveRange(), warning_ranges=check_range.AllInclusiveRange()): assert 'FcA' in gps_type_per_source and 'FcB' in gps_type_per_source self._gps_type_per_source = gps_type_per_source super(AgreementCheck, self).__init__(for_log, normal_ranges, warning_ranges)
def __init__(self, for_log, normal_ranges=check_range.AllInclusiveRange(), warning_ranges=check_range.AllInclusiveRange(), name=None, sort_by_sequence=True): """Initialize a check. Args: for_log: True if this check targets log data. False if it checks AIO messages. normal_ranges: A BaseRange object in which values are regarded as normal. warning_ranges: A BaseRange object in which values should raise warnings, if they fall out of normal_ranges. Values falling out of warning_ranges should raise errors. name: Name of the check. sort_by_sequence: If true, messages will be sorted by sequence number, instead of orderd by time of receiving. Raises: ValueError: Raised if the __init__ function is not decorated with RegisterSpecs. """ # Values that fall within any of the normal ranges are normal. self._normal_ranges = check_range.BuildRanges(normal_ranges) # Values that fall outside of all normal ranges but inside any warning # ranges raise warnings. If the values fall even out of the warning # ranges, then they raise errors. self._warning_ranges = check_range.BuildRanges(warning_ranges) # Name of the check. self._name = name # True if the inputs should be sorted by sequence (marked at sender). self._sort_by_sequence = sort_by_sequence # Results of the check. if for_log: # If the check processes a log file, the result is formed as # {<check_name>: # {<warning_level>: {"total": ..., "count": ..., "range": ...}}}. self._results = {} else: # If the check processes AIO messages, the resut is formed as # [{"name": ..., "value": ..., "stoplight": ...}, ...] self._results = [] # Inputs needed by the check, in the form of a list of DataIndex objects. self._fields = self._RegisterInputs() # True if the check is performed over log data instead of AIO messages. self._for_log = for_log if not hasattr(self, '_kwargs'): raise ValueError( '%s.__init__ is missing the "@base.check.RegisterSpecs" decorate.' % type(self).__name__) # Merge selected regions into one section if their distance is less than # this parameter. self._min_gap = _DEFAULT_MIN_GAP
def CheckForFailure(values, target_ranges, error_if_fail, name): """Checking values against normal ranges. Args: values: Values of the field. target_ranges: A BaseRange object in which values are regarded as normal. It can also be a list of basic objects that create BaseRange objects. Please refer to check_range.RangeChecker for details. error_if_fail: True if failed values raise errors, otherwise they raise warnings. name: Name of the check. Returns: Check results in the form of { warning_name: { 'total': ..., # Total number of samples. 'count': ..., # Number of samples in this range. 'range': [min_value, max_value], }, error_name: {...} } """ if error_if_fail: return CheckByRange(values, target_ranges, check_range.AllExclusiveRange(), name) else: return CheckByRange(values, target_ranges, check_range.AllInclusiveRange(), name)
def GetChecker(mapping, check_type, default): value = mapping.get(check_type, default) if value == 'any': return check_range.AllInclusiveRange() elif value is None: # No checks for this type. return None else: return check_range.RangeChecker(value)
def __init__(self, for_log, window_size, window_step, normal_ranges, warning_ranges=check_range.AllInclusiveRange(), name=None): super(FilteredCheckItem, self).__init__(for_log, normal_ranges, warning_ranges, name) self._window_size = window_size assert window_size >= 1 self._window_step = window_step if window_step else window_size if not self._for_log: self._history = collections.defaultdict( lambda: collections.deque(maxlen=window_size))
def _Check(self, cn0, num_obs, type_bits): """Check the carrier-to-noise ratio.""" if num_obs == 0: return if self._for_log: avg_cn0, max_cn0 = self.GetAvgAndMaxCn0FromTimeSeries( cn0, num_obs, type_bits) else: avg_cn0, max_cn0, _ = self.GetAvgAndMaxCn0(cn0, num_obs, type_bits) avg_ranges = check_range.Interval([40.0, None]) max_ranges = check_range.Interval([45.0, None]) all_inclusive = check_range.AllInclusiveRange() self._CheckByRange('%s (Avg)' % self._name, avg_cn0, avg_ranges, all_inclusive) self._CheckByRange('%s (Max)' % self._name, max_cn0, max_ranges, all_inclusive)
def __init__(self, mode, **widget_kwargs): super(StarboardPosChart, self).__init__(mode, 'Star Ail Pos [°]', ['A5', 'A7', 'A8'], show_cmd=True, **widget_kwargs) self._SetLimits( { self._ObservationLabel(n): (check_range.Interval(numpy.rad2deg( flap_limits.FlapsToServos( flap_limits.GetControlCrosswindLimits())[n]).tolist(), inclusiveness=(False, False)), check_range.AllInclusiveRange()) for n in ['A7', 'A8'] }, [ control_types.kFlightModeCrosswindNormal, control_types.kFlightModeCrosswindPrepTransOut ])
def __init__(self, mode, **widget_kwargs): nodes = ['E1', 'E2'] super(ElePosChart, self).__init__(mode, 'Ele Pos [°]', nodes, show_cmd=True, **widget_kwargs) limits = flap_limits.FlapsToServos( flap_limits.GetControlCrosswindLimits())['E1'] limits = numpy.rad2deg(limits).tolist() self._SetLimits( { self._ObservationLabel(n): (check_range.Interval(limits, inclusiveness=(False, False)), check_range.AllInclusiveRange()) for n in nodes }, [ control_types.kFlightModeCrosswindNormal, control_types.kFlightModeCrosswindPrepTransOut ])
def CheckForFailure(values, target_ranges, error_if_fail, error_name=None, min_gap=1000): """Checking values against normal ranges. Args: values: Values of the field. target_ranges: A BaseRange object in which values are regarded as normal. It can also be a list of basic objects that create BaseRange objects. Please refer to check_range.RangeChecker for details. error_if_fail: True if failed values raise errors, otherwise they raise warnings. error_name: Name of the error/warning. min_gap: Merge selected regions into one section if their distance is less than min_gap. Returns: Check results in the form of { warning_name: { 'total': ..., # Total number of samples. 'count': ..., # Number of samples in this range. 'range': [min_value, max_value], }, error_name: {...} } """ if error_if_fail: error_name = DEFAULT_ERROR_NAME if not error_name else error_name return CheckByRange(values, target_ranges, check_range.AllExclusiveRange(), DEFAULT_WARNING_NAME, error_name, min_gap) else: error_name = DEFAULT_WARNING_NAME if not error_name else error_name return CheckByRange(values, target_ranges, check_range.AllInclusiveRange(), error_name, DEFAULT_ERROR_NAME, min_gap)
def __init__(self, for_log, source): normal_ranges = check_range.Interval((None, 3)) warning_ranges = check_range.AllInclusiveRange() super(NovAtelDiffCheck, self).__init__(for_log, source, normal_ranges, warning_ranges)