Exemple #1
0
def playersPerGameStats(date):
    # db = database.connectDB('2019-20')
    # cursor = db.cursor(dictionary = True)

    # cursor.execute("SELECT * FROM playerstats201920")

    # stats = cursor.fetchall()
    # return jsonify(stats)

    year, month, day = date.split('-')

    if (int(month) > 8):
        season = year + '-' + str((int(year) + 1) % 100)
    else:
        season = str(int(year) - 1) + '-' + str(int(year) % 100)
    season_split = season.replace('-', '')

    db = database.connectDB(season)
    mycursor = db.cursor(dictionary=True)
    mycursor.execute('SELECT * FROM games' + season_split +
                     ' WHERE(gamedate = STR_TO_DATE("' + str(date) +
                     '","%Y-%m-%e")) ')
    games = mycursor.fetchall()
    players = []

    for game in games:
        mycursor.execute('SELECT * FROM playerstats' + season_split +
                         ' WHERE(teamid = ' + str(game['teamid']) + ')')
        players += mycursor.fetchall()
    players.sort(key=lambda x: x['pts'], reverse=True)
    db.disconnect()
    return jsonify(players)
Exemple #2
0
def zscores():
    db = database.connectDB('2019-20')
    cursor = db.cursor(dictionary=True)

    cursor.execute("SELECT * FROM playerstatsz201920")

    stats = cursor.fetchall()
    return jsonify(stats)
Exemple #3
0
def test(player):
    db = database.connectDB('2019-20')
    mycursor = db.cursor(dictionary=True)
    mycursor.execute("SELECT * FROM playergamelog201920 WHERE(playerid = %s)" %
                     (player))
    games = mycursor.fetchall()
    fg_pct = {}
    ft_pct = {}
    fg3m = {}
    reb = {}
    ast = {}
    stl = {}
    blk = {}
    pts = {}
    tov = {}
    chartList = [fg_pct, ft_pct, fg3m, reb, ast, stl, blk, pts, tov]
    fg_pct['title'] = "Field Goal Percentage"
    ft_pct['title'] = "Free Throw Percentage"
    fg3m['title'] = "Three Pointers Made"
    reb['title'] = " Rebounds"
    ast['title'] = "Assists"
    stl['title'] = "Steals"
    blk['title'] = "Blocks"
    pts['title'] = "Points"
    tov['title'] = "Turnovers"

    for chart in chartList:
        chart['axis'] = {'x': {'type': 'category', 'categories': []}, 'y': {}}
        chart['data'] = {
            'columns': [['data1']],
            'type': 'line',
            'names': {
                'data1': chart['title']
            }
        }
        chart['axis']['x']['show'] = False
        chart['axis']['y']['min'] = 0
    fg_pct['axis']['y']['max'] = 1
    ft_pct['axis']['y']['max'] = 1
    fg_pct['axis']['y']['padding'] = {'top': 0, 'bottom': 0}
    ft_pct['axis']['y']['padding'] = {'top': 0, 'bottom': 0}
    for game in games:
        gamedate = date.strftime(game['gamedate'], '%m/%d/%Y')
        fg_pct['data']['columns'][0].append(game['fg_pct'])
        ft_pct['data']['columns'][0].append(game['ft_pct'])
        fg3m['data']['columns'][0].append(game['fg3m'])
        reb['data']['columns'][0].append(game['reb'])
        ast['data']['columns'][0].append(game['ast'])
        stl['data']['columns'][0].append(game['stl'])
        blk['data']['columns'][0].append(game['blk'])
        pts['data']['columns'][0].append(game['pts'])
        tov['data']['columns'][0].append(game['tov'])
        for chart in chartList:
            chart['axis']['x']['categories'].append(gamedate)

    return jsonify(chartList)
Exemple #4
0
def allPlayersPerGame():
    db = database.connectDB('2019-20')
    cursor = db.cursor(dictionary=True)

    cursor.execute("SELECT * FROM playerstats201920")

    stats = cursor.fetchall()
    db.disconnect()
    stats.sort(key=lambda x: x['pts'], reverse=True)
    return jsonify(stats)
Exemple #5
0
def todo_category_keyboard_content(chat_id, todolist):
    # Get categories IDs from database for a chat
    categories = db.getCategoriesIdFromChat(chat_id)
    keyboard = []
    db.connectDB()

    print('accessing categories', categories)
    for category in categories:
        keyboard.append((category["name"], category["id"]))
    if todolist:
        keyboard.append((_("All categories"), -1))
    else:
        keyboard.append((_("Create new category"), -1))

    db.closeDB()
    keyboard_elements = [
        [element] for element in keyboard
    ]  # Create list of list (each button on different row)
    print('keyboard_elements', keyboard_elements)
    return keyboard_elements
