def changeSoldSeats(self, voyage, flight_str, new_seats_str): '''Takes in voyage instance, string that dictates which flight is being changed (home or out), and string of new seats number''' all_airplanes = IO_API().loadAirplaneFromFile() airplane_id = voyage.getAircraftID() if airplane_id != 'empty': # get total seats of plane for airplane in all_airplanes: if airplane.get_planeInsignia() == airplane_id: total_seats = airplane.get_planeCapacity() while True: # if sold seats are fewer than total seats if int(new_seats_str) <= int(total_seats): if flight_str == 'home': voyage.setSeatsSoldHome(new_seats_str) else: voyage.setSeatsSoldOut(new_seats_str) return IO_API().changeVoyageFile(voyage) else: print('Invalid input! The airplane only has {} seats!'. format(int(total_seats))) else: print( '\nNo aircraft has been assigned to the voyage, please add an aircraft first!\n' )
def getNumberOfPilotsWithLicense(self): '''Returns a dictionary with airplane types as keys and number of pilots with license on that type as value''' airplane_type_list = self.loadAirplaneTypes() crew_list = IO_API().loadCrewFromFile() airplane_type_dict = {} # Go through all the crew members and match their # license with an airplane type, add them to the dict for crew_member in crew_list: for airplane_type in airplane_type_list: if crew_member.getLicense() == airplane_type.getplaneTypeID(): if str(airplane_type) in airplane_type_dict: airplane_type_dict[str(airplane_type)] += 1 else: airplane_type_dict[str(airplane_type)] = 1 # If the airplane type has no licensed pilots for airplane_type in airplane_type_list: if str(airplane_type) not in airplane_type_dict: airplane_type_dict[str(airplane_type)] = 0 return airplane_type_dict
def addVoyage(self, destination, departure_time, plane): '''Finds values from input to register a new voyage. Returns a list with all info.''' voyage_id = self.assignVoyageID() # Flight numbers flight_depart_num, flight_arrive_num = self.assignFlightNo( destination, departure_time) # arrival time in other country added, time difference taken into account arrival_time_gmt = self.findArrivalTime(destination, departure_time) arrival_time_out = self.TimeDifference(arrival_time_gmt, destination) # plane stops at destination for 1 hour departure_time_back = arrival_time_out + datetime.timedelta(hours=1) arrival_time_back = self.findArrivalTimeHome(departure_time, destination) # info added to list in same order as in allvoyages.csv info_list = [voyage_id, flight_depart_num, self.seats_sold_out, 'KEF', destination,\ departure_time.isoformat(), arrival_time_out.isoformat(),\ flight_arrive_num, self.seats_sold_home, destination, 'KEF',\ departure_time_back.isoformat(), arrival_time_back.isoformat(),\ plane] # staff not yet added so those values will be empty for i in range(5): info_list.append('empty') new_voyage_str = ','.join(info_list) IO_API().addVoyageToFile(new_voyage_str)
def changeFlightNo(self, voyage_instance): '''Changes flight number of later voyages if a new voyage is added earlier time''' #flight numbers depart_num, arrival_num = voyage_instance.getFlightNumbers() # add 2 to the numbers latter_two_depart = str(int(depart_num[-2:]) + 2) latter_two_arrive = str(int(arrival_num[-2:]) + 2) # zero is removed in int() so it is added back if needed if len(latter_two_depart) == 1: latter_two_depart = '0' + latter_two_depart latter_two_arrive = '0' + latter_two_arrive # new numbers new_depart_num = depart_num[:-2] + latter_two_depart new_arrival_num = arrival_num[:-2] + latter_two_arrive # add new numbers to instance voyage_instance.setDepartNum(new_depart_num) voyage_instance.setArrivalNum(new_arrival_num) # load to file IO_API().changeVoyageFile(voyage_instance)
def getVoyageInDateRange(self, start_datetime, end_datetime): ''' Returns a list of instances of all voyages in a certain date range''' # all voyages voyages_instance_list = IO_API().loadVoyageFromFile() voyages_on_date_list = [] list_of_dates = [] # value to add a day to datetime object delta = datetime.timedelta(days=1) # make a list of all dates between start and end time while start_datetime <= end_datetime: list_of_dates.append(start_datetime.date().isoformat()) start_datetime += delta # change date format to string and check if depart or arrive time is in list of times for voyage in voyages_instance_list: departure_datetime = voyage.getDepartureTime() departure_date = departure_datetime[:10] arrival_datetime = voyage.getArrivalTimeHome() arrival_date = arrival_datetime[:10] if departure_date in list_of_dates: voyages_on_date_list.append(voyage) elif arrival_date in list_of_dates: voyages_on_date_list.append(voyage) return voyages_on_date_list
def assignVoyageID(self): '''Assign a voyage an id based on last voyage in file.''' # Get voyage id of last voyage in file voyage_list = IO_API().loadVoyageFromFile() last_voyageID_str = voyage_list[-1].getVoyageID() new_id_int = int(last_voyageID_str) + 1 return str(new_id_int)
def getAirplaneInsigniaList(self): '''Gets a list of all airplane insignias ''' airplane_insignia_list = [] airplanes = IO_API().loadAirplaneFromFile() for airplane in airplanes: airplane_insignia_list.append(airplane.get_planeInsignia()) return airplane_insignia_list
def getOneVoyage(self, voyage_to_get_ID_str): '''Takes in voyage id and returns the voyage class instance that has that id''' # all voyages voyage_instance_list = IO_API().loadVoyageFromFile() for voyage_instance in voyage_instance_list: # if inputted ID is the same as ID of voyage voyage_ID_str = voyage_instance.getVoyageID() if voyage_ID_str == voyage_to_get_ID_str: return voyage_instance # if no instance is returned return None
def getUpcomingVoyages(self): '''Returns a list of instances of all future voyages''' # all voyages voyage_list = IO_API().loadVoyageFromFile() date_today = datetime.date.today() upcoming_voyages_list = [] for voyage in voyage_list: # datetime of voyage instance voyage_departure_datetime = AirplaneLL( ).revertDatetimeStrtoDatetime(voyage.getDepartureTime()) voyage_departure_date = voyage_departure_datetime.date() # if departure of voyage is in the future if voyage_departure_date >= date_today: upcoming_voyages_list.append(voyage) return upcoming_voyages_list
def loadAirplaneTypes(self): '''Gets a list of airplane types''' return IO_API().loadAirplaneTypes()
def addAirplaneType(self,planeTypeId,manufacturer,model,capacity,\ emptyWeight,maxTakeoffWeight,unitThrust,serviceCeiling,length,height,wingspan): '''Adds an airplane type a file''' return IO_API().addAirplaneType(planeTypeId,manufacturer,model,capacity,\ emptyWeight,maxTakeoffWeight,unitThrust,serviceCeiling,length,height,wingspan)
def addAirplane(self, planeInsignia, planeTypeID, manufacturer, seats): '''Gets information about a new airplane and adds it to the file''' return IO_API().addAirplaneToFile(planeInsignia, planeTypeID, manufacturer, seats)
def getDestination(self): ''' Gets destination from Destination class''' return IO_API().loadDestinationFromFile()
def changeDestinationFile(self, new_dest_instance): ''' Updates Destination file with new information ''' return IO_API().changeDestinationFile(new_dest_instance)
def addDestination(self,new_destination): '''Adds new destination it to destination file''' IO_API().addDestinationToFile(new_destination)
def changeVoyageFile(self, voyage): '''Sends class instance of updated employee into IO layer to read into file''' return IO_API().changeVoyageFile(voyage)