def test_get(self): """ Check the basic agent assignment. """ Agent.init(self.agents, self.start) # Should assign agent with better expertise. agent, wait = Agent.get(self.customers[0]) self.assertEqual(agent.agent_id, self.agents[1]["agent_id"]) self.assertEqual(wait, 0) # Should assign agent avaialable, even if not best match. agent, wait = Agent.get(self.customers[1]) self.assertEqual(agent.agent_id, self.agents[0]["agent_id"]) self.assertEqual(wait, 0) # Should pick better-rated agent to tie break, even when both finish simultaneously. agent, wait = Agent.get(self.customers[2]) self.assertEqual(agent.agent_id, self.agents[1]["agent_id"]) self.assertEqual(wait, 120) # Should get commission only if deal closes. self.assertEqual(Agent.list[0].closes, 0) self.assertEqual(Agent.list[1].closes, 2) # Should show revenue generated. revenues = 0, sum([CARS[c]["price"] for c in [0, 2]]) self.assertEqual(Agent.list[0].revenue, revenues[0]) self.assertEqual(Agent.list[1].revenue, revenues[1]) # Nobody should have got a bonus. self.assertEqual(Agent.list[0].bonuses, 0) self.assertEqual(Agent.list[1].bonuses, 0)
def test_2_agents_done_at_once(self): """ Test for picking the highest rating agent and picking the right agent when two agents are finish at the same time """ # Test highest rating agent agent, wait_time = Agent.get(TEST_CUSTOMERS[0]) self.assertEqual((TEST_AGENTS[1], 0), (agent.agent, wait_time)) # Test 2 agents done at the same time Agent.get(TEST_CUSTOMERS[1]) agent, wait_time = Agent.get(TEST_CUSTOMERS[2]) self.assertEqual((TEST_AGENTS[1], 60), (agent.agent, wait_time))
def showTable(): """ Show all the performaces results and display them in a QTableWidget """ random.seed(0) # Check if user enter 0 if Sales.agents == 0 or Sales.customers == 0: Sales.table.setRowCount(0) Sales.mean.setText("0.0") Sales.median.setText("0.0") Sales.sd.setText("0.0") return # Else do regular logic and display result to the table else: Agent.init(agents(Sales.agents), datetime.today().replace(hour=HOURS[0])) waits = [] for customer in customers(Sales.customers): agent, wait = Agent.get(customer) waits.append(wait) locale.setlocale(locale.LC_ALL, locale.getlocale()) Sales.mean.setText(str(statistics.mean(waits))) Sales.median.setText(str(statistics.median(waits))) if len(waits) == 1: Sales.sd.setText("0.0") else: Sales.sd.setText("{:.2f}".format(statistics.stdev(waits))) Sales.table.setRowCount(Sales.agents) for index, agent in enumerate(Agent.list): Sales.table.setItem(index, 0, QTableWidgetItem(str(agent.agent_id))) Sales.table.setItem(index, 1, QTableWidgetItem(str(agent.closes))) Sales.table.setItem( index, 2, QTableWidgetItem(str(locale.currency(agent.revenue)))) Sales.table.setItem( index, 3, QTableWidgetItem(str(locale.currency(agent.closes * 10000)))) Sales.table.setItem( index, 4, QTableWidgetItem( str(locale.currency(agent.bonuses * 100000))))
def test_init(self): agent1_id = 675765 expertise1 = [3, 2, 4, 1] service_time1 = 8 rating1 = 0.987 agent1 = [agent1_id, expertise1, service_time1, rating1] for agent in Agent.init(agent1): assert agent._agent_id == 675765 assert agent._expertise == [3, 2, 4, 1] assert agent._service_time == 8 assert agent._rating == 0.987
def sales(self): """ Loop through customers to determine how the agents did. """ customer_num = 100 agents = Agent.get() customers_ = create_customers_list(customer_num) for customer in customers_: agent = agents.get_agent(customer) agents.check_deal(agent, customer) print(agents)
def sales(self): """ Simulate sales using test data and print out customer and agent reports. """ wait_times = [] for agent in AGENTS: Agent.innit(agent) for customer in CUSTOMERS: agent, time = Agent.get(customer) wait_times.append(time) print("{:8} {:8} {:8}".format("Mean", "Median", "Standard deviation")) print("{:<8.2f} {:<8} {:<8.2f} \n".format( statistics.mean(wait_times), statistics.median(wait_times), statistics.stdev(wait_times))) print("{:<7} {:<7} {:<20} {:<15} {:<20}".format( "ID", "DEALS", "REVENUE", "COMMISSION", "BONUS")) for agent in Agent.working_agents: agent_id, deals, revenue, commission, bonus = agent.performace_report( ) print("{:<7} {:<6} ${:<19,.2f} ${:<14,.2f} ${:<19,.2f}".format( agent_id, deals, float(revenue), commission, float(bonus)))
def report(self): """ Simulate sales using test data and print out customer and agent reports. """ random.seed(0) Agent.init(agents(5), datetime.today().replace(hour=HOURS[0])) waits = [] for customer in customers(100): agent, wait = Agent.get(customer) waits.append(wait) locale.setlocale(locale.LC_ALL, locale.getlocale()) print("{:<9.4}{:<9.4}{:<9.4}".format("MEAN", "MED", "SD")) print("{:<9.4}{:<9.4}{:<9.4}".format(statistics.mean(waits), statistics.median(waits), statistics.stdev(waits))) print("\n{:<9}{:>6}{:>18}{:>18}{:>18}".format("ID", "DEALS", "REVENUE", "COMMISSION", "BONUS")) for agent in Agent.list: print("{:<9}{:>6}{:>18}{:>18}{:>18}".format( agent.agent_id, agent.closes, locale.currency(agent.revenue), locale.currency(agent.closes * 10000), locale.currency(agent.bonuses * 100000)))
def test_init(self): """ Do a rudumentary check on initialization. """ Agent.init(self.agents, self.start) self.assertEqual(len(Agent.list), len(self.agents))
def test_get(cls, customer): for agent in Agent.init(agents(1)): assert agent.deals_closed == 10 assert agent._bonus > customer["arrival_time"] if agent.bonus == 100000: print("this test works")
class Run(object): """ Run the sales. """ def sales(self): """ Simulate sales using test data and print out customer and agent reports showing (1) Summary statistics, with the mean, median, and SD of customer wait times. (2) Agent data showing agent ID, deals closed, total revenue generated, commission earned, and bonus awarded, in a tabular form. """ Agent.init(agents(5)) agents = Agent._agents agent_stats = [] agents = [] wait_times = [] for customer in customers(100): stats = Agent.get(customer) wait_times.append(stats[0]) agent_stats.append(stats[1:]) #Calculating Mean, Median, SD wait_time_mean = ((sum(wait_times)) / float(len(wait_times))) wait_time_median = median(wait_times) SD = stdev(wait_times)
def setUp(self): for agent in TEST_AGENTS: Agent.innit(agent)