Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Relaxing the compulsory seat order #7

Open
timonoortman-aas opened this issue Feb 9, 2021 · 0 comments · May be fixed by #10
Open

Relaxing the compulsory seat order #7

timonoortman-aas opened this issue Feb 9, 2021 · 0 comments · May be fixed by #10

Comments

@timonoortman-aas
Copy link

Currently the algorithm follows a compulsory order in which the seat configuration should be specified "seat designator should be in fixed order according to standard" However, sometimes SSIM files are received that do not stick to this fixed order. So e.g. J50O24Y202VV10 instead of J50Y202O24VV10. As a result, only part of the aircraft_configuration_string in _explode_aircraft_configuration_string() is being read.
image

I would recommend to focus on the aircraft_configuration_string instead of the fixed order in seat_class_designators. So replacing

    string_remainder = aircraft_configuration_string.rstrip()

    seat_class_designators = [
        "P",
        "F",
        "A",
        "J",
        "C",
        "D",
        "I",
        "Z",
        "W",
        "S",
        "Y",
        "B",
        "H",
        "K",
        "L",
        "M",
        "N",
        "Q",
        "T",
        "V",
        "X",
        "G",
        "U",
        "E",
        "O",
        "R",
    ]

    cargo_designators = ["LL", "PP"]  # unit load devices (containers)  # pallets

    integer_designators = {"seats": seat_class_designators, "cargo": cargo_designators}

    acv_info = {}

    # seat designator should be in fixed order according to standard
    for designator_type, designators in integer_designators.items():
        for designator in designators:
            if string_remainder.startswith(designator) and (  # only continue if string starts with designator and...
                len(designator) > 1
                or not (  # either have a multi length designator
                    (len(string_remainder) > 1 and string_remainder[1] == string_remainder[0])
                    or string_remainder.startswith("V V")
                )
            ):  #

                acv_info_key = designator_type + "_" + designator

                # for next iteration, remove designator from beginning of string
                string_remainder = string_remainder[len(designator):]

                # standard specifies that there may be an int following. If not return empty string (to later on destinguish from NaN if data gets put in a data frame)
                acv_info_val = ""
                acv_regex = re.search(r"^\d*", string_remainder).group()

                # if int found, add it to total and remove it from string to process as well
                if acv_regex:
                    acv_info_val = int(acv_regex)
                    if designator_type == "seats":
                        if designator_type in acv_info.keys():
                            acv_info[designator_type] += acv_info_val
                        else:
                            acv_info[designator_type] = acv_info_val

                    string_remainder = string_remainder[len(acv_regex):]

                # store found information
                acv_info[acv_info_key] = acv_info_val

    # remainer are general designators
    if string_remainder.startswith("BB"):
        acv_info["BB"] = ""

    # aircraft type
    if string_remainder.startswith("VV"):
        acv_info["VV"] = string_remainder[2:]
    elif string_remainder.startswith("V V"):  # aircraft type alt. Assuming it won't appear together with VV.
        acv_info["V V"] = string_remainder[3:]
    elif len(string_remainder.strip()):
        log_text = (
            "After trying to process aircraft configuration string, there should be no remainder. However, the following string remains in this instance: (%s)"
            % string_remainder
        )
        if raw_line:
            log_text += "\n Raw slot line: " + raw_line
        logging.warning(log_text)

by e.g.

    string_remainder = aircraft_configuration_string.rstrip().replace(' ', '')

    seat_class_designators = [
        "P",
        "F",
        "A",
        "J",
        "C",
        "D",
        "I",
        "Z",
        "W",
        "S",
        "Y",
        "B",
        "H",
        "K",
        "L",
        "M",
        "N",
        "Q",
        "T",
        "V",
        "X",
        "G",
        "U",
        "E",
        "O",
        "R",
    ]

    # unit load devices (containers), number of pallets
    cargo_designators = [
        "LL", 
        "PP"
    ]  

    # general designators
    general_designators = [
        "VV", 
        "BB"
    ]  

    allowed_designators = {
        **{x: "seats" for x in seat_class_designators},
        **{y: "cargo" for y in cargo_designators},
        **{z: "general" for z in general_designators}
    }

    acv_info = {}

    included_designators = re.findall(r'(\w+?)(\d+)', string_remainder)
    for designator_pair in included_designators:
        assert len(designator_pair) == 2, \
            "designator_pair does not contain type and number information"

        designator = designator_pair[0]
        acv_info_val = int(designator_pair[1])
        
        if designator in allowed_designators.keys():
            acv_info_type = allowed_designators[designator]
        else:
            log_text = (
                "Designator (%s) is not recognised as valid type. Please check schedule"
                % designator
            )
            if raw_line:
                log_text += "\n Raw slot line: " + raw_line
            logging.warning(log_text)
            acv_info_type = "unknown"
        acv_info_key = acv_info_type + "_" + designator            

        if acv_info_type == "seats":
            if acv_info_type in acv_info.keys():
                acv_info[acv_info_type] += acv_info_val
            else:
                acv_info[acv_info_type] = acv_info_val

        # store found information
        acv_info[acv_info_key] = acv_info_val
@timonoortman-aas timonoortman-aas linked a pull request Feb 25, 2021 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants