def test_wildcard_match(self):
     params = ['ILS Localizer', 
               'ILS Localizer (R)',
               'ILS Localizer (L)',
               'ILS Localizer (L) (Capt)',
               'Rate of Climb', 
               'Altitude STD',
               'Brake (R) Pressure Ourboard', 
               'Brake (L) Pressure Inboard', 
               'ILS Localizer Deviation Warning',
               'ILS Localizer Test Tube Inhibit', 
               'ILS Localizer Beam Anomaly',
               'ILS Localizer Engaged']
     # exact match
     res = wildcard_match('ILS Localizer', params)
     self.assertEqual(res, ['ILS Localizer'])
     ### wildcard
     ##res = wildcard_match('ILS Localizer', params)
     ##self.assertEqual(res, [
         ##'ILS Localizer', 'ILS Localizer (L)', 
         ##'ILS Localizer (L) (Capt)', 'ILS Localizer (R)', 
         ##'ILS Localizer Beam Anomaly',  'ILS Localizer Deviation Warning',
         ##'ILS Localizer Engaged', 'ILS Localizer Test Tube Inhibit'])
     # test single char match
     res = wildcard_match('ILS Localizer (*)', params)
     expected_output_star = ['ILS Localizer (L)', 'ILS Localizer (R)']
    def test_wildcard_match_multiple_chars(self):
        params = ['Spoiler (%d)' % n for n in range(1, 13)]
        res = wildcard_match('Spoiler (*)', params)
        self.assertEqual(len(res), 12)

        # ensure without (n) is found
        params.append('Spoiler')
        res = wildcard_match('Spoiler (*)', params)
        self.assertEqual(len(res), 13)
Esempio n. 3
0
 def test_wildcard_match_multiple_chars(self):
     params = ['Spoiler (%d)' % n for n in range(1,13)]
     res = wildcard_match('Spoiler (*)', params)
     self.assertEqual(len(res), 12)
     
     # ensure without (n) is found
     params.append('Spoiler')
     res = wildcard_match('Spoiler (*)', params)
     self.assertEqual(len(res), 13)
Esempio n. 4
0
    def search(self, pattern, lfl_keys_only=False):
        '''
        Searches for param names that matches with (*) or (?) expression. If
        found, the pattern is converted to a regex and matched against the
        param names in the hdf file. If a match is found, the param is added
        as a key in a list and returned.

        If a match with the regular expression is not found, then a list of
        params are returned that contains the substring 'pattern'.

        :param pattern: Pattern to search for (case insensitve).
        :type pattern: string
        :param lfl_keys_only: Search only within LFL keys
        :type lfl_keys_only: boolean
        :returns: list of sorted keys(params)
        :rtype: list
        '''
        if lfl_keys_only:
            keys = self.lfl_keys()
        else:
            keys = self.keys()
        if '(*)' in pattern or '(?)' in pattern:
            return wildcard_match(pattern, keys)
        else:
            PATTERN = pattern.upper()
            return sorted(
                filter(lambda k: PATTERN in k.upper(), keys))
Esempio n. 5
0
    def search(self, pattern, lfl_keys_only=False):
        '''
        Searches for param names that matches with (*) or (?) expression. If
        found, the pattern is converted to a regex and matched against the
        param names in the hdf file. If a match is found, the param is added
        as a key in a list and returned.

        If a match with the regular expression is not found, then a list of
        params are returned that contains the substring 'pattern'.

        :param pattern: Pattern to search for (case insensitve).
        :type pattern: string
        :param lfl_keys_only: Search only within LFL keys
        :type lfl_keys_only: boolean
        :returns: list of sorted keys(params)
        :rtype: list
        '''
        if lfl_keys_only:
            keys = self.lfl_keys()
        else:
            keys = self.keys()
        if '(*)' in pattern or '(?)' in pattern:
            return wildcard_match(pattern, keys)
        else:
            PATTERN = pattern.upper()
            return sorted(
                filter(lambda k: PATTERN in k.upper(), keys))
