def update(self, insert_time): data = da.read_queue_car_time(insert_time) data_n = da.read_notice_car_time(insert_time) for i in range(len(data)): self.car_queue[data.iloc[i, 1]] = Car(data.ix[i].tolist()) for i in range(len(data_n)): self.car_notice[data.iloc[i, 1]] = Car(data_n.ix[i].tolist())
def rent(): count_cars = int(input("How many cars do you want to rent: ")) client_name = input("Enter client name: ") for i in Human: if person.get_name(i) == client_name: if count_cars > 3: while count_cars > 0: choose_car = input( "enter the registration number of the car you want: ") for j in Vehicle: if car.get_regnum(j) == choose_car: time = input( "Choose between 'hours', a 'day' or a 'week': " ) if time == "hours": rent_time = int( input("How many hours(enter number): ")) total_price = (car.get_pphour(j) * rent_time) elif time == "day": total_price = car.price_per_day() elif time == "week": total_price = car.price_per_week() discount = discount + (total_price * 0.3) rented = car.get_car(j), person.get_clients(i) Rent_cars.append(rented) Vehicle.remove(j) count_cars = count_cars - 1 else: print("no such car") Rent_cars.extend(discount) else: choose_car = input( "enter the registration number of the car you want: ") for j in Vehicle: if car.get_regnum(j) == choose_car: time = input( "Choose between 'hours', a 'day' or a 'week': ") if time == "hours": rent_time = int( input("How many hours(enter number): ")) total_price = (car.get_pphour(j) * rent_time) elif time == "day": total_price = car.price_per_day() elif time == "week": total_price = car.price_per_week() rented = car.get_car(j), person.get_clients( i), total_price Rent_cars.append(rented) Vehicle.remove(j)
def factory_data_init(self): # 厂内车辆 {TASK_ID:car} factory_car = dict() # 厂内各仓库的车辆 {仓库代码:[TASK_ID]} warehouse_car = dict() # 厂内各品种车辆 {品种代码:[TASK_ID]} kind_car = dict() # 厂内各车的预计结束 {TASK_ID:时间} car_predict_finish_time = dict() # 读取数据 data = da.read_factory_car_time(self.__init_time__) # 初始化factory_car for i in range(len(data)): factory_car[data.iloc[i, 1]] = Car(data.ix[i].tolist()) for i in factory_car.keys(): # 初始化warehouse_car if factory_car[i].warehouse_code not in warehouse_car.keys(): warehouse_car[factory_car[i].warehouse_code] = [ factory_car[i].task_id ] else: warehouse_car[factory_car[i].warehouse_code].append( factory_car[i].task_id) # 初始化kind_car if factory_car[i].kind_code not in kind_car.keys(): kind_car[factory_car[i].kind_code] = [factory_car[i].task_id] else: kind_car[factory_car[i].kind_code].append( factory_car[i].task_id) # 初始化car_predict_finish_time = 进厂时间 + 花费时间 car_predict_finish_time[ factory_car[i].task_id] = tool.cal_predict_finish_time( factory_car[i].entry_time, factory_car[i].cost) return Factory(da.read_plan_day(self.__init_day__), warehouse_car, kind_car, car_predict_finish_time, factory_car)
def ConfigCars(levels): print(f"please enter the number of cars") carsc = open("CarConfig.uma" , "w") NrOCars = input() NrOCars = int(NrOCars) carsc.write(f"{NrOCars}") #Configures car properties into object and config file level = ["all"] cars = [] calls = [] for i in range(0,NrOCars): cars.append(Car(0,level, calls, 0.0 , i , "st")) print(f"does the car nr. {i} stop at all the floors?(y/n)") temp = input() temp.lower() if temp != "y": cars[i].erase_floors() for m in range(0, len(levels)): print(f"does the car nr. {i} stop at floor {m}") temp1 = input() temp1.lower() if temp1 == "y": cars[i].append_floor("exclusive",True) else: cars[i].append_floor("exclusive", False) else: carsc.write(f"\nall") continue carsc.write(f"\n{cars[i].floors}") carsc.close() return cars
def verifyBooking(self, booking_ID): ''' This function is used to verify the booking of the customer when they scan/input the booking_ID at the entrance. If the booing is valid, the car licence plate is scanned. All the data related to the booking is stored in the dictionary Bookings :param booking_ID: The ID scanned/inserted by the customer at the entrance :return: car_Licence_Plate_Number scanned at the entrance once the booking is verified ''' b = Booking(booking_ID) booking_Ledger = b.get_Bookings() if booking_ID in booking_Ledger: print('Your booking is valid.') c = Car(booking_ID) licence_number = c.licence_plate_number() b.vehicle_Entered(booking_ID, licence_number) print('A car entered with license number:', booking_Ledger[booking_ID]['car_Licence_Plate_Number']) return licence_number
def initCars(levels): cars =[] cr = open("CarConfig.uma", "r") numberOCars =int(cr.readline(-1)) #Reads data from config for i in range(0,numberOCars): calls = [] currentCar = cr.readline(-1) if currentCar == "all": cars.append(Car(0, ["all"], calls, 0.0, i , "st")) else: currentCar = currentCar.strip("[") currentCar = currentCar[:len(currentCar)-2] currentCar = currentCar.strip("\n") currentCar = currentCar.split(",") levels = [] for level in currentCar: levels.append(eval(level)) cars.append(Car(0, levels, calls, 0.0, i , "st")) return cars
def release_cars(self): i = 0 # Place cars on the road at a specified rate while i < self.num_cars: for j in range(0, self.cars_per_sec): i += 1 self.StopLightQueue.put(Car(i, self.left, self.right)) if i >= self.num_cars: break # Wait 1 sec after each batch of cars to accomplish cars/sec time.sleep(1/self.time_scale_factor) self.EventQueue.get()
def buy(self, model_name, model_description, register_id, price, carList, index): if (self.__balance >= price): # Adds a car to the dealer's inventory, if the balance is enough to purchase a car self.__inventory.append( Car(model_name, model_description, register_id, price)) del carList[index] # Balance will be decremented accordingly self.__balance -= price else: input( "Unfortunatley, you don't have enough money to purchase this car.\n" + "Press enter to go back to the list of available cars.")
from Cars import Car from Drivers import Driver driver_1 = Driver('Ben', 'Ellis', 21) driver_2 = Driver('Louis', 'Smith', 22) driver_3 = Driver('Alex', 'Chatfield', 22) driver_4 = Driver('Louise', 'Ellis', 55) car_1 = Car('VW', 'Polo', '1L', 3, 'Hatchback', '60mpg', '100mph', '59bhp', 'Petrol') car_2 = Car('VW', 'Golf', '1.4L', 5, 'Hatchback', '40mpg', '127mph', '138bhp', 'Petrol') car_3 = Car('BMW', '2 Series Active Tourer', '2L', 5, 'Hatchback', '50mpg', '130mph', '200bhp', 'Diesel') car_4 = Car('BMW', '3 Series', '3L', 5, 'Saloon', '23mpg', '155mph', '255bhp', 'Petrol') car_5 = Car('BMW', '6 Series', '4.8L', 3, 'Coupe', '18mpg', '155mph', '360bhp', 'Petrol') car_6 = Car('Jaguar', 'XKR', '5L', 3, 'Coupe', '15mpg', '155mph', '500bhp', 'Petrol') car_7 = Car('Citroen', 'C1', '1L', 3, 'Hatchback', '60mpg', '90mph', '40bhp', 'Petrol') car_8 = Car('Audi', 'A5', '3.2L', 3, 'Coupe', '30mpg', '155mph', '270bhp', 'Petrol') vw = [car_1.make_and_model(), car_2.make_and_model()] bmw = [car_3.make_and_model(), car_4.make_and_model(), car_5.make_and_model()] jaguar = [car_6.make_and_model()] citroen = [car_7.make_and_model()] Audi = [car_8.make_and_model()]
#imports from Cars import Car from Dealership import Dealership my_dealership = Dealership() #create cars my_car_one = Car("Model T", 1908) my_car_two = Car("Phantom", 2020, "Rolls Royce") #add car to delership my_dealership.add_car(my_car_one) my_dealership.add_car(my_car_two) num = 1 print("\n====DEALERSHIP====") for car in my_dealership: print(f"----Car {num}----") print(f"Make: {car.make}") print(f"Model: {car.model}") print(f"Year: {car.year}") car.go("Fast") car.stop() car.go("Fast") num += 1 print("\n====MY CARS====") print(my_car_two) print(my_car_one) if my_car_one == my_car_two:
def find_kind_early_finish_car(self, car, kind_car, car_predict_finish_time): """ 找出厂内+厂外该车辆品种最早结束车辆的预计结束时间 :param car: 当前来的车辆 :return: """ early_time = '9999-99-99 99:99:99' if car.kind_code == 'other': return early_time else: for i in kind_car[car.kind_code]: if car_predict_finish_time[i] < early_time: early_time = car_predict_finish_time[i] return early_time m = Main() a = da.read_test_car_time('2019-07-21 00:00:00', '2019-07-21 01:00:00') for i in range(len(a)): car = Car(a.ix[i].tolist()) # 厂外情况更新 m.queue.update(car.queue_start_time) # 厂内情况更新,得到一个实时的厂内数据 m.factory.update(car.queue_start_time) m.queue.insert(car, car.queue_start_time) print(car.task_id, car.wait_time)
def list_cars(): for i in Vehicle: car.print_car(i)
from Cars import Car my_new_car = Car('audi', 'a4', 2016) print my_new_car.get_descriptive_name() my_new_car.odometer_reading = 23 my_new_car.read_odometer()
def main(): # CarList.txt contains total of 18 used cars for dealer to purchase within his budget of 50,000EUR filename = input( "Enter the name of a file ('CarList.txt' for this project): \n") try: file = open(filename, "r") linelist = file.readlines() del linelist[0] file.close() carList = [] for line in linelist: line = line.rstrip() split = line.split(", ") carList.append(Car(split[0], split[1], split[2], split[3])) dealerName = input("You are a car dealer. Please type your name: \n") dealer = Dealer(dealerName) print( "\nHello {}. You are a car dealer and have a budget of 50,000EUR.\n" .format(dealerName) + "First, you can purchase cars to sell from the market within your budget.\n" ) print("There are three options you can select as a dealer.") choice = 0 while (choice != "3"): choice = input( "[1] Check available cars in the market and make a purchase.\n" + "[2] Check your inventory of purchased cars.\n" + "[3] Quit (Only when you finished purchasing cars)\n" + "\nChoose the number and press enter: ") if choice == "1": nextChoice = "" # QUIT : exit program. "Quit" and "quit" both are accepted while nextChoice != "Quit" or nextChoice != "quit": print("Available cars in the market at this moment:\n") printCarList(carList) nextChoice = input( "If you want to purchase a car, choose the number and press enter...\n" + "or to go back to the list of options, please type '{}' and press enter: " .format("Quit")) if nextChoice.lower() == "quit": print("Going back to the list of options...") break elif isInt(nextChoice) and int(nextChoice) in range( 1, len(carList) + 1): index = int(nextChoice) - 1 # BUY <register id> "<model description>" <price> : Buys a car with given register number and model desription at a given price, and adds it to the dealer invetory. dealer.buy(carList[index].get_model_name(), carList[index].get_description(), carList[index].get_id(), carList[index].get_price(), carList, index) else: input( "Wrong input. Please choose a index number of available car or 'Quit' to go back.\n" ) elif choice == "2": dealer.inv() input("Press enter to go back to the list of options.") elif choice == "3": input( "Now dealer's part is over. Press enter to move on to the buyer's part." ) else: print( "\nYou typed invalid number. Please choose a number between 1 to 3." ) input("Press enter to go back to the list of options.") # Continue with the Buyer's part - Implement OFFER / SELL / HISTORY / QUIT buyerList = [] print( "There are five buyers in this simulation, please type their names." ) countText = ["first", "second", "third", "fourth", "last"] textCounter = 0 for counter in range(1, 6): name = input( "Please type your {} buyer name for the bidding process:\n". format(countText[textCounter])) buyerList.append(Buyer(name)) textCounter += 1 input( "Buyers' names are registered successfully. Press enter to continue." ) auctionList = {} for buyer in buyerList: print( "\nHello {}. Now, it's your turn.\nYou can make an offer to a car from the dealer's inventory." .format(buyer.get_name())) #input("Press enter to continue...") print( "\nHere are a list of available cars in the dealer's inventory at this moment:\n" ) innerCounter = 1 for car in dealer.get_inventory(): print("{}. {}, {}, {}".format(innerCounter, car.get_model_name(), car.get_description(), car.get_id())) innerCounter += 1 counter += 1 # Data sturcture (dictionary) where the bidding history will be saved number = "" while (not (isInt(number) and int(number) in range( 1, len(dealer.get_inventory()) + 1))): number = input( "Please select the number of the car you would like to bid for: " ) if (not (isInt(number) and int(number) in range( 1, len(dealer.get_inventory()) + 1))): print("Please type the number of the car in the list...") if isInt(number) and int(number) in range( 1, len(dealer.get_inventory()) + 1): amount = "Test" while not isFloat(amount) or float(amount) <= 0: amount = input( "Please type the amount you want to offer to this car: " ) if (not isFloat(amount) or float(amount) <= 0): print( "Wrong input. Please type the valid offer amount: positive integer or decimal number > 0" ) else: # Calls buyer's OFFER method to make an offer to a chosen car buyer.offer(buyer.get_name(), dealer.get_inventory()[int(number) - 1], amount, auctionList) else: input("Please type the number of the car in the list.") input("Now back to the dealer's part again. Press enter to continue.") # Implement sell (in the bidding list), history choice = 0 while (choice != "3"): choice = input( "[1] Check a bid list.\n" + "[2] Check your current inventory.\n" + "[3] Quit (This will end the simulation and returns your total profit)\n" + "\nChoose the number and press enter: ") if choice == "1": for biddedCar in auctionList: print("\n{}, {}, {}\nPurchased price: {}".format( biddedCar.get_model_name(), biddedCar.get_description(), biddedCar.get_id(), biddedCar.get_price())) print( "-> This car has recevied total {} offer(s).\n".format( len(auctionList.get(biddedCar)))) innerCounter = 1 # print the list of cars with bid history in decreasing offer amount order for bidInfo in sorted(auctionList.get(biddedCar), key=lambda x: x[1], reverse=True): print( "Bid {}. An offer of {}EUR received from the {}.". format(innerCounter, bidInfo[1], bidInfo[0])) innerCounter += 1 input("Press enter to go back to the previous step...") elif choice == "2": dealer.inv() print("\nTotal spent on purchasing cars is: {}EUR".format( dealer.get_money_spent())) input("Press enter to go back to the list of options.") # Auction cannot choose whether to sell or not based on the given bids # If there is a bid, you must sell and if there are more than 1 bid, sell to the highest bidder # Therefore, here the seller doesn't get to choose which car to sell but is forced to sell # all cars that have recived offer from the bidders. # So, when choose "quit" -> all cars in auctionList will be sold to the highest bidder elif choice == "3": input("Processing sales to the highest bidders...\n" + "Press enter to see your profit for each car sold.\n") dealer.sell(auctionList) dealer.history() else: print( "\nYou chose invalid number. Please choose a number between 1 to 3." ) input("Press enter to go back to the list of options.") except OSError: print("Error in reading file ", filename, ". closing program...")
def queue_data_init(self): # 厂外等待的车辆队列 {TASK_ID:car} 排队但未叫号 car_queue = dict() # 已经叫号但还未入厂的车辆 car_notice = dict() # 厂内情况 factory = self.factory # 厂内 + 厂外所有车辆的预计结束时间 {TASK_ID:时间} car_predict_end_time = copy.deepcopy( self.factory.car_predict_finish_time) # 厂内 + 厂外各仓库的车辆 {仓库代码:[TASK_ID]} warehouse_car = copy.deepcopy(self.factory.warehouse_car) # 厂内 + 厂外各品种车辆 {品种代码:[TASK_ID]} kind_car = copy.deepcopy(self.factory.kind_car) # 读取数据 data = da.read_queue_car_time(self.__init_time__) data_n = da.read_notice_car_time(self.__init_time__) # 初始化car_queue for i in range(len(data)): car_queue[data.iloc[i, 1]] = Car(data.ix[i].tolist()) for i in range(len(data_n)): car_notice[data_n.iloc[i, 1]] = Car(data_n.ix[i].tolist()) sort_notice = sorted(car_notice.values(), key=lambda x: int(x.queue_num)) for car in sort_notice: # # 判断是否已经达到了今日的计划量 # if self.judge_plan(i): # # 已经达到计划量,预计结束时间为第二天零点+cost # ''' # 实际上线 # car_predict_end_time[i.task_id] = tool.cal_predict_finish_time(str(tool.string_to_datetime( # datetime.datetime.now().strftime("%Y-%m-%d 00:00:00")) + datetime.timedelta(days=1)), i.cost) # ''' # car_predict_end_time[i.task_id] = tool.cal_predict_finish_time(str(tool.string_to_datetime(self.__init_time__) + datetime.timedelta(days=1)), i.cost) # # 没有达到计划量,代表今日可以入厂,判断是否可以直接入厂 # el if len(self.factory.car_predict_finish_time) < self.factory.__factory_max_count__ \ and self.judge_factory_warehouse(car) and self.judge_factory_kind(car): # 此时均未达到厂内最大车辆、该车仓库最大量、该车物料最大量,代表可以直接入厂,等待时间为0 ''' 实际上线 car_predict_end_time[i.task_id] = tool.cal_predict_finish_time(tool.datetime_to_string(datetime.datetime.now()), i.cost) ''' car_predict_end_time[ car.task_id] = tool.cal_predict_finish_time( self.__init_time__, car.cost) # 不可以直接入厂,需要计算等待时间,厂内+厂外考虑 else: # 有相同品种且有相同仓库的,等待时间=仓库最早出来的和品种车辆的最早出来的偏晚的值 if self.find_warehouse_early_finish_car(car, warehouse_car, car_predict_end_time) != '9999-99-99 99:99:99'\ and self.find_kind_early_finish_car(car, kind_car, car_predict_end_time) != '9999-99-99 99:99:99': car_predict_end_time[car.task_id] = tool.cal_predict_finish_time\ (max(self.find_warehouse_early_finish_car(car, warehouse_car, car_predict_end_time), self.find_kind_early_finish_car(car, kind_car, car_predict_end_time)), car.cost) # 只有相同仓库的 elif self.find_warehouse_early_finish_car( car, warehouse_car, car_predict_end_time) != '9999-99-99 99:99:99': car_predict_end_time[car.task_id] = tool.cal_predict_finish_time\ ((self.find_warehouse_early_finish_car(car, warehouse_car, car_predict_end_time)), car.cost) # 只有相同品种的 else: car_predict_end_time[car.task_id] = tool.cal_predict_finish_time\ ((self.find_kind_early_finish_car(car, kind_car, car_predict_end_time)), car.cost) if car.warehouse_code not in warehouse_car.keys(): warehouse_car[car.warehouse_code] = [car.task_id] else: warehouse_car[car.warehouse_code].append(car.task_id) if car.kind_code not in kind_car.keys(): kind_car[car.kind_code] = [car.task_id] else: kind_car[car.kind_code].append(car.task_id) # 让厂外排队车辆根据排队号码排序 sort_queue=[car] sort_queue = sorted(car_queue.values(), key=lambda x: int(x.queue_num)) # 初始化厂外排队车辆的预计结束时间 for car in sort_queue: # # # 判断是否已经达到了今日的计划量 # if self.judge_plan(i): # # 已经达到计划量,预计结束时间为第二天零点+cost # ''' # 实际上线 # car_predict_end_time[i.task_id] = tool.cal_predict_finish_time(str(tool.string_to_datetime( # datetime.datetime.now().strftime("%Y-%m-%d 00:00:00")) + datetime.timedelta(days=1)), i.cost) # ''' # car_predict_end_time[i.task_id] = tool.cal_predict_finish_time(str(tool.string_to_datetime(self.__init_time__) + datetime.timedelta(days=1)), i.cost) # # 没有达到计划量,代表今日可以入厂,判断是否可以直接入厂 # el # if len( self.factory.car_predict_finish_time ) < self.factory.__factory_max_count__ and self.judge_factory_warehouse( car) and self.judge_factory_kind(car): # 此时均未达到厂内最大车辆、该车仓库最大量、该车物料最大量,代表可以直接入厂,等待时间为0 ''' 实际上线 car_predict_end_time[i.task_id] = tool.cal_predict_finish_time(tool.datetime_to_string(datetime.datetime.now()), i.cost) ''' car_predict_end_time[ car.task_id] = tool.cal_predict_finish_time( self.__init_time__, car.cost) # 不可以直接入厂,需要计算等待时间,厂内+厂外考虑 else: # 有相同品种且有相同仓库的,等待时间=仓库最早出来的和品种车辆的最早出来的偏晚的值 if self.find_warehouse_early_finish_car(car, warehouse_car, car_predict_end_time) != '9999-99-99 99:99:99'\ and self.find_kind_early_finish_car(car, kind_car, car_predict_end_time) != '9999-99-99 99:99:99': car_predict_end_time[car.task_id] = tool.cal_predict_finish_time\ (max(self.find_warehouse_early_finish_car(car, warehouse_car, car_predict_end_time), self.find_kind_early_finish_car(car, kind_car, car_predict_end_time)), car.cost) # 只有相同仓库的 elif self.find_warehouse_early_finish_car( car, warehouse_car, car_predict_end_time) != '9999-99-99 99:99:99': car_predict_end_time[car.task_id] = tool.cal_predict_finish_time \ ((self.find_warehouse_early_finish_car(car, warehouse_car, car_predict_end_time)), car.cost) # 只有相同品种的 else: car_predict_end_time[car.task_id] = tool.cal_predict_finish_time \ ((self.find_kind_early_finish_car(car, kind_car, car_predict_end_time)), car.cost) if car.warehouse_code not in warehouse_car.keys(): warehouse_car[car.warehouse_code] = [car.task_id] else: warehouse_car[car.warehouse_code].append(car.task_id) # 初始化kind_car if car.kind_code not in kind_car.keys(): kind_car[car.kind_code] = [car.task_id] else: kind_car[car.kind_code].append(car.task_id) return Queue(car_queue, factory, warehouse_car, kind_car, car_notice, car_predict_end_time)
def owner(self, car): return '{} drives {}'.format(Driver.full_name(self), Car.summary(car))
from Cars import ElectricCar, Car my_beetle = Car('Volkswagen', 'beetle', 2016) print my_beetle.get_descriptive_name() my_tesla = ElectricCar('tesla', 'model s', 2016) print my_tesla.get_descriptive_name() my_tesla.battery.describe_battery() my_tesla.battery.battery_size = 85 my_tesla.battery.get_range()
# Variable and list Storage got = [] # Screen setup screen = Screen() screen.setup(width=600, height=600) screen.bgcolor("black") screen.title("Crossy Roads") screen.tracer(0) # 0 = off # Classes being defined player = player() level = Level() lives = Lives() car = Car() # Controls screen.listen() screen.onkey(key="w", fun=player.up) screen.onkey(key="s", fun=player.down) while lives.Lives > 0: car.move_cars() screen.update() time.sleep(0.1) # Level Up if player.ycor() > 280: player.reset()
AU.welcome() #welcome user if username and password matched print("Car Rental System dashboard") crs1 = CRS(username) #create instance of CSR class crs1.show_cars() #show list of cars crs1.show_hired_car() #show hires cars details crs1.show_client_details() #show client /user details if (login_type == 2): #if user select client mode username = input("Enter username :"******"Enter Password :"******"Please Enter 1 to Hire Car 2 to Rent car 3 to exit :")) if (c_oper == 1): #Hire mode print("###############################") print("####Select car category #######") c1.show_category() #show available category df = pd.read_csv("cars.csv") #read cars file df_cat = df.category.unique() #selecting category id x = 1 while x > 0: sel_cat = input( "Enter category id from( 0 to {}) to select category :"