예제 #1
0
 def test_sanitize_line(self):
     """
     Tests a function which fixes common new-line signifiers in TAF reports
     """
     for line in ("1 BEC 1", "1 BE CMG1", "1 BEMG 1"):
         self.assertEqual(_core.sanitize_line(line), "1 BECMG 1")
     for line in ("1 TEMP0 1", "1 TEMP 1", "1 TEMO1", "1 T EMPO1"):
         self.assertEqual(_core.sanitize_line(line), "1 TEMPO 1")
     self.assertEqual(_core.sanitize_line("1 2 3 4 5"), "1 2 3 4 5")
예제 #2
0
 def test_sanitize_line(self):
     """
     Tests a function which fixes common new-line signifiers in TAF reports
     """
     for line in ('1 BEC 1', '1 BE CMG1', '1 BEMG 1'):
         self.assertEqual(_core.sanitize_line(line), '1 BECMG 1')
     for line in ('1 TEMP0 1', '1 TEMP 1', '1 TEMO1', '1 T EMPO1'):
         self.assertEqual(_core.sanitize_line(line), '1 TEMPO 1')
     self.assertEqual(_core.sanitize_line('1 2 3 4 5'), '1 2 3 4 5')
예제 #3
0
def parse_lines(lines: [str], units: Units, use_na: bool = True) -> [dict]:
    """
    Returns a list of parsed line dictionaries
    """
    parsed_lines = []
    prob = ""
    while lines:
        raw_line = lines[0].strip()
        line = _core.sanitize_line(raw_line)
        # Remove prob from the beginning of a line
        if line.startswith("PROB"):
            # Add standalone prob to next line
            if len(line) == 6:
                prob = line
                line = ""
            # Add to current line
            elif len(line) > 6:
                prob = line[:6]
                line = line[6:].strip()
        if line:
            parsed_line = (parse_na_line if use_na else parse_in_line)(line,
                                                                       units)
            for key in ("start_time", "end_time"):
                parsed_line[key] = _core.make_timestamp(parsed_line[key])
            parsed_line["probability"] = _core.make_number(prob[4:])
            parsed_line["raw"] = raw_line
            if prob:
                parsed_line[
                    "sanitized"] = prob + " " + parsed_line["sanitized"]
            prob = ""
            parsed_lines.append(parsed_line)
        lines.pop(0)
    return parsed_lines