def getDayVoyages(self): #fetch Voyage info voyagePackage = IOAPI().opener(self.dataFiles["UPCOMING_FLIGHTS_FILE"]) #ask for datetime from user user_input = InputHandler().dateOnly() user_date = DateUtil(user_input).date schedule_list = [] #goes through all flights, finds flights of the chosen date and compiles a list of tuples with the SSN and 3 letter arrival for line in voyagePackage: departure = DateUtil(line['departure']).date if user_date == departure: schedule_list.append(line) return self.printData(schedule_list, header="Voyages of chosen day:")
def selectDepartureTime(self, questionDate: str, questionTime: str, errorMessage: str): """Prompts the user to input date and time""" #ERROR Check if there is any departing from Iceland at this dateTime departingFlights_list = IOAPI().opener( self.dataFiles["UPCOMING_FLIGHTS_FILE"]) departingOnDate_list = [] selectedDate = InputHandler().dateOnly(questionDate) # just collect the flights departing on same day for flight in departingFlights_list: if flight['departingFrom'] == self.__departingFrom: if flight['departure'][:10] == selectedDate[:10]: departingOnDate_list.append(flight) # print the list of flights departing on that day headerDepartingOnDate_str = "List of other flights departing on same day" if len(departingOnDate_list) == 0: DisplayScreen().printText(["No departing flights"], headerDepartingOnDate_str) else: DisplayScreen().printList(departingOnDate_list, headerDepartingOnDate_str) #ask the user for a time before entering the loop selectedDepartureTime_str = InputHandler().timeOnly(questionTime) while True: #check through list of flights and check their departure time if len(departingOnDate_list) != 0: for flight in departingOnDate_list: flightDeparture = flight['departure'] timeCheckDate = DateUtil().updateTime( selectedDate, selectedDepartureTime_str) #if airport was occupied, then print the list again and ask for time input if flightDeparture == timeCheckDate: DisplayScreen().printList( departingOnDate_list, "Departure time not available, please try again") selectedDepartureTime_str = InputHandler().timeOnly( "Please select a different time, " + questionTime) continue else: #if everything is alright, then return the dateTime return timeCheckDate else: return DateUtil().updateTime(selectedDate, selectedDepartureTime_str)
def getWorking(self): #fetch employee info employeePackage = IOAPI().opener(self.dataFiles['CREW_FILE']) #fetch Voyage info voyagePackage = IOAPI().opener(self.dataFiles["UPCOMING_FLIGHTS_FILE"]) #fetch destination info destinationPackage = IOAPI().opener( self.dataFiles['DESTINATIONS_FILE']) #ask for datetime from user user_input = InputHandler().dateOnly() user_date = DateUtil(user_input).date combo_list = [] #goes through all flights, finds flights of the chosen date and compiles a list of tuples with the SSN and 3 letter arrival for line in voyagePackage: departure = DateUtil(line['departure']).date if user_date == departure: if line['captain'] != "" and line['captain'] not in combo_list: combo_list.append((line['captain'], line["arrivingAt"])) if line['copilot'] != "" and line['copilot'] not in combo_list: combo_list.append((line['copilot'], line["arrivingAt"])) if line['fsm'] != "" and line['fsm'] not in combo_list: combo_list.append((line['fsm'], line["arrivingAt"])) if line['fa1'] != "" and line['fa1'] not in combo_list: combo_list.append((line['fa1'], line["arrivingAt"])) if line['fa2'] != "" and line['fa2'] not in combo_list: combo_list.append((line['fa2'], line["arrivingAt"])) if len(combo_list) == 0: self.printData([], "No employee is working on the specified day") return False working_list = [] #finds the employees who were on the flights and finds the destination name based on the 3 letter arrival for employee in employeePackage: for x in combo_list: if x[0] == employee['ssn']: #puts all the info together in one dict and adds to the list temp_dict = employee dest_dict = next( (item for item in destinationPackage if item["id"] == x[1]), None) if dest_dict: temp_dict["destination"] = dest_dict["destination"] working_list.append(temp_dict) else: break return self.printData( working_list, header="employees working and their destination:")
def findDaysDuration(departureFlight, arrivalFlight): """Finds the days that the voyage will cover""" departureDate = departureFlight["departure"] returnDate = arrivalFlight["arrival"] departureDate_obj = DateUtil(departureDate).createObject() returnDate_obj = departureDate_obj + datetime.timedelta(days=1) compiledDates_list = [departureDate, returnDate_obj.isoformat()] return compiledDates_list
def getWeekWork(self): #fetch employee info employeePackage = IOAPI().opener(self.dataFiles['CREW_FILE']) #fetch Voyage info voyagePackage = IOAPI().opener(self.dataFiles["UPCOMING_FLIGHTS_FILE"]) #ask for SSN user_ssn = InputHandler().ssn( "Please input the SSN of the Employee you want a schedule of: ") for employee in employeePackage: if user_ssn == employee['ssn']: ssn_exists = True if ssn_exists: pass else: print("An employee with that SSN does not exist") return False #ask for datetime from user refDate_str = InputHandler().dateOnly("Input starting date of week: ") refDate_obj = DateUtil(refDate_str).createObject() #collect the days of a week checkWeek_list = [] checkWeek_list.append(refDate_str) #@ts-ignore for day in range(7): refDate_obj = refDate_obj + datetime.timedelta(days=1) checkWeek_list.append(refDate_obj.isoformat()) schedule_list = [] #find all the flights that are in the range of the week and check those flights for the employee ssn and add the flight to the schedule if so for flight in voyagePackage: departure = DateUtil(flight['departure']).date for date in checkWeek_list: if date[:10] == departure: if user_ssn == flight['captain'] or user_ssn == flight[ 'copilot'] or user_ssn == flight[ 'fsm'] or user_ssn == flight[ 'fa1'] or user_ssn == flight['fa2']: schedule_list.append(flight) return self.printData(schedule_list, header="Chosen employee work schedule:")
def calculateArrival(self, departure: str, flightTime: str): """Calculates arrival time, requires the datetime of departure and the flightTime""" departureTime = DateUtil(departure).createObject() #split the flighttime into parts hours, minutes, seconds = map(int, flightTime.split(':')) #get the arrivaltime arrival = departureTime + datetime.timedelta( hours=hours, minutes=minutes, seconds=seconds) return str(arrival.isoformat())
def getWeekVoyages(self): #fetch Voyage info voyagePackage = IOAPI().opener(self.dataFiles["UPCOMING_FLIGHTS_FILE"]) #ask for datetime from user refDate_str = InputHandler().dateOnly("Input starting date of week: ") refDate_obj = DateUtil(refDate_str).createObject() #collect the days of a week checkWeek_list = [] checkWeek_list.append(refDate_str) #@ts-ignore for day in range(7): refDate_obj = refDate_obj + datetime.timedelta(days=1) checkWeek_list.append(refDate_obj.isoformat()) schedule_list = [] #find all the flights that are in the range of the week for flight in voyagePackage: departure = DateUtil(flight['departure']).date for date in checkWeek_list: if date[:10] == departure: schedule_list.append(flight) return self.printData(schedule_list, header="Voyages of chosen week:")
def getAway(self, date: str = "", noPrint: bool = False): #fetch employee info employeePackage = IOAPI().opener(self.dataFiles['CREW_FILE']) #fetch Voyage info voyagePackage = IOAPI().opener(self.dataFiles["UPCOMING_FLIGHTS_FILE"]) #if no date is given in arguments, then ask for input if date == "": #ask for datetime from user user_input = InputHandler().dateOnly() else: user_input = date user_date = DateUtil(user_input).date ssn_list = [] #goes through all flights, finds flights at the chosen date and compiles a unique list of SSN for line in voyagePackage: departure = DateUtil(line['departure']).date if user_date == departure: if line['captain'] != "" and line['captain'] not in ssn_list: ssn_list.append(line['captain']) if line['copilot'] != "" and line['copilot'] not in ssn_list: ssn_list.append(line['copilot']) if line['fsm'] != "" and line['fsm'] not in ssn_list: ssn_list.append(line['fsm']) if line['fa1'] != "" and line['fa1'] not in ssn_list: ssn_list.append(line['fa1']) if line['fa2'] != "" and line['fa2'] not in ssn_list: ssn_list.append(line['fa2']) #everybody who isn't working is everyone who isn't in the ssn_list away_list = [] for employee in employeePackage: if employee['ssn'] not in ssn_list: away_list.append(employee) if noPrint != True: self.printData(away_list, header="Employees not working:") return away_list
def dateTime(self, questionDate:str = "Input a date (DD/MM/YYYY): ", questionTime:str ="Input time (HH:MM): "): """Input is date and time""" print("") date = self.dateOnly(questionDate) print("") time = self.timeOnly(questionTime) print("") if date and time: #create a datetime year, month, day = map(int,DateUtil(date).date.split('-')) hour,minute,second = map(int,time.split(':')) newDate = datetime.datetime(year,month,day,hour,minute,second).isoformat() return str(newDate) else: #if either date or time returned false return False
def createVoyage(self): '''Create a new voyage, voyage contains of two flights with different flight numbers. have to get destination that we already fly to, date that the voyage will occur and than when the flight back home to Iceland is ''' # Get and print list of available destinations destination_list = IOAPI().opener(self.dataFiles["DESTINATIONS_FILE"]) DisplayScreen().printOptions(destination_list, "destinations") # Seect a destination destination_str = InputHandler().numChoices( len(destination_list), "Select index of destination for this voyage: ") self.__destination = destination_list[int(destination_str) - 1] # Departure messages for inputHandler inputDepartureDate_str = "Enter departure date from Iceland to {} (DD/MM/YYYY): ".format( self.__destination["destination"]) inputDepartureTime_str = "Enter departure time (HH:MM): " ErrorDepartureTime_str = "ERROR: Airport is occupied at selected time \nplease input a new departure time: " # get the departure time from inputHandler self.__departure = self.selectDepartureTime(inputDepartureDate_str, inputDepartureTime_str, ErrorDepartureTime_str) # Find a date and time for arrival departingDate_obj = DateUtil(self.__departure).createObject() flightDuration = self.__destination["flightDuration"].split(":") durationHours = flightDuration[0] durationMinutes = flightDuration[1] minReturnDate_obj = departingDate_obj + datetime.timedelta( hours=int(durationHours), minutes=int(durationMinutes)) minReturnDate_util = DateUtil(minReturnDate_obj.isoformat()) inputArrivalDate_str = "Enter return date to Iceland from {} (DD/MM/YYYY): ".format( self.__destination["destination"]) inputArrivalTime_str = "Enter time for return (HH:MM): " while True: try: returnDate_str = InputHandler().dateTime( inputArrivalDate_str, inputArrivalTime_str) returnDate_obj = DateUtil(returnDate_str).createObject() #return date/time needs to be greater than departure date/time if returnDate_obj > departingDate_obj: #return needs to be at least departure + flightduration if returnDate_obj >= minReturnDate_obj: self.__return = returnDate_str break raise Exception else: raise Exception except Exception: returnDate_str = "{}/{}/{}".format(minReturnDate_util.day, minReturnDate_util.month, minReturnDate_util.year) errorMessage_list = [ "Return needs to be at least {}h and {}m after departure". format(durationHours, durationMinutes), "That would be at least {} and {}".format( returnDate_str, minReturnDate_util.time) ] DisplayScreen().printText( errorMessage_list, "Choose a date and time for return flight from {}".format( self.__destination["destination"])) # Find available aircraft self.selectAircraft() # print all the info about the voyage for the user and ask if the info is correct, if not than edit info, else save to data # Make a flightnumber for both flights, the flight numbers are different depending on the destination and how many other flights have gone to the destination on this same day self.createFlights()