Exemplo n.º 1
0
 def __init__(self):
     self.LLAPI = LLAPI()
     self.header = "{:^8}|{:^15}|{:^25}|{:^12}|{:^20}|{:^14}|{:^9}|{:^21}|{:^21}|{:^21}|{:^21}".format(
         "VoyageID", "DestinationID", "Departure Time", "Aircraft ID",
         "Head flight attendant", "Captain SSN", "IsStaffed",
         "Outgoing seats sold", "Outgoing Flight ID", "Incoming seats sold",
         "Incoming flight ID")
Exemplo n.º 2
0
 def __init__(self):
     try:
         self.LLAPI = LLAPI()
         self.header = "{:20}{:25}{:25}{:25}{:35}{:25}{:25}".format("Destination ID", "Country", "Airport",
         "Flight Duration", "Distance From Reykjavik", "Contact Name", "Contact Number")
     except:
         print("Unexpected error has occured, returning to home screen")
         return
Exemplo n.º 3
0
class CrewUI():
    def __init__(self):
        self.LLAPI = LLAPI()

    def printAllCrewmembers(self):
        crewList = self.LLAPI.getAllCrewmembers()
        printList = list()

        for c in crewList:
            printList.append([c.get_ssn(), c.get_name(), c.get_phoneNumber()])

        print(tabulate(printList, headers=['SSN', 'name', 'phonenumber']))

    def printCrewmember(self, ssn):
        crewmember = self.LLAPI.getCrewmemberBySSN(ssn)
        print(crewmember)

    def printAllPilots(self):
        pilotList = self.LLAPI.getAllPilots()
        printList = list()

        for pilot in pilotList:
            printList.append(
                [pilot.get_ssn(),
                 pilot.get_name(),
                 pilot.get_phoneNumber()])

        print(tabulate(printList, headers=['SSN', 'name', 'phonenumber']))

    def printAllFlightServants(self):
        faList = self.LLAPI.getAllFlightServants()
        printList = list()

        for fa in faList:
            printList.append(
                [fa.get_ssn(),
                 fa.get_name(),
                 fa.get_phoneNumber()])

        print(tabulate(printList, headers=['SSN', 'name', 'phonenumber']))

    def addPilot(self, name, ssn, address, phoneNR, email, rank, licence):
        role = "Pilot"
        pilot = Crew(ssn, name, role, rank, licence, address, phoneNR, email)
        self.LLAPI.storeCrewmember(pilot)

    def addFlightServant(self, name, ssn, address, phoneNR, email, rank):
        role = "Cabincrew"
        licence = "N/A"

        if rank == "Manager":
            rank = "Flight Service Manager"
        elif rank == "Attendant":
            rank = "Flight Attendant"

        servant = Crew(ssn, name, role, rank, licence, address, phoneNR, email)

        self.LLAPI.storeCrewmember(servant)
Exemplo n.º 4
0
class AircraftUI:
    def __init__(self):
        self.LLAPI = LLAPI()

    def printAllAircrafts(self):
        aircraftList = self.LLAPI.getAllAircrafts()
        printList = list()

        for aircraft in aircraftList:
            aircraftType = self.LLAPI.getAircraftTypeByPlaneType(
                aircraft.get_planeType())
            printList.append([
                aircraft.get_planeInsignia(),
                aircraftType.get_manufacturer() + ' ' +
                aircraftType.get_model()
            ])

        print(tabulate(printList, headers=['Plane Insignia', 'Plane Type']))

    def addAircraft(self, manufacturer, model, capacity, insignia):
        planeType = 'NA' + re.sub(r"\s+", "", manufacturer) + re.sub(
            r"\s+", "", model)
        aircraftType = AircraftType(planeType, manufacturer, model, capacity)
        aircraft = Aircraft(insignia, planeType)
        self.LLAPI.storeAircraftType(aircraftType)
        self.LLAPI.storeAircraft(aircraft)
Exemplo n.º 5
0
    def register_destination(self):
        try:
            print("\n\tRegister a new destination")
            destination_country = input('Country: ')
            airport_str = input('Airport: ')
            flight_duration = input('Flight duration: ')
            distanceFromReykjavik = input('Distance from Reykjavík: ')
            contactName_str = input('Contact name: ')
            contactNr_str = input('Contact number: ')

            LLAPI().RegisterDestination(destination_country, airport_str, flight_duration, distanceFromReykjavik, contactName_str, contactNr_str)
            
            return
        except:
            print("Unexpected error has occured, returning to home screen")
            return
Exemplo n.º 6
0
class DestinationUI:
    def __init__(self):
        self.LLAPI = LLAPI()

    def printAllDestinations(self):
        destinationList = self.LLAPI.getAllDestinations()
        printList = list()
        # print(DestinationList)
        for destination in destinationList:
            printList.append([
                destination.get_destinationID(),
                destination.get_destination(),
                destination.get_country(),
                destination.get_airport(),
                destination.get_contact(),
                destination.get_emergencyNR()
            ])

        print(
            tabulate(printList,
                     headers=[
                         'ID', 'Name', 'Country', 'Airport',
                         'Emergency Contact', 'Emergency Number'
                     ]))
Exemplo n.º 7
0
 def __init__(self):
     self.LLAPI = LLAPI()
     self.header = "{:40}\t{:10}\t{:20}\t{:10}\t{:35}\t{:20}\t{}".format("Name", "SSN", "Address", "Phone", "Email", "Pilot status", "Licenses")
Exemplo n.º 8
0
class EmployeeUI:
    def __init__(self):
        self.LLAPI = LLAPI()
        self.header = "{:40}\t{:10}\t{:20}\t{:10}\t{:35}\t{:20}\t{}".format("Name", "SSN", "Address", "Phone", "Email", "Pilot status", "Licenses")