Esempio n. 6
0
def get_parameter_correction(parameter_name):

    if parameter_name in PARAMETER_CORRECTIONS:
        return PARAMETER_CORRECTIONS[parameter_name]

    for pattern, mapping in PARAMETER_CORRECTIONS.items():
        if wildcard_match(pattern, [parameter_name]):
            return mapping
Esempio n. 7
0
def get_parameter_correction(parameter_name):

    if parameter_name in PARAMETER_CORRECTIONS:
        return PARAMETER_CORRECTIONS[parameter_name]

    for pattern, mapping in PARAMETER_CORRECTIONS.items():
        if wildcard_match(pattern, [parameter_name]):
            return mapping
Esempio n. 8
0
 def test_wildcard_match(self):
     params = [
         'Altitude STD',
         'Brake (L) Pressure Inboard', 
         'Brake (R) Pressure Ourboard', 
         'ILS Localizer (L) (1)',
         'ILS Localizer (L) (2)',
         'ILS Localizer (L) (Capt)',
         'ILS Localizer (L)',
         'ILS Localizer (R) (1)',
         'ILS Localizer (R)',
         'ILS Localizer Beam Anomaly',
         'ILS Localizer Deviation Warning',
         'ILS Localizer Engaged',
         'ILS Localizer Test Tube Inhibit', 
         'ILS Localizer', 
         'Rate of Climb', 
     ]
     # exact match
     self.assertEqual(wildcard_match('ILS Localizer', params),
                      ['ILS Localizer'])
     # test single char match
     self.assertEqual(wildcard_match('ILS Localizer (*)', params),
                      ['ILS Localizer',
                       'ILS Localizer (L)',
                       'ILS Localizer (R)'])
     # test two wildcards
     self.assertEqual(wildcard_match('ILS Localizer (*) (1)', params),
                      ['ILS Localizer (L) (1)',
                       'ILS Localizer (R) (1)'])
     self.assertEqual(wildcard_match('ILS Localizer (*) (*)', params),
                      ['ILS Localizer',
                       'ILS Localizer (L)',
                       'ILS Localizer (L) (1)',
                       'ILS Localizer (L) (2)',
                       'ILS Localizer (L) (Capt)',
                       'ILS Localizer (R)',
                       'ILS Localizer (R) (1)'])
     
     self.assertEqual(wildcard_match('ILS Localizer (L) (*)', params),
                      ['ILS Localizer (L)',
                       'ILS Localizer (L) (1)',
                       'ILS Localizer (L) (2)',
                       'ILS Localizer (L) (Capt)'])
    def test_wildcard_match_without_brackets(self):
        params = [
            'ILS Frequency',
            'ILS (1) Frequency',
            'ILS (2) Frequency',
            'ILS (Capt) Frequency',
            'ILS (R) Frequency',
            'ILS (L) (Capt) Frequency',
        ]

        res = wildcard_match('ILS (*) Frequency', params)
        self.assertIn('ILS Frequency', res)
        self.assertNotIn('ILS (L) (Capt) Frequency', res)
        self.assertEqual(set(res), set(params[0:5]))
Esempio n. 10
0
 def test_wildcard_match_without_brackets(self):
     params = [
         'ILS Frequency',
         'ILS (1) Frequency',
         'ILS (2) Frequency',
         'ILS (Capt) Frequency',
         'ILS (R) Frequency',
         'ILS (L) (Capt) Frequency',
     ]
     
     res = wildcard_match('ILS (*) Frequency', params)
     self.assertIn('ILS Frequency', res)
     self.assertNotIn('ILS (L) (Capt) Frequency', res)
     self.assertEqual(set(res), set(params[0:5]))
