def testMPs_one_hand(self): hand_results = [] hand_results.append( HandResult(1, 1, 2, 400, 0, Calls("GT", "", "", ""))) hand_results.append( HandResult(1, 3, 4, 150, 50, Calls("T", "", "", ""))) hand_results.append(HandResult(1, 5, 6, 100, 0, Calls("", "", "", ""))) hand_results.append( HandResult(1, 7, 8, 70, -70, Calls("", "", "T", ""))) boards = [Board(1, hand_results)] hand_results = [] hand_results.append( HandResult(2, 1, 3, 400, 0, Calls("GT", "", "", ""))) hand_results.append( HandResult(2, 2, 7, 120, 80, Calls("T", "", "", ""))) hand_results.append(HandResult(2, 4, 8, 300, 0, Calls("T", "", "", ""))) hand_results.append(HandResult(2, 6, 5, 0, 300, Calls("", "", "T", ""))) boards.append(Board(2, hand_results)) team_summaries = Calculate(boards, 2) OrderBy(team_summaries, "MP") self.compareStats(team_summaries[0], 1, 1, 6, 11.05, 505, 9) self.compareStats(team_summaries[1], 2, 4, 4.5, 9.70, 275, 1) self.compareStats(team_summaries[2], 3, 7, 4, 0.43, 25, 0) self.compareStats(team_summaries[3], 4, 5, 3.5, 1.56, 325, 3) self.compareStats(team_summaries[4], 5, 6, 2.5, -1.56, -325, 0) self.compareStats(team_summaries[5], 6, 8, 2, -1.42, -145, 3) self.compareStats(team_summaries[6], 7, 2, 1, -9.63, -285, 1) self.compareStats(team_summaries[7], 8, 3, 0.5, -10.13, -375, 2)
def testAPs_avg(self): hand_results = [] hand_results.append( HandResult(8, 1, 2, 0, 400, Calls("", "", "", "GT"))) hand_results.append( HandResult(8, 3, 6, 0, 400, Calls("", "", "", "GT"))) hand_results.append( HandResult(8, 4, 5, 'AVG', 'AVG', Calls("", "", "", ""))) boards = [Board(8, hand_results)] team_summaries = Calculate(boards, 1) OrderBy(team_summaries, "AP") self.compareStats(team_summaries[0], 1, 1, 1, 0, 0, 0) self.compareStats(team_summaries[1], 2, 2, 1, 0, 0, 0) self.compareStats(team_summaries[2], 3, 3, 1, 0, 0, 0) self.compareStats(team_summaries[3], 4, 4, 1, 0, 0, 0) self.compareStats(team_summaries[4], 5, 5, 1, 0, 0, 0) self.compareStats(team_summaries[5], 6, 6, 1, 0, 0, 0)
def testMPs_avg(self): hand_results = [] hand_results.append( HandResult(1, 1, 2, 400, 0, Calls("GT", "", "", ""))) hand_results.append( HandResult(1, 3, 4, 160, 40, Calls("T", "", "", ""))) hand_results.append(HandResult(1, 5, 6, 100, 0, Calls("", "", "", ""))) hand_results.append( HandResult(1, 7, 8, 70, -70, Calls("", "", "T", ""))) hand_results.append( HandResult(1, 9, 10, 'AVG', 'AVG--', Calls("", "", "", ""))) hand_results.append( HandResult(1, 11, 12, 'AVG++', 'AVG-', Calls("", "", "", ""))) hand_results.append( HandResult(1, 13, 14, 'AVG+', 'AVG+', Calls("", "", "", ""))) boards = [Board(1, hand_results)] team_summaries = Calculate(boards, 1) OrderBy(team_summaries, "MP") self.compareStats(team_summaries[0], 1, 11, 4.8, 3.21, 126, 0) self.compareStats(team_summaries[1], 2, 1, 4.5, 5.35, 210, 5) self.compareStats(team_summaries[2], 3, 6, 4.5, 4.51, 90, 0) self.compareStats(team_summaries[3], 4, 13, 3.6, 1.07, 42, 0) self.compareStats(team_summaries[4], 5, 14, 3.6, 1.07, 42, 0) self.compareStats(team_summaries[5], 6, 4, 3.5, 4.26, 70, 0) self.compareStats(team_summaries[6], 7, 7, 3.5, -3.93, -50, 0) self.compareStats(team_summaries[7], 8, 9, 3, 0, 0, 0) self.compareStats(team_summaries[8], 9, 8, 2.5, 3.93, 50, 3) self.compareStats(team_summaries[9], 10, 3, 2.5, -4.26, -70, 2) self.compareStats(team_summaries[10], 11, 12, 2.4, -1.07, -42, 0) self.compareStats(team_summaries[11], 12, 5, 1.5, -4.51, -90, 0) self.compareStats(team_summaries[12], 13, 2, 1.5, -5.35, -210, 0) self.compareStats(team_summaries[13], 14, 10, 1.2, -3.21, -126, 0)
def testMPs_avg2(self): hand_results = [] hand_results.append( HandResult(6, 11, 4, 70, -170, Calls("", "", "", "GT"))) hand_results.append( HandResult(6, 6, 9, 180, 20, Calls("T", "", "", ""))) hand_results.append( HandResult(6, 5, 10, 'AVG', 'AVG', Calls("", "", "", ""))) hand_results.append(HandResult(6, 1, 3, 15, 85, Calls("", "", "", ""))) hand_results.append( HandResult(6, 8, 7, -35, 235, Calls("", "T", "GT", ""))) boards = [Board(6, hand_results)] team_summaries = Calculate(boards, 1) OrderBy(team_summaries, "MP") self.compareStats(team_summaries[0], 1, 7, 3.5, 5.66, 285, 4) self.compareStats(team_summaries[1], 2, 11, 3.5, 5.42, 225, 0) self.compareStats(team_summaries[2], 3, 6, 2.5, 4.98, 145, 2) self.compareStats(team_summaries[3], 4, 3, 2.5, 4.45, 85, 0) self.compareStats(team_summaries[4], 5, 5, 2, 0, 0, 0) self.compareStats(team_summaries[5], 6, 10, 2, 0, 0, 0) self.compareStats(team_summaries[6], 7, 1, 1.5, -4.45, -85, 0) self.compareStats(team_summaries[7], 8, 9, 1.5, -4.98, -145, 0) self.compareStats(team_summaries[8], 9, 4, .5, -5.42, -225, 4) self.compareStats(team_summaries[9], 10, 8, .5, -5.66, -285, 2)
def ReadXlsxInput(filename): """ Reads input from an Xlsx file. Input file must have a sheet titled "Team Names" and sheet titled "Raw Hand Scores". This code will read the first continuous block of hand records, stopping at the first blank line. Args: filename: path to the input file. Returns: A tuple (input wb object, list of Boards from the input in no defined order). """ wb = load_workbook(filename) board_no_to_hr_list = {} teams_sheet = wb["Team Names"] raw_input_sheet = wb["Raw Hand Scores"] first = True for row in raw_input_sheet.rows: if not row[0].value: break if first: first = False else: board_no = int(row[0].value) hr_list = board_no_to_hr_list.setdefault(board_no, []) # For Tichu calls, need to make sure empty cells default to '' for i in xrange(3, 7): row[i].value = '' if not row[i].value else row[i].value hr_list.append( HandResult(board_no, int(row[1].value), int(row[2].value), int(row[7].value), int(row[8].value), Calls(row[3].value, row[4].value, row[5].value, row[6].value))) board_list = [] for k, v in board_no_to_hr_list.items(): board_list.append(Board(k, v)) return (wb, board_list)