Update session
This commit is contained in:
parent
fbab30b272
commit
bf34d99c80
10
IDManager.py
10
IDManager.py
@ -24,9 +24,11 @@ class idManager():
|
|||||||
self.gid = 0
|
self.gid = 0
|
||||||
|
|
||||||
def iniId(self, ip):
|
def iniId(self, ip):
|
||||||
self.gid += 1
|
self.ip_dic[ip] = ip
|
||||||
self.ip_dic[ip] = str(self.gid)
|
# self.gid += 1
|
||||||
return str(self.gid)
|
# self.ip_dic[ip] = str(self.gid)
|
||||||
|
# return str(self.gid)
|
||||||
|
return ip
|
||||||
|
|
||||||
def getId(self, ip):
|
def getId(self, ip):
|
||||||
return self.ip_dic[ip]
|
return self.ip_dic[ip]
|
||||||
@ -89,8 +91,10 @@ class idManager():
|
|||||||
|
|
||||||
def setControl(self, ip, content):
|
def setControl(self, ip, content):
|
||||||
if content == "A":
|
if content == "A":
|
||||||
|
print("A" + ip)
|
||||||
self.ip_control[ip] = 0
|
self.ip_control[ip] = 0
|
||||||
else:
|
else:
|
||||||
|
print("B" + ip)
|
||||||
self.ip_control[ip] = 1
|
self.ip_control[ip] = 1
|
||||||
|
|
||||||
def setTimes(self, ip):
|
def setTimes(self, ip):
|
||||||
|
21
main.py
21
main.py
@ -1,14 +1,15 @@
|
|||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import struct
|
import struct
|
||||||
|
import uuid
|
||||||
|
|
||||||
from IDManager import idManager
|
from IDManager import idManager
|
||||||
|
|
||||||
from flask import Flask, render_template, request, redirect, url_for
|
from flask import Flask, render_template, request, redirect, url_for, session
|
||||||
|
|
||||||
app = Flask(__name__, static_folder='')
|
app = Flask(__name__, static_folder='')
|
||||||
idm = idManager()
|
idm = idManager()
|
||||||
|
app.secret_key = 'fkdjsafjdkfdlkjfadskjfadskljdsfklj'
|
||||||
replayDataPath = "reps/"
|
replayDataPath = "reps/"
|
||||||
evalDataPath = "evals/"
|
evalDataPath = "evals/"
|
||||||
|
|
||||||
@ -16,6 +17,11 @@ questionarePath = "data/questionare.csv"
|
|||||||
annotationPath = "data/annotation.csv"
|
annotationPath = "data/annotation.csv"
|
||||||
annotationPath2 = "data/annotation2.csv"
|
annotationPath2 = "data/annotation2.csv"
|
||||||
|
|
||||||
|
#id=idm.getId(request.remote_addr)
|
||||||
|
def getId():
|
||||||
|
if 'name' not in session:
|
||||||
|
session['name'] = str(uuid.uuid4())
|
||||||
|
return session['name']
|
||||||
|
|
||||||
@app.route('/')
|
@app.route('/')
|
||||||
def gamewelcome():
|
def gamewelcome():
|
||||||
@ -32,7 +38,8 @@ def gamequestion():
|
|||||||
def gamepreplay():
|
def gamepreplay():
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
result = request.form
|
result = request.form
|
||||||
ip = request.remote_addr
|
# ip = request.remote_addr
|
||||||
|
ip = getId()
|
||||||
cid = idm.iniId(ip)
|
cid = idm.iniId(ip)
|
||||||
# Save the result to questionare
|
# Save the result to questionare
|
||||||
idm.write_csv(questionarePath,
|
idm.write_csv(questionarePath,
|
||||||
@ -59,7 +66,7 @@ def gametutorial(id):
|
|||||||
|
|
||||||
@app.route('/again')
|
@app.route('/again')
|
||||||
def gamepreplayAgain():
|
def gamepreplayAgain():
|
||||||
return redirect(url_for('gameplay', id=idm.getId(request.remote_addr)))
|
return redirect(url_for('gameplay', getId))
|
||||||
|
|
||||||
|
|
||||||
@app.route('/gametutorial/<id>/data')
|
@app.route('/gametutorial/<id>/data')
|
||||||
@ -85,7 +92,7 @@ def getJSONData(id):
|
|||||||
|
|
||||||
@app.route('/annotation')
|
@app.route('/annotation')
|
||||||
def gamepreanno():
|
def gamepreanno():
|
||||||
return redirect(url_for('gameanno', id=idm.getId(request.remote_addr)))
|
return redirect(url_for('gameanno', getId))
|
||||||
|
|
||||||
|
|
||||||
@app.route('/annotation/<id>')
|
@app.route('/annotation/<id>')
|
||||||
@ -118,7 +125,7 @@ def getRadioData():
|
|||||||
|
|
||||||
@app.route('/gameplay2')
|
@app.route('/gameplay2')
|
||||||
def gamepreplay2():
|
def gamepreplay2():
|
||||||
return redirect(url_for('gameplay2', id=idm.getId(request.remote_addr)))
|
return redirect(url_for('gameplay2', getId))
|
||||||
|
|
||||||
|
|
||||||
@app.route('/gameplay2/<id>')
|
@app.route('/gameplay2/<id>')
|
||||||
@ -139,7 +146,7 @@ def getJSONData2(id):
|
|||||||
|
|
||||||
@app.route('/annotation2')
|
@app.route('/annotation2')
|
||||||
def gamepreanno2():
|
def gamepreanno2():
|
||||||
return redirect(url_for('gameanno2', id=idm.getId(request.remote_addr)))
|
return redirect(url_for('gameanno2', getId))
|
||||||
|
|
||||||
|
|
||||||
@app.route('/annotation2/<id>')
|
@app.route('/annotation2/<id>')
|
||||||
|
Loading…
Reference in New Issue
Block a user