-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
executable file
·66 lines (49 loc) · 1.34 KB
/
app.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
#!python3
import json
from flask import Flask, request, jsonify
import api
from db import Database
from spark import Spark
app = Flask(__name__)
spark = Spark()
db = Database(spark)
@app.route("/player", methods=["GET"])
def get_player():
"""
Get features of a player
"""
data = json.loads(request.data)
player = api.get_player(db, data["playerName"], data["season"])
return jsonify(player)
@app.route("/team", methods=["GET"])
def get_team():
"""
Get features of a team
"""
data = json.loads(request.data)
team = api.get_team(
db, data["teamName"], data["season"], __handle_compact_field(data)
)
return jsonify(team)
@app.route("/table", methods=["GET"])
def get_table():
"""
Get the final league table
"""
data = json.loads(request.data)
table = api.get_table(
db, data["league"], data["season"], __handle_compact_field(data)
)
return jsonify(table)
@app.route("/predict", methods=["GET"])
def predict_table():
"""
Perform predictions
"""
data = json.loads(request.data)
prediction = api.get_prediction(db, data["league"], data["season"])
return jsonify(prediction)
def __handle_compact_field(data) -> bool:
return data["compact"] if "compact" in data.keys() else False
if __name__ == "__main__":
app.run(port=8080, debug=True)