コード例 #1
0
ファイル: excel.py プロジェクト: milanoid/aircon-parser
def convert_to_aircon_format(source_workbook_filename):
    workbook_source = load_workbook(source_workbook_filename)
    sheet = workbook_source.active
    passengers = []

    for i in range(8, sheet.max_row):

        if sheet.cell(i, 3).value is not None:
            passenger = PassengerParser(sheet.cell(i, 3).value)
            passengers.append(
                Passenger(passenger.first_name, passenger.last_name,
                          passenger.gender))
            if passenger.has_infant:
                infant = InfantParser(sheet.cell(i, 4).value)
                passengers.append(
                    Passenger(first_name=infant.first_name,
                              last_name=infant.last_name,
                              gender="?",
                              has_infant=False,
                              is_infant=True))

    header_to_parse = sheet.cell(3, 1).value

    writer = OutputWriter(passengers=passengers,
                          header=HeaderParser(header_to_parse),
                          filename=source_workbook_filename + "aircon.xlsx")
    writer.write_passengers().write_header().save()
コード例 #2
0
    def __getPasstList__(self, time):
        passList = []
        print('time = ' + str(time) + 'sec')
        if (len(self.cache) != 0):
            if (self.cache[0] == time):
                tmp_pass = Passenger(0, 0, 0)
                print(self.cache)
                [tmpt, tmp_pass.ID, tmp_pass.start,
                 tmp_pass.dest] = [int(x) for x in self.cache]
                passList = [tmp_pass]
            else:
                return passList

        for line in self.rdr:
            if int(line[0]) != time:
                self.cache = [int(x) for x in line]
                #print('cache = '+str(self.cache))
                return passList
            else:
                tmp_pass = Passenger(0, 0, 0)
                [tmp_pass.ID, tmp_pass.start,
                 tmp_pass.dest] = [int(x) for x in line]
                passList.append(tmp_pass)

        return passList
コード例 #3
0
    def seatBusiness(self, passenger: Passenger):
        """
        :param passenger: Passenger object that needs a seat
        :return: Integer holding the passenger's assigned seat number
        """

        # If there is not at least 1 open seat, returns -1 to indicate full plane
        for i in range(0, 120):
            if self.seatList[i].isAvailable():
                break
            elif i == 119:
                return -1

        # Variable to hold passenger's preferred seat
        passengerPref = passenger.getPref() - 1

        # If the preferred seat is not occupied...
        if self.seatList[passengerPref].isAvailable() and passengerPref != -1:

            # Adds the passenger to that seat, sets rating equal to 0 since preference is granted
            self.seatList[passengerPref].addPassenger(passenger)
            passenger.rating = 0

            # Passenger appended to instance variable list for passengers
            self.passengerList.append(passenger)
            return passengerPref
        else:

            # Checks the business select seats for availability and adds the passenger to the first that is open
            for i in range(0, 12):
                if self.seatList[i].isAvailable():
                    self.seatList[i].addPassenger(passenger)
                    passenger.rating = 0
                    self.passengerList.append(passenger)
                    return i

                # If none of the business select seats are available...
                elif i == 11:

                    # Checks the rest of the seats on the plane and assigns passenger to the first available seat
                    for j in range(12, 120):
                        if self.seatList[j].isAvailable():
                            self.seatList[j].addPassenger(passenger)

                            # Sets passenger rating, then adds them to the passenger list
                            passenger.rating = -5
                            self.passengerList.append(passenger)
                            return j
コード例 #4
0
	def calculateSurvivalTotalFromTestData(self, database):
		# Inputs::
		#	database -- SQLite3 Database connection object
		# Outputs::
		#	survivals_test_total -- int
		#	deaths_test_total -- int

		conn = database.cursor()
		conn.execute('''SELECT * FROM test_passengers''')
		all_passengers = conn.fetchall()
		for passenger in all_passengers:
			
			test_passenger_class = passenger[1]
			test_passenger_name = passenger[2]
			test_passenger_gender = passenger[3]
			test_passenger_age = passenger[4]
			test_sibling_count = passenger[5]
			test_parent_sibling_count = passenger[6]
			test_fare = passenger[7]
			test_embarked = passenger[8]

			p = Passenger(test_passenger_class, test_passenger_name, test_passenger_gender, test_passenger_age,
				test_sibling_count, test_parent_sibling_count, test_fare, test_embarked)
			if self.didPassengerSurvive(p):
				self.survivals_test_total += 1
			else:
				self.deaths_test_total += 1

		return self.survivals_test_total, self.deaths_test_total
コード例 #5
0
 def Update_Passenger_List(self):
     Passenger_List_temp = []
     self.cursor.execute("SELECT * FROM Passenger")
     for row in self.cursor.fetchall():
         U1 = Passenger(row[0], row[1], row[3], row[2])
         Passenger_List_temp.append(U1)
     self.Passenger_List = Passenger_List_temp
