-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.py
69 lines (53 loc) · 1.89 KB
/
server.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
import random
from flask import Flask, render_template, request, jsonify
import json
from webappAthleteScraper import getAthlete, login
from webappFilter import Filter, percentile
from dataFormatters import cards, graph
import pandas as pd
app = Flask(__name__)
s = login()
database = pd.read_csv("database.csv")
print('Loaded database')
def getPercentile(package):
#print(package)
aid = package['aid']
#print(aid)
athleteData = getAthlete(aid, s, 'regular', package['location'])
#print(athleteData)
package['name'] = athleteData['name']
package['gender'] = athleteData['gender']
package['results'] = athleteData['results']
print(package['stateStatus'])
if package['stateStatus']:
package['location'] = athleteData['location']
else:
package['stateStatus'] = 'False'
package['location'] = 'Everywhere'
for results in package['results']:
'''
if package['grade'] == 'True':
package['gradeLevel'] = results['gradeLevel']
'''
filteredTable = Filter(results, database, package['stateStatus'], package['grade'], package['genderStatus'])
updatedAthleteData = percentile(filteredTable, results)
results['percentile'] = str(updatedAthleteData[0]).split('.')[0] + '%'
results['dataSize'] = updatedAthleteData[1]
return package
@app.route('/')
def index():
return render_template('index.html')
@app.route('/api/', methods=['POST', 'GET'])
def api():
if request.method=="POST":
state = request.get_json()
#print(state)
data = getPercentile(state)
state["cardResults"] = cards(data)
#print(state["cardResults"])
state["graphResults"] = graph(data)
print(state)
return jsonify(state)
if __name__ == '__main__':
app.run(debug=True)
testRequest = {'aid':'13940334', 'form':{"state":"", "grade":"True", "gender":"f"}}