Exemplo n.º 1
0
def get_players(position, team, height, weight, limit):
    (weight, limit) = convert_to_int(weight=weight, limit=limit)
    if height is not None:
        try:
            height = int(height)
            height = int_height_to_string(height)
        except ValueError as _:
            pass
    raw_players = select('players',
                         limit,
                         position=position,
                         team=team,
                         height=height,
                         weight=weight)
    players = []
    for raw_player in raw_players:
        player = {
            'name': raw_player['name'],
            'team': raw_player['team'],
            'number': raw_player['number'],
            'weight': toInt(raw_player['weight']),
            'height': raw_player['height'],
            'age': raw_player['age'],
            'birthday': str(raw_player['birthday']),
            'university': raw_player['university'],
            'position': raw_player['position'],
            'stats': get_player_stats(raw_player['name'],
                                      raw_player['position'])
        }
        players.append(player)
    return players
Exemplo n.º 2
0
def get_games(team_a, team_b, limit):
    limit = convert_to_int(limit=limit)[0]
    teams = []
    if team_a is not None:
        teams.append(team_a)
    if team_b is not None:
        teams.append(team_b)

    if len(teams) == 0:
        raw_games = select('games', limit)
    elif len(teams) == 1:
        raw_games = select('games', limit, home_team=teams[0])
        raw_games += select('games', limit, away_team=teams[0])
    else:
        raw_games = select('games',
                           limit,
                           home_team=teams[0],
                           away_team=teams[1])
        raw_games += select('games',
                            limit,
                            away_team=teams[0],
                            home_team=teams[1])

    games = []
    i = 0
    for raw_game in raw_games:
        if i == limit:
            break
        if raw_game['away_score'] > raw_game['home_score']:
            winner = raw_game['away_team']
        elif raw_game['away_score'] < raw_game['home_score']:
            winner = raw_game['home_team']
        else:
            winner = 'tie'

        games.append({
            'date': str(raw_game['date']),
            'away_team': raw_game['away_team'],
            'home_team': raw_game['home_team'],
            'away_score': raw_game['away_score'],
            'home_score': raw_game['home_score'],
            'winner': winner
        })
        i += 1
    return games
Exemplo n.º 3
0
def get_defense_stats(name):
    data = select('player_defense', name=name, limit=1)
    if len(data) == 0:
        return get_null_stats()
    data = data[0]
    numbers = {
        'games': data['games_played'],
        'interceptions': data['interceptions'],
        'tackles': data['tackles'],
        'sacks': data['sacks']
    }
    return {'type': 'defense', 'numbers': numbers}
Exemplo n.º 4
0
def get_suggestions(limit):
    limit = convert_to_int(limit=limit)[0]
    raw_suggestions = select('user_suggestions', limit)

    suggestions = []
    for suggestion in raw_suggestions:
        suggestions.append({
            'id': suggestion['id'],
            'user_name': suggestion['user_name'],
            'suggestion': suggestion['suggestion'],
        })
    return suggestions
Exemplo n.º 5
0
def get_rushing_stats(name):
    data = select('player_rushing', name=name, limit=1)
    if len(data) == 0:
        return get_null_stats()
    data = data[0]
    numbers = {
        'games': data['games'],
        'rushes_attempted': data['rushes_attempted'],
        'yards': data['yards'],
        'avg_yards': data['avg_yards'],
        'yards_per_game': data['yards_per_game'],
        'touchdowns': data['touchdowns']
    }
    return {'type': 'rushing', 'numbers': numbers}
Exemplo n.º 6
0
def get_team(name):
    if name is None:
        raise BlankException(f'''The parameter [name] is required''', 400)

    data = select('teams', 1, team_name=name)
    if len(data) == 0:
        raise BlankException(f'''There is no season for the team [{name}]''',
                             404)

    data = data[0]
    return {
        'name': data['team_name'],
        'state': data['state'],
        'division': data['division'],
        'conference': data['conference']
    }
Exemplo n.º 7
0
def get_passing_stats(name):
    data = select('player_passing', name=name, limit=1)
    if len(data) == 0:
        return get_null_stats()
    data = data[0]
    numbers = {
        'games': data['games'],
        'games_starting': data['games_starting'],
        'completed_passes': data['completed_passes'],
        'attempted_passes': data['attempted_passes'],
        'completion_percent': data['completion_percent'],
        'yards': data['yards'],
        'touchdowns': data['touchdowns'],
        'touchdown_percent': data['touchdown_percent'],
        'interceptions': data['interceptions'],
        'interception_percent': data['interception_percent']
    }
    return {'type': 'passing', 'numbers': numbers}
Exemplo n.º 8
0
def get_season(team):
    if team is None:
        raise BlankException(f'''The parameter [team] is required''', 400)

    data = select('season', 1, team_name=team)
    if len(data) == 0:
        raise BlankException(f'''There is no season for the team [{team}]''',
                             404)

    data = data[0]
    return {
        'name': data['team_name'],
        'wins': data['wins'],
        'losses': data['losses'],
        'ties': data['ties'],
        'playoffs': data['playoffs'],
        'superbowl_champ': data['superbowl_champ'],
    }
Exemplo n.º 9
0
def get_receiving_stats(name):
    data = select('player_receiving', name=name, limit=1)
    if len(data) == 0:
        return get_null_stats()
    data = data[0]
    numbers = {
        'games': data['games'],
        'games_starting': data['games_starting'],
        'receptions': data['receptions'],
        'reception_percent': toInt(data['catch_percent'] * 100),
        'receptions_per_game': data['catches_per_game'],
        'yards': data['yards'],
        'yards_per_catch': data['yards_per_catch'],
        'yards_per_game': data['yards_per_game'],
        'touchdowns': data['touchdowns'],
        'fumbles': data['fumbles']
    }
    return {'type': 'receiving', 'numbers': numbers}
Exemplo n.º 10
0
def get_kicking_stats(name):
    data = select('player_kicking', name=name, limit=1)
    if len(data) == 0:
        return get_null_stats()
    data = data[0]
    numbers = {
        'games': data['games_played'],
        'fg_attempted': data['fg_attempted'],
        'fg_made': data['fg_made'],
        'fg_percentage': toInt(data['fg_percentage'] * 100),
        'xp_attempted': data['xp_attempted'],
        'xp_made': data['xp_made'],
        'xp_percentage': toInt(data['xp_percentage'] * 100),
        'kickoffs': data['kickoffs'],
        'kickoff_yards': data['kickoff_yards'],
        'kickoff_avg': data['kickoff_avg'],
        'punts': data['punts'],
        'punt_yards': data['punt_yards'],
        'yards_per_punt': data['yards_per_punt']
    }
    return {'type': 'kicking', 'numbers': numbers}
Exemplo n.º 11
0
def select(coffee_id):
    coffee = database.select(Coffee, coffee_id)
    return coffee.representation()