Example #1
0
def getDifference(game, aRost=None, hRost=None, aStart=None, hStart=None):
    """Returns the injury difference for a past game (away team - home team)"""
    awayTeam = Base.getLoser(game[2], [game[0], game[1]])
    awayInj = findInjuries(awayTeam, 0, game[4], roster=aRost, starters=aStart)
    homeInj = findInjuries(game[2], 1, game[4], roster=hRost, starters=hStart)

    diff = subtract(awayInj, homeInj)
    return diff
Example #2
0
    def findSpecial(self):
        """Finds something special in the season (like one simulation)"""
        ###Finds one simulation in the season and returns it
        if("sim" in self.searchFor):
            i = 0
            ###Can choose what sim you want (ex. 1776)
            while(i < int(self.searchFor["sim"])):
                ###_simSeason() only updates the results for the reg. Season
                ###For the entire season, you have to sim reg. season, then post seasn
                self._startSeason()
                self._regSeason()
                ###Update records to get tiebreakers for post season
                for j in self.leagueSched:
                    self.records[j[0]] += 1
                ###Get champions and results
                afcRes, nfcRes = self._postSeason(True)
                afcChamp, afcSched, nfcChamp, nfcSched = afcRes[0], afcRes[1], nfcRes[0], nfcRes[1]
                ###Add wildcards from both confs, then divs, then championship
                self.leagueSched.extend(afcSched[:2]); self.leagueSched.extend(nfcSched[:2])
                self.leagueSched.extend(afcSched[2:4]); self.leagueSched.extend(nfcSched[2:4])
                self.leagueSched.append(afcSched[4]); self.leagueSched.append(nfcSched[4])
                sbChamp = self._sim(afcChamp, nfcChamp, homeField=False)
                sbLose = Base.getLoser(sbChamp, [afcChamp, nfcChamp])
                self.leagueSched.append([sbChamp, sbLose])
                i += 1
            return self.leagueSched

        if("playoffs" in self.searchFor):
            seeds = self.searchFor["playoffs"]
            if(self.sixTeam): afcSeeds, nfcSeeds = seeds[:6], seeds[6:]
            else: afcSeeds, nfcSeeds = seeds[:7], seeds[7:]
            for i in range(Base.SIM_NUM):
                if(i%100 == 0):
                    print(i, end=' ')
                afcChamp = self._toSB(afcSeeds)
                nfcChamp = self._toSB(nfcSeeds)
                afcName = '. '.join(afcChamp.split('. ')[1:])
                nfcName = '. '.join(nfcChamp.split('. ')[1:])
                sbChamp = self._sim(afcName, nfcName, homeField=False)
                self.champ[sbChamp] += 1
                self.inSB[afcName] += 1; self.inSB[nfcName] += 1
            for i in range(len(afcSeeds)):
                ###All of these teams were in the playoffs
                if(i <= 3):
                    self.wonDiv[afcSeeds[i]] = Base.SIM_NUM
                    self.wonDiv[nfcSeeds[i]] = Base.SIM_NUM
                self.inPlay[afcSeeds[i]] = Base.SIM_NUM
                self.inPlay[nfcSeeds[i]] = Base.SIM_NUM
                
            return
