def gen_game_graph(game, points, flip=False): ''' Generates the game graph using matplot lib and saves the image with the proper ID and date in game_graphs folder inside the server. ''' start_time = points[0]['events'][0]['timestamp'] xvals = [0] ourscores = [0] theirscores = [0] for point in points: events = point['events'] for event in events: if event['action'] == "Goal": xvals.append(event['timestamp'] - start_time) ourscores.append(point['summary']['score']['ours']) theirscores.append(point['summary']['score']['theirs']) if len(xvals) is 1: return None xvals = [float(x) / float(xvals[-1]) for x in xvals] # if flip is true we are using away team data it should be flipped to # make sure the right points are with the right team # (ourscores --> home_team theirscores-->away_team) if flip: temp = ourscores ourscores = theirscores theirscores = temp ourxpoints = [0] theirxpoints = [0] ourpoints = [0] theirpoints = [0] for i in range(1, len(xvals) - 1): if ourscores[i] > ourscores[i - 1]: ourpoints.append(ourscores[i]) ourxpoints.append(xvals[i]) if theirscores[i] > theirscores[i - 1]: theirpoints.append(theirscores[i]) theirxpoints.append(xvals[i]) # handle the final points of the game # this is messy, but works if ourscores[-1] > ourscores[-2]: ourpoints.append(ourscores[-1]) ourxpoints.append(xvals[-1]) if theirscores[-1] > theirscores[-2]: theirpoints.append(theirscores[-1]) theirxpoints.append(xvals[-1]) home_pnts = zip(ourxpoints, ourpoints) away_pnts = zip(theirxpoints, theirpoints) home_team_abbrev = sr.name_to_abbrev(game.home_team) away_team_abbrev = sr.name_to_abbrev(game.away_team) return [[home_team_abbrev, home_pnts], [away_team_abbrev, away_pnts]] '''
def web_standings(self, params): standings_dict = {} for div, teams in self.Divisions.items(): div_list = [] #print teams for team in teams: t = self.Teams[team] rec = t.record() team_rec_dict = { "name": t.full_name(), "nm": sr.name_to_abbrev(t.full_name()), "id": team, "wins": rec[0], "losses": rec[1], "plmn": rec[2] } div_list.append(team_rec_dict) div_list.sort( key=lambda set: 0 if 0 == set["wins"] + set["losses"] else (float(set["wins"]) / (float(set["wins"] + set["losses"])), float(set["wins"]), -float(set["losses"]), set["plmn"]), reverse=True) #div_list.insert(0,div) standings_dict[div] = div_list return { params['division']: standings_dict[params['division']] } if 'division' in params.keys() else standings_dict
def score_ticker(self, params): ticker_list = [] #convert array data to a dictionary game_list = self.filter_games_by_date(days_behind=3, days_ahead=3) #reverse the ordering of the games by date game_list = game_list[::-1] game_key_list = [ 'home_team', 'hteam_id', 'away_team', 'ateam_id', 'date', 'time', 'home_score', 'away_score', 'status', 'timestamp', 'Quarter' ] for game in game_list: game_dict = {} for key in game_key_list: #game_dict = { key: value for key,value in zip(game_key_list, game) } if key in game.__dict__.keys(): game_dict[key] = game.__dict__[key] #make some final formatting adjustments game_dict['status'] = status_to_string( game_dict['status']) # make status a string game_dict['hteam'] = sr.name_to_abbrev(game_dict['home_team']) game_dict['ateam'] = sr.name_to_abbrev(game_dict['away_team']) game_dict['hteam_id'] = self.name_to_id(game_dict['home_team']) game_dict['ateam_id'] = self.name_to_id(game_dict['away_team']) game_dict = add_quarters_to_dict(game_dict, game.QS) #adjust for missing quarter scores for i in range(len(game.QS), 3): game_dict[quarter_home_keys[i]] = 0 game_dict[quarter_away_keys[i]] = 0 #CORNER CASES if 'status' not in game_dict.keys(): game_dict['status'] = '0' if 'home_score' and 'away_score' not in game_dict.keys(): game_dict['home_score'] = 0 game_dict['away_score'] = 0 ticker_list.append(game_dict) return ticker_list
def score_ticker(self, params): ticker_list = [] #convert array data to a dictionary game_list= self.filter_games_by_date( days_behind = 3, days_ahead = 3) #reverse the ordering of the games by date game_list = game_list[::-1] game_key_list = ['home_team', 'hteam_id', 'away_team', 'ateam_id', 'date', 'time', 'home_score', 'away_score', 'status', 'timestamp', 'Quarter'] for game in game_list: game_dict={} for key in game_key_list: #game_dict = { key: value for key,value in zip(game_key_list, game) } if key in game.__dict__.keys(): game_dict[key]=game.__dict__[key] #make some final formatting adjustments game_dict['status'] = status_to_string(game_dict['status']) # make status a string game_dict['hteam'] = sr.name_to_abbrev(game_dict['home_team']) game_dict['ateam'] = sr.name_to_abbrev(game_dict['away_team']) game_dict['hteam_id'] = self.name_to_id(game_dict['home_team']) game_dict['ateam_id'] = self.name_to_id(game_dict['away_team']) game_dict = add_quarters_to_dict(game_dict, game.QS) #adjust for missing quarter scores for i in range(len(game.QS),3): game_dict[quarter_home_keys[i]] = 0 game_dict[quarter_away_keys[i]] = 0 #CORNER CASES if 'status' not in game_dict.keys(): game_dict['status'] = '0' if 'home_score' and 'away_score' not in game_dict.keys(): game_dict['home_score'] = 0 game_dict['away_score'] = 0 ticker_list.append(game_dict) return ticker_list
def game_tuple(self, g): date = g.date time = g.time team1 = sr.name_to_abbrev(g.home_team) team1ID = self.name_to_id(g.home_team) team2 = sr.name_to_abbrev(g.away_team) team2ID = self.name_to_id(g.away_team) week = g.week if hasattr(g, 'home_score') and hasattr(g, 'away_score'): hscore = g.home_score ascore = g.away_score else: hscore = 0 ascore = 0 status = 0 if not hasattr(g,'status') else g.status game_tuple=(team1,team1ID,team2,team2ID,date,time,hscore,ascore,status,g.tstamp.isoformat(), week) return game_tuple
def return_latest_game(self): game_dict = {} #get today's date today = dt.today().date() min_diff = None nearest_game = None for key, game in self.Games.items(): #find the game that is the closest to today's date game_date = game.tstamp.date() diff = abs((game_date - today).days) print abs((game_date - today).days) if (diff < min_diff or None == min_diff): min_diff = diff nearest_game = game #now populate the game dictionary game_dict['time'] = nearest_game.time game_dict['timestamp'] = nearest_game.tstamp.isoformat() game_dict['date'] = nearest_game.date game_dict['home_team'] = nearest_game.home_team game_dict['hteam'] = sr.name_to_abbrev(nearest_game.home_team) game_dict['hteam_id'] = self.League.name_to_id(nearest_game.home_team) game_dict['away_team'] = nearest_game.away_team game_dict['ateam'] = sr.name_to_abbrev(nearest_game.away_team) game_dict['ateam_id'] = self.League.name_to_id(nearest_game.away_team) game_dict['status'] = 0 if not hasattr( nearest_game, 'status') else status_to_string(nearest_game.status) game_dict['Quarter'] = nearest_game.Quarter game_dict = add_quarters_to_dict(game_dict, nearest_game.QS) if hasattr(nearest_game, 'home_score') and hasattr( nearest_game, 'away_score'): game_dict['home_score'] = nearest_game.home_score game_dict['away_score'] = nearest_game.away_score else: game_dict['home_score'] = 0 game_dict['away_score'] = 0 return game_dict
def return_schedule(self): """ Returns the team's schedule with the team's city+name and ID as the first two values of the list. """ AUDL_Name = self.City+ " " + self.Name sched = [] for game in self.Games: if AUDL_Name in self.Games[game].home_team: hmay = "Home" opponent = self.Games[game].away_team else: hmay = "Away" opponent = self.Games[game].home_team game_tup = (self.Games[game].date, self.Games[game].time, sr.name_to_abbrev(opponent), self.League.name_to_id(opponent),self.Games[game].week, hmay) sched.append(game_tup) sched.sort(key= lambda set: dt.strptime(set[0], '%m/%d/%Y')) sched = [sr.name_to_abbrev(AUDL_Name), self.ID ]+sched return sched
def game_tuple(self, g): date = g.date time = g.time team1 = sr.name_to_abbrev(g.home_team) team1ID = self.name_to_id(g.home_team) team2 = sr.name_to_abbrev(g.away_team) team2ID = self.name_to_id(g.away_team) week = g.week if hasattr(g, 'home_score') and hasattr(g, 'away_score'): hscore = g.home_score ascore = g.away_score else: hscore = 0 ascore = 0 status = 0 if not hasattr(g, 'status') else g.status game_tuple = (team1, team1ID, team2, team2ID, date, time, hscore, ascore, status, g.tstamp.isoformat(), week) return game_tuple
def return_latest_game(self): game_dict={} #get today's date today = dt.today().date() min_diff = None nearest_game = None for key, game in self.Games.items(): #find the game that is the closest to today's date game_date = game.tstamp.date() diff = abs((game_date - today).days) print abs((game_date - today).days) if ( diff < min_diff or None == min_diff): min_diff = diff nearest_game = game #now populate the game dictionary game_dict['time'] = nearest_game.time game_dict['timestamp']= nearest_game.tstamp.isoformat() game_dict['date'] = nearest_game.date game_dict['home_team'] = nearest_game.home_team game_dict['hteam'] = sr.name_to_abbrev(nearest_game.home_team) game_dict['hteam_id'] = self.League.name_to_id(nearest_game.home_team) game_dict['away_team'] = nearest_game.away_team game_dict['ateam'] = sr.name_to_abbrev(nearest_game.away_team) game_dict['ateam_id'] = self.League.name_to_id(nearest_game.away_team) game_dict['status'] = 0 if not hasattr(nearest_game, 'status') else status_to_string(nearest_game.status) game_dict['Quarter']= nearest_game.Quarter game_dict = add_quarters_to_dict(game_dict, nearest_game.QS) if hasattr(nearest_game, 'home_score') and hasattr(nearest_game, 'away_score'): game_dict['home_score'] = nearest_game.home_score game_dict['away_score'] = nearest_game.away_score else: game_dict['home_score'] = 0 game_dict['away_score'] = 0 return game_dict
def return_schedule(self): """ Returns the team's schedule with the team's city+name and ID as the first two values of the list. """ AUDL_Name = self.City + " " + self.Name sched = [] for game in self.Games: if AUDL_Name in self.Games[game].home_team: hmay = "Home" opponent = self.Games[game].away_team else: hmay = "Away" opponent = self.Games[game].home_team game_tup = (self.Games[game].date, self.Games[game].time, sr.name_to_abbrev(opponent), self.League.name_to_id(opponent), self.Games[game].week, hmay) sched.append(game_tup) sched.sort(key=lambda set: dt.strptime(set[0], '%m/%d/%Y')) sched = [sr.name_to_abbrev(AUDL_Name), self.ID] + sched return sched
def web_standings(self, params): standings_dict={} for div,teams in self.Divisions.items(): div_list=[] #print teams for team in teams: t = self.Teams[team] rec = t.record() team_rec_dict = {"name" : t.full_name(), "nm" : sr.name_to_abbrev(t.full_name()), "id": team, "wins" : rec[0], "losses" : rec[1], "plmn" : rec[2]} div_list.append(team_rec_dict) div_list.sort(key= lambda set: 0 if 0 == set["wins"]+set["losses"] else (float(set["wins"])/(float(set["wins"]+set["losses"])),float(set["wins"]),-float(set["losses"]),set["plmn"]), reverse=True) #div_list.insert(0,div) standings_dict[div] = div_list return { params['division'] : standings_dict[params['division']] } if 'division' in params.keys() else standings_dict
def gen_game_graph(game,points,flip=False): ''' Generates the game graph using matplot lib and saves the image with the proper ID and date in game_graphs folder inside the server. ''' start_time = points[0]['events'][0]['timestamp'] xvals=[0] ourscores=[0] theirscores=[0] for point in points: events = point['events'] for event in events: if event['action'] == "Goal": xvals.append(event['timestamp']-start_time) ourscores.append(point['summary']['score']['ours']) theirscores.append(point['summary']['score']['theirs']) if len(xvals) is 1: return None xvals = [float(x)/float(xvals[-1]) for x in xvals] # if flip is true we are using away team data it should be flipped to # make sure the right points are with the right team # (ourscores --> home_team theirscores-->away_team) if flip: temp = ourscores ourscores = theirscores theirscores = temp ourxpoints=[0] theirxpoints=[0] ourpoints=[0] theirpoints=[0] for i in range(1,len(xvals)-1): if ourscores[i] > ourscores[i-1]: ourpoints.append(ourscores[i]) ourxpoints.append(xvals[i]) if theirscores[i] > theirscores[i-1]: theirpoints.append(theirscores[i]) theirxpoints.append(xvals[i]) # handle the final points of the game # this is messy, but works if ourscores[-1] > ourscores[-2]: ourpoints.append(ourscores[-1]) ourxpoints.append(xvals[-1]) if theirscores[-1] > theirscores[-2]: theirpoints.append(theirscores[-1]) theirxpoints.append(xvals[-1]) home_pnts=zip(ourxpoints,ourpoints) away_pnts=zip(theirxpoints,theirpoints) home_team_abbrev = sr.name_to_abbrev(game.home_team) away_team_abbrev = sr.name_to_abbrev(game.away_team) return [[home_team_abbrev,home_pnts],[away_team_abbrev,away_pnts]] '''