def splitKickoff(self, gameData): fname = sys._getframe().f_code.co_name self.logger.debug("\n{0}{1}()".format(self.ind, fname)) changes = [] for idr in range(len(gameData)): drivePlays = gameData[idr].plays for dp in range(len(drivePlays)): playData = drivePlays[dp] if playData.valid is not True: continue if isinstance(playData.play, kickoffplay): self.logger.debug("{0} Kickoff Play: {1}".format( self.ind, playData.play.text)) newReturnPlay = returnplay(text=playData.play.text) newReturnPlay.pa.kickoffplay = False newReturnPlay.pa.touchdown = playData.play.pa.touchdown newReturnPlay.pa.fumble = playData.play.pa.fumble newReturnPlay.pa.runback = playData.play.pa.runback playData.play.pa.touchdown = False playData.play.pa.fumble = False playData.play.pa.runback = False newPossession = playpossession(start=None, end=None, text=playData.play.text) if playData.play.pa.getKey( "forced" ) is not None and not playData.possession.isKnownStart(): self.logger.debug( "{0} Using previous kickoff data to set possession to {1}" .format(playData.play.pa.forced)) newPossession.start = playData.play.pa.forced playData.play.pa.forced = False playData.possession.start = self.flipPossession( newPossession.start) else: newPossession.start = self.flipPossession( playData.possession) newPlayData = playsummary(possession=newPossession, start=playData.start.copy(), play=newReturnPlay, valid=playData.valid) drivePlays.insert(dp + 1, newPlayData) newReturnPlay.connectedPlays.append(playData) playData.play.connectedPlays.append(newReturnPlay) changes.append(idr) break self.logger.debug("{0}Found {1} Drives With Splits in {2}()".format( self.ind, len(changes), fname)) for idr in set(changes): self.dc.showDrive(gameData[idr], idr, "Drive {0}".format(idr)) return gameData
def splitInterception(self, gameData): fname = sys._getframe().f_code.co_name self.logger.debug("\n{0}{1}()".format(self.ind, fname)) changes = [] mixposs = mixedpossession() for idr in range(len(gameData)): drivePlays = gameData[idr].plays for dp in range(len(drivePlays)): playData = drivePlays[dp] if playData.valid is not True: continue if isinstance(playData.play, passingplay ) and playData.play.pa.getKey("interception"): self.logger.debug("{0} Interception Play: {1}".format( self.ind, playData.play.text)) newReturnPlay = returnplay(text=playData.play.text) newReturnPlay.pa.passingplay = False newReturnPlay.pa.touchdown = playData.play.pa.touchdown newReturnPlay.pa.fumble = playData.play.pa.fumble newReturnPlay.pa.runback = playData.play.pa.runback newReturnPlay.pa.interception = False playData.play.pa.touchdown = False playData.play.pa.fumble = False playData.play.pa.runback = False playData = mixposs.determineInterception( playData, drivePlays, dp) newPossession = playpossession(start=None, end=None, text=playData.play.text) try: newPossession.start = self.copMap[ playData.possession.start] except: newPossession.start = playData.possession.setUnknownStart( ) newPlayData = playsummary(possession=newPossession, start=playData.start.copy(), play=newReturnPlay, valid=playData.valid) drivePlays.insert(dp + 1, newPlayData) newReturnPlay.connectedPlays.append(playData) playData.play.connectedPlays.append(newReturnPlay) changes.append(idr) break self.logger.debug("{0}Found {1} Drives With Splits in {2}()".format( self.ind, len(changes), fname)) for idr in set(changes): self.dc.showDrive(gameData[idr], idr, "Drive {0}".format(idr)) return gameData
def returns(self, gameData): self.logger.debug("\n{0}".format(2*self.sep)) self.logger.debug("{0}Analyzing Kickoff Returns".format(self.ind)) for idr,driveData in enumerate(gameData): drivePlays = driveData.plays retval = self.getKickoffPlays(drivePlays) if retval is None: continue try: kickplay, retplay, genplay = retval except: raise ValueError("Could not parse return value: {0}".format(retval)) self.dc.showDrive(driveData, idr) ### Get starting place startingLine = kickplay.start.distToEndZone kickingYards = kickplay.play.yds.yards self.logger.debug("{0} Starting/Kicking -> {1} {2}".format(self.ind, startingLine, kickingYards)) ### Set starting line returnStart = startingLine - kickingYards if returnStart < 65: retplay.start.side = retplay.possession.start retplay.start.startY = returnStart else: raise ValueError("Not sure what to do about this kickoff!!!") if kickplay.play.pa.getKey("outofbounds") is True: retplay.play.yds.yards = None oobplay = self.pt.getPlay("No Play") oobplay.text = "Penalty: Kickoff Out of Bounds" oobplay.penalty = penalty(oobplay.text) oobposs = playpossession(start=kickplay.possession.start, end=None, text=oobplay.text) oobstart = kickplay.start.copy() oobstart.startY = 35 playResult = playsummary(possession=oobposs, start=oobstart, play=oobplay, valid=True) playResult.start.setYards(playResult.possession.start) drivePlays.insert(1, playResult) noretplay = self.pt.getPlay("") noretplay.text = "Post Penalty: Starting at 35 yard line" noretplay.yds.yards = 0 noretposs = playpossession(start=retplay.possession.start, end=None, text=noretplay.text) noretstart = retplay.start.copy() noretstart.startY = 35 playResult = playsummary(possession=noretposs, start=noretstart, play=noretplay, valid=True) playResult.start.setYards(playResult.possession.start) drivePlays.pop(2) ## get rid of old return play drivePlays.insert(2, playResult) ## insert new return play of zero yards self.dc.showDrive(driveData, idr) self.logger.debug("{0}Analyzing Kickoff Returns -> Done".format(self.ind)) return gameData
def splitTouchdown(self, gameData): fname = sys._getframe().f_code.co_name self.logger.debug("\n{0}{1}()".format(self.ind, fname)) changes = [] mixposs = mixedpossession() for idr in range(len(gameData)): drivePlays = gameData[idr].plays for dp in range(len(drivePlays)): playData = drivePlays[dp] if playData.valid is not True: continue if playData.play.pa.getKey("touchdown") is True: playData = mixposs.determineTouchdown(playData, drivePlays, dp, debug=False) if sum([isinstance(x.play, patplay) for x in drivePlays]) > 0: break playData.play.pa.addPAT() if playData.play.pa.getKey("addpat") is True: self.logger.debug("{0} Touchdown Play: {1}".format( self.ind, playData.play.text)) playData.play.pa.addpat = False ## Split Depends on Offense vs Defense PAT if playData.play.pa.getKey("defpat"): newPATPlay = patplay(text=playData.play.text) newPATPlay.pa.touchdown = False newPATPlay.pa.runback = playData.play.pa.runback playData.play.pa.runback = False newPossession = playpossession( start=None, end=None, text=playData.play.text) try: newPossession.start = self.copMap[ playData.possession.start] except: newPossession.start = playData.possession.setUnknownStart( ) self.logger.debug( "{0}This is a DEF PAT with POSS = {1}".format( self.ind, newPossession.start)) newPlayData = playsummary( possession=newPossession, start=playData.start.copy(), play=newPATPlay, valid=playData.valid) newPATPlay.connectedPlays.append(playData) playData.play.connectedPlays.append(newPATPlay) drivePlays.insert(dp + 1, newPlayData) changes.append(idr) else: newPATPlay = patplay(text=playData.play.text) newPATPlay.pa.touchdown = False newPATPlay.pa.runback = playData.play.pa.runback playData.play.pa.runback = False newPossession = playpossession( start=None, end=None, text=playData.play.text) newPossession.start = playData.possession.start self.logger.debug( "{0}This is a REGULAR PAT with POSS = {1}". format(self.ind, newPossession.start)) newPlayData = playsummary( possession=playData.possession, start=playData.start.copy(), play=newPATPlay, valid=playData.valid) drivePlays.insert(dp + 1, newPlayData) newPATPlay.connectedPlays.append(playData) playData.play.connectedPlays.append(newPATPlay) changes.append(idr) break self.logger.debug("{0}Found {1} Drives With Splits in {2}()".format( self.ind, len(changes), fname)) for idr in set(changes): self.dc.showDrive(gameData[idr], idr, "Drive {0}".format(idr)) return gameData
def splitFumble(self, gameData): fname = sys._getframe().f_code.co_name self.logger.debug("\n{0}{1}()".format(self.ind, fname)) changes = [] mixposs = mixedpossession() for idr in range(len(gameData)): drivePlays = gameData[idr].plays for dp in range(len(drivePlays)): playData = drivePlays[dp] if playData.valid is not True: continue if playData.play.pa.getKey("fumble") is True: self.logger.debug("{0} Fumble Play: {1}".format( self.ind, playData.play.text)) lostFumble = True try: if playData.possession.start == drivePlays[ dp + 1].possession.start and drivePlays[ dp + 1].valid is True: lostFumble = False except: lostFumble = True newReturnPlay = returnplay(text=playData.play.text) newReturnPlay.pa.touchdown = playData.play.pa.touchdown newReturnPlay.pa.fumble = False newReturnPlay.pa.runback = playData.play.pa.runback playData.play.pa.touchdown = False playData.play.pa.runback = False playData.play.pa.fumblereturn = False playData = mixposs.determineFumble(playData, drivePlays, dp, debug=False) newPossession = playpossession(start=None, end=None, text=playData.play.text) if playData.play.pa.getKey("forced") is not None: self.logger.debug( "{0}Using previous fumble data to set possession to {1}" .format(self.ind, playData.play.pa.forced)) newPossession.start = playData.play.pa.forced try: playData.possession.start = self.copMap[ playData.possession.start] except: playData.possession.setPreviousStart() playData.play.pa.forced = False else: self.logger.debug( "{0}Result of a lost fumble is {1}".format( self.ind, lostFumble)) if lostFumble: try: newPossession.start = self.copMap[ playData.possession.start] except: newPossession.setPreviousStart() else: newPossession.start = playData.possession.start self.logger.debug("{0}Fumble Old possession is {1}".format( self.ind, playData.possession.start)) self.logger.debug("{0}Fumble New possession is {1}".format( self.ind, newPossession.start)) changes.append(idr) gameData[idr].plays[dp] = playData if lostFumble: newPlayData = playsummary(possession=newPossession, start=playData.start.copy(), play=newReturnPlay, valid=playData.valid) newReturnPlay.connectedPlays.append(playData) playData.play.connectedPlays.append(newReturnPlay) drivePlays.insert(dp + 1, newPlayData) break self.logger.debug("{0}Found {1} Drives With Splits in {2}()".format( self.ind, len(changes), fname)) for idr in set(changes): self.dc.showDrive(gameData[idr], idr, "Drive {0}".format(idr)) return gameData
def splitPunt(self, gameData): fname = sys._getframe().f_code.co_name self.logger.debug("\n{0}{1}()".format(self.ind, fname)) changes = [] mixposs = mixedpossession() for idr in range(len(gameData)): drivePlays = gameData[idr].plays for dp in range(len(drivePlays)): playData = drivePlays[dp] if playData.valid is not True: continue if isinstance(playData.play, puntplay): ## Ignore if there is a safety if playData.play.pa.getKey("safety") is True: continue self.logger.debug("{0} Punt Play: {1}".format( self.ind, playData.play.text)) newReturnPlay = returnplay(text=playData.play.text) newReturnPlay.pa.puntplay = False newReturnPlay.pa.touchdown = playData.play.pa.touchdown newReturnPlay.pa.fumble = playData.play.pa.fumble newReturnPlay.pa.runback = playData.play.pa.runback playData.play.pa.touchdown = False playData.play.pa.fumble = False playData.play.pa.runback = False playData = mixposs.determinePunt(playData, drivePlays, dp, debug=False) newPossession = playpossession(start=None, end=None, text=playData.play.text) newPossession.start = self.flipPossession( playData.possession) try: newPossession.start = self.copMap[ playData.possession.start] except: newPossession.start = playData.possession.setUnknownStart( ) newPlayData = playsummary(possession=newPossession, start=playData.start.copy(), play=newReturnPlay, valid=playData.valid) drivePlays.insert(dp + 1, newPlayData) newReturnPlay.connectedPlays.append(playData) playData.play.connectedPlays.append(newReturnPlay) changes.append(idr) ## Check if the first play of the next drive is unknown try: if not gameData[idr + 1].plays[0].possession.isKnownStart(): gameData[idr + 1].plays[ 0].possession.start = newPossession.start except: pass break self.logger.debug("{0}Found {1} Drives With Splits in {2}()".format( self.ind, len(changes), fname)) for idr in set(changes): self.dc.showDrive(gameData[idr], idr, "Drive {0}".format(idr)) return gameData