forked from romimo-93/Final-Project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
application.py
158 lines (133 loc) · 4.73 KB
/
application.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# import necessary libraries
from flask import (Flask, render_template, jsonify, request, redirect)
import logging
from src import sql_repo
from cluster import cluster
logger = logging.getLogger()
logger.setLevel(logging.INFO)
#################################################
# Flask Setup
#################################################
application = Flask(__name__)
#################################################
# Cached Data
#################################################
seasons = None
#################################################
# Routes
#################################################
# create route that renders index.html template
@application.route("/")
def home():
return render_template("index.html")
@application.route("/api/data")
def data():
sql = sql_repo.sql_query("sql_data")
if (sql != ""):
results = sql_repo.sql(sql)
return jsonify(results)
@application.route("/api/seasons")
def seasons():
sql = sql_repo.sql_query("sql_seasons")
if (sql != ""):
results = sql_repo.sql_list(sql)
return jsonify(results)
@application.route("/api/playerstats/<season>!<player_id>!<team_id>")
def daterequested(season, player_id, team_id):
results = {}
if ((player_id.isnumeric() == True) and (season.isnumeric() == True) & (team_id.isnumeric() == True)):
sql = sql_repo.sql_query("sql_daterequested",season, team_id, player_id)
if (sql != ""):
results = sql_repo.sql(sql)
return jsonify(results)
@application.route("/api/playerinfo/<player_id>")
def playerinfo(player_id):
results = {}
sql = sql_repo.sql_query("sql_playerinfo", "", "", player_id)
if (sql != ""):
results = sql_repo.sql(sql)
return jsonify(results)
@application.route("/api/players/")
def players():
results = {}
sql = sql_repo.sql_query("sql_players")
if (sql != ""):
results = sql_repo.sql(sql)
return jsonify(results)
@application.route("/api/aggplayerstats/<player_id>")
def aggplayerstats(player_id):
results = {}
sql = sql_repo.sql_query("sql_aggplayerstats")
if ((player_id.isnumeric() == True) & (sql != "")):
sql += " where player_id = " + player_id + ";"
else:
sql += ";"
if (sql != ""):
results = sql_repo.sql(sql)
return jsonify(results)
@application.route("/api/avgplayerstats/<player_id>")
def avgplayerstats(player_id):
sql = sql_repo.sql_query("sql_avgplayerstats")
if ((player_id.isnumeric() == True) & (sql != "")):
sql += " where player_id = " + player_id + ";"
else:
sql += ";"
if sql != "":
results = sql_repo.sql(sql)
return jsonify(results)
@application.route("/api/playerpred/<player_id>")
def avgplayerpred(player_id):
sql = sql_repo.sql_query("sql_avgplayerpred")
if ((player_id.isnumeric() == True) & (sql != "")):
sql += " where player_id = " + player_id + ";"
else:
sql += ";"
if sql != "":
results = sql_repo.sql(sql)
return jsonify(results)
@application.route("/api/teams")
def teams():
results = {}
sql = sql_repo.sql_query("sql_teams")
if (sql != ""):
results = sql_repo.sql(sql)
return jsonify(results)
@application.route("/api/seasonTeamPlayers/<season>/<team_id>")
def seasonTeamPlayers(season, team_id):
results = {}
sql = sql_repo.sql_query("seasonTeamPlayers", season, team_id)
if (sql != ""):
results = sql_repo.sql(sql)
return jsonify(results)
@application.route("/api/seasonTeams/<season>")
def seasonTeams(season):
results = {}
sql = sql_repo.sql_query("seasonTeams", season)
print(sql)
if (sql != ""):
results = sql_repo.sql(sql)
return jsonify(results)
@application.route("/tableau")
def tableau():
return render_template("tableau.html")
@application.route("/routes")
def routes():
return render_template("routes.html")
#### This route was used to generate the clustering images
# @application.route("/get/cluster-images")
# def clusterimages():
# results = sql(f"SELECT * FROM dbo.avgplayerstats")
# xs = ["assists", "goals", "shots", "blocked", "hits", "penaltyMinutes", "takeaways", "giveaways"]
# ys = ["timeOnIce", "evenTimeOnIce", "shortHandedTimeOnIce", "powerPlayTimeOnIce"]
# for x in xs:
# for y in ys:
# cluster_data = []
# for player in results:
# cluster_data.append([player[x],player[y]])
# cluster(cluster_data, x, y)
# return redirect("/", 304)
#################################################
# End Routes
#################################################
if __name__ == '__main__':
application.run(debug=True)