# method to register a new employee
    def print_register_employee(self):
        try:
            rows_len, columns_len = os.get_terminal_size() # checks on length of terminal, this repeats.

            print("\n\tRegister a new employee")
            print("-" * (rows_len - 1))
            e_name = input("Full employee name: ")
            e_ssn = input("Employee social securtiy number: ")
            e_address = input("Employee Address: ")
            e_phone = input("Employe phone number: ")
            e_email = input("Employee email: ")
            
            e_pilot = input("Is employee a pilot? yes/no: ").lower()
            if e_pilot == "yes":
                e_pilot = True
                e_planelicense = input("Employee plane license: ")
            else:
                e_planelicense = None
                e_pilot = False
            
            error = self.LLAPI.RegisterEmployee(e_name, e_ssn, e_address, e_phone, e_email, e_pilot, e_planelicense)
            if error != 1:
                print("Error, input not valid!")
                repeat_inquiry = input("Would you like to try again? yes/no: ").lower()
                if repeat_inquiry == "yes":
                    return print_register_employee()
            print(("-" * (int((rows_len - 24) / 2))) + "New Employee Registered" + ("-" * ((int((rows_len -24) / 2)))))
            print(self.header)
            print("-" * (rows_len - 1))
            new_employee = self.LLAPI.GetEmployeeBySSN(e_ssn)
            print(new_employee)
            print("-" * (rows_len - 1))
            print("\n")
            return
        except:
            print("Unexpected error has occured, returning to home screen")
            return
    
    # Metheod to print all employees
    def print_all_employees(self):
        try:
            rows_len, columns_len = os.get_terminal_size()

            print("\n\tList all employess\n")

            print(self.header)
            all_employees = self.LLAPI.ListAllEmployees()
            for employee in all_employees:
                print("-" * (rows_len - 1))
                print(employee)
                
            print("\n")
        except:
            print("Unexpected error has occured, returning to home screen")
            return
        
    # method to print all flight attendants
    def print_flight_attendants(self):
        try:
            rows_len, columns_len = os.get_terminal_size()

            print("\n\tList all flight attendants")
            print("-" * (rows_len-1))
            print(self.header)
            flight_attendants = self.LLAPI.ListFlightAttendants()
            for attendant in flight_attendants:
                print("-" * (rows_len-1))
                print(attendant)
            print("\n")
        except:
            print("Unexpected error has occured, returning to home screen")
            return
    
    # method to print  all pilots
    def print_pilots(self):
        try:
            rows_len, columns_len = os.get_terminal_size()


            print("\n\tList all pilots")
            print("-" * (rows_len - 1))
            print(self.header)

            all_pilots = self.LLAPI.ListPilots()
            for pilot in all_pilots:
                print("-" * (rows_len - 1))
                print(pilot)
            print("\n")
        except:
            print("Unexpected error has occured, returning to home screen")
            return
    
    # method to print assigned employees
    def print_assigned_employees(self):
        try:
            rows_len, columns_len = os.get_terminal_size()

            print("\n\tList all already assigned employees on a given day")
            year = int(input("Input year: "))
            month = int(input("Input month: "))
            day = int(input("Input day: "))
            date_iso = datetime(year, month, day).isoformat()
            assinged_employees = self.LLAPI.ListAssignedEmployees(date_iso)
            if len(assinged_employees) < 1:
                print("\nThere are no employees assigned on the imputed day ")
            else:
                print(self.header)
                print("-" * (rows_len - 1))
                for employee in assinged_employees:
                    print("-" * (rows_len - 1))
                    print(employee)
            print("\n")
        except:
            print("Unexpected error has occured, returning to home screen")
            return

    # method to print unassigned employees
    def print_unassigned_employees(self):
        try:
            rows_len, columns_len = os.get_terminal_size()
            
            print("\n\tList all unassigned employees on a given day")
            year = int(input("Input year: "))
            month = int(input("Input month: "))
            day = int(input("Input day: "))
            date_iso = datetime(year, month, day).isoformat()
            unassinged_employees = self.LLAPI.ListUnassignedEmployees(date_iso)
            if len(unassinged_employees) < 1:
                print("There are no employees that are unassigned")
            else:
                print(self.header)
                print("-" * (rows_len - 1))
                for employee in unassinged_employees:
                    print("-" * (rows_len - 1))
                    print(employee)
            
            print("\n")
        except:
            print("Unexpected error has occured, returning to home screen")
            return


    # method to update infomation of an employee
    def print_update_employee_infomation(self):
        try:
            finalize = True
            rows_len, columns_len = os.get_terminal_size()
            print("\n\tUpdate employee information")
            employee_name = input("Input name of employee you want to update: ")
            employees_with_name = self.LLAPI.ListAllEmployeesWithName(employee_name)
            # If there are more employees with same name you get a list and have to select manually the ssn of the employee.
            if len(employees_with_name) > 1:
                print("More than one employee was found with that name")
                print("-" * (rows_len - 1))
                print(self.header)
                print("-" * (rows_len - 1))
                for employee in employees_with_name:
                    print(employee)
                    print("-" * (rows_len - 1))
                employee_ssn = input("Please input the ssn of employee you want to update: ")
                
                employee = self.LLAPI.GetEmployeeBySSN(employee_ssn)
                print("What would you like to change?\n")
                while finalize:
                    print("\t1. Address",
                    "\n\t2. Phone number ",
                    "\n\t3. Email",
                    "\n\t4. Pilot status",
                    "\n\t5. Plane license\n")
                    command_index = int(input("Please input a number: "))
                    if command_index == 1:
                        employee.address = input("New employee Address: ")
                    elif command_index == 2:
                        employee.phone = input("New employee phone number: ")
                    elif command_index == 3:
                        employee.email = input("New employee email address: ")
                    elif command_index == 4:
                        pilot_str = input("Is employee a Pilot? yes/no: ").lower()
                        if pilot_str == "yes":
                            employee.pilot_bool = True
                            employee.license = input("Employee plane license: ")
                        else:
                            employee.pilot_bool = False
                    elif command_index == 5:
                        employee.planeType = input("New plane license: ")
                    finalize_changes = input("Would you like to finalze your changes? yes/no: ").lower()
                    if finalize_changes == "yes":
                        finalize = False
                    else:
                        finalize = True
            # If there is only one employee with the name requested it goes straight to asking what would user want to change
            elif len(employees_with_name) == 1:
                employee = self.LLAPI.GetEmployeeBySSN(employees_with_name[0].ssn)
                print("What would you like to change?\n")
                while finalize:
                    print("\t1. Address",
                    "\n\t2. Phone number ",
                    "\n\t3. Email",
                    "\n\t4. Pilot status",
                    "\n\t5. Plane license\n")
                    command_index = int(input("Please input a number: "))
                    if command_index == 1:
                        employee.address = input("New employee Address: ")
                    elif command_index == 2:
                        employee.phone = input("New employee phone number: ")
                    elif command_index == 3:
                        employee.email = input("New employee email address: ")
                    elif command_index == 4:
                        pilot_str = input("Is employee a Pilot? yes/no: ").lower()
                        if pilot_str == "yes":
                            employee.pilot_bool = True
                            employee.license = input("Employee plane license: ")
                        else:
                            employee.pilot_bool = False
                    elif command_index == 5:
                        employee.planeType = input("New plane license: ")
                    finalize_changes = input("Would you like to finalze your changes? yes/no: ").lower()
                    if finalize_changes == "yes":
                        finalize = False
                    else:
                        finalize = True
            else:
                print("No employee with that name was found")

            self.LLAPI.UpdateEmployeeInfo(employee)

            return
        except EntryNotInDatabase:
            print("ERROR! Employee not found, please input correct ssn")
        except AttributeError:
            print("ERROR! you put in the wrong ssn! please try again")
            return
        except:
            print("Unexpected error has occured, returning to home screen")
            return


# prints all pilots with a certain aircrat priveldge
    def print_pilots_with_aircraft_privilage(self):
        try:
            rows_len, columns_len = os.get_terminal_size()

            print("\n\tList all pilots with a certain aircraft privilage")
            aircraft_model = input("Input aircraft model (case sensitive): ")
            pilot_licenses = self.LLAPI.ListPilotsWithAircraftPrivilege(aircraft_model)
            print(self.header)
            print("-" * (rows_len - 1))
            for pilot_license in pilot_licenses:
                print(pilot_license)
                print("-" * (rows_len - 1))
            print("\n")
        except:
            print("Unexpected error has occured, returning to home screen")
            return


# prints a worksummary for an employee
    def print_work_summary(self):
        rows_len, columns_len = os.get_terminal_size()

        print("\n\tGet the work summary of an employee")

        try:
            employee_name = input("Input employee name: ")
            employees_with_name = self.LLAPI.ListAllEmployeesWithName(employee_name)
            if len(employees_with_name) > 1:
                print("More than one employee has that same name")
                print("-" * (rows_len - 1))
                print(self.header)
                print("-" * (rows_len - 1))
                for employee in employees_with_name:
                    print(employee)
                    print("-" * (rows_len - 1))

                employee_ssn = input("Input the ssn of employee you requested: ")

            elif len(employees_with_name) == 1:
                employee_ssn = employees_with_name[0].ssn
            else:
                print("No employ with that name was found")
                return
            print("Please input the dates to get the work summary of", employee_name)
            year = int(input("Input year: "))
            month = int(input("Input month: "))
            day = int(input("Input day: "))
            date_iso = datetime(year, month, day).isoformat()
            work_procedures = self.LLAPI.GetWorkSummary(employees_with_name[0].ssn, date_iso)
            if len(work_procedures) > 0:
                for voy in work_procedures:
                    requested_emp = self.LLAPI.GetEmployeeBySSN(employee_ssn)
                    print("-" * (rows_len -1))
                    print("Employee", requested_emp.name, "Worked on", voy.departureTime)
                    print("Destination: ", voy.destination, "Aircraft ID: ", voy.aircraftID)
                    print("\tCaptain of Aircraft: ", voy.captain)
                    print("|Incoming flight ID: ", voy.incomingFlightID, "|Outgoing flight ID: ", voy.outgoingFlightID)
                    print("-" * (rows_len - 1))
                    
            else:
                print("\nNo work procedures were found")



        except EntryNotInDatabase:
            print("\nThere is No employee with the name " + employee_name)

        except ValueError:
            print('\nDates must be within defined ranges, months 1-12, days 1-31.\n')
        except:
            print("Unexpected error has occured, returning to home screen")
            return


