Example #1
0
    def __update_state_of_entity(entity, state_of_voyage):

        voyage_states = State.get_voyage_states()
        entity_states = State.get_employee_states()

        state_index = voyage_states.index(state_of_voyage)
        if entity:
            entity.set_state(entity_states[(state_index + 1) % 5])
Example #2
0
    def __update_state_of_voyage(voyage, current_date_and_time):

        flights = voyage.get_flights()

        flight1_departure_time = flights[0].get_departure_time()
        flight1_arrival_time = flights[0].get_arrival_time()

        flight2_departure_time = flights[1].get_departure_time()
        flight2_arrival_time = flights[1].get_arrival_time()

        #state_of_voyage = voyage.get_state()

        voyage_states = State.get_voyage_states()

        
        if flight2_arrival_time <= current_date_and_time:
            voyage.set_state(voyage_states[4])

        elif flight2_departure_time <= current_date_and_time:
            voyage.set_state(voyage_states[3])

        elif flight1_arrival_time <= current_date_and_time:
            voyage.set_state(voyage_states[2])
        
        elif flight1_departure_time <= current_date_and_time:
            voyage.set_state(voyage_states[1])

        else:
            voyage.set_state(voyage_states[0])    
Example #3
0
    def get_employees_off_duty():
        all_employees = DataAPI.get_all_employees()
        not_scheduled_state = State.get_employee_states()[0]
        employees_off_duty = []
        for employee in all_employees:
            if employee.get_state() == not_scheduled_state:
                employees_off_duty.append(employee)

        return EmployeeLogic.__sort_list_by_name(employees_off_duty)
Example #4
0
    def get_completed_voyages():  #needs testing
        all_voyages = DataAPI.get_all_voyages()
        completed_voyages = []
        completed_state = State.get_voyage_states()[4]

        for voyage in all_voyages:
            if voyage.get_state() == completed_state:
                completed_voyages.append(voyage)

        return completed_voyages
Example #5
0
    def get_ongoing_voyages():  #needs testing
        all_voyages = DataAPI.get_all_voyages()
        ongoing_voyages = []
        completed_state = State.get_voyage_states()[4]

        for voyage in all_voyages:
            if voyage.get_state() != completed_state:
                ongoing_voyages.append(voyage)

        return ongoing_voyages
    def __show_new_airplane_constructor():
               
        option_tuple = ("Name", "Type", "Manufacturer", "Seating capacity")

        valid_user_inputs = ComponentUI.make_valid_menu_options_tuple(len(option_tuple))

        input_message_tuple = ("Insert Name: ", "Insert Type: ", "Insert Manufacturer: ", "Insert Seating capacity: ")

        user_input_list = [""] * len(option_tuple)
        user_input_list.append(State.get_airplane_states()[0]) #State default value
        valid_for_submit_list = [False, False] # only 2 chosse here * len(option_tuple) #list that contains bools if all true then ok to submit


        user_input = ""



        while user_input not in AirplanesUI.__NAVIGATION_BAR_OPTIONS:

            ComponentUI.print_frame_constructor_menu(option_tuple, ComponentUI.get_main_options()[2],\
                 "New airplane", user_input_list, True, 1000, [2,3], True)

            user_input = ComponentUI.get_user_input()

            if not user_input:
                continue

            user_input = ComponentUI.remove_brackets(user_input)

            if user_input in valid_user_inputs:
                index = int(user_input) - 1


                if index == 0:
                    ComponentUI.print_frame_constructor_menu(option_tuple, ComponentUI.get_main_options()[2],\
                     "New airplane", user_input_list, False, index)
                    user_input = input(input_message_tuple[index]).strip()
                elif index == 1:

                    #### PICK AIRPLANE TYPE BY TABLE LIST ###
                    table_header_tuple = ("Type", "Manufacturer", "Seats")
                 
                    airplane_type_list = LogicAPI.get_all_airplane_types()
                    airplanes_type_getfunctions_tuple = ([aircraft_type.get_plane_type() for aircraft_type in airplane_type_list],[aircraft_type.get_manufacturer() for aircraft_type in airplane_type_list],\
                        [aircraft_type.get_seat_count() for aircraft_type in airplane_type_list])
                    table_height = len(airplane_type_list)


                    ComponentUI.print_frame_table_menu(table_header_tuple, airplanes_type_getfunctions_tuple, table_height,\
                        ComponentUI.get_main_options()[2], "New airplane")

                    user_input = ComponentUI.get_user_input("Insert number of desired type: ")

                    user_input = ComponentUI.remove_brackets(user_input)
                    if not user_input.isdigit() or int(user_input) > table_height or not user_input:
                        continue

                    table_index = int(user_input) - 1
                    chosen_table_line = airplane_type_list[table_index]
                    ###                LINE PICKED           ##


                    user_input_list[1] = chosen_table_line.get_plane_type()
                    user_input_list[2] = chosen_table_line.get_manufacturer()
                    user_input_list[3] = chosen_table_line.get_seat_count()
                    valid_for_submit_list[1] = True

                #Check if airplane name already exists
                if index == 0: 
                    user_input = user_input.capitalize()
                    if not LogicAPI.is_airplane_name_available(user_input):
                        user_input = user_input + " " + TextEditor.color_text_background("Airplane name already exists, another input is required", TextEditor.RED_BACKGROUND)
                        valid_for_submit_list[0] = False
                    else:
                        valid_for_submit_list[0] = True

                if index == 0:
                    user_input_list[index] = user_input
                
                user_input = ""

            elif user_input.startswith('s'):
                if all(valid_for_submit_list):

                    new_airplane = Airplane(
                        user_input_list[0],
                        user_input_list[1],
                        user_input_list[2],
                        user_input_list[3],
                        user_input_list[4]
                    )
                    LogicAPI.save_new_airplane(new_airplane)
                    user_input = "A new airplane has been registered"

                    break

        return user_input
