From bf34d99c80003f47af44ea4b9582bdbc86e7f212 Mon Sep 17 00:00:00 2001 From: bigJIU <1572204178@qq.com> Date: Wed, 8 Mar 2023 15:50:05 +0800 Subject: [PATCH] Update session --- IDManager.py | 10 +++++++--- main.py | 21 ++++++++++++++------- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/IDManager.py b/IDManager.py index 5dc3a53..7b6b804 100644 --- a/IDManager.py +++ b/IDManager.py @@ -24,9 +24,11 @@ class idManager(): self.gid = 0 def iniId(self, ip): - self.gid += 1 - self.ip_dic[ip] = str(self.gid) - return str(self.gid) + self.ip_dic[ip] = ip + # self.gid += 1 + # self.ip_dic[ip] = str(self.gid) + # return str(self.gid) + return ip def getId(self, ip): return self.ip_dic[ip] @@ -89,8 +91,10 @@ class idManager(): def setControl(self, ip, content): if content == "A": + print("A" + ip) self.ip_control[ip] = 0 else: + print("B" + ip) self.ip_control[ip] = 1 def setTimes(self, ip): diff --git a/main.py b/main.py index 26f6772..7de99e0 100644 --- a/main.py +++ b/main.py @@ -1,14 +1,15 @@ import json import os import struct +import uuid 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='') idm = idManager() - +app.secret_key = 'fkdjsafjdkfdlkjfadskjfadskljdsfklj' replayDataPath = "reps/" evalDataPath = "evals/" @@ -16,6 +17,11 @@ questionarePath = "data/questionare.csv" annotationPath = "data/annotation.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('/') def gamewelcome(): @@ -32,7 +38,8 @@ def gamequestion(): def gamepreplay(): if request.method == 'POST': result = request.form - ip = request.remote_addr + # ip = request.remote_addr + ip = getId() cid = idm.iniId(ip) # Save the result to questionare idm.write_csv(questionarePath, @@ -59,7 +66,7 @@ def gametutorial(id): @app.route('/again') def gamepreplayAgain(): - return redirect(url_for('gameplay', id=idm.getId(request.remote_addr))) + return redirect(url_for('gameplay', getId)) @app.route('/gametutorial//data') @@ -85,7 +92,7 @@ def getJSONData(id): @app.route('/annotation') def gamepreanno(): - return redirect(url_for('gameanno', id=idm.getId(request.remote_addr))) + return redirect(url_for('gameanno', getId)) @app.route('/annotation/') @@ -118,7 +125,7 @@ def getRadioData(): @app.route('/gameplay2') def gamepreplay2(): - return redirect(url_for('gameplay2', id=idm.getId(request.remote_addr))) + return redirect(url_for('gameplay2', getId)) @app.route('/gameplay2/') @@ -139,7 +146,7 @@ def getJSONData2(id): @app.route('/annotation2') def gamepreanno2(): - return redirect(url_for('gameanno2', id=idm.getId(request.remote_addr))) + return redirect(url_for('gameanno2', getId)) @app.route('/annotation2/')