Example #3
0
def predict(game, homeTeam, rating, seasRating, xy=False):
    """Predicts at the start and end of all drives in a game.
game is a tuple for the game
homeTeam is 1 for percentage for the home team, 0 for the away team
rating is a All-Time Ratings dictionary
seasRating is a Season Ratings dictionary
If xy=True, it returns a list of (seconds left, % chance) pairs"""
    if(len(game) == 3): away, home = game[0], game[1]
    elif(len(game) == 5):
        away, home = game[2], Base.getLoser(game[2], [game[1], game[0]])

    awayAbbr, homeAbbr = Base.TEAM_ABBRS[away].upper(), Base.TEAM_ABBRS[home].upper()
    ###Home wins is used as the y for training
    data = getAllData(game[-1], awayAbbr, homeAbbr, 0)

    rateDiff = rating[away] - rating[home]
    seasDiff = seasRating[away] - seasRating[home]
    newData = []
    ###There are some repeats. This stores the seconds of all drives
    secVals = []
    indexes = []
    for i in range(len(data)):
        j = data[i]
        if(j[1] in secVals): continue
        if(j[0] == homeTeam):
            line = [rateDiff, seasDiff, j[1], j[3], j[4]]
        else:
            line = [-rateDiff, -seasDiff, j[1], j[3], j[4]]
        secVals.append(j[1])
        newData.append(line)
        indexes.append(i)

    vals = list(Base.IN_GAME.predict_proba(newData)[:, 1])
    finalList = []
    for i in range(len(vals)):
        ###indexes[i] is the index of the data point used
        ###data[indexes[i]] is what was used.
        ###data[indexes[i]][0] is the away/home of that data point
        ###If it is hometeam, it is for the correct team
        if(data[indexes[i]][0] == homeTeam):
            finalList.append(vals[i]*100)
        else:
            finalList.append((1-vals[i])*100)

    if(not(xy)):
        return finalList
    finalList = list(zip(secVals, finalList))
    finalList = [list(i) for i in finalList]
    return finalList
Example #4
0
    def _sim(self, home, away, num=100, homeField=True, sb=False):
        """Sims a game for the postseason. (For the regular season, it only randomizes once)
    home is False for the Super Bowl, when there is no HFA"""
        ###Win totals for both team
        expect, notExpect = 0, 0
        ###Home's Point of View
        allDiff = (self.allRate[home] - self.allRate[away])
        seasDiff = (self.seasRate[home] - self.seasRate[away])
        
        line = [1, 17, allDiff, seasDiff] + [0 for i in range(12)]
        if(not(homeField) or sb):
            line[0] = 0.5
        result = getResult(home, away, line, times=num)
        self._ratingChange(result[0], Base.getLoser(result[0], [home, away]), result[1])

        return result[0]
Example #5
0
    def _playoffRound(self, games, sb=False):
        """Sims a round of the playoffs, adds it to the schedule, and returns
    the winners"""
        homeVal = 0.5 if sb else 1
        
        diffs = [[self.allRate[i[0]]-self.allRate[i[1]], self.seasRate[i[0]]-self.seasRate[i[1]]]
                 for i in games]
        diffs = [[homeVal,17]+i+[0 for j in range(12)] for i in diffs]
        probs = [getResult(games[i][0], games[i][1], diffs[i]) for i in range(len(games))]
        resultList = []

        for i in range(len(probs)):
            line = [probs[i][0], Base.getLoser(probs[i][0], games[i][:2])]
            line.extend([probs[i][3], str(probs[i][2]), str(probs[i][1])])
            resultList.append(line)

        for i in resultList:
            self.leagueSched.append(i)

        return [i[0] for i in resultList]
Example #6
0
 def _predictRating(self, games, week):
     """Uses Season._randomWinner() to predict the winner of games based only on rating"""
     ###Turn each game into a list that can go into RATING_ONLY
     ###games are [away, home], so this is done from the Home's Point of View
     rates = [[self.allRate[i[1]]-self.allRate[i[0]], self.seasRate[i[1]]-self.seasRate[i[1]]]
              for i in games]
     ###Predict, and add HFA, since it's from Home's POV
     rates = [[1,week]+i+[0 for j in range(12)] for i in rates]
     ###allProbs is a list of [winner, points, Percent, home]
     allProbs = []
     for i in range(len(rates)):
         allProbs.append(getResult(games[i][1], games[i][0], rates[i]))
     ###Get a [winner, loser] list
     resultList = [[allProbs[i][0], Base.getLoser(allProbs[i][0], games[i][:2])]
                    for i in range(len(allProbs))]
     
     for i in range(len(resultList)):
         holdLine = [allProbs[i][3], str(allProbs[i][2]), str(allProbs[i][1])]
         line = resultList[i] + holdLine
         self._ratingChange(resultList[i][0], resultList[i][1], allProbs[i][1])
         self.leagueSched.append(line)