def handleLoginButton(self): try: # Attempt to find the user account in the database sql = '''SELECT loginID from BlueSky.Login WHERE emailAddress = %s AND password = %s''' data = (self.getUsername(), self.getPassword()) count = self.sqlConnection.cursor.execute(sql, data) if count == 0: # Notify the user if the account does not exist msgBox = QMessageBox() msgBox.setWindowTitle("BlueSky Airlines") msgBox.setWindowIcon(QIcon('media/favicon.ico')) msgBox.setIcon(QMessageBox.Critical) msgBox.setText("Invalid username and/or password") msgBox.exec() else: # Store the user's account number to populate the data in the forms loginID = self.sqlConnection.cursor.fetchone() self.account = loginID[0] # Switch to the Passenger window self.passengerWin = Passenger.Passenger(self.sqlConnection, self.passengersLeft, self.passengerNum, self.account, self.flightID, self.flightDates) self.passengerWin.show() self.close() except Exception as e: print(str(e))
def update(self, counter): """updates (position of) all user independent objects""" self.waiting = 0 for l in self.lines: l.update() for s in self.stations: s.update(counter) self.waiting += len(s.passengers) if FREE_PASSENGERS: for p in self.passengers: p.update() if random.random( ) < PROBABILITY_START + counter * PROBABILITY_DIFF: try: newp = Passenger.Passenger(self) except Exception as e: if str(e) == "nopos": if 'passenger' in DEBUG: print "found no pos, exception: ", str(e) else: raise e else: self.passengers.append(newp) self.waiting += len(self.passengers) if self.waiting > MAXWAITING: raise GameOver("to many passengers waiting")
def _handleArrival(self, curTime): prob = randint(0.0, 1.0) if 0.0 <= prob and prob <= self._arriveprob: person = Passenger(self._numPassengers + 1, curTime) self._passengers.enqueue(person) self._numPassengers += 1 print("Time Passenger")
def updatePassengerList(self, num, list): passengerList = [] for i in range(0, len(list)): p = Passenger(list[i][0], list[i][1], list[i][2]) passengerList.append(p) for i in range(0, len(self.__listOfPlane)): if num == self.__listOfPlane[i].getNumber(): self.__listOfPlane[i].setList(passengerList)
def handleGuestButton(self): # Switch to the Passenger window self.passengerWin = Passenger.Passenger(self.sqlConnection, self.passengersLeft, self.passengerNum, self.account, self.flightID, self.flightDates) self.passengerWin.show() self.close()
def read_file(url=""): ELEMENTS_IN_TRAIN = 13 ELEMENTS_IN_TEST = 12 with open(url, newline='') as csv_file: reader = csv.reader(csv_file, delimiter=',',quotechar='|') next(reader) # skip first line (titles) passengers = [] for row in reader: if len(row) == ELEMENTS_IN_TRAIN: # train based on Kaggle's csv. new_passenger = Passenger.Passenger(row[0], row[6], row[7], row[10], row[2], row[5], row[1]) elif len(row) == ELEMENTS_IN_TEST: # test new_passenger = Passenger.Passenger(row[0], row[5], row[6], row[9], row[1], row[4],"") passengers.append(new_passenger) return passengers
def read(path): rVal = [] f = open(path) counter = 0 for line in f: rVal.append(Passenger(line.strip())) counter += 1 print 'DataReader: ' + str(counter) + ' items read.' return rVal
def update(self, counter): if STATION_PASSENGERS: if random.random( ) < PROBABILITY_START + counter * PROBABILITY_DIFF: self.passengers.append(Passenger.Passenger(self)) if len(self.passengers) > MAXWAITING_STATION: raise GameOver("to many passengers waiting at station")
def delete_track(self): """deletes the last track from the line""" if 'track' in DEBUG: print("delete track from line with color: ", self.color) track = self.tracks[-1] l = len(self.tracks) if track.cars and not l == 1: self.game.status = "we can't delete tracks with cars (unless last one)" else: # TODO: can we use some kind of destructor here instead? # delete track at stations starttracks = self.game.get_station(track.startpos).tracks endtracks = self.game.get_station(track.endpos).tracks # print starttracks, endtracks track = self.tracks.pop() # if car is deleted, we handle passengers here if l == 1 and track.cars: if 'track' in DEBUG: print( "special handling of passengers in last track activated!" ) for c in track.cars: offset = float(CARCAPACITY) / 2 + 0.5 for p in c.passengers: offset -= 1 if FREE_PASSENGERS: if 'track' in DEBUG: print("passenger leaves car.") newpass = Passenger.Passenger( self.game, None, c.pos, p.shape) c.shift_passenger(newpass, offset) self.game.passengers.append(newpass) #else: TODO without FREE_PASSENGERS they should go to next station if 'track' in DEBUG: print("passenger with shape ", p.shape, " handled.") # delete semaphores for deleted cars for c in track.cars: if c.has_semaphore: station = self.game.get_station(c.next_stationpos()) station.sem.free() # delete tracks at stations if track in starttracks: starttracks.remove(track) if track in endtracks: endtracks.remove(track) if l == 1: self.game.LINES.append(track.color) del track
def addPlane(self, num, company, numSeats, destination, list): passengerList = [] if len(list) > int(numSeats): raise ValueError else: for i in range(0, len(list)): p = Passenger(list[i][0], list[i][1], list[i][2]) passengerList.append(p) p = Plane(num, company, numSeats, destination, passengerList) self.__listOfPlane.append(p)
def updatePlane(self, num, company, numSeats, destination, list): passengerList = [] for i in range(0, len(self.__listOfPlane)): if num == self.__listOfPlane[i].getNumber(): self.__listOfPlane[i].setCompany(company) self.__listOfPlane[i].setNumberSeats(numSeats) self.__listOfPlane[i].setDestination(destination) for j in range(0, len(list)): p = Passenger(list[j][0], list[j][1], list[j][2]) passengerList.append(p) self.__listOfPlane[i].setList(passengerList)
def bookBusinessTicket(): """ Method to book a business seat :return: None """ # Creating a list for the passengers and seats to generate the tickets passengerList = [] seatList = [] # Grabs the name from the name entry box fullName = businessName.get() # Checks to see the user entered a first AND last name if len(fullName) > 1: # Splits the name into the first and last name for the passenger object first, last = fullName.split(' ') # Grabs the users preference and typecasts it into an integer for list indexing preference = int(businessPref.get()) # Hides the business ticket window businessTicket.withdraw() # Clears both of the entry boxes businessName.delete(0, END) businessPref.delete(0, END) # Creates a new passenger object to be seated newPassenger = Passenger(first, last, 'Business', preference) # Calling the business seating algorithm from the AppModel class businessSeatNumber = app.seatBusiness(newPassenger) # Checks to see if the plane is full or not and returns a dialog box if true if businessSeatNumber == -1: messagebox.showwarning( title='Flight Overbooked', message='Sorry, this flight is currently full.') else: # Appends the passenger and seat to their lists for ticket generation passengerList.append(newPassenger) seatList.append(businessSeatNumber + 1) # Calls the method to generate the user's ticket generateTickets(passengerList, seatList) # Updates both views to show the newly booked seat passengerViewButtons[businessSeatNumber].config(bg='red') managerViewButtons[businessSeatNumber].config(bg='red') # Returns a dialog prompt letting the user know their seat messagebox.showinfo( title='Seat', message=f'Your seat is {businessSeatNumber + 1}') else: # Error message if the user does not enter their first and last name messagebox.showwarning( title='Your Name', message='Please enter your first and last name.')
def bookTouristTicket(): """ Method for booking the tourist's seats :return: None """ # Creating a list for the passengers and seats to generate the tickets passengerList = [] seatList = [] # Grabs the names of both passengers fullName1 = touristName1.get() fullName2 = touristName2.get() # Checks to see both users entered their first and last name if len(fullName1) > 1 and len(fullName2) > 1: # Splits the names into first and last names for passenger object creation first1, last1 = fullName1.split(' ') first2, last2 = fullName2.split(' ') # Grabs the users preferences typecasted to integers for list indexing pref1 = int(touristPref1.get()) pref2 = int(touristPref2.get()) # Checks to see the users did not request the same seat if they enter a preference if (pref1 == pref2) and (pref1 != 0 and pref2 != 0): messagebox.showwarning( title='Seat', message='You must choose two different seats.') elif (pref1 > 12 and pref2 > 12) or (pref1 == 0 and pref2 == 0): # Hides the tourist ticket window and clears all the entry boxes in the window touristTicket.withdraw() touristName1.delete(0, END) touristPref1.delete(0, END) touristName2.delete(0, END) touristPref2.delete(0, END) # Creates two passenger objects for the tourist seating algorithm passenger1 = Passenger(first1, last1, 'Tourist', pref1) passenger2 = Passenger(first2, last2, 'Tourist', pref2) # Saves the two seated passengers touristSeat1, touristSeat2 = app.seatingAlgorithmTourist( passenger1, passenger2) # Checks to see if the plane is full and returns a dialog prompt if true if touristSeat1 == -1 or touristSeat2 == -1: messagebox.showwarning( title='Flight Overbooked', message='Sorry, this flight is currently full.') else: # Appends the passengers and their seats for ticket creation passengerList.append(passenger1) passengerList.append(passenger2) seatList.append(touristSeat1 + 1) seatList.append(touristSeat2 + 1) # Calls method to generate tickets generateTickets(passengerList, seatList) # Updates both button views for the newly seated passengers passengerViewButtons[touristSeat1].config(bg='red') passengerViewButtons[touristSeat2].config(bg='red') managerViewButtons[touristSeat1].config(bg='red') managerViewButtons[touristSeat2].config(bg='red') # Displays a dialog prompt with the user's seats messagebox.showinfo( title='Seats', message= f'Your seats are {touristSeat1 + 1} & {touristSeat2 + 1}') else: # Returns an error if the user requests business seating messagebox.showwarning( title='Invalid Seating', message='Seats 1-12 are reserved for Business class.') else: # Returns an error if the users do not enter their first and last names messagebox.showwarning( title='Your Name', message='Please enter both of your first and last names.')
def updatePassenger(self, num, index, list): for i in range(0, len(self.__listOfPlane)): if num == self.__listOfPlane[i].getNumber(): p = Passenger(list[0], list[1], list[2]) self.__listOfPlane[i].updateToList(index, p)
print(' # exit') to_do = input('what do you want to ?').lower().strip() while True: if to_do == 'list all flights': print(flight1.flight_ID, flight1.destination) print(flight2.flight_ID, flight2.destination) print(flight3.flight_ID, flight3.destination) to_do = input('do you want to do something else?').lower().strip() elif to_do == 'add a passenger': passname = input('what is the passenger name?') passpassport = input('what is the passenger passport number?') passemail = input('what is the passengers email?') passenger = Passenger(passname, passemail, passengerid, passpassport) print(f'your passenger id is {passengerid}') passengerlist.append(passenger.passid) passengerlist.append(passenger.name) passengerlist.append('////') passengerid = passengerid + 1 to_do = input('do you want to do something else?').lower().strip() elif to_do == 'list all passengers': print(passengerlist) to_do = input('do you want to do something else?').lower().strip() elif to_do == 'add a passenger to a flight': passid = int(input('what is the ID number of the passenger') ) # use my new add to passenger list method
def __addPassenger(self, command): passenger = Passenger(self.passengerCount, int(command[2]), int(command[4:])) self.passengerCount += 1 self.stations[int(command[2]) - 1].passengers.enQueue(passenger)
def bookFamilyTicket(): """ Method for seating the family category :return: None """ # Grabs the names from the entry boxes fullname1 = familyName1.get() fullname2 = familyName2.get() fullname3 = familyName3.get() fullname4 = familyName4.get() fullname5 = familyName5.get() # Checks to see if the minimum number of family members have filled in their first and last name if len(fullname1) > 1 and len(fullname2) > 1 and len(fullname3) > 1: # Creates lists for ticket generation passengerList = [] seatList = [] # Splits the full names into their first and last names first1, last1 = fullname1.split(' ') first2, last2 = fullname2.split(' ') first3, last3 = fullname3.split(' ') # Withdraws the family ticket window and clears all the entry boxes familyTicket.withdraw() familyName1.delete(0, END) familyName2.delete(0, END) familyName3.delete(0, END) familyName4.delete(0, END) familyName5.delete(0, END) # Creates three passenger objects for the first three entry boxes passenger1 = Passenger(first1, last1, 'Family', 0) passenger2 = Passenger(first2, last2, 'Family', 0) passenger3 = Passenger(first3, last3, 'Family', 0) # Checks to see if a fourth family member is added if len(fullname4) > 1: # Splits the full name into the first and last name and creates a new passenger object first4, last4 = fullname4.split(' ') passenger4 = Passenger(first4, last4, 'Family', 0) # Checks to see if a fifth family member is added if len(fullname5) > 1: # Splits the full name into the first and last name and creates a family object first5, last5 = fullname5.split(' ') passenger5 = Passenger(first5, last5, 'Family', 0) # Runs the five member family algorithm for seats seat1, seat2, seat3, seat4, seat5 = app.familyFive( passenger1, passenger2, passenger3, passenger4, passenger5) # Checks to see if the plane is full and returns a prompt if true if seat1 == -1 or seat2 == -1 or seat3 == -1 or seat4 == -1 or seat5 == -1: messagebox.showwarning( title='Flight Overbooked', message='Sorry, this flight is currently full.') else: # Appends all five members and their seats to their lists for ticket generation passengerList.append(passenger1) passengerList.append(passenger2) passengerList.append(passenger3) passengerList.append(passenger4) passengerList.append(passenger5) seatList.append(seat1 + 1) seatList.append(seat2 + 1) seatList.append(seat3 + 1) seatList.append(seat4 + 1) seatList.append(seat5 + 1) # Calls method for generating the tickets generateTickets(passengerList, seatList) # Updates each view's buttons to show the newly booked seats passengerViewButtons[seat1].config(bg='red') passengerViewButtons[seat2].config(bg='red') passengerViewButtons[seat3].config(bg='red') passengerViewButtons[seat4].config(bg='red') passengerViewButtons[seat5].config(bg='red') managerViewButtons[seat1].config(bg='red') managerViewButtons[seat2].config(bg='red') managerViewButtons[seat3].config(bg='red') managerViewButtons[seat4].config(bg='red') managerViewButtons[seat5].config(bg='red') # Returns a dialog prompt with the family's seats messagebox.showinfo( title='Seats', message= f'Your seats are {seat1 + 1}, {seat2 + 1}, {seat3 + 1}, {seat4 + 1}, & {seat5 + 1}' ) else: # Runs the four member algorithm seat3, seat2, seat1, seat4 = app.familyFour( passenger1, passenger2, passenger3, passenger4) # Checks to see if the plane is full and returns a error if true if seat1 == -1 or seat2 == -1 or seat3 == -1 or seat4 == -1: messagebox.showwarning( title='Flight Overbooked', message='Sorry, this flight is currently full.') else: # Appends all four members and their seats to their lists for ticket generation passengerList.append(passenger1) passengerList.append(passenger2) passengerList.append(passenger3) passengerList.append(passenger4) seatList.append(seat1 + 1) seatList.append(seat2 + 1) seatList.append(seat3 + 1) seatList.append(seat4 + 1) # Calls method for generating tickets generateTickets(passengerList, seatList) # Updates the plane views to show the newly booked seats passengerViewButtons[seat1].config(bg='red') passengerViewButtons[seat2].config(bg='red') passengerViewButtons[seat3].config(bg='red') passengerViewButtons[seat4].config(bg='red') managerViewButtons[seat1].config(bg='red') managerViewButtons[seat2].config(bg='red') managerViewButtons[seat3].config(bg='red') managerViewButtons[seat4].config(bg='red') # Returns dialog box with the family's seats messagebox.showinfo( title='Seats', message= f'Your seats are {seat1 + 1}, {seat2 + 1}, {seat3 + 1}, & {seat4 + 1}' ) else: # Runs the three member algorithm seat3, seat2, seat1 = app.familyThree(passenger1, passenger2, passenger3) # Checks to see if the plane is full and returns an error if so if seat1 == -1 or seat2 == -1 or seat3 == -1: messagebox.showwarning( title='Flight Overbooked', message='Sorry, this flight is currently full.') else: # Appends the passengers and their seats to the lists for ticket generation passengerList.append(passenger1) passengerList.append(passenger2) passengerList.append(passenger3) seatList.append(seat1 + 1) seatList.append(seat2 + 1) seatList.append(seat3 + 1) # Calls method for generating tickets generateTickets(passengerList, seatList) # Updates plane views to show newly booked seats passengerViewButtons[seat1].config(bg='red') passengerViewButtons[seat2].config(bg='red') passengerViewButtons[seat3].config(bg='red') managerViewButtons[seat1].config(bg='red') managerViewButtons[seat2].config(bg='red') managerViewButtons[seat3].config(bg='red') # Returns dialog box with the family's seats messagebox.showinfo( title='Seats', message= f'Your seats are {seat1 + 1}, {seat2 + 1}, & {seat3 + 1}') else: # Returns an error if any of the family members do not enter their first and last name messagebox.showwarning( title='Your Name', message='Please enter all of your first and last names.')