コード例 #6
0
 def play(self, should_stow):
     stepsCounter = StepCounter()
     steps = 0
     stow_times = list(
         np.random.normal(loc=self.stowing_mean,
                          size=self.number_of_passengers)
     ) if should_stow else [0] * self.number_of_passengers
     for i in range(self.number_of_passengers):  #creating passengers
         World.get_instance().add_passenger(
             Passenger(random.choice(self.randomColors), self.destinies[i],
                       i, stow_times[i]))
     while True:
         steps += 1
         stepsCounter.updateSteps(steps)
         for passenger in World.get_instance().passengers:
             passenger.move()
         #end of symulation
         end = True
         for ball in World.get_instance().passengers:
             if ball.position != ball.destiny:
                 end = False
         if end == True:
             World.get_instance().reset()
             stepsCounter.clear()
             World.get_instance().update()
             break
         if self.visualise:
             World.get_instance().update()
             time.sleep(0.2)
     return steps
コード例 #7
0
 def Add_Passenger(self, Name, Pass, Age):
     index = len(self.Passenger_List) + 1
     sql = "INSERT INTO Passenger (UserName, Password, UserID, Age) VALUES (%s,%s,%s,%s)"
     val = (Name, Pass, str(index), str(Age))
     self.cursor.execute(sql, val)
     self.DB.db.commit()
     print("Record inserted successfully into table")
     U1 = Passenger(Name, Pass, Age, index)
     self.Passenger_List.append(U1)
     return index
コード例 #8
0
 def summon_passengers(self):
     for i in range(self.dim_x):
         for j in range(self.dim_y):
             if self.grid[i, j] == -1:
                 continue
             else:
                 roll = random.random()
                 if roll < self.grid[i, j]:
                     self.passengers.append(Passenger((i, j)))
                     self.passengers[-1].set_destination(
                         self.choose_rand_point())
コード例 #9
0
def main(argv):
    ##################################################################################
    # Used only by main for randomization
    # Wasn't sure if y'all wanted me to make another class to house the main stuff
    from Position import Position
    from PassengerRoute import PassengerRoute
    ##################################################################################

    # Random routes
    route1 = PassengerRoute(
        [Position(0, 0, 0),
         Position(0, 0, 0),
         Position(0, 0, 0)])
    print("Route1: ", type(route1))
    route2 = PassengerRoute(
        [Position(0, 0, 0),
         Position(0, 0, 0),
         Position(0, 0, 0)])
    print("Route2: ", type(route2))

    # Random passengers
    passenger1 = Passenger(route1, 0, True, 5.0)
    print("Passenger1: ", type(passenger1))
    passenger2 = Passenger(route1, 0, True, 7.0)
    print("Passenger2: ", type(passenger2))
    passenger3 = Passenger(route2, 0, True, 5.0)
    print("Passenger3: ", type(passenger3))

    # Random walkway
    walkway1 = Walkway(Position(0, 0, 0), 0, 3, 2, 4.0, True)
    print("Walkway1: ", type(walkway1))

    station = Station()
    station.PassengerEnter(passenger1)
    station.PassengerEnter(passenger2)
    station.PassengerEnter(passenger3)
    station.AddWalkway(walkway1)
    print("Station: ", type(station))
コード例 #10
0
ファイル: ElevatorSimulator.py プロジェクト: ido90/Elevators
 def handle_arrival(self):
     a = self.future_arrivals[0]
     if self.debug:
         self.log("Arrive", f"n={a.n:d}\t({a.d:.1f})\t{a.xi:d} -> {a.xf:d}")
     del (self.future_arrivals[0])
     new_passengers = [Passenger(a) for _ in range(a.n)]
     missions = self.manager.handle_arrival(self.sim_time, a.xi, a.xf)
     if self.debug:
         print(missions)
     if -1 in missions:
         for ps in new_passengers:
             ps.assigned_el = missions[-1]
     self.waiting_passengers.extend(new_passengers)
     self.update_missions(missions)
コード例 #11
0
ファイル: Levart.py プロジェクト: dimitra-savvani/Levart
class Levart:
    from sys import exit

    companyInfo = ['261094735', '261094756', '*****@*****.**']
    L = LevartSettings
    T = Traveler
    Pa = PanicButton("48.067906", "12.860655", "Φωτογραφία")
    D = Driver("Aθήνα", "Πάτρα", "12/5/20", "Μεγάλη Βαλίτσα", "Ναι", "4")
    P = Passenger("Aθήνα", "Πάτρα", "12/5/20", "Μεγάλη Βαλίτσα", "Ναι", "4")
    Pe = PendingReservations("Πάτρα", "Αθήνα", "12/12/2020", "Ναι",
                             "Μεγάλη Βαλίτσα", "3")
    k = True
    while k:
        print(
            "Για να μπείτε στις ρυθμίσεις της εφαρμογής πληκτρολογήστε το 1, \n"
        )
        print(
            "Για να μπείτε στις ρυθμίσεις λογαριασμού πληκτρολογήστε το 2, \n")
        print("Για να κάνετε ανάρτηση ταξιδιού πληκτρολογήστε το 3, \n")
        print("Για να κάνετε αναζήτηση ταξιδιού πληκτρολογήστε το 4, \n")
        print(
            "Για να κάνετε επεξεργασία των ταξιδιών που εκκρεμούν πληκτρολογήστε το 5, \n"
        )
        print("Για να ενεργοποιήσετε το Panic Button πληκτρολογήστε το 6, \n")
        print("Για να κάνετε έξοδο από την Levart πληκτρολογήστε το 0.")

        e = input("Παρακαλώ επιλέξτε τι θέλετε να κάνετε:\n")
        if e == "1":
            L.LanguageSettings()
            False
        elif e == "2":
            T.TravelerSettings(T)
            False
        elif e == "3":
            D.FormFill()
            False
        elif e == "4":
            P.FormFill()
            False
        elif e == "5":
            Pe.Form()
            False
        elif e == "6":
            Pa.RequestDangerList()
            False
        elif e == "0":
            exit(0)
        else:
            print("Παρακαλώ επιλέξτε σύμφωνα με τις οδηγίες\n")