# method to print infomation on a specific employee
    def print_specific_employee(self):
        try:
            employee_name = input('Input employee name: ')
            employees_with_name = self.LLAPI.ListAllEmployeesWithName(employee_name)
            print("{:30}\t{:10}\t{:20}\t{:10}\t{:25}\t{:20}\t{}".format("Name", "SSN", "Address", "Phone", "Email", "Pilot status", "Licenses"))
            emp_id = str(employees_with_name)[-11:-1]
            emp = self.LLAPI.GetEmployeeBySSN(emp_id)
            if emp.pilot_bool:
                pilot = "True"
            else:
                pilot = "False"
            print("{:30}\t{:10}\t{:20}\t{:10}\t{:25}\t{:20}\t{}".format(emp.name, emp.ssn, emp.address, emp.phone, emp.email, pilot, emp.planeType))
        except EntryNotInDatabase:
            print("\nThere is No employee with the name " + employee_name)
        except:
            print("Unexpected error has occured, returning to home screen")
            return
Exemplo n.º 9
0
 def __init__(self):
     self.LLAPI = LLAPI()
Exemplo n.º 10
0
class AircraftUI:
    def __init__(self):
        self.LLAPI = LLAPI()

# method to register a new aircraft

    def register_aircraft(self):
        try:
            manufacturer = input('Enter Aircraft Manufacturer: ')
            model = input('Enter Aircraft Model: ')
            total_seats = input('Enter Total Number of Seats: ')

            self.LLAPI.RegisterAircraft(manufacturer, model, total_seats)
        except:
            print("Unexpected error has occured, returning to home screen")
            return
        return

# method to print all aircrafts

    def print_aircrafts(self):
        try:
            print("\n##### List All Aircrafts #####\n")
            aircrafts = self.LLAPI.ListAllAircrafts()
            for aircraft in aircrafts:
                print(aircraft)
            print("\n")
        except:
            print("Unexpected error has occured, returning to home screen")
            return

# method to show status of all aircrafts

    def showAircraftStatus(self):
        print("\nAircraft Status")
        id = input("\nEnter Aircraft ID: ")
        try:
            aircraftStatus = self.LLAPI.AircraftStatus(
                id,
                datetime.now().isoformat())
            print("\nThe Aircraft is " + aircraftStatus)
        except EntryNotInDatabase:
            print(
                "The entered Aircraft ID does not correspond to an entry in the database."
            )
        except:
            print("Unexpected error has occured, returning to home screen")
            return

        print("\n")

# method to print available aircrafts

    def printAvailableAircrafts(self):
        try:
            aircrafts = self.LLAPI.ShowStatusOfAircrafts()
            for aircraft in aircrafts:
                print(aircraft)
            print("\n")
        except:
            print("Unexpected error has occured, returning to home screen")
            return