Esempio n. 11
0
def check_parameter_names(hdf):
    """
    Check if the parameter name is one recognised as a POLARIS parameter
    name.
    Returns two tuples.
      The first a tuple of names matching POLARIS parameters.
      The second, a tuple of names that do not match POLARIS parameters and
      will be ignored by analysis.
    """
    log_subtitle("Checking parameter names")
    hdf_parameters = set(hdf.keys())

    matched_names = set()
    for name in PARAMETER_LIST:
        if WILDCARD in name:
            found = wildcard_match(name, hdf_parameters, remove=' ')
        else:
            found = [name for p in hdf_parameters if p == name]
        if found:
            matched_names.update(found)

    unmatched_names = hdf_parameters - matched_names
    if not matched_names:
        LOGGER.error("None of the %d parameters within HDF file are "
                     "recognised by POLARIS",
                     len(unmatched_names))
    elif unmatched_names:
        LOGGER.info("Number of parameter names recognised by POLARIS: %s",
                    len(matched_names))
        LOGGER.warn("Number of parameters names not recognised by "
                    "POLARIS: %s", len(unmatched_names))
        LOGGER.debug("The following parameters names are recognised by "
                     "POLARIS: %s", matched_names)
        LOGGER.debug("The following parameters names are not recognised by "
                     "POLARIS: %s", unmatched_names)
    else:
        LOGGER.info("All %s parameters names are recognised by POLARIS.",
                    len(matched_names))
    return (tuple(matched_names), tuple(unmatched_names))
Esempio n. 12
0
def check_parameter_names(hdf):
    """
    Check if the parameter name is one recognised as a POLARIS parameter
    name.
    Returns two tuples.
      The first a tuple of names matching POLARIS parameters.
      The second, a tuple of names that do not match POLARIS parameters and
      will be ignored by analysis.
    """
    log_subtitle("Checking parameter names")
    hdf_parameters = set(hdf.keys())

    matched_names = set()
    for name in PARAMETER_LIST:
        if WILDCARD in name:
            found = wildcard_match(name, hdf_parameters, remove=' ')
        else:
            found = [name for p in hdf_parameters if p == name]
        if found:
            matched_names.update(found)

    unmatched_names = hdf_parameters - matched_names
    if not matched_names:
        LOGGER.error("None of the %d parameters within HDF file are "
                     "recognised by POLARIS",
                     len(unmatched_names))
    elif unmatched_names:
        LOGGER.info("Number of parameter names recognised by POLARIS: %s",
                    len(matched_names))
        LOGGER.warn("Number of parameters names not recognised by "
                    "POLARIS: %s", len(unmatched_names))
        LOGGER.debug("The following parameters names are recognised by "
                     "POLARIS: %s", matched_names)
        LOGGER.debug("The following parameters names are not recognised by "
                     "POLARIS: %s", unmatched_names)
    else:
        LOGGER.info("All %s parameters names are recognised by POLARIS.",
                    len(matched_names))
    return (tuple(matched_names), tuple(unmatched_names))
Esempio n. 13
0
    def test_wildcard_match(self):
        params = [
            'Altitude Selected', 'Altitude Selected (1)',
            'Altitude Selected (FMC)', 'Altitude Selected (Bad)',
            'Altitude STD', 'Brake (L) Pressure Inboard',
            'Brake (R) Pressure Ourboard', 'ILS Localizer (L) (1)',
            'ILS Localizer (L) (2)', 'ILS Localizer (L) (Capt)',
            'ILS Localizer (L)', 'ILS Localizer (R) (1)', 'ILS Localizer (R)',
            'ILS Localizer Beam Anomaly', 'ILS Localizer Deviation Warning',
            'ILS Localizer Engaged', 'ILS Localizer Test Tube Inhibit',
            'ILS Localizer', 'Rate of Climb', 'Gear Down', 'Gear (R) Down',
            'Gear (N) Down', 'Gear (L) Down'
        ]
        # exact match
        self.assertEqual(wildcard_match('ILS Localizer', params),
                         ['ILS Localizer'])
        # test single char match
        self.assertEqual(
            wildcard_match('ILS Localizer (*)', params),
            ['ILS Localizer', 'ILS Localizer (L)', 'ILS Localizer (R)'])

        self.assertEqual(
            wildcard_match('ILS Localizer (*)', params, missing=False),
            ['ILS Localizer (L)', 'ILS Localizer (R)'])
        # test two wildcards
        self.assertEqual(wildcard_match('ILS Localizer (*) (1)', params),
                         ['ILS Localizer (L) (1)', 'ILS Localizer (R) (1)'])
        self.assertEqual(wildcard_match('ILS Localizer (*) (*)', params), [
            'ILS Localizer', 'ILS Localizer (L)', 'ILS Localizer (L) (1)',
            'ILS Localizer (L) (2)', 'ILS Localizer (L) (Capt)',
            'ILS Localizer (R)', 'ILS Localizer (R) (1)'
        ])

        self.assertEqual(
            wildcard_match('ILS Localizer (*) (*)', params, missing=False), [
                'ILS Localizer (L) (1)', 'ILS Localizer (L) (2)',
                'ILS Localizer (L) (Capt)', 'ILS Localizer (R) (1)'
            ])

        self.assertEqual(wildcard_match('ILS Localizer (L) (*)', params), [
            'ILS Localizer (L)', 'ILS Localizer (L) (1)',
            'ILS Localizer (L) (2)', 'ILS Localizer (L) (Capt)'
        ])

        self.assertEqual(
            wildcard_match('ILS Localizer (L) (*)', params, missing=False), [
                'ILS Localizer (L) (1)', 'ILS Localizer (L) (2)',
                'ILS Localizer (L) (Capt)'
            ])

        self.assertEqual(
            wildcard_match('Gear (*) Down', params),
            ['Gear (L) Down', 'Gear (N) Down', 'Gear (R) Down', 'Gear Down'])

        self.assertEqual(
            wildcard_match('Gear (*) Down', params, missing=False),
            ['Gear (L) Down', 'Gear (N) Down', 'Gear (R) Down'])

        self.assertEqual(wildcard_match('Altitude (*) Selected (*)', params), [
            'Altitude Selected', 'Altitude Selected (1)',
            'Altitude Selected (FMC)'
        ])