コード例 #12
0
def construct_passengers(num_passengers, average_aisle_to_seat_time,
                         sd_aisle_to_seat_time, lower_bound_aisle_to_seat_time,
                         upper_bound_aisle_to_seat_time):
    passengers = []
    aisle_to_seat_times = generate_truncated_normal_distribution(
        num_passengers, average_aisle_to_seat_time, sd_aisle_to_seat_time,
        lower_bound_aisle_to_seat_time, upper_bound_aisle_to_seat_time)
    # display_histogram(aisle_to_seat_times)

    seats = [x for x in range(num_passengers)]
    shuffle(seats)
    for i in range(num_passengers):
        passengers.append(
            Passenger(int(seats[i] / 6), seats[i] % 6, aisle_to_seat_times[i]))
    return passengers
コード例 #13
0
    def generate_people(self, prob):
        #generate random people in building and button press in each floor
        for floor_num in range(1, self.height):
            if np.random.random() < prob and len(
                    self.people_in_floors[floor_num]
            ) < self.max_people_in_floor:
                people = np.random.randint(1, 6)
                if len(self.people_in_floors[floor_num]
                       ) + people > self.max_people_in_floor:
                    people = self.max_people_in_floor - (
                        len(self.people_in_floors[floor_num]) + people)

                tmp_list = []
                for p in range(people):
                    tmp_list.append(Passenger())
                self.people_in_floors[floor_num] += tmp_list
                self.target += people
コード例 #14
0
def createNewTestPassenger():
    if request.method == 'POST':
        request_data_as_json = json.loads(request.data)
        boarding_class = request_data_as_json['boarding_class']
        name = request_data_as_json['name']
        gender = request_data_as_json['gender']
        age = request_data_as_json['age']
        sibling_count = request_data_as_json['sibling_count']
        parent_child_count = request_data_as_json['parent_child_count']
        fare = request_data_as_json['fare']
        embarked = request_data_as_json['embarked']
        p = Passenger(boarding_class, name, gender, age, sibling_count,
                      parent_child_count, fare, embarked)

        output = {}
        output['did_survive'] = model.didPassengerSurvive(p)
        return json.dumps(output)
    else:
        abort(405)
コード例 #15
0
def loadTestPassenger(passenger_id):
    db = sqlite3.connect(config_json['config']['database'])
    conn = db.cursor()
    conn.execute(
        '''SELECT * FROM test_passengers WHERE id = {}'''.format(passenger_id))
    passenger = conn.fetchone()
    db.close()
    if not passenger:
        return None
    id = passenger[0]
    boarding_class = passenger[1]
    name = passenger[2]
    gender = passenger[3]
    age = passenger[4]
    sibling_count = passenger[5]
    parent_child_count = passenger[6]
    fare = passenger[7]
    embarked = passenger[8]
    p = Passenger(boarding_class, name, gender, age, sibling_count,
                  parent_child_count, fare, embarked)
    return p
コード例 #16
0
def createFamily(size: int):
    if size == 3:
        a, b, c = Passenger('a', 'b', 'c',
                            0), Passenger('a', 'b', 'c',
                                          0), Passenger('a', 'b', 'c', 0)
        a.category = "Family"
        b.category = "Family"
        c.category = "Family"
        return a, b, c
    elif size == 4:
        a, b, c, d = Passenger('a', 'b', 'c',
                               0), Passenger('a', 'b', 'c', 0), Passenger(
                                   'a', 'b', 'c',
                                   0), Passenger('a', 'b', 'c', 0)
        a.category = "Family"
        b.category = "Family"
        c.category = "Family"
        d.category = "Family"
        return a, b, c, d
    else:
        a, b, c, d, e = Passenger('a', 'b', 'c', 0), Passenger(
            'a', 'b', 'c',
            0), Passenger('a', 'b', 'c',
                          0), Passenger('a', 'b', 'c',
                                        0), Passenger('a', 'b', 'c', 0)
        a.category = "Family"
        b.category = "Family"
        c.category = "Family"
        d.category = "Family"
        e.category = "Family"
        return a, b, c, d, e
コード例 #17
0
def createTourists():
    x, y = Passenger(a, b, c, d), Passenger(b, a, c, d)
    x.category = "Tourist"
    y.category = "Tourist"
    return x, y
コード例 #18
0
def createBusiness():
    x = Passenger(a, b, c, d)
    x.category = "Business"
    return x