Exemplo n.º 11
0
class Create_Menu:
    '''Menu for Create options

        This class allows the user to choose what to create.
        -----------------------------------------------------
    
        -create_employee = indicates if we would like to create new employee on the system 
        -create_destination = indicates if we would like to create new destination on the system
        -create_airplane = indicates if we would like to create new airplane on the system
        -create__voyage = indicates if we woule like to create new voyage on the system
        
    '''
    def __init__(self):
        self.__llapi = LLAPI()

    def create_menu(self):
        action = ""
        while (action != "b"):
            print(header_string("CREATE", 50))
            print_create_menu()

            action = input("Choose an option: ").lower()
            while action not in ["1", "2", "3", "4", "b"]:
                print("Invalid input. Please choose from the list")
            if action == "1":
                self.__create_employee()
            elif action == "2":
                self.__create_destination()
            elif action == "3":
                self.__create_airplane()
            elif action == "4":
                self.__new_voyage()
            elif action == "b":
                pass

    def __create_employee(self):
        '''Takes no input. Prints on the screen and asks for input to create
           an employee in the database. If all input is there and correctly
           typed it is saved to the employee.csv data file'''
        print(header_string("CREATE EMPLOYEE", 50))
        occupation_str = self.__llapi.choose_occupation()
        if occupation_str:
            print(please_fill_info())
            print("Occupation: ", occupation_str)
            name_str = get_string("Name")
            SO_str = input("Social Security Number: ")
            while not (self.__llapi.is_ssn_valid(SO_str)):
                print("Please insert a valid 10-digit social security number.")
                SO_str = input("Social Security Number: ")

            if self.__llapi.check_if_ssn_unique(SO_str):
                address_str = get_address()
                home_phone_str = self.__llapi.get_phone("Home")
                cell_phone_str = self.__llapi.get_phone("Cell")
                email_str = get_email()
                if occupation_str in ["C", "P"]:
                    print("")
                    print('List of airplane models')
                    airplanes = self.__llapi.get_airplanes()
                    print_airplane_models(airplanes)
                    airplane_license_str = self.__llapi.get_airplane_model()
                else:
                    airplane_license_str = "N/A"
                print("")

                if is_correct():
                    new_employee = Employee(occupation_str, name_str, SO_str,
                                            address_str, home_phone_str,
                                            cell_phone_str, email_str,
                                            airplane_license_str)
                    if self.__llapi.add_employee(new_employee):
                        print(header_string("SUCCESS!", 50))
                        press_enter()
                    else:
                        print(
                            "Oh-oh something went wrong! Please fill in all information"
                        )
                        try_again()
                        self.__create_employee()
                else:
                    self.__create_employee()
            else:
                print("The SSN already exists!")
                press_enter()

    def __create_destination(self):
        '''Takes no input. Prints on the screen and asks for input to create
           a destination in the database. If all input is there and correctly
           typed it is saved to the destination.csv data file'''
        print(header_string("CREATE DESTINATION", 50))
        print(please_fill_info())
        country_str = get_string("Country")
        airport_str = get_string("Airport")
        if self.__llapi.is_airport_unique(airport_str):
            duration_str = self.__llapi.get_destination_duration()
            distance_str = get_number("Distance from Iceland (km)")
            contact_name_str = get_string("Contact name")
            contact_phone_nr_str = self.__llapi.get_phone("Contact")
            if is_correct():
                new_destination = Destination(country_str, airport_str,
                                              duration_str, distance_str,
                                              contact_name_str,
                                              contact_phone_nr_str)
                if self.__llapi.add_destination(new_destination):
                    print(header_string("SUCCESS!", 50))
                    press_enter()
                else:
                    print("Oh no something went wrong! Please try again.")
                    try_again()
                    self.__create_destination()
            else:
                self.__create_destination()
        else:
            print("Airport already exists.")
            press_enter()

    def __create_airplane(self):
        '''Takes no input. Prints on the screen and asks for input to create
           a new airplane in the database. If all input is there and correctly
           typed it is saved to the airplane.csv data file'''
        print(header_string("CREATE AIRPLANE", 50))
        print(please_fill_info())
        name_str = input("Name: ")
        if self.__llapi.is_airplane_unique(name_str):
            model_str = input("Model: ")
            producer_str = input("Producer: ")
            number_of_seats_str = get_number("Number of seats")
            print("")
            if is_correct():
                print(header_string("SUCCESS!", 50))
                new_airplane = Airplane(name_str, model_str, producer_str,
                                        number_of_seats_str)
                self.__llapi.add_airplane(new_airplane)
                press_enter()
            else:
                self.__create_airplane()
        else:
            print("Airplane already exists")
            press_enter()

    def __new_voyage(self):
        '''Takes no input. Prints on the screen and asks for input to create
           a new voyage in the database. First step is to input airport name
           and then it calls copy_voyage function if user wants to copy an older
           voyage already in the system. If not it calls the create_voyage
           function.'''
        print(header_string("CREATE VOYAGE", 50))
        print(please_fill_info())
        airport = self.__llapi.get_destination()
        print_airport(airport)
        destination_str = self.__llapi.get_voyage_airport()
        copy_voyage = input(
            "\nDo you want to copy an existing voyage? (Y/N): ").lower()
        while copy_voyage != "y" and copy_voyage != "n":
            print("Wrong input. Please choose Y or N")
            copy_voyage = input(
                "\nDo you want to copy an existing voyage? (Y/N): ").lower()
        if copy_voyage == "y":
            self.__copy_voyage(destination_str)
        else:
            self.__create_voyage(destination_str)

    def __copy_voyage(self, airport):
        '''Takes in a name of the airport that the voyage is scheduled for. Asks for if 
           user wants to man voyage if needed and if user wants to change employees on
           the voyage. Then it writes the new voyage to the voyage.csv file.'''
        print("\nWhat date are you looking for? (only use numbers)")
        airport_str = airport
        copy_year_str, copy_month_str, copy_day_str = self.__llapi.get_voyage_date(
        )
        voyages = self.__llapi.get_voyage_destination(airport,
                                                      int(copy_year_str),
                                                      int(copy_month_str),
                                                      int(copy_day_str))
        if print_voyages_destination(voyages, airport):
            flight_number = input(
                "Please insert flight number for the voyage: ").upper()
            the_voyage = self.__llapi.get_the_voyage(airport,
                                                     int(copy_year_str),
                                                     int(copy_month_str),
                                                     int(copy_day_str),
                                                     flight_number)
            copy_voyage = the_voyage[0]
        new_year_str, new_month_str, new_day_str = self.__llapi.get_voyage_date(
        )
        print("")
        availableplanes = self.__llapi.get_airplane_status(
            int(new_year_str), int(new_month_str), int(new_day_str))
        new_hour_str, new_minutes_str = self.__llapi.get_voyage_time()
        new_departure_time = datetime.datetime(int(new_year_str),
                                               int(new_month_str),
                                               int(new_day_str),
                                               int(new_hour_str),
                                               int(new_minutes_str),
                                               0).isoformat()
        airplane_str = copy_voyage.airplane

        if copy_voyage.captain == "N/A":
            man_voyage = input(
                "Would you like to man the voyage at this time? (Y/N): "
            ).lower()
            while man_voyage != "y" and man_voyage != "n":
                print("Wrong input. Please choose Y or N")
                man_voyage = input(
                    "Would you like to man the voyage at this time? (Y/N): "
                ).lower()
            if man_voyage == "y":
                self.__man_voyage(airport_str, new_departure_time,
                                  airplane_str, new_year_str, new_month_str,
                                  new_day_str, new_hour_str, new_minutes_str)
            else:
                new_voyage = Voyage(airport_str, new_departure_time,
                                    airplane_str)
                self.__llapi.add_voyage(new_voyage)
        else:
            change_employees = input(
                "Would you like to change employees for the voyage? (Y/N): "
            ).lower()
            while change_employees != "y" and change_employees != "n":
                print("Wrong input. Please choose Y or N")
                change_employees = input(
                    "Would you like to change employees for the voyage? (Y/N): "
                ).lower()
            if change_employees == "y":
                self.__man_voyage(airport_str, new_departure_time,
                                  airplane_str, new_year_str, new_month_str,
                                  new_day_str, new_hour_str, new_minutes_str)
            else:
                new_voyage = Voyage(airport_str, new_departure_time,
                                    airplane_str, copy_voyage.captain,
                                    copy_voyage.pilot, copy_voyage.fsm,
                                    copy_voyage.flight_attendant)
                self.__llapi.add_voyage(new_voyage)

    def __create_voyage(self, destination):
        '''Takes in a name of the airport that the voyage is scheduled for. Asks for if 
           user wants to man voyage. Then it writes the new voyage to the voyage.csv file.'''
        destination_str = destination
        year_str, month_str, day_str = self.__llapi.get_voyage_date()
        hour_str, minutes_str = self.__llapi.get_voyage_time()
        new_departure_time = datetime.datetime(int(year_str), int(month_str),
                                               int(day_str), int(hour_str),
                                               int(minutes_str),
                                               0).isoformat()

        all_planes = self.__llapi.get_airplane(int(year_str), int(month_str),
                                               int(day_str), int(hour_str),
                                               int(minutes_str))
        temp_lst = []
        for item in all_planes:
            if item.plane_status == "Available":
                temp_lst.append(item.name)

        print_airplane_name_and_models(all_planes)
        print("The listed airplanes are available for the given date and time")
        airplane_str = self.__llapi.get_voyage_airplane(temp_lst)
        print("")
        man_voyage = input(
            "Would you like to man the voyage at this time? (Y/N): ").lower()
        while man_voyage != "y" and man_voyage != "n":
            print("Wrong input. Please choose Y or N")
            man_voyage = input(
                "Would you like to man the voyage at this time? (Y/N): "
            ).lower()
        if man_voyage == "y":
            self.__man_voyage(destination_str, new_departure_time,
                              airplane_str, year_str, month_str, day_str,
                              hour_str, minutes_str)
        else:
            new_voyage = Voyage(destination_str, new_departure_time,
                                airplane_str)
            self.__llapi.add_voyage(new_voyage)

    def __man_voyage(self, destination_str, new_departure_time, airplane_str,
                     year_str, month_str, day_str, hour_str, minutes_str):
        '''Takes in name of airport (destination), departure time, airplane name 
           and date and time to create a new voyage. If all input is valid it
           vill write the voyage to the voyage.csv file.'''
        ''' Prenta lausa flugstjóra'''
        airplanes = self.__llapi.get_airplane(int(year_str), int(month_str),
                                              int(day_str), int(hour_str),
                                              int(minutes_str))
        for item in airplanes:
            if airplane_str == item.name:
                model = item.model
        pilots_model = self.__llapi.get_available_pilots(
            int(year_str), int(month_str), int(day_str), model)
        print_pilots_by_model(pilots_model)

        captain_str = self.__llapi.get_crew("captain")
        while not self.__llapi.check_occupation("C", captain_str,
                                                pilots_model):
            print(not_licensed())
            captain_str = self.__llapi.get_crew("captain")

        pilot_str = self.__llapi.get_crew("pilot")
        while not self.__llapi.check_occupation("P", pilot_str, pilots_model):
            print(not_licensed())
            pilot_str = self.__llapi.get_crew("pilot")

        flight_attendants = self.__llapi.get_available_crew(
            int(year_str), int(month_str), int(day_str))
        print_flight_attendants(flight_attendants)

        fsm_str = self.__llapi.get_crew("flight service manager")
        while not self.__llapi.check_occupation("FSM", fsm_str,
                                                flight_attendants):
            print(not_licensed())
            fsm_str = self.__llapi.get_crew("flight service manager")
        fa_on_voyage_str = input(
            "Would you like to add a Flight Attendant on this voyage? (Y/N): "
        ).lower()
        while fa_on_voyage_str != "y" and fa_on_voyage_str != "n":
            print("Wrong input. Please choose Y or N")
            fa_on_voyage_str = input(
                "Would you like to add a Flight Attendant on this voyage? (Y/N): "
            ).lower()
        if fa_on_voyage_str == "y":
            fa_str = self.__llapi.get_crew("flight attendant")
            while not self.__llapi.check_occupation("FA", fa_str,
                                                    flight_attendants):
                print(not_licensed())
                fa_str = self.__llapi.get_crew("flight attendant")
        else:
            fa_str = "N/A"

        if is_correct():
            print(header_string("SUCCESS!", 50))
            new_voyage = Voyage(destination_str, new_departure_time,
                                airplane_str, captain_str, pilot_str, fsm_str,
                                fa_str)
            self.__llapi.add_voyage(new_voyage)
            press_enter()
        else:
            self.__create_voyage(destination_str)
Exemplo n.º 12
0
 def __init__(self):
     self.llAPI = LLAPI()
     self.staffUI = StaffMemberUI(self.llAPI)
     self.destUI = DestinationUI(self.llAPI)
     self.airplaneUI = AirplaneUI(self.llAPI)
     self.voyageUI = VoyageUI(self.llAPI)
