@@ -0,0 +1,1881 @@
+from flask import Flask, render_template, request, redirect%0Aimport pandas as pd%0Aimport matplotlib.pyplot as plt%0Afrom matplotlib.colors import Normalize%0Aimport os%0Aimport psycopg2%0Aimport urlparse%0Aimport sqlalchemy%0A%0Adef get_data(pitcher_name):%0A    urlparse.uses_netloc.append(%22postgres%22)%0A    url = urlparse.urlparse(os.environ%5B%22DATABASE_URL%22%5D)%0A%0A    database=url.path,%0A    user=url.username,%0A    password=url.password,%0A    host=url.hostname,%0A    port=url.port%0A    scheme = url.scheme%0A%0A    engine = sqlalchemy.create_engine('%25s://%25s:%25s@%25s:%25s/%25s' %25 (scheme, user%5B0%5D, password%5B0%5D, host%5B0%5D, port, database%5B0%5D%5B1:%5D))%0A    conn = engine.connect()%0A%0A    query = '''%0A        SELECT pitch_type,%0A            start_speed,%0A            pfx_x,%0A            pfx_z%0A        FROM pitches%0A        JOIN (%0A                SELECT *%0A                FROM atbats%0A                WHERE pitcher = (%0A                                SELECT eliasid%0A                                FROM players%0A                                WHERE first = '%25s'%0A                                AND last = '%25s'%0A                                )%0A            ) atbats%0A        ON pitches.ab_id = atbats.ab_id%0A        WHERE start_speed IS NOT NULL%0A            AND pitches.des != 'Intent Ball'%0A            AND sv_id %3E '150000_000000'%0A        ''' %25 (pitcher_name.split()%5B0%5D, pitcher_name.split()%5B1%5D)%0A    data = pd.read_sql(query, engine)%0A    %0A    conn.close()%0A%0A    return data%0A%0Adef make_figure(df):%0A    fig = plt.figure(figsize=(10,8))%0A%0A    plt.scatter(df%5B'pfx_x'%5D, df%5B'pfx_z'%5D, c=df%5B'start_speed'%5D, %5C%0A                    alpha=.3, cmap='inferno', norm = Normalize(70, 100))%0A    plt.colorbar().set_label('Velocity')%0A    plt.xlim(%5B-20, 20%5D)%0A    plt.ylim(%5B-20, 20%5D)%0A    plt.xlabel('Horizontal movement')%0A    plt.ylabel('Vertical movement')%0A    plt.show()%0A%0Adef main(pitcher_name):%0A    make_figure(get_data(pitcher_name))%0A%0Aprint main('Jon Lester')

Make a test file for plotting outside web app