def show_team_standings(): rd = setup_nav() # Determine season(s) to get information from teamgames = get_r_seasons() form = SeasonSelectForm(request.form) form.seasons.choices = [(x, str(x)[0:4] + "-" + str(x)[4:]) for x in sorted(teamgames.keys(), reverse=True)] try: form.seasons.data = [int(x) for x in form.seasons.data] except: pass allseasons = [(x, str(x)[0:4] + "-" + str(x)[4:]) for x in sorted(teamgames.keys(), reverse=True)] if request.method == "POST" and form.validate(): seasons = [int(x) for x in form.seasons.data] else: smax = max(teamgames.keys()) seasons = [ smax, ] seasongames = get_r_standings(teamgames, seasons=seasons) return render_template('teams/teams.html', rd=rd, seasongames=seasongames, form=form, allseasons=allseasons, seasons=seasons)
def iframe_woi(pagename): rd = setup_nav() print pagename return render_template("woi-frame.html", page=pagename, rd=rd, url="http://biscuit.war-on-ice.com/" + pagename)
def glossary(): rd = setup_nav() tf = open("html/glossary_text.txt") tf = tf.read().decode('utf-8') text = ast.literal_eval(tf) return render_template("misc/glossary.html", rd = rd, text=text)
def show_player(): rd = setup_nav() rdata = get_rdata(CAP_DATA) keys = [] for cap in rdata["team.two"]: print cap["Name"], cap["S20152016"] break return render_template('players/players.html', rd=rd)
def show_games(): """ Shows recent game summaries, same table as the one on the home page""" rd = setup_nav() games = get_r_games() return render_template('game/games.html', rd=rd, games=games, teamname=filters.teamname)
def show_game_summary_header(gameId): rd = setup_nav() season = gameId[0:8] gcode = gameId[8:] # Get GamesTest information gamedata = GamesTest.query.filter_by(season=season, gcode=int(gcode)).first() return render_template('game/gamesummaryheader.html', gamedata=gamedata)
def show_game_summary_test(gameId): rd = setup_nav() return render_template('game/gamesummary2.html', gameId = gameId, strength_situations = constants.strength_situations, score_situations = constants.score_situations, periods = constants.periods, rd = rd)
def show_gar(): rd = setup_nav() csv = resources.get_csv("http://war-on-ice.com/data/GAR-seasonal.csv") cd = resources.combine_data(csv) total = resources.combine_seasons(cd) return render_template("players/gar.html", rd=rd, cd=cd, total=total)
def show_player_contract(playerId): rd = setup_nav() selectedPlayer = Player.query.filter_by(PlayerId=playerId).first() selectedPlayerContracts = Contract.query.filter_by(PlayerID=playerId).order_by(desc(Contract.EffectiveSeason)).all() return render_template('cap/playercap.html', player = selectedPlayer, contractDetails = selectedPlayerContracts, title = selectedPlayer.FullName, rd=rd)
def show_player_contract(playerId): rd = setup_nav() selectedPlayer = Player.query.filter_by(PlayerId=playerId).first() selectedPlayerContracts = Contract.query.filter_by( PlayerID=playerId).order_by(desc(Contract.EffectiveSeason)).all() return render_template('cap/playercap.html', player=selectedPlayer, contractDetails=selectedPlayerContracts, title=selectedPlayer.FullName, rd=rd)
def show_team_current(teamId): rd = setup_nav() selectedTeam = Team.query.filter_by(TeamId=teamId).first() return render_template('cap/teamcap.html', team = selectedTeam, rd=rd) # # @app.route('/team/<teamId>/<seasonId>/') # def show_team_historical(teamId, seasonId): # selectedTeam = models.Teams.query.filter_by(TeamId=teamId).first() # return render_template('teamcap.html', # team = selectedTeam)
def show_game_summary(gameId): # Get game information from URL season = gameId[0:8] gcode = gameId[8:] # Get form results or default form = GameSummaryForm(request.form) if request.method == "POST" and form.validate(): tablecolumns = form.tablecolumns.data teamstrengths = form.teamstrengths.data scoresituations = form.scoresituations.data period = constants.periods_options[form.period.data]["value"] else: tablecolumns = "0" teamstrengths = constants.strength_situations_dict[ constants.strength_situations["default"]]["value"] scoresituations = constants.score_situations_dict[ constants.score_situations["default"]]["value"] period = [0] period.extend( constants.periods_options[constants.periods["default"]]["value"]) # Prepare form results for queries scorediffcat = int(scoresituations) gamestate = int(teamstrengths) period = [int(x) for x in period] # Setup nav rd = setup_nav() # Get GamesTest information gamedata = GamesTest.query.filter_by(season=season, gcode=int(gcode)).first() if gamedata.status == 3: live = False else: live = True return render_template('game/gamesummary.html', tablecolumns=int(tablecolumns), gameId=gameId, strength_situations=constants.strength_situations, score_situations=constants.score_situations, periods=constants.periods, rd=rd, gamestate=gamestate, period=period, gamedata=gamedata, form=form, live=live)
def show_team_current(teamId): rd = setup_nav() selectedTeam = Team.query.filter_by(TeamId=teamId).first() return render_template('cap/teamcap.html', team=selectedTeam, rd=rd) # # @app.route('/team/<teamId>/<seasonId>/') # def show_team_historical(teamId, seasonId): # selectedTeam = models.Teams.query.filter_by(TeamId=teamId).first() # return render_template('teamcap.html', # team = selectedTeam)
def show_game_summary(gameId): # Get game information from URL season = gameId[0:8] gcode = gameId[8:] # Get form results or default form = GameSummaryForm(request.form) if request.method == "POST" and form.validate(): tablecolumns = form.tablecolumns.data teamstrengths = form.teamstrengths.data scoresituations = form.scoresituations.data period = constants.periods_options[form.period.data]["value"] else: tablecolumns = "0" teamstrengths = constants.strength_situations_dict[constants.strength_situations["default"]]["value"] scoresituations = constants.score_situations_dict[constants.score_situations["default"]]["value"] period = [0] period.extend(constants.periods_options[constants.periods["default"]]["value"]) # Prepare form results for queries scorediffcat = int(scoresituations) gamestate = int(teamstrengths) period = [int(x) for x in period] # Setup nav rd = setup_nav() # Get GamesTest information gamedata = GamesTest.query.filter_by(season=season, gcode=int(gcode)).first() if gamedata.status == 3: live = False else: live = True return render_template('game/gamesummary.html', tablecolumns=int(tablecolumns), gameId=gameId, strength_situations=constants.strength_situations, score_situations=constants.score_situations, periods=constants.periods, rd=rd, gamestate=gamestate, period=period, gamedata = gamedata, form = form, live=live)
def iframe_cap(): rd = setup_nav() endurls = [("quicksheet", "Quick Look"), ("recent-signings", "Recent Signings"), ("playerroster", "Player AAV By Season"), ("attained-bonuses", "Performance Bonuses Attained")] urls = [] for u in endurls: tu = {} tu["id"] = u[0] tu["name"] = u[1] tu["url"] = "http://www.war-on-ice.com/cap/" + u[0] + ".html" urls.append(tu) rd["urls"] = urls return render_template("iframe_cap.html", cap=True, rd=rd)
def index(): rd = setup_nav() teamDict = constants.teamDict teamDict["Atlanta Thrashers"] = "ATL" search = [] for team in teamDict: line = [team, teamDict[team]] search.append(line) players = models.RosterMaster.query.all() count = 0 for player in players: count += 1 line = [player.FullName, player.__dict__["PlayerId"]] search.append(line) games = calls.get_r_games() #games = calls.get_games() return render_template("index.html", rd=rd, games=games, search=search)
def show_team_standings(): rd = setup_nav() # Determine season(s) to get information from teamgames = get_r_seasons() form = SeasonSelectForm(request.form) form.seasons.choices = [(x, str(x)[0:4] + "-" + str(x)[4:]) for x in sorted(teamgames.keys(), reverse=True)] try: form.seasons.data = [int(x) for x in form.seasons.data] except: pass allseasons = [(x, str(x)[0:4] + "-" + str(x)[4:]) for x in sorted(teamgames.keys(), reverse=True)] if request.method == "POST" and form.validate(): seasons = [int(x) for x in form.seasons.data] else: smax = max(teamgames.keys()) seasons = [smax, ] seasongames = get_r_standings(teamgames, seasons=seasons) return render_template('teams/teams.html', rd=rd, seasongames=seasongames, form=form, allseasons=allseasons, seasons=seasons)
def show_series(): """ Show series information between two teams for a season.""" rd = setup_nav() form = SeriesSummaryForm(request.form) teamgames = get_r_seasons() # Update season choices based on teamgames data form.season.choices = [(x, str(x)[0:4] + "-" + str(x)[4:]) for x in sorted(teamgames.keys(), reverse=True)] if request.method == "POST": period = constants.periods_options[form.period.data]["value"] else: # All periods by default period = [0] period.extend( constants.periods_options[constants.periods["default"]]["value"]) tablecolumns = form.tablecolumns.data # Find games where these teams faced each other games = GamesTest.query.filter( GamesTest.season == form.season.data, or_(GamesTest.hometeam == form.team1.data, GamesTest.hometeam == form.team2.data), or_(GamesTest.awayteam == form.team1.data, GamesTest.awayteam == form.team2.data)) gcodes = set() for game in games: gcodes.add(game.gcode) # Overall game data gamedata = [] # Team specific data for table teams = [] # Goalie specific data for goalie table goalies = [] # Values that should be skipped in accumulation skip = [ "period", "home", "Opponent", "gamestate", "gcode", "Team", "TOI", "Gm", "ID", "season" ] gamefound = set() foundplayers = set() goaliefound = set() playerfound = set() away = [] home = [] allplayers = [] playerteams = {} players = set() coplayers = {} pbp = [] # For each gcode, get the RData file for that game for gcode in gcodes: rdata = get_rdata("http://data.war-on-ice.net/games/" + str(form.season.data) + str(gcode) + ".RData") pbp.extend(rdata["playbyplay"]) rteamrun = rdata["teamrun"] coplayers = get_coplayers(rdata, coplayers) for tr in sorted(rteamrun, key=lambda x: x["TOI"], reverse=True): gid = str(tr["gcode"]) + str(tr["season"]) + str(tr["Team"]) if tr["period"] in period and int(tr["gamestate"]) == int( form.teamstrengths.data) and gid not in gamefound: gamefound.add(gid) ar = None for team in teams: if team["Team"] == tr["Team"]: ar = team break if ar is None: tr["MSF"] = int(tr["FF"]) - int(tr["SF"]) tr["BSF"] = tr["CF"] - tr["MSF"] - tr["SF"] teams.append(tr) else: for key in tr: if key not in skip: ar[key] += tr[key] ar["MSF"] += int(tr["FF"]) - int(tr["SF"]) ar["BSF"] += tr["CF"] - (int(tr["FF"]) - int(tr["SF"])) - tr["SF"] ar["TOI"] += float(tr["TOI"]) rgoalies = rdata["goalierun"] for tr in sorted(rgoalies, key=lambda x: x["TOI"], reverse=True): gid = str(tr["gcode"]) + str(tr["season"]) + str(tr["Team"]) + str( tr["ID"]) if tr["period"] in period and tr["gamestate"] == int( form.teamstrengths.data) and gid not in goaliefound: goaliefound.add(gid) ar = None for goalie in goalies: if goalie["ID"] == tr["ID"] and goalie["Team"] == tr[ "Team"]: ar = goalie break if ar is None: tr["gu"] = tr["goals.0"] tr["su"] = tr["shots.0"] tr["gl"] = tr["goals.1"] tr["sl"] = tr["shots.1"] tr["gm"] = tr["goals.2"] tr["sm"] = tr["shots.2"] tr["gh"] = tr["goals.3"] + tr["goals.4"] tr["sh"] = tr["shots.3"] + tr["shots.4"] tr["TOI"] = float( tr["TOI"]) # round(float(tr["TOI"]) / 60.0, 1) tr["Gm"] = 1 goalies.append(tr) foundplayers.add(tr["ID"]) else: ar["gu"] += tr["goals.0"] ar["su"] += tr["shots.0"] ar["gl"] += tr["goals.1"] ar["sl"] += tr["shots.1"] ar["gm"] += tr["goals.2"] ar["sm"] += tr["shots.2"] ar["gh"] += tr["goals.3"] + tr["goals.4"] ar["sh"] += tr["shots.3"] + tr["shots.4"] ar["TOI"] += float( tr["TOI"]) #round(float(tr["TOI"]) / 60.0, 1) ar["Gm"] += 1 rplayerrun = rdata["playerrun"] for tr in sorted(rplayerrun, key=lambda x: x["TOI"], reverse=True): if tr["ID"] not in foundplayers: foundplayers.add(tr["ID"]) gid = str(tr["gcode"]) + str(tr["season"]) + str(tr["Team"]) + str( tr["ID"]) if tr["period"] in period and tr["gamestate"] == int( form.teamstrengths.data) and gid not in playerfound: playerfound.add(gid) players.add(tr["ID"]) ar = None pteam = None for p in allplayers: if p["ID"] == tr["ID"]: ar = p break if ar is None: tr["G"] = int(tr["GOAL1"] + tr["GOAL2"] + tr["GOAL3"] + tr["GOAL4"]) tr["TOI"] = float( tr["TOI"]) # round(float(tr["TOI"]) / 60.0, 1) tr["Gm"] = 1 allplayers.append(tr) playerteams[tr["ID"]] = tr["Team"] else: for key in tr: if key not in skip: ar[key] += tr[key] ar["G"] += int(tr["GOAL1"] + tr["GOAL2"] + tr["GOAL3"] + tr["GOAL4"]) ar["TOI"] += float( tr["TOI"]) # round(float(tr["TOI"]) / 60.0, 1) ar["Gm"] += 1 ht = None at = None for player in allplayers: if ht is None: home.append(player) ht = player["Team"] elif ht == player["Team"]: home.append(player) elif at == None: away.append(player) else: away.append(player) for co in coplayers: matchup = coplayers[co] for p in ["p1", "p2"]: foundplayers.add(matchup[p]) woiid = get_player_info(foundplayers) hvh, hometeam, awayteam = get_hvh(coplayers, playerteams, woiid) homecorsi = [] awaycorsi = [] for line in home: for key in line: if type(line[key]).__module__ == "numpy" and numpy.isnan( line[key]): line[key] = 0 if line["ID"] in woiid and woiid[line["ID"]]["pos"] != "G": line["full_name"] = str(woiid[line["ID"]]["full_name"]) homecorsi.append(line) for line in away: for key in line: if type(line[key]).__module__ == "numpy" and numpy.isnan( line[key]): line[key] = 0 if line["ID"] in woiid and woiid[line["ID"]]["pos"] != "G": line["full_name"] = str(woiid[line["ID"]]["full_name"]) awaycorsi.append(line) # ev.team pbphome = [] pbpaway = [] scoresituations = int(form.scoresituations.data) for play in pbp: if play["period"] in period and ( play["score.diff.cat"] == scoresituations or scoresituations == 7) and play["etype"] in ["GOAL", "SHOT", "BLOCK", "MISS"]: for key in play: if type(play[key]).__module__ == "numpy" and numpy.isnan( play[key]): play[key] = 0 # get Names if play["ev.player.1"] != "xxxxxxxNA": play["P1"] = woiid[play["ev.player.1"]]["full_name"] if play["ev.player.2"] != "xxxxxxxNA": play["P2"] = woiid[play["ev.player.2"]]["full_name"] if play["ev.player.3"] != "xxxxxxxNA": play["P3"] = woiid[play["ev.player.3"]]["full_name"] if play["ev.team"] == hometeam: if int(form.teamstrengths.data) in calc_strengths(play, True): pbphome.append(play) elif play["ev.team"] == awayteam: if int(form.teamstrengths.data) in calc_strengths(play, False): pbpaway.append(play) return render_template("game/series.html", rd=rd, hvh=hvh, form=form, woiid=woiid, teamrun=teams, goalies=goalies, hometeam=hometeam, awayteam=awayteam, gamedata=gamedata, coplayers=coplayers, home=home, homecorsi=homecorsi, away=away, awaycorsi=awaycorsi, pbphome=pbphome, pbpaway=pbpaway, tablecolumns=int(tablecolumns))
def show_game_summary_tables(gameId): rd = setup_nav() if request.method == "GET": tablecolumns = request.args.get("tablecolumns") teamstrengths = request.args.get("teamstrengths") scoresituations = request.args.get("scoresituation") period = constants.periods_options[request.args.get("period")]["value"] else: tablecolumns = "0" teamstrengths = constants.strength_situations_dict[ constants.strength_situations["default"]]["value"] scoresituations = constants.score_situations_dict[ constants.score_situations["default"]]["value"] period = [0] period.extend( constants.periods_options[constants.periods["default"]]["value"]) # Get game information from URL season = gameId[0:8] gcode = gameId[8:] # Prepare form results for queries scorediffcat = int(scoresituations) gamestate = int(teamstrengths) period = [int(x) for x in period] rdata = get_rdata("http://data.war-on-ice.net/games/" + season + gcode + ".RData") eventcount = { "homepp": [], "awaypp": [], "4v4": [], "homegoal": [], "awaygoal": [], "emptynet": [], "homesc": [{ "seconds": 0, "value": 0 }], "awaysc": [{ "seconds": 0, "value": 0 }], "homesa": [{ "seconds": 0, "value": 0 }], "awaysa": [{ "seconds": 0, "value": 0 }], "pend": [] } pbp = rdata["playbyplay"] rteamrun = rdata["teamrun"] teamrun = [] teams = set() hometeam = "" awayteam = "" previous = 1000 for tr in sorted(rteamrun, key=lambda x: x["TOI"], reverse=True): if hometeam == "" and tr["home"] == 1: hometeam = tr["Team"] elif awayteam == "" and tr["home"] == 0: awayteam = tr["Team"] if tr["period"] in period and tr["gamestate"] == gamestate: if tr["Team"] not in teams: tr["MSF"] = int(tr["FF"]) - int(tr["SF"]) tr["BSF"] = tr["CF"] - tr["MSF"] - tr["SF"] tr["TOI"] = float( tr["TOI"]) # round(float(tr["TOI"]) / 60.0, 1) teamrun.append(tr) teams.add(tr["Team"]) goalies = [] rgoalies = rdata["goalierun"] teams = set() foundplayers = set() for tr in sorted(rgoalies, key=lambda x: x["TOI"], reverse=True): if tr["period"] in period and tr["gamestate"] == gamestate: if tr["ID"] not in foundplayers: tr["gu"] = tr["goals.0"] tr["su"] = tr["shots.0"] tr["gl"] = tr["goals.1"] tr["sl"] = tr["shots.1"] tr["gm"] = tr["goals.2"] tr["sm"] = tr["shots.2"] tr["gh"] = tr["goals.3"] + tr["goals.4"] tr["sh"] = tr["shots.3"] + tr["shots.4"] tr["TOI"] = float( tr["TOI"]) # round(float(tr["TOI"]) / 60.0, 1) goalies.append(tr) teams.add(tr["Team"]) foundplayers.add(tr["ID"]) rplayerrun = rdata["playerrun"] away = [] home = [] players = set() playerteams = {} for tr in sorted(rplayerrun, key=lambda x: x["TOI"], reverse=True): if tr["ID"] not in foundplayers: foundplayers.add(tr["ID"]) playerteams[tr["ID"]] = tr["Team"] if tr["period"] in period and tr["gamestate"] == gamestate and tr[ "ID"] not in players: players.add(tr["ID"]) tr["G"] = int(tr["GOAL1"] + tr["GOAL2"] + tr["GOAL3"] + tr["GOAL4"]) tr["TOI"] = float(tr["TOI"]) #round(float(tr["TOI"]) / 60.0, 1) if tr["home"] == 1: home.append(tr) else: away.append(tr) # Get GamesTest information gamedata = GamesTest.query.filter_by(season=season, gcode=int(gcode)).first() woiid = get_player_info(foundplayers) homecorsi = [] awaycorsi = [] for line in home: for key in line: if type(line[key]).__module__ == "numpy" and numpy.isnan( line[key]): line[key] = 0 if line["ID"] in woiid and woiid[line["ID"]]["pos"] != "G": line["full_name"] = str(woiid[line["ID"]]["full_name"]) homecorsi.append(line) for line in away: for key in line: if type(line[key]).__module__ == "numpy" and numpy.isnan( line[key]): line[key] = 0 if line["ID"] in woiid and woiid[line["ID"]]["pos"] != "G": line["full_name"] = str(woiid[line["ID"]]["full_name"]) awaycorsi.append(line) pbphome = [] pbpaway = [] for play in pbp: if play["period"] in period and (play["score.diff.cat"] == int(scoresituations) or int(scoresituations) == 7): if play["etype"] in ["MISS", "GOAL", "SHOT", "BLOCK"]: # Shot Attempt if play["ev.team"] == hometeam: if gamestate in calc_strengths(play, True): eventcount["homesa"].append({ "seconds": play["seconds"], "value": len(eventcount["homesa"]) }) eventcount["homesc"] = calc_sc(eventcount["homesc"], play) else: if gamestate in calc_strengths(play, False): eventcount["awaysa"].append({ "seconds": play["seconds"], "value": len(eventcount["awaysa"]) }) eventcount["awaysc"] = calc_sc(eventcount["awaysc"], play) # Goal if play["etype"] == "GOAL": if play["ev.team"] == hometeam: eventcount["homegoal"].append({ "seconds": play["seconds"], "value": len(eventcount["homegoal"]) + 1 }) else: eventcount["awaygoal"].append({ "seconds": play["seconds"], "value": len(eventcount["awaygoal"]) + 1 }) elif play["etype"] == "PENL": # Penalty seconds = int(re.findall("\d+", play["type"])[0]) * 60 if play["ev.team"] == hometeam: eventcount["awaypp"].append({ "seconds": play["seconds"], "length": seconds }) elif play["ev.team"] == awayteam: eventcount["homepp"].append({ "seconds": play["seconds"], "length": seconds }) elif play["etype"] == "PEND": # Period End eventcount["pend"].append(play["seconds"]) if play["etype"] in ["MISS", "GOAL", "SHOT", "BLOCK", "MISS"]: for key in play: if type(play[key]).__module__ == "numpy" and numpy.isnan( play[key]): play[key] = 0 # get Names if play["ev.player.1"] != "xxxxxxxNA": play["P1"] = woiid[play["ev.player.1"]]["full_name"] if play["ev.player.2"] != "xxxxxxxNA": play["P2"] = woiid[play["ev.player.2"]]["full_name"] if play["ev.player.3"] != "xxxxxxxNA": play["P3"] = woiid[play["ev.player.3"]]["full_name"] if play["ev.team"] == hometeam: if gamestate in calc_strengths(play, True): pbphome.append(play) elif play["ev.team"] == awayteam: if gamestate in calc_strengths(play, False): pbpaway.append(play) # Find PowerPlay Goals eventcount = findPPGoal(eventcount, "homepp", "homegoal") eventcount = findPPGoal(eventcount, "awaypp", "awaygoal") homelast = eventcount["homesa"][-1]["seconds"] awaylast = eventcount["awaysa"][-1]["seconds"] if homelast < awaylast: eventcount["homesa"].append({ "seconds": awaylast, "value": eventcount["homesa"][-1]["value"] }) elif homelast > awaylast: eventcount["awaysa"].append({ "seconds": homelast, "value": eventcount["awaysa"][-1]["value"] }) homelast = eventcount["homesc"][-1]["seconds"] awaylast = eventcount["awaysc"][-1]["seconds"] if homelast < awaylast: eventcount["homesc"].append({ "seconds": awaylast, "value": eventcount["homesc"][-1]["value"] }) elif homelast > awaylast: eventcount["awaysc"].append({ "seconds": homelast, "value": eventcount["awaysc"][-1]["value"] }) # Get coplayer data coplayers = get_coplayers(rdata) hvh, hometeam, awayteam = get_hvh(coplayers, playerteams, woiid) return render_template('game/gamesummarytables.html', tablecolumns=int(tablecolumns), home=home, homecorsi=homecorsi, away=away, awaycorsi=awaycorsi, gamedata=gamedata, goalies=goalies, woiid=woiid, pbphome=pbphome, pbpaway=pbpaway, teamrun=teamrun, eventcount=eventcount, hvh=hvh)
def about(): rd = setup_nav() return render_template("misc/about.html", rd=rd)
def show_team_current(teamId): rd = setup_nav() #caps = ContractHeader.query.filter(ContractHeader.ContractTeamID==teamId).order_by(desc(ContractHeader.EffectiveSeason)) #players = {} #playerids = set() #for cap in caps: # if cap.PlayerID not in players: # players[cap.PlayerID] = cap # playerids.add(cap.PlayerID) caps = PlayerCap.query.filter(PlayerCap.Team==teamId).order_by(desc(PlayerCap.Date)) players = {} maxdate = None for cap in caps: if maxdate is None: maxdate = cap.Date elif maxdate > cap.Date: break players[cap.PlayerId] = cap woiid = get_player_info(players.keys()) forwards = {} defensemen = {} goalies = {} gone = {} its = {} now = datetime.datetime.now() cy = now.year years = [] while len(years) < 5: years.append(cy-1) cy += 1 for player in players: if player in woiid: currplayer = {} currplayer["ID"] = player position = woiid[player]["pos"] if players[player].DayStatus == "Major": if position == "D": defensemen[player] = currplayer elif position == "G": goalies[player] = currplayer else: forwards[player] = currplayer elif players[player].DayStatus == "Minor": its[player] = currplayer return render_template('cap/teamcap.html', teamId=teamId, rd=rd, woiid=woiid, forwards=forwards, defensemen=defensemen, goalies=goalies, its=its, years=years) # # @app.route('/team/<teamId>/<seasonId>/') # def show_team_historical(teamId, seasonId): # selectedTeam = models.Teams.query.filter_by(TeamId=teamId).first() # return render_template('teamcap.html', # team = selectedTeam)
def show_team_comparisons(): rd = setup_nav() cpg = ComparisonGraphForm() teamgames = get_r_seasons() tablecolumns = [0, ] form = ComparisonForm(request.form) form.startingSeason.choices = [(x, str(x)[0:4] + "-" + str(x)[4:]) for x in sorted(teamgames.keys(), reverse=True)] form.endingSeason.choices = [(x, str(x)[0:4] + "-" + str(x)[4:]) for x in sorted(teamgames.keys(), reverse=True)] filterteams = form.filterTeams.data if filterteams is None: filterteams = [] allteams = form.filterTeams.choices try: oldStart = form.startingSeason.data oldEnd = form.endingSeason.data form.startingSeason.data = int(form.startingSeason.data) form.endingSeason.data = int(form.endingSeason.data) except: pass allseasons = [(x, str(x)[0:4] + "-" + str(x)[4:]) for x in sorted(teamgames.keys(), reverse=True)] usedates = False if request.method == "POST" and form.validate(): startingSeason = form.startingSeason.data endingSeason = form.endingSeason.data form.startingSeason.data = oldStart form.endingSeason.data = oldEnd startingDate = form.startingDate.data endingDate = form.endingDate.data usedates = form.bydate.data if not usedates: if endingSeason > startingSeason: begin = startingSeason end = endingSeason else: begin = endingSeason end = startingSeason currSeason = begin seasons = [begin, ] # TODO: Error check this? while begin != end: bsplit = str(begin)[0:4] begin = int(bsplit) * 10000 + 10001 + int(bsplit) + 1 seasons.append(begin) else: if endingDate < startingDate: temp = endingDate endingDate = startingDate startingDate = temp else: smax = max(teamgames.keys()) seasons = [smax, ] # Filter teamrun based on form data teamstrengths = int(form.teamstrengths.data) if teamstrengths == 7: teamstrengths = [constants.strength_situations_dict[x]["value"] for x in constants.strength_situations_dict] else: teamstrengths = [teamstrengths, ] scoresituations = int(form.scoresituations.data) if scoresituations == 7: scoresituations = [constants.score_situations_dict[x]["value"] for x in constants.score_situations_dict] homeaway = form.homeAway.data if homeaway == "all": homeaway = [0, 1] else: homeaway = [int(homeaway), ] periods = constants.periods_options[form.period.data]["value"] if 0 in periods: periods = [0, ] if 7 in scoresituations: scoresituations = [7, ] if 7 in teamstrengths: teamstrengths = [7, ] if not usedates: if len(filterteams) == 0: teamrun = TeamRun.query.filter(TeamRun.season.in_(seasons), TeamRun.gamestate.in_(teamstrengths), TeamRun.scorediffcat.in_(scoresituations), TeamRun.home.in_(homeaway), TeamRun.period.in_(periods)).all() else: teamrun = TeamRun.query.filter(TeamRun.season.in_(seasons), TeamRun.gamestate.in_(teamstrengths), TeamRun.scorediffcat.in_(scoresituations), TeamRun.home.in_(homeaway), TeamRun.Team.in_(filterteams), TeamRun.period.in_(periods)).all() else: if len(filterteams) == 0: teamrun = TeamRun.query.filter(TeamRun.Date >= startingDate, TeamRun.Date <= endingDate, TeamRun.gamestate.in_(teamstrengths), TeamRun.scorediffcat.in_(scoresituations), TeamRun.home.in_(homeaway), TeamRun.period.in_(periods)).all() else: teamrun = TeamRun.query.filter(TeamRun.Date >= startingDate, TeamRun.Date <= endingDate, TeamRun.gamestate.in_(teamstrengths), TeamRun.scorediffcat.in_(scoresituations), TeamRun.home.in_(homeaway), TeamRun.Team.in_(filterteams), TeamRun.period.in_(periods)).all() games, seasons = helpers.calculate(teamrun, form.divideSeason.data) if form.splitgame.data == True: summaries = games else: summaries = seasons return render_template('teams/teamcomparison.html', rd=rd, form=form, summaries=summaries, cpg=cpg, filterteams=filterteams, allteams=allteams)
def show_team_cap(): rd = setup_nav() return render_template('cap/teamscap.html', rd=rd)
def iframe_test(): rd = setup_nav() return render_template("iframe_test.html", rd=rd)
def index(): rd = setup_nav() return render_template("index.html", rd=rd)
def show_by_team(): rd = setup_nav() return render_template("teams/team.html", rd=rd)
def show_series(): """ Show series information between two teams for a season.""" rd = setup_nav() form = SeriesSummaryForm(request.form) teamgames = get_r_seasons() # Update season choices based on teamgames data form.season.choices = [(x, str(x)[0:4] + "-" + str(x)[4:]) for x in sorted(teamgames.keys(), reverse=True)] if request.method == "POST": period = constants.periods_options[form.period.data]["value"] else: # All periods by default period = [0] period.extend(constants.periods_options[constants.periods["default"]]["value"]) tablecolumns = form.tablecolumns.data # Find games where these teams faced each other games = GamesTest.query.filter(GamesTest.season==form.season.data, or_(GamesTest.hometeam==form.team1.data, GamesTest.hometeam==form.team2.data), or_(GamesTest.awayteam==form.team1.data, GamesTest.awayteam==form.team2.data)) gcodes = set() for game in games: gcodes.add(game.gcode) # Overall game data gamedata = [] # Team specific data for table teams = [] # Goalie specific data for goalie table goalies = [] # Values that should be skipped in accumulation skip = ["period", "home", "Opponent", "gamestate", "gcode", "Team", "TOI", "Gm", "ID", "season"] gamefound = set() foundplayers = set() goaliefound = set() playerfound = set() away = [] home = [] allplayers = [] playerteams = {} players = set() coplayers = {} pbp = [] # For each gcode, get the RData file for that game for gcode in gcodes: rdata = get_rdata("http://data.war-on-ice.net/games/" + str(form.season.data) + str(gcode) + ".RData") pbp.extend(rdata["playbyplay"]) rteamrun = rdata["teamrun"] coplayers = get_coplayers(rdata, coplayers) for tr in sorted(rteamrun, key=lambda x: x["TOI"], reverse=True): gid = str(tr["gcode"]) + str(tr["season"]) + str(tr["Team"]) if tr["period"] in period and int(tr["gamestate"]) == int(form.teamstrengths.data) and gid not in gamefound: gamefound.add(gid) ar = None for team in teams: if team["Team"] == tr["Team"]: ar = team break if ar is None: tr["MSF"] = int(tr["FF"]) - int(tr["SF"]) tr["BSF"] = tr["CF"] - tr["MSF"] - tr["SF"] teams.append(tr) else: for key in tr: if key not in skip: ar[key] += tr[key] ar["MSF"] += int(tr["FF"]) - int(tr["SF"]) ar["BSF"] += tr["CF"] - (int(tr["FF"]) - int(tr["SF"])) - tr["SF"] ar["TOI"] += float(tr["TOI"]) rgoalies = rdata["goalierun"] for tr in sorted(rgoalies, key=lambda x: x["TOI"], reverse=True): gid = str(tr["gcode"]) + str(tr["season"]) + str(tr["Team"]) + str(tr["ID"]) if tr["period"] in period and tr["gamestate"] == int(form.teamstrengths.data) and gid not in goaliefound: goaliefound.add(gid) ar = None for goalie in goalies: if goalie["ID"] == tr["ID"] and goalie["Team"] == tr["Team"]: ar = goalie break if ar is None: tr["gu"] = tr["goals.0"] tr["su"] = tr["shots.0"] tr["gl"] = tr["goals.1"] tr["sl"] = tr["shots.1"] tr["gm"] = tr["goals.2"] tr["sm"] = tr["shots.2"] tr["gh"] = tr["goals.3"] + tr["goals.4"] tr["sh"] = tr["shots.3"] + tr["shots.4"] tr["TOI"] = float(tr["TOI"]) # round(float(tr["TOI"]) / 60.0, 1) tr["Gm"] = 1 goalies.append(tr) foundplayers.add(tr["ID"]) else: ar["gu"] += tr["goals.0"] ar["su"] += tr["shots.0"] ar["gl"] += tr["goals.1"] ar["sl"] += tr["shots.1"] ar["gm"] += tr["goals.2"] ar["sm"] += tr["shots.2"] ar["gh"] += tr["goals.3"] + tr["goals.4"] ar["sh"] += tr["shots.3"] + tr["shots.4"] ar["TOI"] += float(tr["TOI"]) #round(float(tr["TOI"]) / 60.0, 1) ar["Gm"] += 1 rplayerrun = rdata["playerrun"] for tr in sorted(rplayerrun, key=lambda x: x["TOI"], reverse=True): if tr["ID"] not in foundplayers: foundplayers.add(tr["ID"]) gid = str(tr["gcode"]) + str(tr["season"]) + str(tr["Team"]) + str(tr["ID"]) if tr["period"] in period and tr["gamestate"] == int(form.teamstrengths.data) and gid not in playerfound: playerfound.add(gid) players.add(tr["ID"]) ar = None pteam = None for p in allplayers: if p["ID"] == tr["ID"]: ar = p break if ar is None: tr["G"] = int(tr["GOAL1"] + tr["GOAL2"] + tr["GOAL3"] + tr["GOAL4"]) tr["TOI"] = float(tr["TOI"]) # round(float(tr["TOI"]) / 60.0, 1) tr["Gm"] = 1 allplayers.append(tr) playerteams[tr["ID"]] = tr["Team"] else: for key in tr: if key not in skip: ar[key] += tr[key] ar["G"] += int(tr["GOAL1"] + tr["GOAL2"] + tr["GOAL3"] + tr["GOAL4"]) ar["TOI"] += float(tr["TOI"]) # round(float(tr["TOI"]) / 60.0, 1) ar["Gm"] += 1 ht = None at = None for player in allplayers: if ht is None: home.append(player) ht = player["Team"] elif ht == player["Team"]: home.append(player) elif at == None: away.append(player) else: away.append(player) for co in coplayers: matchup = coplayers[co] for p in ["p1", "p2"]: foundplayers.add(matchup[p]) woiid = get_player_info(foundplayers) hvh, hometeam, awayteam = get_hvh(coplayers, playerteams, woiid) homecorsi = [] awaycorsi = [] for line in home: for key in line: if type(line[key]).__module__ == "numpy" and numpy.isnan(line[key]): line[key] = 0 if line["ID"] in woiid and woiid[line["ID"]]["pos"] != "G": line["full_name"] = str(woiid[line["ID"]]["full_name"]) homecorsi.append(line) for line in away: for key in line: if type(line[key]).__module__ == "numpy" and numpy.isnan(line[key]): line[key] = 0 if line["ID"] in woiid and woiid[line["ID"]]["pos"] != "G": line["full_name"] = str(woiid[line["ID"]]["full_name"]) awaycorsi.append(line) # ev.team pbphome = [] pbpaway = [] scoresituations = int(form.scoresituations.data) for play in pbp: if play["period"] in period and (play["score.diff.cat"] == scoresituations or scoresituations == 7) and play["etype"] in ["GOAL", "SHOT", "BLOCK", "MISS"]: for key in play: if type(play[key]).__module__ == "numpy" and numpy.isnan(play[key]): play[key] = 0 # get Names if play["ev.player.1"] != "xxxxxxxNA": play["P1"] = woiid[play["ev.player.1"]]["full_name"] if play["ev.player.2"] != "xxxxxxxNA": play["P2"] = woiid[play["ev.player.2"]]["full_name"] if play["ev.player.3"] != "xxxxxxxNA": play["P3"] = woiid[play["ev.player.3"]]["full_name"] if play["ev.team"] == hometeam: if int(form.teamstrengths.data) in calc_strengths(play, True): pbphome.append(play) elif play["ev.team"] == awayteam: if int(form.teamstrengths.data) in calc_strengths(play, False): pbpaway.append(play) return render_template("game/series.html", rd=rd, hvh=hvh, form=form, woiid=woiid, teamrun=teams, goalies=goalies, hometeam=hometeam, awayteam=awayteam, gamedata=gamedata, coplayers=coplayers, home=home, homecorsi=homecorsi, away=away, awaycorsi=awaycorsi, pbphome=pbphome, pbpaway=pbpaway, tablecolumns=int(tablecolumns))
def glossary(): rd = setup_nav() tf = open("html/glossary_text.txt") tf = tf.read().decode('utf-8') text = ast.literal_eval(tf) return render_template("misc/glossary.html", rd=rd, text=text)
def show_goals_above_baseline(): rd = setup_nav() csv = get_csv("http://war-on-ice.com/data/GAR-seasonal.csv") cd = combine_data(csv) return render_template("teams/gab.html", rd=rd)
def show_team_history(): rd = setup_nav() form = HistoryForm(request.form, prefix="form") cpg = ComparisonGraphForm() ggf = GameGraphForm(request.form, prefix="game-form") cpg.xaxis.data = "season" now = datetime.datetime.now().date() extrateams = [] if request.method == "POST" and form.validate(): extrateams = ggf.steam.data; print extrateams else: form.endingDate.data = now form.startingDate.data = datetime.datetime.strptime("2002-10-01", "%Y-%m-%d").date() startingDate = form.startingDate.data endingDate = form.endingDate.data if endingDate is None: endingDate = datetime.datetime.strptime("2002-10-01", "%Y-%m-%d").date() team = form.filterTeams.data team = [team, ] team.extend(extrateams) columns = form.tablecolumns.data regularplayoffs = form.regularplayoffs.data # Filter teamrun based on form data teamstrengths = int(form.teamstrengths.data) if teamstrengths == 7: teamstrengths = [constants.strength_situations_dict[x]["value"] for x in constants.strength_situations_dict] else: teamstrengths = [teamstrengths, ] scoresituations = int(form.scoresituations.data) if scoresituations == 7: scoresituations = [constants.score_situations_dict[x]["value"] for x in constants.score_situations_dict] homeaway = form.homeAway.data if homeaway == "all": homeaway = [0, 1] else: homeaway = [int(homeaway), ] periods = constants.periods_options["All"]["value"] if 0 in periods: periods = [0, ] if 7 in scoresituations: scoresituations = [7, ] if 7 in teamstrengths: teamstrengths = [7, ] teamrun = TeamRun.query.filter(TeamRun.Date >= startingDate, TeamRun.Date <= endingDate, TeamRun.gamestate.in_(teamstrengths), TeamRun.scorediffcat.in_(scoresituations), TeamRun.home.in_(homeaway), TeamRun.Team.in_(team), TeamRun.period.in_(periods)).all() games, seasons = helpers.calculate(teamrun, True) return render_template("teams/teamhistory.html", rd=rd, cpg=cpg, ggf=ggf, form=form, games=games, seasons=seasons)
def show_team_comparisons(): rd = setup_nav() cpg = ComparisonGraphForm() teamgames = get_r_seasons() tablecolumns = [ 0, ] form = ComparisonForm(request.form) form.startingSeason.choices = [ (x, str(x)[0:4] + "-" + str(x)[4:]) for x in sorted(teamgames.keys(), reverse=True) ] form.endingSeason.choices = [ (x, str(x)[0:4] + "-" + str(x)[4:]) for x in sorted(teamgames.keys(), reverse=True) ] filterteams = form.filterTeams.data if filterteams is None: filterteams = [] allteams = form.filterTeams.choices try: oldStart = form.startingSeason.data oldEnd = form.endingSeason.data form.startingSeason.data = int(form.startingSeason.data) form.endingSeason.data = int(form.endingSeason.data) except: pass allseasons = [(x, str(x)[0:4] + "-" + str(x)[4:]) for x in sorted(teamgames.keys(), reverse=True)] usedates = False if request.method == "POST" and form.validate(): startingSeason = form.startingSeason.data endingSeason = form.endingSeason.data form.startingSeason.data = oldStart form.endingSeason.data = oldEnd startingDate = form.startingDate.data endingDate = form.endingDate.data usedates = form.bydate.data if not usedates: if endingSeason > startingSeason: begin = startingSeason end = endingSeason else: begin = endingSeason end = startingSeason currSeason = begin seasons = [ begin, ] # TODO: Error check this? while begin != end: bsplit = str(begin)[0:4] begin = int(bsplit) * 10000 + 10001 + int(bsplit) + 1 seasons.append(begin) else: if endingDate < startingDate: temp = endingDate endingDate = startingDate startingDate = temp else: smax = max(teamgames.keys()) seasons = [ smax, ] # Filter teamrun based on form data teamstrengths = int(form.teamstrengths.data) if teamstrengths == 7: teamstrengths = [ constants.strength_situations_dict[x]["value"] for x in constants.strength_situations_dict ] else: teamstrengths = [ teamstrengths, ] scoresituations = int(form.scoresituations.data) if scoresituations == 7: scoresituations = [ constants.score_situations_dict[x]["value"] for x in constants.score_situations_dict ] homeaway = form.homeAway.data if homeaway == "all": homeaway = [0, 1] else: homeaway = [ int(homeaway), ] periods = constants.periods_options[form.period.data]["value"] if 0 in periods: periods = [ 0, ] if 7 in scoresituations: scoresituations = [ 7, ] if 7 in teamstrengths: teamstrengths = [ 7, ] if not usedates: if len(filterteams) == 0: teamrun = TeamRun.query.filter( TeamRun.season.in_(seasons), TeamRun.gamestate.in_(teamstrengths), TeamRun.scorediffcat.in_(scoresituations), TeamRun.home.in_(homeaway), TeamRun.period.in_(periods)).all() else: teamrun = TeamRun.query.filter( TeamRun.season.in_(seasons), TeamRun.gamestate.in_(teamstrengths), TeamRun.scorediffcat.in_(scoresituations), TeamRun.home.in_(homeaway), TeamRun.Team.in_(filterteams), TeamRun.period.in_(periods)).all() else: if len(filterteams) == 0: teamrun = TeamRun.query.filter( TeamRun.Date >= startingDate, TeamRun.Date <= endingDate, TeamRun.gamestate.in_(teamstrengths), TeamRun.scorediffcat.in_(scoresituations), TeamRun.home.in_(homeaway), TeamRun.period.in_(periods)).all() else: teamrun = TeamRun.query.filter( TeamRun.Date >= startingDate, TeamRun.Date <= endingDate, TeamRun.gamestate.in_(teamstrengths), TeamRun.scorediffcat.in_(scoresituations), TeamRun.home.in_(homeaway), TeamRun.Team.in_(filterteams), TeamRun.period.in_(periods)).all() games, seasons = helpers.calculate(teamrun, form.divideSeason.data) if form.splitgame.data == True: summaries = games else: summaries = seasons return render_template('teams/teamcomparison.html', rd=rd, form=form, summaries=summaries, cpg=cpg, filterteams=filterteams, allteams=allteams)
def show_game_summary_tables(gameId): rd = setup_nav() if request.method == "GET": tablecolumns = request.args.get("tablecolumns") teamstrengths = request.args.get("teamstrengths") scoresituations = request.args.get("scoresituation") period = constants.periods_options[request.args.get("period")]["value"] else: tablecolumns = "0" teamstrengths = constants.strength_situations_dict[constants.strength_situations["default"]]["value"] scoresituations = constants.score_situations_dict[constants.score_situations["default"]]["value"] period = [0] period.extend(constants.periods_options[constants.periods["default"]]["value"]) # Get game information from URL season = gameId[0:8] gcode = gameId[8:] # Prepare form results for queries scorediffcat = int(scoresituations) gamestate = int(teamstrengths) period = [int(x) for x in period] rdata = get_rdata("http://data.war-on-ice.net/games/" + season + gcode + ".RData") eventcount = {"homepp": [], "awaypp": [], "4v4": [], "homegoal": [], "awaygoal": [], "emptynet": [], "homesc": [{"seconds": 0, "value": 0}], "awaysc": [{"seconds": 0, "value": 0}], "homesa": [{"seconds": 0, "value": 0}], "awaysa": [{"seconds": 0, "value": 0}], "pend": []} pbp = rdata["playbyplay"] rteamrun = rdata["teamrun"] teamrun = [] teams = set() hometeam = "" awayteam = "" previous = 1000 for tr in sorted(rteamrun, key=lambda x: x["TOI"], reverse=True): if hometeam == "" and tr["home"] == 1: hometeam = tr["Team"] elif awayteam == "" and tr["home"] == 0: awayteam = tr["Team"] if tr["period"] in period and tr["gamestate"] == gamestate: if tr["Team"] not in teams: tr["MSF"] = int(tr["FF"]) - int(tr["SF"]) tr["BSF"] = tr["CF"] - tr["MSF"] - tr["SF"] tr["TOI"] = float(tr["TOI"]) # round(float(tr["TOI"]) / 60.0, 1) teamrun.append(tr) teams.add(tr["Team"]) goalies = [] rgoalies = rdata["goalierun"] teams = set() foundplayers = set() for tr in sorted(rgoalies, key=lambda x: x["TOI"], reverse=True): if tr["period"] in period and tr["gamestate"] == gamestate: if tr["ID"] not in foundplayers: tr["gu"] = tr["goals.0"] tr["su"] = tr["shots.0"] tr["gl"] = tr["goals.1"] tr["sl"] = tr["shots.1"] tr["gm"] = tr["goals.2"] tr["sm"] = tr["shots.2"] tr["gh"] = tr["goals.3"] + tr["goals.4"] tr["sh"] = tr["shots.3"] + tr["shots.4"] tr["TOI"] = float(tr["TOI"]) # round(float(tr["TOI"]) / 60.0, 1) goalies.append(tr) teams.add(tr["Team"]) foundplayers.add(tr["ID"]) rplayerrun = rdata["playerrun"] away = [] home = [] players = set() playerteams = {} for tr in sorted(rplayerrun, key=lambda x: x["TOI"], reverse=True): if tr["ID"] not in foundplayers: foundplayers.add(tr["ID"]) playerteams[tr["ID"]] = tr["Team"] if tr["period"] in period and tr["gamestate"] == gamestate and tr["ID"] not in players: players.add(tr["ID"]) tr["G"] = int(tr["GOAL1"] + tr["GOAL2"] + tr["GOAL3"] + tr["GOAL4"]) tr["TOI"] = float(tr["TOI"]) #round(float(tr["TOI"]) / 60.0, 1) if tr["home"] == 1: home.append(tr) else: away.append(tr) # Get GamesTest information gamedata = GamesTest.query.filter_by(season=season, gcode=int(gcode)).first() woiid = get_player_info(foundplayers) homecorsi = [] awaycorsi = [] for line in home: for key in line: if type(line[key]).__module__ == "numpy" and numpy.isnan(line[key]): line[key] = 0 if line["ID"] in woiid and woiid[line["ID"]]["pos"] != "G": line["full_name"] = str(woiid[line["ID"]]["full_name"]) homecorsi.append(line) for line in away: for key in line: if type(line[key]).__module__ == "numpy" and numpy.isnan(line[key]): line[key] = 0 if line["ID"] in woiid and woiid[line["ID"]]["pos"] != "G": line["full_name"] = str(woiid[line["ID"]]["full_name"]) awaycorsi.append(line) pbphome = [] pbpaway = [] for play in pbp: if play["period"] in period and (play["score.diff.cat"] == int(scoresituations) or int(scoresituations) == 7): if play["etype"] in ["MISS", "GOAL", "SHOT", "BLOCK"]: # Shot Attempt if play["ev.team"] == hometeam: if gamestate in calc_strengths(play, True): eventcount["homesa"].append({"seconds": play["seconds"], "value": len(eventcount["homesa"])}) eventcount["homesc"] = calc_sc(eventcount["homesc"], play) else: if gamestate in calc_strengths(play, False): eventcount["awaysa"].append({"seconds": play["seconds"], "value": len(eventcount["awaysa"])}) eventcount["awaysc"] = calc_sc(eventcount["awaysc"], play) # Goal if play["etype"] == "GOAL": if play["ev.team"] == hometeam: eventcount["homegoal"].append({"seconds": play["seconds"], "value": len(eventcount["homegoal"]) + 1}) else: eventcount["awaygoal"].append({"seconds": play["seconds"], "value": len(eventcount["awaygoal"]) + 1}) elif play["etype"] == "PENL": # Penalty seconds = int(re.findall("\d+", play["type"])[0]) * 60 if play["ev.team"] == hometeam: eventcount["awaypp"].append({"seconds": play["seconds"], "length": seconds}) elif play["ev.team"] == awayteam: eventcount["homepp"].append({"seconds": play["seconds"], "length": seconds}) elif play["etype"] == "PEND": # Period End eventcount["pend"].append(play["seconds"]) if play["etype"] in ["MISS", "GOAL", "SHOT", "BLOCK", "MISS"]: for key in play: if type(play[key]).__module__ == "numpy" and numpy.isnan(play[key]): play[key] = 0 # get Names if play["ev.player.1"] != "xxxxxxxNA": play["P1"] = woiid[play["ev.player.1"]]["full_name"] if play["ev.player.2"] != "xxxxxxxNA": play["P2"] = woiid[play["ev.player.2"]]["full_name"] if play["ev.player.3"] != "xxxxxxxNA": play["P3"] = woiid[play["ev.player.3"]]["full_name"] if play["ev.team"] == hometeam: if gamestate in calc_strengths(play, True): pbphome.append(play) elif play["ev.team"] == awayteam: if gamestate in calc_strengths(play, False): pbpaway.append(play) # Find PowerPlay Goals eventcount = findPPGoal(eventcount, "homepp", "homegoal") eventcount = findPPGoal(eventcount, "awaypp", "awaygoal") homelast = eventcount["homesa"][-1]["seconds"] awaylast = eventcount["awaysa"][-1]["seconds"] if homelast < awaylast: eventcount["homesa"].append({"seconds": awaylast, "value": eventcount["homesa"][-1]["value"]}) elif homelast > awaylast: eventcount["awaysa"].append({"seconds": homelast, "value": eventcount["awaysa"][-1]["value"]}) homelast = eventcount["homesc"][-1]["seconds"] awaylast = eventcount["awaysc"][-1]["seconds"] if homelast < awaylast: eventcount["homesc"].append({"seconds": awaylast, "value": eventcount["homesc"][-1]["value"]}) elif homelast > awaylast: eventcount["awaysc"].append({"seconds": homelast, "value": eventcount["awaysc"][-1]["value"]}) # Get coplayer data coplayers = get_coplayers(rdata) hvh, hometeam, awayteam = get_hvh(coplayers, playerteams, woiid) return render_template('game/gamesummarytables.html', tablecolumns=int(tablecolumns), home=home, homecorsi=homecorsi, away=away, awaycorsi=awaycorsi, gamedata=gamedata, goalies=goalies, woiid=woiid, pbphome=pbphome, pbpaway=pbpaway, teamrun=teamrun, eventcount=eventcount, hvh=hvh)
def show_team_current(teamId): rd = setup_nav() #caps = ContractHeader.query.filter(ContractHeader.ContractTeamID==teamId).order_by(desc(ContractHeader.EffectiveSeason)) #players = {} #playerids = set() #for cap in caps: # if cap.PlayerID not in players: # players[cap.PlayerID] = cap # playerids.add(cap.PlayerID) caps = PlayerCap.query.filter(PlayerCap.Team == teamId).order_by( desc(PlayerCap.Date)) players = {} maxdate = None for cap in caps: if maxdate is None: maxdate = cap.Date elif maxdate > cap.Date: break players[cap.PlayerId] = cap woiid = get_player_info(players.keys()) forwards = {} defensemen = {} goalies = {} gone = {} its = {} now = datetime.datetime.now() cy = now.year years = [] while len(years) < 5: years.append(cy - 1) cy += 1 for player in players: if player in woiid: currplayer = {} currplayer["ID"] = player position = woiid[player]["pos"] if players[player].DayStatus == "Major": if position == "D": defensemen[player] = currplayer elif position == "G": goalies[player] = currplayer else: forwards[player] = currplayer elif players[player].DayStatus == "Minor": its[player] = currplayer return render_template('cap/teamcap.html', teamId=teamId, rd=rd, woiid=woiid, forwards=forwards, defensemen=defensemen, goalies=goalies, its=its, years=years) # # @app.route('/team/<teamId>/<seasonId>/') # def show_team_historical(teamId, seasonId): # selectedTeam = models.Teams.query.filter_by(TeamId=teamId).first() # return render_template('teamcap.html', # team = selectedTeam)
def show_team_history(): rd = setup_nav() form = HistoryForm(request.form, prefix="form") cpg = ComparisonGraphForm() ggf = GameGraphForm(request.form, prefix="game-form") cpg.xaxis.data = "season" now = datetime.datetime.now().date() extrateams = [] if request.method == "POST" and form.validate(): extrateams = ggf.steam.data print extrateams else: form.endingDate.data = now form.startingDate.data = datetime.datetime.strptime( "2002-10-01", "%Y-%m-%d").date() startingDate = form.startingDate.data endingDate = form.endingDate.data if endingDate is None: endingDate = datetime.datetime.strptime("2002-10-01", "%Y-%m-%d").date() team = form.filterTeams.data team = [ team, ] team.extend(extrateams) columns = form.tablecolumns.data regularplayoffs = form.regularplayoffs.data # Filter teamrun based on form data teamstrengths = int(form.teamstrengths.data) if teamstrengths == 7: teamstrengths = [ constants.strength_situations_dict[x]["value"] for x in constants.strength_situations_dict ] else: teamstrengths = [ teamstrengths, ] scoresituations = int(form.scoresituations.data) if scoresituations == 7: scoresituations = [ constants.score_situations_dict[x]["value"] for x in constants.score_situations_dict ] homeaway = form.homeAway.data if homeaway == "all": homeaway = [0, 1] else: homeaway = [ int(homeaway), ] periods = constants.periods_options["All"]["value"] if 0 in periods: periods = [ 0, ] if 7 in scoresituations: scoresituations = [ 7, ] if 7 in teamstrengths: teamstrengths = [ 7, ] teamrun = TeamRun.query.filter(TeamRun.Date >= startingDate, TeamRun.Date <= endingDate, TeamRun.gamestate.in_(teamstrengths), TeamRun.scorediffcat.in_(scoresituations), TeamRun.home.in_(homeaway), TeamRun.Team.in_(team), TeamRun.period.in_(periods)).all() games, seasons = helpers.calculate(teamrun, True) return render_template("teams/teamhistory.html", rd=rd, cpg=cpg, ggf=ggf, form=form, games=games, seasons=seasons)
def about(): rd = setup_nav() return render_template("misc/about.html", rd = rd)