Exemplo n.º 13
0
class VoyageUI:
    def __init__(self):
        self.LLAPI = LLAPI()
        self.header = "{:^8}|{:^15}|{:^25}|{:^12}|{:^20}|{:^14}|{:^9}|{:^21}|{:^21}|{:^21}|{:^21}".format(
            "VoyageID", "DestinationID", "Departure Time", "Aircraft ID",
            "Head flight attendant", "Captain SSN", "IsStaffed",
            "Outgoing seats sold", "Outgoing Flight ID", "Incoming seats sold",
            "Incoming flight ID")

# private method to format prints

    def __print_information(self, voyage):
        try:
            '''Prints information regarding voyages'''
            is_full_bool = self.LLAPI.IsFullyStaffed(voyage)
            row_len, coloumn_len = os.get_terminal_size()
            row_len_half = 2 // row_len
            seperator_str = ("-" * (row_len - 1) + "\n")
            info_str = "{:^8} {:^15} {:^25} {:^12} {:^20} {:^14} {:^9} {:^21} {:^21} {:^21} {:^21}".format(
                str(voyage.voyageID), str(voyage.destination),
                str(voyage.departureTime), str(voyage.aircraftID),
                str(voyage.headFlightAttendant), str(voyage.captain),
                str(is_full_bool), str(voyage.seatingSoldOutgoing),
                str(voyage.outgoingFlightID), str(voyage.seatingSoldIncoming),
                str(voyage.incomingFlightID))
            print(seperator_str, info_str)
        except:
            print("Unexpected error has occured, returning to home screen")
            return

# method to register a new voyage

    def register_Voyage(self):
        try:
            print('\n##### Register New Voyage #####\n')
            destinations = self.LLAPI.ListAllDestinations()
            idList = [str(dest.dest_id) for dest in destinations]
            # print(idList)
            print('Available Destinations:')
            print('ID \t Name')
            for dest in destinations:
                print(str(dest.dest_id) + ' \t' + str(dest.airport_str))
            Voyage_destination_id = input(
                'Enter Destination ID: ')  # NEEDS RE CONFIGUREING
            if Voyage_destination_id not in idList:
                print('\nInvalid destinationID selection returning to main.')
                return
            print('\nSelect Time of Voyage\n')

            Voyage_year = int(input('Enter Year: '))
            Voyage_month = int(input('Enter Month: '))
            Voyage_day = int(input('Enter Day: '))
            Voyage_hour = int(input('Enter hour: '))
            Voyage_minute = int(input('Enter minute: '))

            departureTime = datetime(Voyage_year, Voyage_month, Voyage_day,
                                     Voyage_hour, Voyage_minute)

            if datetime.now() > departureTime:
                print(
                    '\nYou Must Select a Date in the Future, Returning to Main.'
                )
                return

            self.LLAPI.AddVoyage(Voyage_destination_id,
                                 departureTime.isoformat())

            print('\nVoyage Successfully Added.\n')
            return

        except ToFewAvailableEmployees:
            print(
                '\nThere are to few available employees at that time to create a voyage, returning to main.\n'
            )
            return
        except DepartureTimeOccupied:
            print(
                '\nThe Selected Departure Time is already taken, to flights can not take off similtaniously, returning to main.\n'
            )
            return
        except ValueError:
            print(
                'The Selected date is invalid, month must be 1-12 and day must be 1-31'
            )
            return
        except:
            print("Unexpected error has occured, returning to home screen")
            return

# Method to register recurring voyages

    def register_recuring_voyage(self):
        try:
            print('\nRegister A recurring voyage\n')

            destinations = self.LLAPI.ListAllDestinations()
            idList = [str(dest.dest_id) for dest in destinations]
            print('Available Destinations:')
            print('ID \t Name')
            for dest in destinations:
                print(str(dest.dest_id) + ' \t' + str(dest.airport_str))
            Voyage_destination_id = input('Enter Destination ID: ')
            if Voyage_destination_id not in idList:
                print('\nInvalid destinationID selection returning to main.')
                return

            dayInterval = int(
                input(
                    '\nEnter How Many Days are Desired Between The Recurring Events (7 for a week): '
                ))
            if dayInterval < 1:
                print("\nInvalid day interval, returning to main.")
                return

            print("\nEnter the date and time of the first voyage below:")
            year = int(input("\nEnter the Year: "))
            month = int(input("\nEnter The Month: "))
            day = int(input("\nEnter the Day: "))
            hour = int(input("\nEnter the Hour: "))
            minute = int(input("\nEnter the Minute: "))

            firstTime = datetime(year, month, day, hour, minute).isoformat()

            quantity = int(
                input(
                    "\nEnter how many voyages you want to assign with the entered period: "
                ))

            self.LLAPI.AddRecurringVoyages(Voyage_destination_id, firstTime,
                                           dayInterval, quantity)
            print('\n', quantity, " Voyages have been successfully added.")
            return
        except ValueError:
            print("\nDate is incorrectly set, returning to main")
            return
        except DepartureTimeOccupied:
            print(
                "\nThe selected date and time already has a voyage, consider delaying the voyage, returning to main."
            )
            return
        except:
            print("Unexpected error has occured, returning to home screen")
            return

# Method to register an aircraft to a voyage

    def register_aircraft_to_voyage(self):
        try:
            Voyage_id = input('Enter Desired Voyage ID: ')
            voyage = self.LLAPI.getVoyageByVoyageID(Voyage_id)
            print("\nAvailable aircrafts for Voyage:\n")
            availableAircrafts = self.LLAPI.ListAvailableAircrafts(
                voyage.departureTime)
            print('{:15}{:20}{:20}'.format('AircraftID', 'Manufacturer',
                                           'Model'))

            airID_lst = [str(air.aircraftID) for air in availableAircrafts]

            if len(airID_lst) < 1:
                print(
                    '\nThere are no available Aircrafts at the time of the selected Voyage, returning to main.\n'
                )
                return

            for air in availableAircrafts:
                print('{:15}{:20}{:20}'.format(air.aircraftID,
                                               air.manufacturer, air.model))

            aircraft_id = input('\nEnter Aircraft ID: ')

            if aircraft_id not in airID_lst:
                print('\nInvalid ID Choice, returning to main.\n')
                return

            self.LLAPI.AssignAircraftToVoyge(Voyage_id, aircraft_id)

            print('\nSuccessfully assigned aircraft to voyage\n')

        except EntryNotInDatabase:
            print('\nInvalid Voyage ID, returning to main')
            return
        except:
            print("Unexpected error has occured, returning to home screen")
            return

# Method to register an employee to a voyage

    def register_employees_to_voyage(self):
        employee_name = "default"
        try:
            rows_len, columns_len = os.get_terminal_size()

            voyage_id = input('Voyage ID: ')
            voyage = self.LLAPI.getVoyageByVoyageID(voyage_id)
            employee_name = input('Input the Name of the Employee: ')
            employees_with_name = self.LLAPI.ListAllEmployeesWithName(
                employee_name)

            if len(employees_with_name) == 1:
                employeeSSN = employees_with_name[0].ssn

            elif len(employees_with_name) > 1:
                employeeSSN_lst = [emp.ssn for emp in employees_with_name]

                print("More than one employee was found with that name")
                print("-" * (rows_len - 1))
                print("{:40}\t{:10}\t{:20}\t{:10}\t{:35}\t{:20}\t{}".format(
                    "Name", "SSN", "Address", "Phone", "Email", "Pilot status",
                    "Licenses"))
                print("-" * (rows_len - 1))
                for employee in employees_with_name:
                    print(employee)
                    print("-" * (rows_len - 1))
                employeeSSN = input(
                    "\nPlease input the ssn of employee you want to update: ")

                if employeeSSN not in employeeSSN_lst:
                    print("\nInvalid ssn Selection, returning to main.\n")
                    return

            else:
                print("\nThere is no employee called " + employee_name +
                      " in our system, returning to main.\n")
                return
            self.LLAPI.AddStaffToVoyage(voyage_id, employeeSSN)

        except EntryNotInDatabase:
            print("\nThere is no employee called " + employee_name +
                  " in our system, returning to main.\n")
            return
        except EmployeeAlreadyAssigned:
            print('\n' + employee_name + ' is already assigned to this flight')
        except AircraftNotRegistered:
            print(
                '\nYou Must Assign a Plane to the Voyage before Assigning Staff, returning to main\n'
            )
        except:
            print("Unexpected error has occured, returning to home screen")
            return