コード例 #19
0
    def familyThree(self, passOne: Passenger, passTwo: Passenger,
                    passThree: Passenger):
        """
        :param passOne: First passenger to be seated
        :param passTwo: Second passenger to be seated
        :param passThree: Third passenger to be seated
        :return: Integer values for seats for each passenger
        """

        # Initializes variables for checking for three available seats throughout the plane
        availableSeatOne = -1
        availableSeatTwo = -1
        availableSeatThree = -1
        checkSeats = 0

        # Loops through to check for any three open seats
        for i in range(12, 120):
            if self.seatList[i].isAvailable():
                checkSeats += 1
                if checkSeats == 1:
                    availableSeatOne = i
                if checkSeats == 2:
                    availableSeatTwo = i
                if checkSeats == 3:
                    availableSeatThree = i
                    break

            # If three can not be found, returns -1 default value
            elif i == 119:
                return -1, -1, -1

        # Checks for three seats grouped together to keep family together (on the left side of the plane)
        # Assigns them to those seats if possible
        for i in range(14, 120, 6):
            if self.seatList[i].isAvailable() and self.seatList[
                    i - 1].isAvailable and self.seatList[i - 2].isAvailable():
                self.seatList[i].addPassenger(passOne)
                self.seatList[i - 1].addPassenger(passTwo)
                self.seatList[i - 2].addPassenger(passThree)

                # Sets ratings for each family member, adds them to the passenger list
                passOne.rating, passTwo.rating, passThree.rating = 15, 15, 15
                self.passengerList.append(passOne)
                self.passengerList.append(passTwo)
                self.passengerList.append(passThree)
                return i, i - 1, i - 2

        # Checks for three seats grouped together (on the right side of the plane)
        # Assigns the passengers to those three seats if possible
        for i in range(15, 120, 6):
            if self.seatList[i].isAvailable() and self.seatList[
                    i + 1].isAvailable and self.seatList[i + 2].isAvailable():
                self.seatList[i].addPassenger(passOne)
                self.seatList[i + 1].addPassenger(passTwo)
                self.seatList[i + 2].addPassenger(passThree)

                # Sets ratings and appends passengers to the passenger list
                passOne.rating, passTwo.rating, passThree.rating = 15, 15, 15
                self.passengerList.append(passOne)
                self.passengerList.append(passTwo)
                self.passengerList.append(passThree)
                return i, i + 1, i + 2

        # If no three grouped seats are found, uses the first three available seats found
        self.seatList[availableSeatOne].addPassenger(passOne)
        self.seatList[availableSeatTwo].addPassenger(passTwo)
        self.seatList[availableSeatThree].addPassenger(passThree)

        # Sets ratings for each passenger and appends them to the passenger list
        passOne.rating, passTwo.rating, passThree.rating = -10, -10, -10
        self.passengerList.append(passOne)
        self.passengerList.append(passTwo)
        self.passengerList.append(passThree)
        return availableSeatOne, availableSeatTwo, availableSeatThree
