2022-10-26 03:49:14 +00:00
|
|
|
import os
|
2022-11-03 09:07:12 +00:00
|
|
|
from pyExcel import ExcelWork
|
2022-10-26 03:49:14 +00:00
|
|
|
|
2022-10-20 14:48:14 +00:00
|
|
|
from flask import Flask, render_template, request, redirect, url_for
|
|
|
|
|
2022-10-21 09:46:57 +00:00
|
|
|
app = Flask(__name__, static_folder='')
|
|
|
|
|
2022-10-26 03:49:14 +00:00
|
|
|
replayDataPath = "reps/"
|
|
|
|
evalDataPath = "evals/"
|
2022-10-20 14:48:14 +00:00
|
|
|
|
2022-11-03 09:07:12 +00:00
|
|
|
questionarePath = "data/questionare.xlsx"
|
|
|
|
|
|
|
|
|
|
|
|
@app.route('/annotation')
|
|
|
|
def gamepreanno():
|
|
|
|
return redirect(url_for('gameanno', id=request.remote_addr))
|
|
|
|
|
|
|
|
|
|
|
|
@app.route('/result', methods=['POST', 'GET'])
|
|
|
|
def gamepreplay():
|
|
|
|
if request.method == 'POST':
|
|
|
|
result = request.form
|
|
|
|
ip = request.remote_addr
|
|
|
|
# Save the result to questionare
|
|
|
|
excel = ExcelWork(questionarePath)
|
|
|
|
questionareLine = excel.getMaxRow()+1
|
|
|
|
print(questionareLine)
|
|
|
|
excel.setCell(questionareLine,1,ip)
|
|
|
|
excel.setCell(questionareLine, 2, result.get("gamestyle"))
|
|
|
|
excel.setCell(questionareLine, 3, result.get("frequency"))
|
|
|
|
excel.setCell(questionareLine, 4, result.get("age"))
|
|
|
|
excel.saveFile()
|
|
|
|
print(questionareLine)
|
|
|
|
print(result.get("gamestyle"))
|
|
|
|
return redirect(url_for('gameplay', id=ip))
|
|
|
|
|
|
|
|
|
|
|
|
@app.route('/')
|
|
|
|
def gamequestion():
|
|
|
|
return render_template('GameQuestion.html')
|
|
|
|
|
|
|
|
|
|
|
|
@app.route('/gameplay/<id>')
|
|
|
|
def gameplay(id):
|
|
|
|
print(id)
|
2022-11-02 07:14:16 +00:00
|
|
|
return render_template('GamePlay.html')
|
2022-10-21 09:46:57 +00:00
|
|
|
|
2022-10-20 14:48:14 +00:00
|
|
|
|
2022-11-03 09:07:12 +00:00
|
|
|
@app.route('/annotation/<id>')
|
|
|
|
def gameanno(id):
|
|
|
|
print("anno " + id)
|
2022-11-02 07:14:16 +00:00
|
|
|
return render_template('GameAnnotation.html')
|
2022-10-24 11:48:43 +00:00
|
|
|
|
|
|
|
|
2022-11-03 09:07:12 +00:00
|
|
|
#
|
|
|
|
@app.route('/gameplay/<id>/data', methods=['POST'])
|
|
|
|
def getJSONData(id):
|
2022-10-24 14:17:55 +00:00
|
|
|
if request.method == 'POST':
|
2022-10-26 03:49:14 +00:00
|
|
|
print("POST Game")
|
2022-11-03 09:07:12 +00:00
|
|
|
print(request.values)
|
2022-10-26 03:49:14 +00:00
|
|
|
saveFile(replayDataPath, request.json[4], request.json)
|
|
|
|
return "Catch JSON Data"
|
2022-10-24 14:17:55 +00:00
|
|
|
|
2022-11-03 09:07:12 +00:00
|
|
|
|
|
|
|
@app.route('/annotation/<id>/data', methods=['POST'])
|
|
|
|
def getRadioData(id):
|
2022-10-21 09:46:57 +00:00
|
|
|
if request.method == 'POST':
|
2022-10-26 03:49:14 +00:00
|
|
|
print("POST Eval")
|
2022-11-02 07:14:16 +00:00
|
|
|
print(request.values)
|
|
|
|
|
2022-11-03 09:07:12 +00:00
|
|
|
# saveFile(evalDataPath,"gameanno",request.json[0]+request.json[1]+request.json[2])
|
2022-10-26 03:49:14 +00:00
|
|
|
return "catch Radio"
|
|
|
|
|
2022-11-03 09:07:12 +00:00
|
|
|
|
|
|
|
def saveFile(path, filename, content):
|
2022-10-26 03:49:14 +00:00
|
|
|
file_dir = os.path.join(os.getcwd(), path)
|
2022-11-03 09:07:12 +00:00
|
|
|
file_path = os.path.join(file_dir, filename + ".txt")
|
2022-10-26 03:49:14 +00:00
|
|
|
f = open(file_path, "w", encoding="utf8")
|
|
|
|
f.write(content)
|
|
|
|
f.close()
|
2022-10-20 14:48:14 +00:00
|
|
|
|
2022-11-03 09:07:12 +00:00
|
|
|
|
2022-10-20 14:48:14 +00:00
|
|
|
if __name__ == '__main__':
|
2022-10-21 09:46:57 +00:00
|
|
|
app.debug = True
|
|
|
|
app.run()
|
|
|
|
app.run(debug=True)
|