# Method to assign a head flightattendant to a voyage

    def assign_head_flightattendant_to_voyage(self):
        try:
            print("Assign head flightattendant to voyage\n")
            Voyage_id = input('Voyage ID: ')
            voyage = self.LLAPI.getVoyageByVoyageID(Voyage_id)
            if len(voyage.flightAttendants_lst) < 1:
                print(
                    '\nYou must assign a flight attendant to Voyage before assigning Head flight attendant.'
                )
                return
            elif len(voyage.flightAttendants_lst) == 1:
                flight_att = self.LLAPI.GetEmployeeBySSN(
                    voyage.flightAttendants_lst[0])
                self.LLAPI.UpdateVoyageHeadFlightAttendant(
                    Voyage_id, voyage.flightAttendants_lst[0])
                print(
                    str(flight_att.name) +
                    ' Has Been set as head flight attendant')

                return
            else:
                print(
                    '\nPlease Select what Flight Attendant You Want To Make Head flight attendant:\n'
                )
                for flight_person in voyage.flightAttendants_lst:
                    print(self.LLAPI.GetEmployeeBySSN(flight_person))
                SSN = input('Flight attendant SSN: ')
                if SSN not in voyage.flightAttendants_lst:
                    print('Invalid Selection, Returning to menu.')
                    return
                self.LLAPI.UpdateVoyageHeadFlightAttendant(Voyage_id, SSN)
                return
        except:
            print("Unexpected error has occured, returning to home screen")
            return

# method to assign a captain to a voyage

    def assign_captain_to_voyage(self):
        try:
            print("Assign captain to voyage\n")
            Voyage_id = input('Voyage ID: ')
            voyage = self.LLAPI.getVoyageByVoyageID(Voyage_id)
            if len(voyage.pilots_lst) < 1:
                print(
                    '\nYou must assign more pilots to Voyage before assigning Captain, returning to main'
                )
                return

            elif len(voyage.pilots_lst) == 1:
                cap = self.LLAPI.GetEmployeeBySSN(voyage.pilots_lst[0])
                self.LLAPI.UpdateVoyageCaptain(Voyage_id, voyage.pilots_lst[0])
                print('\n' + str(cap.name) + ' Has Been set as voyage Captain')

                return
            else:
                print('\nPlease Select what Pilot You Want To Make Captain:\n')
                print(self.LLAPI.GetEmployeeBySSN(voyage.pilots_lst[0]))
                print(self.LLAPI.GetEmployeeBySSN(voyage.pilots_lst[1]))
                capSSN = input('Pilot SSN: ')
                if capSSN not in voyage.pilots_lst:
                    print('Invalid Selection, Returning to menu.')
                    return
                self.LLAPI.UpdateVoyageCaptain(Voyage_id, capSSN)
                return
        except:
            print("Unexpected error has occured, returning to home screen")
            return

# method to print all voyages for a given day

    def print_voyage_for_day(self):
        try:
            year = int(input("Input year: "))
            month = int(input("Input month: "))
            day = int(input("Input day: "))
            date_iso = datetime(year, month, day).isoformat()
            voyages = self.LLAPI.ListVoyagesForGivenDay(date_iso)

            if len(voyages) == 0:
                print("\nNo Assigned Voyages for date: ", date_iso)
                return

            print(self.header)
            for voyage in voyages:
                self.__print_information(voyage)
            print("\n")
        except:
            print("Unexpected error has occured, returning to home screen")
            return

# method to print all voyages for a certain week

    def print_voyage_for_week(self):
        try:
            print("Input first day of the week you want to look at")
            year = int(input("Input year: "))
            month = int(input("Input month: "))
            day = int(input("Input day: "))
            date_iso = datetime(year, month, day).isoformat()
            voyages = self.LLAPI.ListVoyagesForGivenWeek(date_iso)
            print(self.header)
            for voyage in voyages:
                self.__print_information(voyage)
            print("\n")
        except:
            print("Unexpected error has occured, returning to home screen")
            return

# method to print all voyages

    def print_Voyages(self):
        try:
            row_len, coloumns_len = os.get_terminal_size()
            print("\n\tList all Voyages")
            Voyages = self.LLAPI.ListAllVoyages()
            print(self.header)
            for Voyage in Voyages:
                self.__print_information(Voyage)
            print("\n")
        except:
            print("Unexpected error has occured, returning to home screen")
            return

# Methed to print all voyages by destination

    def print_voyage_by_dest(self):
        # destinations = self.LLAPI.
        try:
            dest_id = input("Destination ID: ")
            Voyages = self.LLAPI.ListVoyagesForDestination(dest_id)
            print(self.header)
            for voyage in Voyages:
                self.__print_information(voyage)
            print("\n")
        except:
            print("Unexpected error has occured, returning to home screen")
            return

# Method to update a voyages captain

    def UpdateVoyageCaptain(self):
        Voyage_id = input("Enter voyage ID:")
        pilot_ssn = input("Enter pilot ID:")
        voyage_captain = self.LLAPI.UpdateVoyageCaptain(Voyage_id, pilot_ssn)
        try:
            voyage = self.LLAPI.getVoyageByVoyageID(Voyage_id)
        except EntryNotInDatabase:
            print("ERROR! Voyage not found, please input correct id")
            return UpdateVoyageCaptain()
        try:
            captain = self.LLAPI.GetEmployeeBySSN(pilot_ssn)
        except EntryNotInDatabase:
            print("ERROR! Pilot not found, please correct ssn")
            return UpdateVoyageCaptain()
        except:
            print("Unexpected error has occured, returning to home screen")
            return

# Method to sell seats to a voyage

    def soldSeatsForVoyage(self):
        try:
            Voyage_id = input("Enter voyage ID:")
            voyage = self.LLAPI.getVoyageByVoyageID(
                Voyage_id)  # so error code hits at the right moment
            flightType = input(
                "Is the flight:\n 1. Outgoing\n 2. Incoming\nFromIceland?: ")
            sold_seats = input("Enter seats:")
            if flightType.lower() == "outgoing" or flightType == '1':
                self.LLAPI.SellSeatsForVoyageOutgoing(Voyage_id,
                                                      int(sold_seats))
                print('\nSold ' + str(sold_seats) +
                      ' seats for the flight, the total is now ' +
                      str(int(sold_seats) + int(voyage.seatingSoldOutgoing)))
                return
            elif flightType.lower() == "incoming" or flightType == '2':
                self.LLAPI.SellSeatsForVoyageIncoming(Voyage_id,
                                                      int(sold_seats))
                print('\nSold ' + str(sold_seats) +
                      ' seats for the flight, the total is now ' +
                      str(int(sold_seats) + int(voyage.seatingSoldIncoming)))
                return
            else:
                print(
                    '\nInvalid Flight Type Selection, Returning to main menu.')
                return
        except EntryNotInDatabase:
            print("\nERROR! Voyage not found, please input correct id")
            return
        except NotEnoughSeats:
            print("\nThere are not enough available seats to sell " +
                  str(sold_seats) + ' seats.')
            return
        except AircraftNotRegistered:
            print(
                "\nYou must register an aircraft to the voyage before selling seats."
            )
        except:
            print("Unexpected error has occured, returning to home screen")
            return

    def ListStatusOfVoyages(self):
        try:
            voyages = self.LLAPI.ListAllVoyages()
            print("\n{:10} {:15} {:20} {:30}".format("Voyage ID", "Airport",
                                                     "Departure Time",
                                                     'Voyage Status'))

            for voy in voyages:
                print("\n{:10} {:15} {:20} {:30}".format(
                    voy.voyageID,
                    self.LLAPI.GetDestinationByDestinationID(
                        voy.destination).airport_str, voy.departureTime,
                    self.LLAPI.GetVoyageStatus(voy)))
        except:
            print("Unexpected error has occured, returning to home screen")
            return