コード例 #20
0
    def familyFour(self, passOne: Passenger, passTwo: Passenger,
                   passThree: Passenger, passFour: Passenger):
        """
        :param passOne: First passenger
        :param passTwo: Second passenger
        :param passThree: Third passenger
        :param passFour: Fourth passenger
        :return: Integer values for seats where passengers are seated
        """

        # Initializes variables to check plane for four available seats
        availableSeatOne = -1
        availableSeatTwo = -1
        availableSeatThree = -1
        availableSeatFour = -1
        checkSeats = 0

        # Checks plane for four available seats
        for i in range(12, 120):
            if self.seatList[i].isAvailable():
                checkSeats += 1
                if checkSeats == 1:
                    availableSeatOne = i
                if checkSeats == 2:
                    availableSeatTwo = i
                if checkSeats == 3:
                    availableSeatThree = i
                if checkSeats == 4:
                    availableSeatFour = i
                    break

            # If four are not found, returns -1 default values for family not to be seated
            elif i == 119:
                return -1, -1, -1, -1

        # Checks the left side of the plane for three seats plus another aisle seat in front of the other three
        # Assigns these seats if possible
        for i in range(14, 120, 6):
            if self.seatList[i].isAvailable() and self.seatList[
                    i - 1].isAvailable and self.seatList[i - 2].isAvailable():

                # Only if i>=20 so that families are not seated in business select
                if i >= 20 and self.seatList[i - 6].isAvailable():
                    self.seatList[i].addPassenger(passOne)
                    self.seatList[i - 1].addPassenger(passTwo)
                    self.seatList[i - 2].addPassenger(passThree)
                    self.seatList[i - 6].addPassenger(passFour)

                    # Sets ratings and appends passengers to passenger list
                    passOne.rating, passTwo.rating, passThree.rating, passFour.rating = 15, 15, 15, 15
                    self.passengerList.append(passOne)
                    self.passengerList.append(passTwo)
                    self.passengerList.append(passThree)
                    self.passengerList.append(passFour)
                    return i, i - 1, i - 2, i - 6

                # Checks to see if the aisle seat across the aisle is available and uses if so
                elif self.seatList[i + 1].isAvailable():
                    self.seatList[i].addPassenger(passOne)
                    self.seatList[i - 1].addPassenger(passTwo)
                    self.seatList[i - 2].addPassenger(passThree)
                    self.seatList[i + 1].addPassenger(passFour)

                    # Sets passenger ratings and appends passengers to the list
                    passOne.rating, passTwo.rating, passThree.rating, passFour.rating = 15, 15, 15, 15
                    self.passengerList.append(passOne)
                    self.passengerList.append(passTwo)
                    self.passengerList.append(passThree)
                    self.passengerList.append(passFour)
                    return i, i - 1, i - 2, i + 1

                # If not in the last row and the seat behind those three is available, assigns passengers to those four
                elif i != 116 and self.seatList[i + 6].isAvailable():
                    self.seatList[i].addPassenger(passOne)
                    self.seatList[i - 1].addPassenger(passTwo)
                    self.seatList[i - 2].addPassenger(passThree)
                    self.seatList[i + 6].addPassenger(passFour)

                    # Sets ratings and appends passengers to the passenger list
                    passOne.rating, passTwo.rating, passThree.rating, passFour.rating = 15, 15, 15, 15
                    self.passengerList.append(passOne)
                    self.passengerList.append(passTwo)
                    self.passengerList.append(passThree)
                    self.passengerList.append(passFour)
                    return i, i - 1, i - 2, i + 6

        # Loops through to check the right side of the plane for three seats and the seat in front of those three
        # Assigns passengers to those seats if possible
        for i in range(15, 120, 6):
            if self.seatList[i].isAvailable() and self.seatList[
                    i + 1].isAvailable and self.seatList[i + 2].isAvailable():

                # Only if i>=21 so that families are not seated in business select
                if i >= 21 and self.seatList[i - 6].isAvailable():
                    self.seatList[i].addPassenger(passOne)
                    self.seatList[i + 1].addPassenger(passTwo)
                    self.seatList[i + 2].addPassenger(passThree)
                    self.seatList[i - 6].addPassenger(passFour)

                    # Sets passenger ratings and appends passengers to the passenger list
                    passOne.rating, passTwo.rating, passThree.rating, passFour.rating = 15, 15, 15, 15
                    self.passengerList.append(passOne)
                    self.passengerList.append(passTwo)
                    self.passengerList.append(passThree)
                    self.passengerList.append(passFour)
                    return i - 6, i, i + 1, i + 2

                # Checks across the aisle
                elif self.seatList[i - 1].isAvailable():
                    self.seatList[i].addPassenger(passOne)
                    self.seatList[i + 1].addPassenger(passTwo)
                    self.seatList[i + 2].addPassenger(passThree)
                    self.seatList[i - 1].addPassenger(passFour)

                    # Sets passenger ratings and appends the passengers to the list
                    passOne.rating, passTwo.rating, passThree.rating, passFour.rating = 15, 15, 15, 15
                    self.passengerList.append(passOne)
                    self.passengerList.append(passTwo)
                    self.passengerList.append(passThree)
                    self.passengerList.append(passFour)
                    return i - 1, i, i + 1, i + 2

                # If not last row, checks for aisle seat behind original three seats found
                elif i != 117 and self.seatList[i + 6].isAvailable():
                    self.seatList[i].addPassenger(passOne)
                    self.seatList[i + 1].addPassenger(passTwo)
                    self.seatList[i + 2].addPassenger(passThree)
                    self.seatList[i + 6].addPassenger(passFour)

                    # Sets passenger ratings and appends passengers to the passenger list
                    passOne.rating, passTwo.rating, passThree.rating, passFour.rating = 15, 15, 15, 15
                    self.passengerList.append(passOne)
                    self.passengerList.append(passTwo)
                    self.passengerList.append(passThree)
                    self.passengerList.append(passFour)
                    return i, i + 1, i + 2, i + 6

        # If no other four seats are found grouped together, assigns them to the initial four open seats that were found
        # Handles ratings accordingly and appends passengers to the passenger list
        self.seatList[availableSeatOne].addPassenger(passOne)
        self.seatList[availableSeatTwo].addPassenger(passTwo)
        self.seatList[availableSeatThree].addPassenger(passThree)
        self.seatList[availableSeatFour].addPassenger(passFour)
        passOne.rating, passTwo.rating, passThree.rating, passFour.rating = -10, -10, -10, -10
        self.passengerList.append(passOne)
        self.passengerList.append(passTwo)
        self.passengerList.append(passThree)
        self.passengerList.append(passFour)
        return availableSeatOne, availableSeatTwo, availableSeatThree, availableSeatFour