Exemple #6
0
def randPlayer():
    db = database.connectDB('2019-20')
    cursor = db.cursor(dictionary=True)
    cursor.execute("SELECT * FROM playerstats201920")
    playersPerGame = cursor.fetchall()
    player = random.randint(0, len(playersPerGame))
    cursor.execute("SELECT * FROM playerstatsz201920 WHERE(playerid = %s)" %
                   (playersPerGame[player]['playerid']))
    playersZscores = cursor.fetchone()
    retPlayer = {'perGame': playersPerGame[player], 'zScore': playersZscores}
    db.disconnect()
    return jsonify(retPlayer)
Exemple #7
0
def todayGames():
    today = date.today()
    db = database.connectDB('2019-20')
    mycursor = db.cursor(dictionary=True)
    today = today.strftime('%Y-%m-%d')
    mycursor.execute(
        'SELECT matchup FROM games201920 WHERE(gamedate = STR_TO_DATE("' +
        str(today) + '","%Y-%m-%e")) ')
    games = mycursor.fetchall()
    db.disconnect()
    #remove duplicates
    seen = set()
    new_games = []
    for d in games:
        t = tuple(d.items())
        if t not in seen:
            seen.add(t)
            new_games.append(d)

    return jsonify(new_games)
Exemple #8
0
    'piechart -- dropped packets': pieChartRun
}

# Open up our config file
config = ConfigParser.ConfigParser()

# Read the config
config.read(CONFIGFILE)

# Loop through the config, starting up whatever we need to.
for section in config._sections:

    # Special case of connecting to DB
    # TODO: Need to have better way of handling the db...
    if section == "SQLite Database Handler":
        connectDB(config._sections[section]["dbname"])
        continue

    # Index to keep track of multiple graphs per section
    i = 1

    # standardize the dict to a normal dict
    kargs = dict(config._sections[section])

    # Loop through the plots
    while kargs.has_key("alias_" + str(i)):
        # Set tag = "<module_i>
        kargs["tag_" + str(i)] = kargs["module_" + str(i)].lower()

        # If there's a custom ctag, add it to the tag
        if kargs.has_key("ctag_" + str(i)) and kargs["ctag_" + str(i)] != "":
import database
import json, urllib.request

season = '2019-20'

data = urllib.request.urlopen(
    "http://data.nba.net/data/10s/prod/v1/2019/schedule.json").read()
output = json.loads(data)

# for key in output['league']:
#     print(key)
# for key in output['league']['standard'][0]:
#     print(key)

mydb = database.connectDB(season)
mycursor = mydb.cursor()

# create table and add game data for each game
season = ''.join(season.split('-'))
mycursor.execute(
    "CREATE TABLE IF NOT EXISTS games" + season +
    " (teamid INT, teamname VARCHAR(255),gamedate DATE, matchup VARCHAR (255), gameid INT, PRIMARY KEY (teamid,gameid))"
)

for game in output['league']['standard']:
    if (game['seasonStageId'] == 2):
        teamid1 = game['hTeam']['teamId']
        team1Abr = game['gameUrlCode'][-3:]
        teamid2 = game['vTeam']['teamId']
        team2Abr = game['gameUrlCode'][-6:-3]
Exemple #10
0
	'piechart -- dropped packets': pieChartRun
}

# Open up our config file
config = ConfigParser.ConfigParser()

# Read the config
config.read(CONFIGFILE)

# Loop through the config, starting up whatever we need to.
for section in config._sections:

	# Special case of connecting to DB
	# TODO: Need to have better way of handling the db...
	if section == "SQLite Database Handler":
		connectDB(config._sections[section]["dbname"])
		continue

	# Index to keep track of multiple graphs per section
	i = 1

	# standardize the dict to a normal dict
	kargs = dict(config._sections[section])

	# Loop through the plots
	while kargs.has_key("alias_" + str(i)):
		# Set tag = "<module_i>
		kargs["tag_" + str(i)] = kargs["module_" + str(i)].lower()

		# If there's a custom ctag, add it to the tag
		if kargs.has_key("ctag_" + str(i)) and kargs["ctag_" + str(i)] != "":