Exemplo n.º 14
0
class Update_Menu:
    def __init__(self):
        self.__llapi = LLAPI()

    def update_menu(self):
        '''Prints the update menu on the screen and asks the user
           to choose an action.'''
        action = ""
        while (action != "b"):
            print(header_string("UPDATE", 50))
            print("1: Update employee")
            print("2: Update airport contact info")
            print("3: Update voyage")
            print("b: Back")
            print("")

            action = input("Choose an option: ").lower()

            if action == "1":
                self.__update_employee()

            elif action == "2":
                self.__update_destination()
            elif action == "3":
                pass
            elif action != 'b':
                print(
                    header_string('WRONG INPUT, please select a valid input!',
                                  50))
                try_again()

            elif action == "3":
                self.__update_voyage()

    def __update_employee(self):
        '''Takes no input. Prints on the screen and asks for input to update/change
           the employee informations that can be changed. There is no output
           printed only saved in the employee.csv data file'''
        new_employee = []
        print(header_string("UPDATE EMPLOYEE", 50))
        emp_to_update = self.__llapi.get_employee()
        print_possible_employee_for_update(emp_to_update)
        employee = input("Social Security Number: ")
        while not (self.__llapi.is_ssn_valid(employee)):
            print("Please insert a valid 10-digit social security number.")
            employee = input("Social Security Number: ")
        if not self.__llapi.check_if_ssn_unique(employee):
            employee_information = self.__llapi.get_employee_information(
                employee)
            print_employee(employee_information)
            new_occupation = self.__llapi.choose_occupation()
            print("Occupation: ", new_occupation)
            print("")
            print("------------------------------------------")
            print("To leave information unchanged press enter")
            print("------------------------------------------")
            new_address = get_address()
            new_home_phone = self.__llapi.get_phone("Home")
            new_cell_phone = self.__llapi.get_phone("Cell")
            new_email = get_email("update")
            if new_occupation in ["C", "P"]:
                print("")
                print('List of airplane models')
                airplanes = self.__llapi.get_airplanes()
                print_airplane_models(airplanes)
                new_licence = self.__llapi.get_airplane_model("update")
            if is_correct():
                new_employee.extend([
                    new_occupation, new_address, new_home_phone,
                    new_cell_phone, new_email, new_licence
                ])
                self.__llapi.update_employee(employee, new_employee)
                print(header_string("SUCCESS!", 50))
                press_enter()
            else:
                self.__update_employee()
        else:
            print("Employee doesn't exist")
            press_enter()

    def __update_destination(self):
        '''Takes no input. Prints on the screen and asks for input to update/change
           the contact informations for a selected destination. There is no output
           printed only saved in the destination.csv data file'''
        print(header_string("UPDATE DESTINATION", 50))
        new_contact = []
        action2 = ""
        airport = self.__llapi.get_destination()
        print_airport(airport)
        destination = self.__llapi.get_voyage_airport()
        print("")
        print("What information would you like to update?")
        print("1: Contact name")
        print("2: Contact phone")
        print("3: Both")
        print("")
        action2 = input("Choose an option: ").lower()
        print("")

        if action2 == "1":
            new_name = get_string("New contact name")
            new_contact.append(new_name)
            new_contact.append("")
        elif action2 == "2":
            new_phone = self.__llapi.get_phone("New contact")
            new_contact.append("")
            new_contact.append(new_phone)
        elif action2 == "3":
            new_name = get_string("New contact name")
            new_phone = self.__llapi.get_phone("New contact")
            new_contact.append(new_name)
            new_contact.append(new_phone)
        if is_correct():
            print(header_string("SUCCESS!", 50))
            self.__llapi.update_destination(destination, new_contact)
            press_enter()
        else:
            self.__update_destination()

    def __update_voyage(self):
        '''Takes no input. Prints on the screen and asks for input to man a voyage.
           There is no output printed only saved in the voyage.csv data file'''
        print(header_string("MAN A VOYAGE", 50))
        '''Lista upp Destination'''
        airport = self.__llapi.get_destination()
        print_airport(airport)
        voyage_destination = self.__llapi.get_voyage_airport()
        '''Velja dagsetningu'''
        print("What date are you looking for? (only use numbers)")
        year_str, month_str, day_str = self.__llapi.get_voyage_date()
        '''Lista upp ómannaðar voyages'''
        voyages = self.__llapi.get_voyage_destination(voyage_destination,
                                                      int(year_str),
                                                      int(month_str),
                                                      int(day_str))
        '''Láta velja voyage'''
        if print_voyages_destination(voyages, voyage_destination):
            the_voyage_lst = self.__llapi.get_flight_number(
                voyage_destination, year_str, month_str, day_str)
            the_voyage = the_voyage_lst[0]

            airplanes = self.__llapi.get_airplanes()
            for item in airplanes:
                if the_voyage.airplane == item.name:
                    model = item.model
            pilots_model = self.__llapi.get_available_pilots(
                int(year_str), int(month_str), int(day_str), model)
            print_pilots_by_model(pilots_model)

            captain_str = self.__llapi.get_crew("captain")
            while not self.__llapi.check_occupation("C", captain_str,
                                                    pilots_model):
                print(not_licensed())
                captain_str = self.__llapi.get_crew("captain")

            pilot_str = self.__llapi.get_crew("pilot")
            while not self.__llapi.check_occupation("P", pilot_str,
                                                    pilots_model):
                print(not_licensed())
                pilot_str = self.__llapi.get_crew("pilot")

            flight_attendants = self.__llapi.get_available_crew(
                int(year_str), int(month_str), int(day_str))
            print_flight_attendants(flight_attendants)

            fsm_str = self.__llapi.get_crew("flight service manager")
            while not self.__llapi.check_occupation("FSM", fsm_str,
                                                    flight_attendants):
                print(not_licensed())
                fsm_str = self.__llapi.get_crew("flight service manager")
            fa_on_voyage_str = input(
                "Would you like to add a Flight Attendant on this voyage? (Y/N): "
            ).lower()
            while fa_on_voyage_str != "y" and fa_on_voyage_str != "n":
                print("Wrong input. Please choose Y or N")
                fa_on_voyage_str = input(
                    "Would you like to add a Flight Attendant on this voyage? (Y/N): "
                ).lower()
            if fa_on_voyage_str == "y":
                fa_str = self.__llapi.get_crew("flight attendant")
                while not self.__llapi.check_occupation(
                        "FA", fa_str, flight_attendants):
                    print(not_licensed())
                    fa_str = self.__llapi.get_crew("flight attendant")
            else:
                fa_str = "N/A"

            if is_correct():
                print(header_string("SUCCESS!", 50))
                self.__llapi.update_voyage(the_voyage, captain_str, pilot_str,
                                           fsm_str, fa_str)

            else:
                self.__update_voyage()
        press_enter()
Exemplo n.º 15
0
class DestinationUI:
    def __init__(self):
        try:
            self.LLAPI = LLAPI()
            self.header = "{:20}{:25}{:25}{:25}{:35}{:25}{:25}".format("Destination ID", "Country", "Airport",
            "Flight Duration", "Distance From Reykjavik", "Contact Name", "Contact Number")
        except:
            print("Unexpected error has occured, returning to home screen")
            return

# private method to format text for printing
    def __printing_information(self, destination):
        try:
            information_str = "{:20}{:25}{:25}{:25}{:35}{:25}{:25}".format(str(destination.dest_id), str(destination.country_str), str(destination.airport_str),
            str(destination.flight_duration), str(destination.distanceFromReykjavik), str(destination.contactName_str), str(destination.contactNr_str))
            len_rows, len_coloumns = os.get_terminal_size()
            return information_str
        except:
            print("Unexpected error has occured, returning to home screen")
            return


# private method to register a new destination
    def register_destination(self):
        try:
            print("\n\tRegister a new destination")
            destination_country = input('Country: ')
            airport_str = input('Airport: ')
            flight_duration = input('Flight duration: ')
            distanceFromReykjavik = input('Distance from Reykjavík: ')
            contactName_str = input('Contact name: ')
            contactNr_str = input('Contact number: ')

            LLAPI().RegisterDestination(destination_country, airport_str, flight_duration, distanceFromReykjavik, contactName_str, contactNr_str)
            
            return
        except:
            print("Unexpected error has occured, returning to home screen")
            return