コード例 #21
0
    def familyFive(self, passOne: Passenger, passTwo: Passenger,
                   passThree: Passenger, passFour: Passenger,
                   passFive: Passenger):
        """
        :param passOne: First passenger
        :param passTwo: Second passenger
        :param passThree: Third passenger
        :param passFour: Fourth passenger
        :param passFive: Fifth passenger
        :return: Integer values for seats passengers are assigned to
        """

        # Initializes variables to check for any five available seats
        availableSeatOne = -1
        availableSeatTwo = -1
        availableSeatThree = -1
        availableSeatFour = -1
        availableSeatFive = -1
        checkSeats = 0

        # Loops through the plane to check for any five available seats
        for i in range(12, 120):
            if self.seatList[i].isAvailable():
                checkSeats += 1
                if checkSeats == 1:
                    availableSeatOne = i
                if checkSeats == 2:
                    availableSeatTwo = i
                if checkSeats == 3:
                    availableSeatThree = i
                if checkSeats == 4:
                    availableSeatFour = i
                if checkSeats == 5:
                    availableSeatFive = i
                    break

            # If five seats are not found, returns -1 default values so that family is not seated
            elif i == 119:
                return -1, -1, -1, -1, -1

        # Checks the left side of the plane for five seats grouped together with two aisle seats
        # Assigns those seats if possible
        for i in range(14, 120, 6):
            if self.seatList[i - 1].isAvailable(
            ) and self.seatList[i].isAvailable() and self.seatList[
                    i + 1].isAvailable() and self.seatList[i +
                                                           2].isAvailable():

                # If the left window seat is available, assigns that and four seats to the right
                if self.seatList[i - 2].isAvailable():
                    self.seatList[i - 2].addPassenger(passOne)
                    self.seatList[i - 1].addPassenger(passTwo)
                    self.seatList[i].addPassenger(passThree)
                    self.seatList[i + 1].addPassenger(passFour)
                    self.seatList[i + 2].addPassenger(passFive)

                    # Sets ratings for passengers and appends passengers to the passenger list
                    passOne.rating, passTwo.rating, passThree.rating, passFour.rating, passFive.rating = 15, 15, 15, 15, 15
                    self.passengerList.append(passOne)
                    self.passengerList.append(passTwo)
                    self.passengerList.append(passThree)
                    self.passengerList.append(passFour)
                    self.passengerList.append(passFive)
                    return i - 2, i - 1, i, i + 1, i + 2

                # If the right window seat is available, assigns that seat and the four seats to the left
                elif self.seatList[i + 3].isAvailable():
                    self.seatList[i + 3].addPassenger(passOne)
                    self.seatList[i - 1].addPassenger(passTwo)
                    self.seatList[i].addPassenger(passThree)
                    self.seatList[i + 1].addPassenger(passFour)
                    self.seatList[i + 2].addPassenger(passFive)

                    # Sets passenger ratings and appends passengers to the passenger list
                    passOne.rating, passTwo.rating, passThree.rating, passFour.rating, passFive.rating = 15, 15, 15, 15, 15
                    self.passengerList.append(passOne)
                    self.passengerList.append(passTwo)
                    self.passengerList.append(passThree)
                    self.passengerList.append(passFour)
                    self.passengerList.append(passFive)
                    return i + 3, i - 1, i, i + 1, i + 2

        # Checks three consecutive seats on the left side
        for i in range(14, 120, 6):
            if self.seatList[i - 2].isAvailable() and self.seatList[
                    i - 1].isAvailable() and self.seatList[i].isAvailable():

                # If the middle and aisle seats in front are also available, assigns those five
                if i >= 20 and self.seatList[i - 6].isAvailable(
                ) and self.seatList[i - 7].isAvailable():
                    self.seatList[i - 2].addPassenger(passOne)
                    self.seatList[i - 1].addPassenger(passTwo)
                    self.seatList[i].addPassenger(passThree)
                    self.seatList[i - 6].addPassenger(passFour)
                    self.seatList[i - 7].addPassenger(passFive)

                    # Sets passenger ratings and appends passengers to the passenger list
                    passOne.rating, passTwo.rating, passThree.rating, passFour.rating, passFive.rating = 15, 15, 15, 15, 15
                    self.passengerList.append(passOne)
                    self.passengerList.append(passTwo)
                    self.passengerList.append(passThree)
                    self.passengerList.append(passFour)
                    self.passengerList.append(passFive)
                    return i - 2, i - 1, i, i - 6, i - 7

                # If not the last row, checks for the middle and aisle seats behind and assigns if possible
                elif i != 116 and self.seatList[i + 5].isAvailable(
                ) and self.seatList[i + 6].isAvailable():
                    self.seatList[i - 2].addPassenger(passOne)
                    self.seatList[i - 1].addPassenger(passTwo)
                    self.seatList[i].addPassenger(passThree)
                    self.seatList[i + 5].addPassenger(passFour)
                    self.seatList[i + 6].addPassenger(passFive)

                    # Sets passenger ratings and appends passengers to the passenger list
                    passOne.rating, passTwo.rating, passThree.rating, passFour.rating, passFive.rating = 15, 15, 15, 15, 15
                    self.passengerList.append(passOne)
                    self.passengerList.append(passTwo)
                    self.passengerList.append(passThree)
                    self.passengerList.append(passFour)
                    self.passengerList.append(passFive)
                    return i - 2, i - 1, i, i + 5, i + 6

        # Checks the for three seats on the right side of the plane
        for i in range(15, 120, 6):
            if self.seatList[i + 2].isAvailable() and self.seatList[
                    i + 1].isAvailable() and self.seatList[i].isAvailable():

                # If the middle and aisle seats in front are available, assigns passengers to those five seats
                if i >= 20 and self.seatList[i - 5].isAvailable(
                ) and self.seatList[i - 6].isAvailable():
                    self.seatList[i - 6].addPassenger(passOne)
                    self.seatList[i - 5].addPassenger(passTwo)
                    self.seatList[i].addPassenger(passThree)
                    self.seatList[i + 1].addPassenger(passFour)
                    self.seatList[i + 2].addPassenger(passFive)

                    # Sets passenger ratings and appends passengers to the passenger list
                    passOne.rating, passTwo.rating, passThree.rating, passFour.rating, passFive.rating = 15, 15, 15, 15, 15
                    self.passengerList.append(passOne)
                    self.passengerList.append(passTwo)
                    self.passengerList.append(passThree)
                    self.passengerList.append(passFour)
                    self.passengerList.append(passFive)
                    return i - 6, i - 5, i, i + 1, i + 2

                # If not last row, checks the middle and aisle seats behind and assigns if possible
                elif i != 117 and self.seatList[i + 6].isAvailable(
                ) and self.seatList[i + 7].isAvailable():
                    self.seatList[i].addPassenger(passOne)
                    self.seatList[i + 1].addPassenger(passTwo)
                    self.seatList[i + 2].addPassenger(passThree)
                    self.seatList[i + 6].addPassenger(passFour)
                    self.seatList[i + 7].addPassenger(passFive)

                    # Sets passenger ratings and appends passengers to the passenger list
                    passOne.rating, passTwo.rating, passThree.rating, passFour.rating, passFive.rating = 15, 15, 15, 15, 15
                    self.passengerList.append(passOne)
                    self.passengerList.append(passTwo)
                    self.passengerList.append(passThree)
                    self.passengerList.append(passFour)
                    self.passengerList.append(passFive)
                    return i, i + 1, i + 2, i + 6, i + 7

        # If no other conditions were met, assigns the first five available seats previously found in the plane
        self.seatList[availableSeatOne].addPassenger(passOne)
        self.seatList[availableSeatTwo].addPassenger(passTwo)
        self.seatList[availableSeatThree].addPassenger(passThree)
        self.seatList[availableSeatFour].addPassenger(passFour)
        self.seatList[availableSeatFive].addPassenger(passFive)

        # Sets passenger ratings accordingly and appends the passengers to the list
        passOne.rating, passTwo.rating, passThree.rating, passFour.rating, passFive.rating = -10, -10, -10, -10, -10
        self.passengerList.append(passOne)
        self.passengerList.append(passTwo)
        self.passengerList.append(passThree)
        self.passengerList.append(passFour)
        self.passengerList.append(passFive)
        return availableSeatOne, availableSeatTwo, availableSeatThree, availableSeatFour, availableSeatFive
