2022-11-03 15:16:45 +00:00
|
|
|
import json
|
2022-10-26 03:49:14 +00:00
|
|
|
import os
|
2022-11-03 14:07:08 +00:00
|
|
|
|
2022-11-03 12:03:04 +00:00
|
|
|
from IDManager import idManager
|
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-11-03 12:03:04 +00:00
|
|
|
idm = idManager()
|
2022-10-21 09:46:57 +00:00
|
|
|
|
2022-10-26 03:49:14 +00:00
|
|
|
replayDataPath = "reps/"
|
|
|
|
evalDataPath = "evals/"
|
2022-10-20 14:48:14 +00:00
|
|
|
|
2022-11-03 12:03:04 +00:00
|
|
|
questionarePath = "data/questionare.csv"
|
2022-11-03 14:07:08 +00:00
|
|
|
annotationPath = "data/annotation.csv"
|
2022-11-03 09:07:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
@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
|
2022-11-03 14:52:38 +00:00
|
|
|
idm.write_csv(questionarePath,
|
|
|
|
[ip, result.get("gamestyle"), result.get("frequency"), result.get("age"), result.get("gender"),
|
|
|
|
""])
|
2022-11-03 12:03:04 +00:00
|
|
|
# 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)
|
2022-11-03 09:07:12 +00:00
|
|
|
print(result.get("gamestyle"))
|
|
|
|
return redirect(url_for('gameplay', id=ip))
|
|
|
|
|
2022-11-03 14:52:38 +00:00
|
|
|
@app.route('/again')
|
|
|
|
def gamepreplayAgain():
|
|
|
|
return redirect(url_for('gameplay', id=request.remote_addr))
|
2022-11-03 09:07:12 +00:00
|
|
|
|
|
|
|
@app.route('/')
|
|
|
|
def gamequestion():
|
|
|
|
return render_template('GameQuestion.html')
|
|
|
|
|
|
|
|
|
|
|
|
@app.route('/gameplay/<id>')
|
|
|
|
def gameplay(id):
|
2022-11-03 12:03:04 +00:00
|
|
|
gamelevels = idm.getLevels(id)
|
2022-11-03 14:07:08 +00:00
|
|
|
return render_template('GamePlay.html', gamelevels=gamelevels)
|
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-03 14:07:08 +00:00
|
|
|
|
2022-11-03 14:52:38 +00:00
|
|
|
gamelevels = idm.getRecent(id)
|
|
|
|
level1 = "lvl"+str(gamelevels[0])
|
|
|
|
level2 = "lvl"+str(gamelevels[1])
|
2022-11-03 14:07:08 +00:00
|
|
|
return render_template('GameAnnotation.html', level1=level1, level2=level2)
|
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 15:16:45 +00:00
|
|
|
print(request.form)
|
|
|
|
print(list(request.form))
|
|
|
|
resultList = list(request.form)[0].split(",")
|
|
|
|
for i,j in request.form.items():
|
|
|
|
print(i)
|
|
|
|
print(j)
|
|
|
|
|
|
|
|
|
2022-11-03 14:52:38 +00:00
|
|
|
# FIXME: NOT SAVING!
|
2022-11-03 15:16:45 +00:00
|
|
|
saveFile(replayDataPath, id+resultList[0] , str(resultList[1:]))
|
2022-11-03 14:52:38 +00:00
|
|
|
return "get!"
|
2022-10-24 14:17:55 +00:00
|
|
|
|
2022-11-03 09:07:12 +00:00
|
|
|
|
2022-11-03 14:52:38 +00:00
|
|
|
@app.route('/radioresult', methods=['POST'])
|
|
|
|
def getRadioData():
|
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-03 14:07:08 +00:00
|
|
|
result = request.form
|
2022-11-03 14:52:38 +00:00
|
|
|
print(result)
|
2022-11-03 14:07:08 +00:00
|
|
|
ip = request.remote_addr
|
2022-11-03 14:52:38 +00:00
|
|
|
ipRecent = idm.getRecent(ip)
|
|
|
|
idm.write_csv(annotationPath, [ip, ipRecent[0],ipRecent[1] , result["fun"]])
|
2022-11-02 07:14:16 +00:00
|
|
|
|
2022-11-03 09:07:12 +00:00
|
|
|
# saveFile(evalDataPath,"gameanno",request.json[0]+request.json[1]+request.json[2])
|
2022-11-03 14:52:38 +00:00
|
|
|
return render_template("GameOver.html")
|
2022-10-26 03:49:14 +00:00
|
|
|
|
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-11-03 14:07:08 +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)
|