def get_weekly_info(context): query_weekly = "select * from thisWeekSummary" weekly = query_db(query_weekly, one=True) context['weekly_info']['top_scorer'] = id_to_name(weekly['topScorerId']) context['weekly_info']["top_score"] = weekly['maxScore'] context['weekly_info']['avg_score'] = weekly['averageScore'] context['weekly_info']['low_scorer'] = id_to_name(weekly['lowScorerId']) context['weekly_info']["low_score"] = weekly['minScore'] context['week'] = weekly['week'] if datetime.datetime.now().month < 9: context['year'] = datetime.datetime.now().year - 1 else: context['year'] = datetime.datetime.now().year query_years = "select * from years where year = %d" % context['year'] points = query_db(query_years) pointsDf = pd.DataFrame.from_dict(points) max_points = max(pointsDf['pointsFor']) min_points = min(pointsDf['pointsFor']) id_max = pointsDf.loc[pointsDf['pointsFor'].idxmax()]['teamId'] id_min = pointsDf.loc[pointsDf['pointsFor'].idxmin()]['teamId'] context['weekly_info']['max_score_team'] = id_to_name(id_max) context['weekly_info']['max_score'] = max_points context['weekly_info']['min_score_team'] = id_to_name(id_min) context['weekly_info']['min_score'] = min_points return context
def get_reigning_champ(context): query_champ = "select * from years where year = %d" % ( datetime.datetime.now().year - 1) champ = query_db(query_champ) for team in champ: if team['finalStanding'] == 1: context['current_champion'] = id_to_name(team['teamId'])
def get_standings(context): query_teams = "select * from years where year = %d" % context['year'] teams = pd.DataFrame.from_dict(query_db(query_teams)) standings = teams.sort_values(by=['wins', 'pointsFor'], ascending=False) standings = standings.loc[:, ['teamId', 'wins', 'losses']] teamNameConversion = lambda x: id_to_name(x) standings['teamName'] = standings['teamId'].apply(teamNameConversion) context['standings'] = standings
def get_roto_records(context): query_years = "select * from years where year = %d" % context['year'] year = query_db(query_years) year = pd.DataFrame.from_dict(year) roto = year.sort_values(by=['rotWins'], ascending=False) roto = roto.loc[:, ['teamId', 'rotWins', 'rotLosses']] teamNameConversion = lambda x: id_to_name(x) roto['teamName'] = roto['teamId'].apply(teamNameConversion) context['roto'] = roto
def get_weekly_extras(context): query_weekly = "select * from thisWeekSummary" weekly = query_db(query_weekly, one=True) week = weekly['week'] context['teamOfWeek'] = teamOfWeek(week) context['teamOrder'] = [ 'QB1', 'RB1', 'RB2', 'WR1', 'WR2', 'Flex', 'TE1', 'D/ST1', 'K1' ] bench, start, pointDiff = badManager(week) context['badManBench'] = bench.to_dict() context['badManStart'] = start.to_dict() context['badManDiff'] = pointDiff context['badManManager'] = id_to_name(bench['team'])
def teamOfWeek(week): """ Identify team of the week. """ df = createPlayersDf(week) teamNameConversion = lambda x: id_to_name(x) df['teamName'] = df['team'].apply(teamNameConversion) team = {} numSpots = {'QB': 1, 'RB': 2, 'WR': 2, 'TE': 1, 'D/ST': 1, 'K': 1} flex_spots = ['WR', 'RB', 'TE'] flex_points = 0 for pos in df.position.unique(): df = df.sort_values(by=['points'], ascending=False) top = df.loc[df['position'] == pos] numPlayers = numSpots[pos] for i in range(numPlayers): p = top.iloc[i] pInfo = [p['name'], p['points'], p['team'], p['teamName']] team[pos + str(i + 1)] = pInfo if pos in flex_spots: f = top.iloc[numPlayers] if f['points'] > flex_points: pInfo = [f['name'], f['points'], f['team'], f['teamName']] team['Flex'] = pInfo flex_points = f['points'] return team
def get_name(context, teamId): context['teamName'] = id_to_name(teamId) context['owner'] = id_to_owner(teamId)