def setUp(self): self.agents = agents.agents(5) self.customers = customers.customers(100) self.agents_list = [] for aget in self.agents: new_agent = agent.Agent(**aget) self.agents_list.append(new_agent)
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 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. """ all_customers = customers(100) all_agents = agents(5) list_of_agent = [] for aget in all_agents: new_agent = agent.Agent(**aget) list_of_agent.append(new_agent) agent.Agent.init(*list_of_agent) date = 0 wait_times = [] for customer in all_customers: """ check if it's a new day. If true, reset the appointment """ if customer.get("arrival_time").day > date: agent.Agent.new_day() date = customer.get("arrival_time").day """ pass the customer the method "get", and return with the selected agent and waittime """ best_agent, wait_time = agent.Agent.get(**customer) wait_times.append(wait_time) """ get the wait_time status """ best_agent.get_stats(*wait_times) for aagent in list_of_agent: agent.Agent.bonus(aagent.agent_id) print() print("Agent_id : ", aagent.agent_id) agent.Agent.get_sales(aagent.agent_id)
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)))
""" Car sales. """ import statistics #from dealer import AGENTS from dealer.agent import Agent from dealer import AGENTS from data.customers import customers CUSTOMERS = customers(100) class Run(object): """ Run the sales. """ 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)))
""" 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) stats = [wait_time_mean, wait_time_median, SD] #Printing Formats print( "----------------------------------------------------------------------------------" ) print("%-2s%14s%12s" % ("MEAN", "MEDIAN", "SD"))