-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
50 lines (44 loc) · 1.42 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
# Dependencies: Flask, Numpy, Pandas
from flask import Flask,render_template, request, jsonify
import pandas as pd
# creating a dataframe for easier data storage
user_data = pd.DataFrame({
"username": ["test"],
"userX": [0],
"userY": [0],
"targetX": [0],
"targetY": [0],
"lvl_max": [0],
"lvl_curr": [0],
"time": [0.0]
})
# initializing Flask
app = Flask(__name__,template_folder="templates", static_url_path='/static')
# rendering the index page template
@app.route("/")
def index():
return render_template('index.html')
# setting up a function to grab coordinates
@app.route('/receive_value', methods=['POST'])
def receive_value():
# get request called by the JS script
try:
data = request.get_json()
# fill in the dataframe
# print(data)
# print(user_data)
for i in data:
user_data[i] = data[i]
# saves only current user progress into the CSV
csv_line = user_data.loc[user_data['username'] == "test"]
if int( csv_line['lvl_curr']) >= int(csv_line['lvl_max']):
csv_line['lvl_max'] = csv_line['lvl_curr']
# converting dataframe into CSV
csv_line.to_csv("user_data.csv", index=False)
return data
except Exception as e:
result = {'status': 'error', 'message': str(e)}
print(str(e))
return jsonify(result), 500
if __name__ == '__main__':
app.run(debug=True)