コード例 #22
0
ファイル: Inheritance.py プロジェクト: rikkouri/project-a
def inheritance_one():
    car = {}

    driver = Passenger()
    driver.setName('Bob')
    driver.setAge(30)
    driver.setSeatPosition(0)
    driver.setIsDriver(True)

    passenger = Passenger()
    passenger.setName('Jim')
    passenger.setAge(40)
    passenger.setSeatPosition(1)

    car['driver'] = driver
    car['passenger'] = passenger

    for key in car:
        occupant = car[key]
        print('Occupant ' + occupant.getName() + (', driving' if occupant.getIsDriver() else ', passenger' ) )
コード例 #23
0
ファイル: Inheritance.py プロジェクト: rikkouri/project-a
def inheritance_two():
    car = {}

    driver = Passenger()
    driver.setName('Bob')
    driver.setAge(30)
    driver.setSeatPosition(0)
    driver.setIsDriver(True)

    passenger = Passenger()
    passenger.setName('Jim')
    passenger.setAge(40)
    passenger.setSeatPosition(1)

    person = Person()
    person.setName('Jack')
    person.setAge(25)

    car['driver'] = driver
    car['passenger'] = passenger
    car['otherpassenger'] = person

    for key in car:
        occupant = car[key]
        try:
            print('Occupant ' + occupant.getName() + (', driving' if occupant.getIsDriver() else ', passenger' ) )
        except AttributeError as ae:
            if isinstance(occupant, Human):
                print('Occupant ' + occupant.getName() )
            else:
                print( 'Error : ' + ae.message)