Example #7
0
    def __show_new_employee_constructor():
        input_message_tuple = ("Insert job title(" + TextEditor.format_text('f', TextEditor.BOLD_TEXT) + " for flight attendant, "\
            + TextEditor.format_text('p', TextEditor.BOLD_TEXT)+ " for pilot): ", "Insert Name: ", "Insert Social security number: ",\
            "Insert Phone number: ", "Insert Home address: ", "Insert E-mail: ", "Insert License: ")
        user_input = ""
        option_tuple = ("Job title", "Name", "Social security number",
                        "Phone number", "Home address", "E-mail", "License")
        user_input_list = [""] * len(option_tuple)
        valid_user_inputs = ComponentUI.make_valid_menu_options_tuple(
            len(option_tuple))
        valid_user_inputs_bool_list = [True] * len(option_tuple)
        while user_input not in EmployeeUI.__NAVIGATION_BAR_OPTIONS:

            greyed_out_option_index_list = [
                6
            ] if not user_input_list[0].lower().startswith('p') else []

            ComponentUI.print_frame_constructor_menu(option_tuple, EmployeeUI.__FRAME_IN_USE_STR, "New employeee",\
            user_input_list, True, greyed_out_option_index_list=greyed_out_option_index_list)
            user_input = ComponentUI.get_user_input()

            if not user_input:
                continue

            user_input = ComponentUI.remove_brackets(user_input)

            if user_input in valid_user_inputs:

                index = int(user_input) - 1

                #Don't allow the user to enter a license if the employee ain't a pilot
                if index == 6:
                    if not user_input_list[0].lower().startswith('p'):
                        continue


                ComponentUI.print_frame_constructor_menu(option_tuple, EmployeeUI.__FRAME_IN_USE_STR, "New employeee",\
                user_input_list, False, index)

                if index == 6:
                    #display table of airplane types and return the type-name the of chosen one , head above the the table
                    user_input = EmployeeUI.__airplane_type_picker(
                        "New employeee")
                else:
                    user_input = input(input_message_tuple[index]).strip()

                if not user_input:
                    continue

                user_input = EmployeeUI.__constructor_error_check(user_input,\
                     valid_user_inputs_bool_list, index, user_input_list)

            elif user_input.startswith('s'):
                job_title_str = user_input_list[0].lower()

                if all(user_input_list) and job_title_str.startswith(
                        'p') and all(valid_user_inputs_bool_list):

                    pilot = Pilot(user_input_list[1], user_input_list[2],
                                  user_input_list[3], user_input_list[4],
                                  user_input_list[5],
                                  State.get_employee_states()[0],
                                  user_input_list[6])
                    LogicAPI.save_new_pilot(pilot)

                    user_input = "A new pilot has been registered"

                    break

                elif all(user_input_list[:-1]) and job_title_str.startswith(
                        'f') and all(valid_user_inputs_bool_list[:-1]):

                    flight_attendant = FlightAttendant(
                        user_input_list[1], user_input_list[2],
                        user_input_list[3], user_input_list[4],
                        user_input_list[5], "Not scheduled for flight today")
                    LogicAPI.save_new_flight_attendant(flight_attendant)

                    user_input = "A new flight attendant has been registered"

                    break

        return user_input