105 lines
2.9 KiB
Python
105 lines
2.9 KiB
Python
import os
|
|
|
|
from IDManager import idManager
|
|
|
|
from flask import Flask, render_template, request, redirect, url_for
|
|
|
|
app = Flask(__name__, static_folder='')
|
|
idm = idManager()
|
|
|
|
replayDataPath = "reps/"
|
|
evalDataPath = "evals/"
|
|
|
|
questionarePath = "data/questionare.csv"
|
|
annotationPath = "data/annotation.csv"
|
|
|
|
|
|
@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
|
|
idm.write_csv(questionarePath,
|
|
[ip, result.get("gamestyle"), result.get("frequency"), result.get("age"), result.get("gender"),
|
|
""])
|
|
# 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('/again')
|
|
def gamepreplayAgain():
|
|
return redirect(url_for('gameplay', id=request.remote_addr))
|
|
|
|
@app.route('/')
|
|
def gamequestion():
|
|
return render_template('GameQuestion.html')
|
|
|
|
|
|
@app.route('/gameplay/<id>')
|
|
def gameplay(id):
|
|
gamelevels = idm.getLevels(id)
|
|
return render_template('GamePlay.html', gamelevels=gamelevels)
|
|
|
|
|
|
@app.route('/annotation/<id>')
|
|
def gameanno(id):
|
|
print("anno " + id)
|
|
|
|
gamelevels = idm.getRecent(id)
|
|
level1 = "lvl"+str(gamelevels[0])
|
|
level2 = "lvl"+str(gamelevels[1])
|
|
return render_template('GameAnnotation.html', level1=level1, level2=level2)
|
|
|
|
|
|
#
|
|
@app.route('/gameplay/<id>/data', methods=['POST'])
|
|
def getJSONData(id):
|
|
if request.method == 'POST':
|
|
print("POST Game")
|
|
print(request.values)
|
|
# FIXME: NOT SAVING!
|
|
saveFile(replayDataPath, request.json[4], request.json)
|
|
return "get!"
|
|
|
|
|
|
@app.route('/radioresult', methods=['POST'])
|
|
def getRadioData():
|
|
if request.method == 'POST':
|
|
print("POST Eval")
|
|
result = request.form
|
|
print(result)
|
|
ip = request.remote_addr
|
|
ipRecent = idm.getRecent(ip)
|
|
idm.write_csv(annotationPath, [ip, ipRecent[0],ipRecent[1] , result["fun"]])
|
|
|
|
# saveFile(evalDataPath,"gameanno",request.json[0]+request.json[1]+request.json[2])
|
|
return render_template("GameOver.html")
|
|
|
|
|
|
def saveFile(path, filename, content):
|
|
file_dir = os.path.join(os.getcwd(), path)
|
|
file_path = os.path.join(file_dir, filename + ".txt")
|
|
f = open(file_path, "w", encoding="utf8")
|
|
f.write(content)
|
|
f.close()
|
|
|
|
|
|
if __name__ == '__main__':
|
|
app.debug = True
|
|
app.run()
|
|
app.run(debug=True)
|