def LoadDataFromText(txtpath): """ load data from text,return PROVIDERS,CUSTOMERS """ fp = open(txtpath, "r") arr = [] for line in fp.readlines(): arr.append(line.replace("\n", "").split(" ")) fp.close() NumberOfProviders = int(arr[0][0]) PROVIDERS = [] for i in range(1, NumberOfProviders + 1): tmp = arr[i] tmpProvider = ProviderPlus() tmpProvider.x = float(tmp[0]) tmpProvider.y = float(tmp[1]) tmpProvider.cnt = int(tmp[2]) for j in range(0, tmpProvider.cnt): tmpProvider.capacity.append(float(tmp[j + 3])) tmpProvider.cost.append(float(tmp[j + 3 + tmpProvider.cnt])) PROVIDERS.append(tmpProvider) NumberOfCustomers = int(arr[NumberOfProviders + 1][0]) CUSTOMERS = [] for i in range(0, NumberOfCustomers): tmp = arr[i + NumberOfProviders + 2] tmpCustomer = Customer() tmpCustomer.x = float(tmp[0]) tmpCustomer.y = float(tmp[1]) tmpCustomer.demand = float(tmp[2]) CUSTOMERS.append(tmpCustomer) return PROVIDERS, CUSTOMERS
def __init__(self, price): # staff self.num_funders = 5 # how many box a staff can make per day self.work_capacity = 50 # how many box a staff can make per month self.work_capacity_per_mon = self.work_capacity * 22 # how man box the funders can make per month self.initial_capacity = self.num_funders * self.work_capacity_per_mon # staff salary per hour self.salary_per_hr = 22 # staff salary per self.salary_per_mon = self.salary_per_hr * 22 * 8 # 1 = 1 month self.pred_length = 36 # price for each box self.price = price # cost for per box self.food_cost = {'chicken': 7.115, 'beef': 6.1697, 'pasta': 5.9055} # the change range of food cost self.cost_offset = 1.0 self.inception_cost = 10000 self.fixed_cost_per_hr = 40 self.fixed_cost_per_month = 30 * 24 * self.fixed_cost_per_hr # predict customer amount customer_predictor = Customer() self.customers = customer_predictor.predict()
def test_is_valid(self): self.assertTrue(self.se.isValid()) # add some customers into the list and verify that the # number of customers waiting is still 0 self.se._customers.update({'a': Customer('C1', 0), 'b': Customer('C2',10)}) self.assertTrue(self.se.isValid())
def simulate(self, total_time): # start the simulation at time 0 time = 0 self.tasting_profit = 0 for i in self.sales: self.sales[i] = 0 # Main simuation looop while True: #find the next event and time untill the next event event_time = min(self.clocks) event = self.clocks.index(event_time) time += event_time # update the clock self.update_clocks(event_time) # run the simulation untill the time is past the total time if time > total_time: break #The event of someone arriving if event == 0: # If the queue has peaple in it just add to the queue if len(self.queue) > 0: self.queue.append(Customer()) else: # if there is a free server send the customer to that server server = self.free_servers() if server > -1: self.take_customer(server, Customer()) # If there are no free servers then put the customer in the queue else: self.queue.append(Customer()) # A server has finished else: self.end_service(event - 1) return self.total_profit()
def test_add_customer_b_to_register(self): test_customer = Customer("B", 1, 3) customers_list_one = deque() customers_list_one.append(test_customer) customers_list_two = deque() expected_registers = {1: customers_list_one, 2: customers_list_two} output_registers = RegisterHelper.create_registers(2) RegisterHelper.add_customer_b_to_register(test_customer, output_registers) for key, value in output_registers.items(): self.assertEqual(expected_registers[key], value, "Customer B added to incorrect register") test_customer2 = Customer("B", 2, 3) expected_registers[2].append(test_customer2) RegisterHelper.add_customer_b_to_register(test_customer2, output_registers) for key, value in output_registers.items(): self.assertEqual(expected_registers[key], value, "Second Customer B added to incorrect register") test_customer3 = Customer("B", 3, 3) expected_registers[1].append(test_customer3) RegisterHelper.add_customer_b_to_register(test_customer3, output_registers) for key, value in output_registers.items(): self.assertEqual(expected_registers[key], value, "Third Customer B added to incorrect register")
def setUp(self) -> None: np.random.seed(100) # first setup a queue self.testq = SimQueue('Q1', Assigner().assignInSequence) # then setup servers self.dist = {} self.dist['dt'] = Distribution("triangular(14400, 14400, 18000)") self.dist['oos'] = Distribution("triangular(300, 600, 1200)") self.dist['st'] = Distribution("exponential(1/300)") # uncomment to test validity of server construction # for k, v in self.dist.items(): # with self.subTest(dist=k): # self.assertTrue(v.isValid()) self.dist['invalid'] = Customer('teddy', 0) self.servers = [ Server(f'Server{i}', 100 * i, self.dist['dt'], self.dist['oos'], self.dist['st']) for i in range(1, 4) ] self.dest = [ SimQueue(f'Queue{i}', Assigner().assignInSequence) for i in range(1, 4) ] self.dest.append(SystemExit('Exit1')) self.cust = [Customer(f'Cust{i}', i * 100) for i in range(1, 11)]
def test_get_num_customers_waiting(self): self.assertEqual(0, self.se.getNumCustomersWaiting()) # add some customers into the list and verify that the # number of customers waiting is still 0 self.se._customers.update({'a': Customer('C1', 0), 'b': Customer('C2',10)}) self.assertEqual(2, len(self.se._customers)) self.assertEqual(0, self.se.getNumCustomersWaiting())
def UpdateCustomerAddress(self, CustomerId, NewAddress, MessageId): CustomerDetails = ServiceRepository().GetCustomer(CustomerId) UpdatedCustomer = Customer(CustomerId, CustomerDetails['FirstName'], CustomerDetails['LastName'], CustomerDetails['Email'], CustomerDetails['Address']) UpdatedCustomer.Address = NewAddress ServiceRepository().SaveCustomer(UpdatedCustomer, MessageId)
def source(self): for i in range(1, self._max_cust+1): num_bags = self._calc_bags() cust = Customer(self._env, str(i), num_bags, random) self._env.process(cust.process(self._check_in_counters, self._equipment_area_queue, self._secuirty_check_queue)) interarrival_time = random.expovariate(1.0/self._rate) yield self._env.timeout(interarrival_time)
def operate(self, all_data, requests_log_file_path): """ Start running the elevator and pass the customer requests to the elevator. Parameters ---------- all_data: list of lists of int Include data for each customer in a sequence of the time they send the requests. requests_log_file_path: str File name to save all the requests from customer. actions_log_file_path: str File name to save all the actions of the elevator. """ # Open a txt file to log the requests requests_log_file_write = open(requests_log_file_path, "w") # actions_log_file_write = open(actions_log_file_path, "w") customer_index = 0 # initiate the elevator myelevator = self.elevator my_thread = self.start_elevator() customer_total_number = len(all_data) while customer_index < customer_total_number : customerID, request_time, floor_from, floor_to = all_data[customer_index] if request_time <= myelevator.time_now: # Initialize a Customer object user = Customer(customerID) # Read customer information from the input data, and then receive requests from the customer request_time, floor_from, floor_to = user.send_request(request_time, floor_from, floor_to) if floor_to > floor_from: move_dir = "up" else: move_dir = "down" requests_log_file_write.write("Customer " + str(customerID) + " sent a " + move_dir + "ward direction request at " + str(request_time) + "s" + " on floor " + str(floor_from) + " and wants to go to floor " + str(floor_to) + " \n") # actions_log_file_write.write("At " + str(myelevator.time_now) + "s" + " the elevator is on floor " + str(myelevator.current_floor) + " the customers now inside the elevator are: " + str(myelevator.customer_inside) + " \n") try: # Send the customer requests to the elevator myelevator.push_button(floor_from, user.customerID, floor_to) # time.sleep(1) customer_index += 1 if floor_from == 0 or floor_to == 0 or myelevator.switch != "on": myelevator.emergency_stop() my_thread.join() return except: print("An exception occurred") if myelevator.up_queue1.is_empty() and myelevator.down_queue1.is_empty(): print ("Program finished.") myelevator.emergency_stop() my_thread.join() return
def testReturnVideo(self): """tests the returning of a video""" video_title = "Braveheart" video = Video(video_title) c1 = Customer(first_name, last_name, phone_number, dob, email) c1.rent_video(video.ID) self.assertEqual(1, len(c1.rented_video_IDs)) c1.return_video(video.ID) self.assertEqual(0, len(c1.rented_video_IDs))
def test_multiple_regular_statement(self): fred = Customer("Fred") fred.add_rental( Rental(Movie("Plan 9 from Outer Space", Movie.REGULAR), 1)) fred.add_rental(Rental(Movie("8 1/2", Movie.REGULAR), 2)) fred.add_rental(Rental(Movie("Eraserhead", Movie.REGULAR), 3)) assert fred.statement( ) == "Rental Record for Fred\n\tPlan 9 from Outer Space\t2.0\n\t8 1/2\t2.0\n\tEraserhead\t3.5\nYou owed 7.5\nYou earned 3 frequent renter points\n"
def test_make_reservation(self): name = "Brian" phone_number = "(802)555-1234" customer = Customer(name, phone_number) restaurant = Restaurant("Tapas", "mexican", 7, 11, 17) res = customer.make_reservation(restaurant, 15, 7) self.assertEqual(res.customer.name, "Brian") self.assertEqual(res.time, 15) self.assertEqual(res.party_size, 7)
def Respond(speech): cust = Customer() cust.IProvider = speech print() if "not interested" in speech: print("Recognized you aren't interested") else: print("Cusetomer said insurance was: " + cust.IProvider) mixer.init(8000) mixer.music.load('C:\SoundBoard\Cheryl\REBUTTALS\cheryl Long rebuttal.mp3') mixer.music.play()
def _create_customer(): while not self.is_sale_end(): #随机等待1~3秒 sleep_time = random.randint(1, 3) #sleep_time = 1 time.sleep(sleep_time) cust = Customer() if cust.choose_goods(self) == None: break else: cust.set_status(1) #压入消费者队列 self.customer_queue.put(cust)
def confirm(self, seats, user): # assign seat for s in seats: self.seats[s] = user # add to customer list if user not in self.customer_list: self.customer_list.append(user) # update the database self.update_DB() # update customer's information c = Customer(user) c.confirm_tickets(seats, self.number)
def main(): store = VideoStore() i1 = AbstractItem("Matrix", "Science Fiction", 3) i2 = AbstractItem("Ladyhawke", "Fantasy", 2) c1 = Customer("João") c2 = Customer("Maria") c3 = Customer("Pedro") store.addCustomer(c1) store.addCustomer(c2) store.addCustomer(c3) store.addItem(i1) store.addItem(i2) print (store.findUser("João")) print (store)
def parseCustomerElement(customer): cname = customer.find(bt + "name").text cust = Customer(cname) cust.btfCid = customer.find(bt + "number").text credElem = customer.find(bt + "avaialable-credit") if credElem is not None: cust.creditAvailable = credElem.text for purchaser in customer.iter(bt + "purchaser"): pname = purchaser.find(bt + "name").text token = purchaser.find(bt + "token").text cust.purchasers[pname] = token return cust
class CustomerTest(unittest.TestCase): def setUp(self): self.customer = Customer("Vesa", "Kuoppala") self.item = Item("Ball") def tearDown(self): pass # Case 1: # Customer buys 4 items of the same kind from store, the total cost is 12$ def test_customer_buys_four_items_and_cost_is_12_dollars(self): cost = self.customer.buy(self.item, 4) self.assertEqual(cost, 12) # Case 2: # Customer buys 3 items of the same kind from store, the total cost is 12$ def test_customer_buys_three_items_and_cost_is_12_dollars(self): cost = self.customer.buy(self.item, 3) self.assertEqual(cost, 12)
class PlotTest(unittest.TestCase): def setUp(self): self.customer = Customer("Vesa", "Kuoppala") self.item = Item("Ball") self.quantities = np.arange(0, 8, 1) def tearDown(self): None def test_customer_creates_table_for_quantities(self): # Add data to list data = [] for i in self.quantities: data_row = [] data_row.append(i) self.item.set_price(i) data_row.append(self.item.price) data_row.append(self.customer.buy(self.item, i)) data.append(data_row) # Define column and row labels for table columns = ('Q', 'P', 'T') fig = plt.figure() ax = fig.add_subplot(111) ax.xaxis.set_visible(False) ax.yaxis.set_visible(False) the_table = ax.table( cellText=data, colLabels=columns, loc='center' ) plt.show()
firstLine = inputFile.readline() line = inputFile.readline() currCustomerID = "" currTransactions = [] while(line): #deal with first customer if currCustomerID == "": currTransactions.append(line) currCustomerID = line.split(",")[0] else: #line belong to the same customer if currCustomerID == line.split(",")[0]: currTransactions.append(line) else: #encounter new customer ## process the customer before first #print(currCustomerID + ":" + str(len(currTransactions))) lastCustomer = Customer(currTransactions) collection.insert(lastCustomer.toDict()) #print(json.dumps(tmpDict)) ## init new customer currCustomerID = "" currTransactions = [] currTransactions.append(line) line = inputFile.readline() client.close()
from Customer import Customer from Account import SavingsAccount, CurrentAccount customer = Customer('Ashish Kumar', {'saving': SavingsAccount(100, 500), 'current': CurrentAccount(1000)}) customer.accounts() try: customer.transfer('saving', 'current', 600) customer.accounts() except ValueError as err: print("Transaction failed: " + str(err)) try: customer.transfer('current', 'saving', 600) customer.accounts() except ValueError as err: print("Transaction failed: " + str(err))
def setUp(self): self.customer = Customer("Vesa", "Kuoppala") self.item = Item("Ball") self.quantities = np.arange(0, 8, 1)
def setUp(self): self.customer = Customer("Vesa", "Kuoppala") self.item = Item("Ball")
def testRentReturnVideo(self): """tests the renting and returning of a video (tests duplicate rents and returns)""" video1 = Video("Braveheart") video2 = Video("The Matrix") video3 = Video("Forrest Gump") c1 = Customer(first_name, last_name, phone_number, dob, email) c1.rent_video(video1.ID) c1.rent_video(video2.ID) c1.rent_video(video3.ID) self.assertEqual(3, len(c1.rented_video_IDs)) c1.return_video(video2.ID) self.assertEqual(2, len(c1.rented_video_IDs)) c1.rent_video(video2.ID) c1.rent_video(video2.ID) # duplicate rental videos (same UUID) self.assertEqual(3, len(c1.rented_video_IDs)) c1.return_video(video3.ID) c1.return_video(video3.ID) # duplicate return videos (same UUID) self.assertEqual(2, len(c1.rented_video_IDs))
def pasteCustCode(self): from Customer import Customer cus = Customer.bring(self.internalId) print cus.Name