Exemplo n.º 1
0
 def get_voyage(self):
     voyage_lst = []
     if voyage_lst == []:
         with open("./data/voyage.csv", newline='', encoding='utf-8-sig') as csvfile:
             reader = csv.DictReader(csvfile)
             for row in reader:
                 new_voyage = Voyage(row['destination'], row['date'], row['time'], row['airplane'])
                 voyage_lst.append(new_voyage)
     return voyage_lst
Exemplo n.º 2
0
 def get_all_voyage_at_date(self, year_int, month_int, day_int):
     voyage_destination_lst = []
     if voyage_destination_lst == []:
         with open("./data/voyage.csv", newline='', encoding='utf-8-sig') as csvfile:
             reader = csv.DictReader(csvfile)
             for row in reader:
                 voyage_departure = dateutil.parser.parse(row['departure_date_time'])
                 voyage_year = voyage_departure.year
                 voyage_month = voyage_departure.month
                 voyage_day = voyage_departure.day
                 if voyage_year == year_int and voyage_month == month_int and voyage_day == day_int:
                     the_voyage_by_date = Voyage(row['destination'], row['departure_date_time'], row['airplane_name'], row['captain_ssn'], row['pilot_ssn'], row['fsm_ssn'], row['fa_ssn'], row['flight_out'], row['flight_in'], row['arrival_at_dest'], row['departure_from_dest'], row['arrival_back_home'])
                     voyage_destination_lst.append(the_voyage_by_date)
     return voyage_destination_lst
Exemplo n.º 3
0
 def get_the_voyage(self, voyage_destination, year_int, month_int, day_int, flight_number):
     voyage_lst_inst = []
     if voyage_lst_inst == []:
         with open("./data/voyage.csv", newline='', encoding='utf-8-sig') as csvfile:
             reader = csv.DictReader(csvfile)
             for row in reader:
                 if row['destination'] == voyage_destination:
                     voyage_departure = dateutil.parser.parse(row['departure_date_time'])
                     voyage_year = voyage_departure.year
                     voyage_month = voyage_departure.month
                     voyage_day = voyage_departure.day
                     if voyage_year == year_int and voyage_month == month_int and voyage_day == day_int and row['flight_out'] == flight_number:
                         the_voyage = Voyage(row['destination'], row['departure_date_time'], row['airplane_name'], row['captain_ssn'], row['pilot_ssn'], row['fsm_ssn'], row['fa_ssn'], row['flight_out'], row['flight_in'], row['arrival_at_dest'], row['departure_from_dest'], row['arrival_back_home'])
                         voyage_lst_inst.append(the_voyage)
                         the_airport = row['destination']
                         the_destination = self.get_destination_by_airport_class(the_airport)
                         voyage_lst_inst.append(the_destination)
                         if row['captain_ssn'] == 'N/A':
                             voyage_lst_inst.append('N/A')
                         else:
                             the_captain = self.get_employee_information_class(row['captain_ssn'])
                             voyage_lst_inst.append(the_captain)
                         if row['pilot_ssn'] == 'N/A':
                             voyage_lst_inst.append('N/A')
                         else:
                             the_pilot = self.get_employee_information_class(row['pilot_ssn'])
                             voyage_lst_inst.append(the_pilot)
                         if row['fsm_ssn'] == 'N/A':
                             voyage_lst_inst.append('N/A')
                         else:
                             the_fsm = self.get_employee_information_class(row['fsm_ssn'])
                             voyage_lst_inst.append(the_fsm)
                         if row['fa_ssn'] == 'N/A':
                             voyage_lst_inst.append('N/A')
                         else:
                             the_fa = self.get_employee_information_class(row['fa_ssn'])
                             voyage_lst_inst.append(the_fa)
     return voyage_lst_inst
Exemplo n.º 4
0
    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)
Exemplo n.º 5
0
    def update_voyage(self, the_voyage, captain_str, pilot_str, fsm_str,
                      fa_str):
        with open("./data/voyage.csv", newline='',
                  encoding='utf-8-sig') as csvfile:
            fieldnames = [
                'destination', 'departure_date_time', 'airplane_name',
                'captain_ssn', 'pilot_ssn', 'fsm_ssn', 'fa_ssn', 'flight_out',
                'flight_in', 'arrival_at_dest', 'departure_from_dest',
                'arrival_back_home'
            ]
            reader = csv.DictReader(csvfile)
            with open("./data/tempfile.csv", "w+",
                      encoding='utf-8-sig') as tempfile:
                writer = csv.DictWriter(tempfile, fieldnames=fieldnames)
                writer.writeheader()
                for row in reader:
                    if row['destination'] == the_voyage.destination and row[
                            'departure_date_time'] == the_voyage.departure and row[
                                'airplane_name'] == the_voyage.airplane and row[
                                    'flight_out'] == the_voyage.flight_out and row[
                                        'flight_in'] == the_voyage.flight_in:
                        updated_voyage = Voyage(
                            row['destination'], row['departure_date_time'],
                            row['airplane_name'], captain_str, pilot_str,
                            fsm_str, fa_str, row['flight_out'],
                            row['flight_in'], row['arrival_at_dest'],
                            row['departure_from_dest'],
                            row['arrival_back_home'])
                        row = ({
                            'destination':
                            updated_voyage.destination,
                            'departure_date_time':
                            updated_voyage.departure,
                            'airplane_name':
                            updated_voyage.airplane,
                            'captain_ssn':
                            updated_voyage.captain,
                            'pilot_ssn':
                            updated_voyage.pilot,
                            'fsm_ssn':
                            updated_voyage.fsm,
                            'fa_ssn':
                            updated_voyage.flight_attendant,
                            'flight_out':
                            updated_voyage.flight_out,
                            'flight_in':
                            updated_voyage.flight_in,
                            'arrival_at_dest':
                            updated_voyage.arrival_at_dest,
                            'departure_from_dest':
                            updated_voyage.departure_from_dest,
                            'arrival_back_home':
                            updated_voyage.arrival_back_home
                        })
                    writer.writerow(row)
        csvfile.close()
        tempfile.close()

        with open("./data/tempfile.csv", encoding='utf-8-sig') as tempfile:
            reader2 = csv.DictReader(tempfile)
            with open("./data/voyage.csv", "w+",
                      encoding='utf-8-sig') as csvfile:
                writer2 = csv.DictWriter(csvfile, fieldnames=fieldnames)
                writer2.writeheader()
                for row in reader2:
                    writer2.writerow(row)
        tempfile.close()
        csvfile.close()
Exemplo n.º 6
0
    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.º 7
0
    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)
Exemplo n.º 8
0
 def __init__(self, dapi_in):
     self.__voyage_repo = dapi_in
     self.__voyage = Voyage()
     self.__get = Get_DL()