# method to print all destinations in the system
    def print_destinations(self):
        try:    
            print("\n\tList all destinations\n")
            destinations = self.LLAPI.ListAllDestinations()
            print(self.header)
            for destination in destinations:
                print(self.__printing_information(destination))
            print("\n")
        except:
            print("Unexpected error has occured, returning to home screen")
            return
      

# Method to change destination contact info
    def change_destination_contact_info(self):
        try:
            print("\n\tUpdate destination information")
            dest_id = input("Destination ID: ")
            contactNr = input("New contact number: ")
            contact = self.LLAPI.UpdateDestinationContactNumber(dest_id, contactNr)
        except:
            print("Unexpected error has occured, returning to home screen")
            return


# Method to show the most popular destination
    def most_popular_destinations(self):
        try:
            most_dest = self.LLAPI.MostPopularDestination()
            print(self.header)
            print(self.__printing_information(most_dest))
        except:
            print("Unexpected error has occured, returning to home screen")
            return
Exemplo n.º 16
0
 def __init__(self):
     self.__llapi = LLAPI()
Exemplo n.º 17
0
class Get_Menu:
    '''Get Option - Menu

        This class allows the user to choose what to he can see/get:
        ------------------------------------------------------------

        -Get_employee = if chosen get a list of employee information 
        -Get_destination = if chosen get a list of destinations
        -Get_airplane = if chosen get airplane information
        -Get_Voyage = if chosen get voyage information
        -back = go back to main menu


    '''
    def __init__(self):
        self.__llapi = LLAPI()

    def get_menu(self):
        '''Prints the get menu on the screen and asks the user
           to choose an action.'''
        action = ""
        while (action != "b"):
            print(header_string("GET", 50))
            print_get_menu()
            action = input("Choose an option: ").lower()

            if action == "1":
                self.__get_employee()

            elif action == "2":
                self.__get_destination()

            elif action == "3":
                self.__get_airplane_information()

            elif action == "4":
                self.__get_voyage()

            elif action != 'b':
                print(
                    header_string('WRONG INPUT, please select a valid input!',
                                  50))
                try_again()

    def __get_employee(self):
        '''Takes no input. Prints on the screen and asks for what employee information
           the user wants to see. Based on more input the output is printed on the 
           screen after it has been fetched from the data files'''
        print(header_string("GET EMPLOYEE INFORMATION", 50))
        get_employee_information()
        action = input("Choose an option: ").lower()
        if action == "1":
            print(header_string("GET ALL EMPLOYEES", 50))
            employees = self.__llapi.get_employee()
            print_employee(employees)
            press_enter()
        elif action == "2":
            print(header_string("GET EMPLOYEE INFORMATION", 50))
            SO_str = input("Social Security Number for the employee: ")
            while not (self.__llapi.is_ssn_valid(SO_str)):
                print("Please insert a valid 10-digit social security number.")
                SO_str = input("Social Security Number: ")
            if not self.__llapi.check_if_ssn_unique(SO_str):
                employee_information = self.__llapi.get_employee_information(
                    SO_str)
                print_employee(employee_information)
            else:
                print("Employee doesn't exist")
            press_enter()
        elif action == "3":
            print(header_string("GET EMPLOYEES BY OCCUPATION", 50))
            print_employee_by_occupation()
            occupation = input(
                "What occupation would you like to get? ").upper()
            while occupation not in ["C", "P", "FA", "FSM"]:
                print("Invalid input. Please choose an option from the list")
                occupation = input(
                    "What occupation would you like to get? ").upper()
            employee_by_occupation = self.__llapi.get_employee_by_occupation(
                occupation)
            print_employee(employee_by_occupation)
            press_enter()
        elif action == "4":
            print(header_string("GET EMPLOYEES BY STATUS", 50))
            print_employee_by_status()
            employee_status = input(
                "What status would you like to get? ").upper()
            while employee_status not in ["A", "B"]:
                print("Invalid input. Please choose employee status.")
                employee_status = input(
                    "What status would you like to get? ").upper()
            employee_by_status = self.__llapi.get_employee_by_status(
                employee_status)
            print_employee(employee_by_status)
            press_enter()
        elif action == "5":
            check = 0
            print(header_string("GET WEEK SCHEDULE FOR AN EMPLOYEE", 50))
            employee = input("Social Security Number: ")
            while not (self.__llapi.is_ssn_valid(employee)):
                print("Please insert a valid 10-digit social security number.")
                employee = input("Social Security Number: ")

            if not (self.__llapi.check_if_ssn_unique(employee)):
                while check == 0:
                    print(
                        "\nPlease insert date and you will get the week schedule that includes that date."
                    )
                    input_year, input_month, input_day = self.__llapi.get_voyage_date(
                    )
                    employee_information = self.__llapi.get_employee_information(
                        employee)
                    week_dates = self.__llapi.get_week_lst(
                        input_year, input_month, input_day)
                    week_schedule_lst = self.__llapi.get_week_schedule(
                        employee, input_year, input_month, input_day)
                    if week_schedule_lst:
                        print_employee_schedule(employee_information,
                                                week_dates, week_schedule_lst)
                        check += 1
                        press_enter()
                    else:
                        print("Date out of bounds. Please try again.")
            else:
                print("Employee does not exist")
                press_enter()
        elif action == "6":
            print(header_string("GET ALL PILOTS BY AIRPLANE MODEL", 50))
            pilots = self.__llapi.get_pilots_by_airplane()
            print_pilots_by_airplane(pilots)
            press_enter()
        elif action == "7":
            print(header_string("GET PILOTS BY AN AIRPLANE MODEL", 50))
            airplanes = self.__llapi.get_airplanes()
            print_airplane_models(airplanes)
            model_to_find = input("What airplane would you like to get? ")
            pilots_model = self.__llapi.get_pilots_by_model(model_to_find)
            if pilots_model:
                print_pilots_by_model(pilots_model)
            else:
                print("\n" + "No pilots are licenced for that airplane")
            press_enter()

    def __get_destination(self):
        '''Takes no input. Prints on the screen information about all destinations that
           NaN air has on its books.'''
        print(header_string("GET DESTINATIONS", 50))
        destination = self.__llapi.get_destination()
        print_destination(destination)
        press_enter()

    def __get_airplane_information(self):
        '''Takes no input. Prints on the screen information about all airplanes that
           NaN air owns and if the are available or not.'''
        print(header_string("GET AIRPLANE INFORMATION", 50))
        today = datetime.datetime.now()
        airplanes = self.__llapi.get_airplane(today.year, today.month,
                                              today.day, today.hour,
                                              today.minute)
        voyages = self.__llapi.get_all_voyage_at_date(today.year, today.month,
                                                      today.day)
        voyages_lst = []
        for item in airplanes:
            if item.plane_status == 'Available':
                voyages_lst.append(" ")
            if item.plane_status != 'Available':
                for voyage in voyages:
                    if item.name == voyage.airplane:
                        voyages_lst.append(voyage)
        print_airplanes(airplanes, voyages_lst)
        press_enter()

    def __get_voyage(self):
        '''Takes no input. Prints on the screen and asks for what voyage the
           user wants to see information for. Based on user selection all 
           information about the selected voyage is printed on the screen.'''
        print(header_string("GET VOYAGE INFORMATION", 50))
        airport = self.__llapi.get_destination()
        print_airport(airport)
        voyage_destination = self.__llapi.get_voyage_airport()
        print("What date are you looking for? (only use numbers)")
        year_str, month_str, day_str = self.__llapi.get_voyage_date()
        voyages = self.__llapi.get_voyage_destination(voyage_destination,
                                                      int(year_str),
                                                      int(month_str),
                                                      int(day_str))
        if print_voyages_destination(voyages, voyage_destination):
            voyage = self.__llapi.get_flight_number(voyage_destination,
                                                    year_str, month_str,
                                                    day_str)
            print_the_voyage(voyage)
        press_enter()