Exemplo n.º 1
0
    def write_schedule_swap_matrix(self, file='swapped schedules.csv'):
        data = {x.name: {x.name: 1} for x in self.teams}
        for tA, tB in itertools.combinations(self.teams, 2):
            A, B = tA.name, tB.name
            # swap the values
            self.schedule[A]['schedule'], self.schedule[B][
                'schedule'] = self.schedule[B]['schedule'], self.schedule[A][
                    'schedule']

            wA, wB = tA.expected_wins(
                tA.project_win_totals()[-1]), tB.expected_wins(
                    tB.project_win_totals()[-1])
            teamA = Team(name=A, schedule=self.schedule)

            data[A][B] = teamA.expected_wins(
                teamA.project_win_totals()[-1]) / wA

            teamB = Team(name=B, schedule=self.schedule)

            data[B][A] = teamB.expected_wins(
                teamB.project_win_totals()[-1]) / wB

            # unswap the values
            self.schedule[A]['schedule'], self.schedule[B][
                'schedule'] = self.schedule[B]['schedule'], self.schedule[A][
                    'schedule']

        with open(file, 'w+', newline='') as outfile:
            cw = csv.writer(outfile)
            cw.writerow(['', *sorted(list(data.keys()))])
            keys = sorted(list(data.keys()))
            for team in keys:
                row = [data[team][x] for x in keys]
                cw.writerow([team, *row])
Exemplo n.º 2
0
 def write_expected_win_csv(self, file='out'):
     result = [['Team', 'Week', 'Expected Wins']]
     for team in self.teams:
         for w in range(0, 13):
             rec = team.project_win_totals(w)[-1]
             row = [team.name.title(), w, Team.expected_wins(rec)]
             result.append(row)
     with open("{}.csv".format(file), 'w', newline='') as outfile:
         writer = csv.writer(outfile)
         for r in result:
             writer.writerow(r)