def read_choices(round_number): ''' This Function will read the choices of teams for each player. The choices will be stored in an SQL table called choices. PARAMETERS: round_number (string): This is the round number you want to read the choices for. RETURNS: (Dictionary) A dictionary of the team choices with player names as keys and the team choice as the value ''' query = 'select name, choice from choices where round = {}'.format(round_number) choices_df = utils.read_from_sql(query, 'name') choices = choices_df.to_dict(orient='index') choices = {k:v['choice'] for k,v in choices.items()} return choices
def get_yesterdays_round(): ''' ''' query = 'SELECT round_number FROM round_info order by round_number desc limit 1 ' yesterday_round = utils.read_from_sql(query)['round_number'][0] return yesterday_round
def read_results(round_number): ''' ''' query = 'SELECT * FROM results WHERE round = {}'.format(round_number) results = utils.read_from_sql(query) return results
def read_points(round_number): ''' ''' query = 'SELECT name, points FROM points WHERE round = {} ORDER BY points'.format(round_number) points = utils.read_from_sql(query, 'name') return points
def check_if_already_submitted(name): ''' ''' query = 'SELECT COUNT(choice) AS num FROM choices WHERE name = "{}" AND round = {}'.format(name, utils.get_current_round()) num = utils.read_from_sql(query)['num'][0] if num > 0: return True return False
def read_added_info(round_number): ''' ''' query = 'SELECT draw_weekend, double_points_weekend FROM round_info WHERE round_number = {}'.format(round_number) added_info = utils.read_from_sql(query) DW = bool(added_info['draw_weekend'][0]) DP = bool(added_info['double_points_weekend'][0]) return DW, DP
def find_standings(): ''' ''' query = 'SELECT name, sum(score) as points FROM scores GROUP BY name ORDER BY points DESC' standings = utils.read_from_sql(query) standings_list = list(standings['name']) standings = str(standings) print(standings, standings_list ) return standings, standings_list
def get_scores_text(round_number): ''' ''' query = "SELECT name, sum(points) AS scores FROM points WHERE round = {} GROUP BY name ORDER BY scores DESC".format(round_number) scores = utils.read_from_sql(query) text = "Scores: \n\n" for row in scores.iterrows(): text = text + "{}: {} \n".format(row[1]['name'], int(row[1]['scores'])) return text
def get_standings_text(): ''' ''' query = 'SELECT name, sum(points) as points FROM points GROUP BY name ORDER BY points DESC' standings = utils.read_from_sql(query) text = "Standings: \n\n" for row in standings.iterrows(): text = text + "{}: {} \n".format(row[1]['name'], int(row[1]['points'])) return text
def check_validity(name, message): ''' ''' team = utils.clean_string(message.split('=')[1]) query = "SELECT COUNT(*) AS count FROM choices WHERE name = '{}' and choice = '{}'".format(name, team) df = utils.read_from_sql(query) times_chosen = df['count'][0] if times_chosen >= 2: validity = False else: validity = True return validity
def read_scores(round_number): ''' This Function will read the points gained for each player from a specified round. PARAMETERS: round_number (string): This is the round number you want to read the choices for. RETURNS: (DataFrame) A DataFrame with two columns called name and points containing the points data for each player for a specific round ''' query = 'SELECT name, sum(points) as scores FROM points WHERE round = {} GROUP BY name ORDER BY scores'.format(round_number) points = utils.read_from_sql(query, 'name') return points