def get_all_game_links(): data = get_json(NHL_URL + ALL_GAMES_2017_2018) dates = data['dates'] for date in dates: games = date['games'] db = db_connect() for game in games: link = game['link'] get_all_shots(BASE + link, db)
def add_player(number): print("ADDING PLAYER") db = db_connect() data = get_json('https://statsapi.web.nhl.com/api/v1/people/' + str(number)) packet = dict() packet['id'] = data['people'][0]['id'] packet['first_name'] = data['people'][0]['firstName'] packet['last_name'] = data['people'][0]['lastName'] try: packet['number'] = data['people'][0]['primaryNumber'] packet['position'] = data['people'][0]['primaryPosition']['name'] packet['team'] = data['people'][0]['currentTeam']['name'] except: print("Not on a team probably") db.add_row(packet, 'player_meta')
# # @author Kevin Jesse # @email [email protected] # """ Entity detect fetches the data of the entity described based on what the table and column. Not being used 9-29-17 """ import database_connect cur = database_connect.db_connect() entity2table = {'genre':('title', 'genres'), 'actor':('name', 'primaryname') , 'director': ('name', 'primaryname'), 'mpaa': ('title', 'mpaa'),} entity_map = {'mpaa': 'Entertainment.ContentRating', 'genre': 'Entertainment.Genre', 'role': 'Entertainment.Role', 'title': 'Entertainment.Title', 'rating': 'Entertainment.UserRating', 'actor': 'Entertainment.Person', 'director' : 'Entertainment.Person'} def entdata(state, entities): for ent in entities: if entity_map[state] == ent['type']: tc = entity2table[state] table = tc[0] column = tc[1] sqlstring = """SELECT COUNT(*) FROM """ + table + """ WHERE """ +column + """ LIKE '%""" + ent['entity'] + """%' LIMIT 1""" cur.execute(sqlstring) rows = cur.fetchall() if rows[0][0] > 0: return True return False def detect(state, entities):
import plotly.graph_objs as pplot from plotly.offline import init_notebook_mode, plot from rink import rink_shapes import plotly.plotly as py from database_connect import db_connect import pandas as pd db = db_connect() id = db.get_player_id(full='Alex Ovechkin')[0][0] all_shots = db.get_shots(id=id) all_shots['x'] = all_shots['x'].apply(lambda x: x * 5.7) all_shots['y'] = all_shots['y'].apply(lambda y: y * 5.7) # Flip axis for i, r in all_shots.iterrows(): if all_shots.loc[i, 'x'] < 0: all_shots.loc[i, 'x'] *= -1 all_shots.loc[i, 'y'] *= -1 goals = all_shots no_goals = all_shots #no_goals = no_goals[no_goals.x < 0] #print (no_goals.period) goals = goals[goals.goal == True] no_goals = no_goals[no_goals.goal == False]