コード例 #24
0
    def seatingAlgorithmTourist(self, passenger: Passenger,
                                passengerTwo: Passenger):
        """
        :param passenger: First passenger to be seated
        :param passengerTwo: Second passenger to be seated
        :return: Integer value for the seat number where each passenger is seated
        """

        # Initializes preference variables
        passengerPref = passenger.getPref() - 1
        prefTwo = passengerTwo.getPref() - 1

        # Initialize variables to check for available seats
        availableSeatOne = -1
        availableSeatTwo = -1
        checkSeats = 0

        # Checks all non-business seats to make sure there are at least two available seats somewhere in the plane for
        # the tourists and stores the available seat values
        for i in range(12, 120):
            if self.seatList[i].isAvailable():
                checkSeats += 1
                if checkSeats == 1:
                    availableSeatOne = i
                if checkSeats == 2:
                    availableSeatTwo = i
                    break

            # If there are not two seats available, returns -1 default values for issue to be handled in GUI
            elif i == 119:
                return -1, -1

        # Checks to see if passenger preferences can be granted and assigns their seats if so
        if (self.seatList[passengerPref].isAvailable() and
                self.seatList[prefTwo].isAvailable()) and (passengerPref != -1
                                                           and prefTwo != -1):
            self.seatList[passengerPref].addPassenger(passenger)
            self.seatList[prefTwo].addPassenger(passengerTwo)

            # Sets passenger ratings and adds them to the list
            passenger.rating = 10
            passengerTwo.rating = 10
            self.passengerList.append(passenger)
            self.passengerList.append(passengerTwo)
            return passengerPref, prefTwo

        # Checks to see if window/middle seat combinations on the left side of the plane are available
        # If so, assigns passengers to those seats
        for i in range(12, 120, 6):
            if self.seatList[i].isAvailable() and self.seatList[
                    i + 1].isAvailable():
                self.seatList[i].addPassenger(passenger)
                self.seatList[i + 1].addPassenger(passengerTwo)

                # Sets passenger ratings, adds them to the passenger list
                passenger.rating = 15
                passengerTwo.rating = 15
                self.passengerList.append(passenger)
                self.passengerList.append(passengerTwo)
                return i, i + 1

        # Checks the window/middle combinations on the right side of the plane
        # Assigns passengers to those seats if possible
        for j in range(16, 120, 6):
            if self.seatList[j].isAvailable() and self.seatList[
                    j + 1].isAvailable():
                self.seatList[j].addPassenger(passenger)
                self.seatList[j + 1].addPassenger(passengerTwo)

                # Sets passenger ratings and adds them to passenger list
                passenger.rating = 15
                passengerTwo.rating = 15
                self.passengerList.append(passenger)
                self.passengerList.append(passengerTwo)
                return j, j + 1

        # Checks the whole plane for two side-by-side seats to keep the tourists together and assigns those seats
        # if possible
        for i in range(12, 120):
            if self.seatList[i].isAvailable() and self.seatList[
                    i + 1].isAvailable():
                self.seatList[i].addPassenger(passenger)
                self.seatList[i + 1].addPassenger(passengerTwo)

                # Sets passenger ratings and adds them to the passenger list
                passenger.rating = 10
                passengerTwo.rating = 10
                self.passengerList.append(passenger)
                self.passengerList.append(passengerTwo)
                return i, i + 1

        # Assigns passengers to the first two available seats if no other combinations could be found
        # Sets ratings, appends them to passenger list
        self.seatList[availableSeatOne].addPassenger(passenger)
        self.seatList[availableSeatTwo].addPassenger(passengerTwo)
        self.passengerList.append(passenger)
        self.passengerList.append(passengerTwo)
        passenger.rating, passengerTwo.rating = -10, -10
        return availableSeatOne, availableSeatTwo
コード例 #25
0
ファイル: Driver.py プロジェクト: rikkouri/project-a
 def __init__(self, can_drive=["auto"]):
     Passenger.__init__(self)
     self.__can_drive = can_drive
コード例 #26
0
 def testBusiness(self):
     a = AppModel()
     x = Passenger('a', 'b', 'Business', 0)
     b = a.seatBusiness(x)
     self.assertEqual(0, b)
コード例 #27
0
#	read flight info
#
print("*** Listing flight information ***")
ffile = open("flights", "r")
for i in ffile:
    (ffrom, to, number) = i.split(",")
    number = number.strip()
    flights.append(Flight(ffrom, to, number))

print("There are %s flight records in all \n" % len(flights))
print("*** Now listing flights ***")
for i in flights:
    print(i)

print("\n*** opening passenger file ***")
pfile = open("passengers", "r")
print("*** processing passengers  ***")
for i in pfile:
    (fname, lname, flight, seat) = i.split(",")
    seat = seat.strip()
    print("processing", fname, lname)
    for f in flights:
        if (f.flightno() == flight):
            f.add(Passenger(fname, lname, flight, seat))
            break

print("\n\n*** Printing flight logs now ***")
for i in flights:
    print("\nTHIS FLIGHT HAS", i.howmany(), "PASSENGERS")
    i.listing()
コード例 #28
0
 def init_passengers(self):
     passengers = []
     for x in range(self.n_passengers):
         passengers.append(Passenger(x, self))
     return passengers
コード例 #29
0
    def add_passenger(self, user, district, complement):
        passenger = Passenger(user, district, complement)

        if not self.is_full() and not self.contains_user(user):
            self._passengers.append(passenger)
コード例 #30
0
ファイル: Polymorphism.py プロジェクト: rikkouri/project-a
from Car import Car
from Passenger import Passenger
from Person import Person

# Create an instance of Car with the default empty occupant list
mycar = Car( make='Kia', model='Sportage')

# Create the driver and passenger, both instances of Passenger
driver = Passenger()
driver.setName('Paul')
driver.setAge(43)
driver.setIsDriver(True)
driver.setSeatPosition(0)

passenger = Passenger()
passenger.setName('Bob')
passenger.setAge(23)
passenger.setIsDriver(False)
passenger.setSeatPosition(1)

# Create a Person object
person = Person()
person.setName('Charlie')
person.setAge(35)

# Add both our passengers
mycar.addOccupant(driver)
mycar.addOccupant(passenger)

# And then our person. The addOccupant method does not specify an object type.
# We could add some handling inside the Car class to raise an error if