Esempio n. 14
0
def validate_values_mapping(hdf, parameter, states=False):
    """
    Check if the parameter attribute values_mapping exists (It is required for
    discrete or multi-state parameter) and reports the value.
    """
    LOGGER.info("Checking parameter attribute: values_mapping")
    if parameter.values_mapping is None:
        if parameter.data_type in ('Discrete', 'Multi-state',
                                   'Enumerated Discrete'):
            LOGGER.error("'values_mapping': No attribute for '%s'. "
                         "Attribute is Required for a %s parameter.",
                         parameter.name, parameter.data_type)
        else:
            LOGGER.info("'values_mapping': No attribute. Not required "
                        "for '%s'.", parameter.name)
    else:
        LOGGER.info("'values_mapping': Attribute value is: %s",
                    parameter.values_mapping)
        try:
            # validate JSON string
            jstr = json.loads(
                hdf.hdf['/series/' + parameter.name].attrs['values_mapping']
            )
            LOGGER.info("'values_mapping': Attribute is a valid json "
                        "string: %s", jstr)
        except ValueError as err:
            LOGGER.error("'values_mapping': Attribute is not a valid JSON "
                         "string. (%s)", err)
        if parameter.data_type == 'Discrete':
            try:
                value0 = parameter.values_mapping[0]  # False values
                LOGGER.debug("'values_mapping': Discrete value 0 maps to "
                             "'%s'.", value0)
            except KeyError:
                LOGGER.debug("'values_mapping': Discrete value 0 has no "
                             "mapping.")
            try:
                value1 = parameter.values_mapping[1]  # True values
                if value1 in ["", "-"]:
                    LOGGER.error("'values_mapping': Discrete value 1 should "
                                 "not map to '-' or an empty string. Value "
                                 "1 maps to '%s'.", value1)
                else:
                    LOGGER.debug("'values_mapping': Discrete value 1 maps "
                                 "to '%s'", value1)
            except KeyError:
                LOGGER.error("'values_mapping': Discrete value 1 has no "
                             "mapping. Needs to have a mapping for this "
                             "value.")
            if len(parameter.values_mapping.keys()) > 2:
                LOGGER.error("'values_mapping': '%s' is a discrete parameter, "
                             "but the values_mapping attribute has %s values. "
                             "There should be no more than 2.",
                             parameter.name,
                             len(parameter.data_type.keys()))

    LOGGER.info("Checking parameter states and checking the validity: states")
    if states:
        if not '(' in parameter.name or not ')' in parameter.name:
            states = PARAMETER_CORRECTIONS.get(parameter.name)
            if states and {k: v for k, v in parameter.values_mapping.items() if v != '-'} != states:
                LOGGER.error("'values_mapping': '%s' does not contain valid states %s, "
                             "the states should be %s.",
                             parameter.name, parameter.values_mapping, states) 
        else:
            for pattern, states in PARAMETER_CORRECTIONS.items():
                found_matches = wildcard_match(pattern, [parameter.name])
                if found_matches is not None and len(found_matches) > 0:
                    for parameter_name in found_matches:
                        if {k: v for k, v in parameter.values_mapping.items() if v != '-'} != states:
                            LOGGER.error("'values_mapping': '%s' does not contain valid states %s, "
                                         "the states should be %s.",
                                         parameter.name, parameter.values_mapping, states)
                            break
                        else:
                            continue
                    break
 def test_wildcard_match(self):
     params = [
         'Altitude Selected',
         'Altitude Selected (1)',
         'Altitude Selected (FMC)',
         'Altitude Selected (Bad)',
         'Altitude STD',
         'Brake (L) Pressure Inboard', 
         'Brake (R) Pressure Ourboard', 
         'ILS Localizer (L) (1)',
         'ILS Localizer (L) (2)',
         'ILS Localizer (L) (Capt)',
         'ILS Localizer (L)',
         'ILS Localizer (R) (1)',
         'ILS Localizer (R)',
         'ILS Localizer Beam Anomaly',
         'ILS Localizer Deviation Warning',
         'ILS Localizer Engaged',
         'ILS Localizer Test Tube Inhibit', 
         'ILS Localizer', 
         'Rate of Climb',
         'Gear Down',
         'Gear (R) Down',
         'Gear (N) Down',
         'Gear (L) Down'
     ]
     # exact match
     self.assertEqual(wildcard_match('ILS Localizer', params),
                      ['ILS Localizer'])
     # test single char match
     self.assertEqual(wildcard_match('ILS Localizer (*)', params),
                      ['ILS Localizer',
                       'ILS Localizer (L)',
                       'ILS Localizer (R)'])
     
     self.assertEqual(wildcard_match('ILS Localizer (*)', params, missing=False),
                      ['ILS Localizer (L)',
                       'ILS Localizer (R)'])
     # test two wildcards
     self.assertEqual(wildcard_match('ILS Localizer (*) (1)', params),
                      ['ILS Localizer (L) (1)',
                       'ILS Localizer (R) (1)'])
     self.assertEqual(wildcard_match('ILS Localizer (*) (*)', params),
                      ['ILS Localizer',
                       'ILS Localizer (L)',
                       'ILS Localizer (L) (1)',
                       'ILS Localizer (L) (2)',
                       'ILS Localizer (L) (Capt)',
                       'ILS Localizer (R)',
                       'ILS Localizer (R) (1)'])
     
     self.assertEqual(wildcard_match('ILS Localizer (*) (*)', params,
                                     missing=False),
                      ['ILS Localizer (L) (1)',
                       'ILS Localizer (L) (2)',
                       'ILS Localizer (L) (Capt)',
                       'ILS Localizer (R) (1)'])
     
     self.assertEqual(wildcard_match('ILS Localizer (L) (*)', params),
                      ['ILS Localizer (L)',
                       'ILS Localizer (L) (1)',
                       'ILS Localizer (L) (2)',
                       'ILS Localizer (L) (Capt)'])
     
     self.assertEqual(wildcard_match('ILS Localizer (L) (*)', params,
                                     missing=False),
                      ['ILS Localizer (L) (1)',
                       'ILS Localizer (L) (2)',
                       'ILS Localizer (L) (Capt)'])
     
     self.assertEqual(wildcard_match('Gear (*) Down', params),
                     ['Gear (L) Down',
                      'Gear (N) Down',
                      'Gear (R) Down',
                      'Gear Down'])
     
     self.assertEqual(wildcard_match('Gear (*) Down', params, missing=False),
                     ['Gear (L) Down',
                      'Gear (N) Down',
                      'Gear (R) Down'])
     
     self.assertEqual(wildcard_match('Altitude (*) Selected (*)', params),
                      ['Altitude Selected',
                       'Altitude Selected (1)',
                       'Altitude Selected (FMC)'])