Skip to content

Instantly share code, notes, and snippets.

@snooplsm
Forked from anonymous/gist:6330876
Created August 24, 2013 23:07
Show Gist options
  • Select an option

  • Save snooplsm/6330908 to your computer and use it in GitHub Desktop.

Select an option

Save snooplsm/6330908 to your computer and use it in GitHub Desktop.
from collections import Counter
import csv
PlayerList = []
Picks = {}
MIN = {"QB":1, "RB":1, "WR":1 , "TE":1 , "IR":2 }
MAX = {"QB":4, "RB":8, "WR":8 , "TE":4 , "IR":50 }
class Player:
def __str__(self):
return "name: " + self.name + " team: " + self.team + " age: " + self.age + " games: " + str(self.games) + " games_started: " + str(self.games_started) + " start_percentage: " + str(self.startPercentage()) + " fantasy_points: " + str(self.getFantasyPoints())
def startPercentage(self):
if self.games == 0:
return 0.0
return self.games_started/float(self.games)
def getFantasyPoints(self):
passingScore = 2*(self.passing_yards/5.0)
interceptionPoints = -30*(self.passing_interceptions)
passingTouchdownPoints = 45*(self.passing_td)
rushingYards = self.rushing_yards
rushingTD = 60*(self.rushing_td)
receivingYards = 1.25*(self.receiving_yards)
receivingTD = 60*(self.receiving_td)
receivingReceptions = 2*(self.receiving_receptions)
return passingScore + interceptionPoints + passingTouchdownPoints + rushingYards + rushingTD + receivingYards + receivingTD + receivingReceptions
positionToPlayers = {}
years = ["2010", "2011", "2012"]
print "using years: ", years
headers = {}
players = {}
playerNames = {}
currentPlayers = None
for year in years:
print year
yearReader = csv.reader(open(year+"FF_00.txt"))
for header in yearReader:
for i in range(len(header)):
headers[header[i]] = i
break
for player in yearReader:
p = Player()
p.position = player[headers["FANTASY_POSITION"]]
p.name = player[headers["NAME"]]
p.team = player[headers["TEAM"]]
p.age = player[headers["AGE"]]
p.receiving_yards = 0
if len(player[headers["RECEIVING_YARDS"]]) != 0:
p.receiving_yards = int(player[headers["RECEIVING_YARDS"]])
p.receiving_receptions = 0
if len(player[headers["RECEIVING_RECEPTIONS"]]) != 0:
p.receiving_receptions = int(player[headers["RECEIVING_RECEPTIONS"]])
p.receiving_td = 0
if len(player[headers["RECEIVING_TD"]]) != 0:
p.receiving_td = int(player[headers["RECEIVING_TD"]])
p.rushing_td = 0
if len(player[headers["RUSHING_TD"]]) != 0:
p.rushing_td = int(player[headers["RUSHING_TD"]])
p.rushing_yards = 0
if len(player[headers["RUSHING_YARDS"]]) != 0:
p.rushing_yards = int(player[headers["RUSHING_YARDS"]])
p.passing_td = 0
if len(player[headers["PASSING_TD"]]) != 0:
p.passing_td = int(player[headers["PASSING_TD"]])
p.passing_interceptions = 0
if len(player[headers["PASSING_INTERCEPTIONS"]]) != 0:
p.passing_interceptions = int(player[headers["PASSING_INTERCEPTIONS"]])
p.passing_yards = 0
if len(player[headers["PASSING_YARDS"]]) != 0:
p.passing_yards = int(player[headers["PASSING_YARDS"]])
p.games = 0
if len(player[headers["GAMES"]]) != 0:
p.games = int(player[headers["GAMES"]])
p.games_started = 0
if len(player[headers["GAMES_STARTED"]]) != 0:
p.games_started = int(player[headers["GAMES_STARTED"]])
print p
PlayerList.append(p)
players = None
if year not in positionToPlayers:
positionToPlayers[year] = {}
if p.position not in positionToPlayers[year]:
players = []
positionToPlayers[year][p.position] = players
else:
players = positionToPlayers[year][p.position]
players.append(p)
#players[player[headers["NAME"]].upper() + "_" + year] = player
#playerName = player[headers["NAME"]]
#if playerName in playerNames:
# print "duplicate", playerName
#playerNames[player[headers["NAME"]]] = None
PlayerList = sorted(PlayerList, key=lambda player: player.getFantasyPoints())
for p in PlayerList:
print p
for key in positionToPlayers[year]:
players = positionToPlayers[year][key]
players = sorted(players, key = lambda player: player.getFantasyPoints())
for player in players:
print key, player
# print headers
class Team:
def __str__(self):
return "Team Name: " + self.name + "Roster: " + self.roster
# keep track of everyone's picks
draftRound = 1
teams = []
numTeams = int(raw_input("How many teams are there? "))
year = "2012"
while len(teams) < numTeams:
newTeam = raw_input("Enter new team ")
team = Team()
team.name = newTeam
teams.append(team)
team.roster = []
team.positions = []
for t in teams:
print str(t.name) + ": " + str(t.roster)
totalRounds = int(raw_input("How many rounds are in the draft? "))
draftRound = 0
while draftRound < totalRounds:
for t in teams:
newPlayer = raw_input("new player " )
toDel = []
for k, players in positionToPlayers[year].items():
print len(players)
for v in players:
if newPlayer in v.name:
t.roster.append(newPlayer)
print "key = " + str(k)
t.positions.append(k)
toDel.append(v)
for d in toDel:
print "to delete: " + str(d)
#else:
#print("Player has already been picked")
for d in toDel:
print "delete "
#delete positionToPlayers[year][d]
print "positions: " + str(t.positions)
c = Counter(t.positions)
for p in t.positions:
c[p] +=1
print c
#player = t.positions[len(t.positions)-1]
#if c[QB] < MIN[player.position]
# print("Need more
#elif c[QB] > QBMax:
draftRound += 1
print t.roster
# how to determine what best next pick is based on what is already chosen (calcuate for everyone)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment