From f451920a684c6b3897067d3a685d83de56637ce4 Mon Sep 17 00:00:00 2001 From: bigJIU <1572204178@qq.com> Date: Thu, 24 Nov 2022 14:49:02 +0800 Subject: [PATCH] Update code structure --- .idea/workspace.xml | 32 ++- IDManager.py | 56 ++++-- __pycache__/main.cpython-39.pyc | Bin 3730 -> 3761 bytes data/questionare.csv | 1 + main.py | 81 ++++++-- templates/GameAnnotation2.html | 346 ++++++++++++++++++++++++++++++++ templates/GameOver.html | 9 +- templates/GamePlay.html | 19 -- templates/GamePlay2.html | 237 ++++++++++++++++++++++ templates/GameQuestion.html | 6 +- templates/GameTutorial.html | 40 ---- templates/GameTutorial2.html | 235 ++++++++++++++++++++++ 12 files changed, 953 insertions(+), 109 deletions(-) create mode 100644 templates/GameAnnotation2.html create mode 100644 templates/GamePlay2.html create mode 100644 templates/GameTutorial2.html diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 5a50a50..00e25b0 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -3,7 +3,12 @@ + + + + + @@ -40,16 +45,21 @@ - { - "keyToString": { - "RunOnceActivity.OpenProjectViewOnStart": "true", - "RunOnceActivity.ShowReadmeOnStart": "true", - "SHARE_PROJECT_CONFIGURATION_FILES": "true", - "WebServerToolWindowFactoryState": "false", - "last_opened_file_path": "C:/Users/duaho/Projects/website materials/MarioWeb/Mario-AI-Interface", - "nodejs_package_manager_path": "npm" + +}]]> + + + + + @@ -162,6 +172,8 @@ + + @@ -181,7 +193,7 @@ - + \ No newline at end of file diff --git a/IDManager.py b/IDManager.py index 72ce568..63ca591 100644 --- a/IDManager.py +++ b/IDManager.py @@ -1,5 +1,7 @@ import random import csv + + class idManager(): levelNum = 200 timeMin = 2 @@ -9,68 +11,84 @@ class idManager(): ip_control = {} ip_time = {} ip_tutorial = {} + def __int__(self): self.levelNum = 200 - - def getLevels(self,ip): + def getLevels(self, ip): if ip not in self.ip_dic.keys(): self.ip_dic[ip] = [] - levels = [random.randint(1,self.levelNum), random.randint(1,self.levelNum)] + levels = [random.randint(1, self.levelNum), random.randint(1, self.levelNum)] while levels[0] in self.ip_dic[ip]: - levels[0] = random.randint(1,self.levelNum) + levels[0] = random.randint(1, self.levelNum) self.ip_dic[ip].append(levels[0]) while levels[1] in self.ip_dic[ip]: levels[1] = random.randint(1, self.levelNum) self.ip_dic[ip].append(levels[1]) - self.ip_recent[ip] = [levels[0],levels[1]] - return ["lvl"+str(levels[0]),"lvl"+str(levels[1])] - #return ["test1","test2"] + self.ip_recent[ip] = [levels[0], levels[1]] + return ["lvl" + str(levels[0]), "lvl" + str(levels[1])] + # return ["test1","test2"] - def getRecent(self,ip): + def getRecent(self, ip): return self.ip_recent[ip] - def setControl(self,ip,content): + + def getLevel(self, ip): + level = random.randint(1, self.levelNum) + while level in self.ip_dic[ip]: + level = random.randint(1, self.levelNum) + self.ip_dic[ip].append(level) + self.ip_recent[ip] = level + return "lvl" + str(level) + + def setControl(self, ip, content): if content == "A": self.ip_control[ip] = 0 else: self.ip_control[ip] = 1 - def getTimes(self,ip): + + def setTimes(self, ip): + self.ip_time[ip] = 0 + + def getTimes(self, ip): print(self.ip_time[ip]) if ip not in self.ip_time.keys(): return 0 else: - if self.ip_time[ip]>=self.timeMin: + if self.ip_time[ip] >= self.timeMin: return 1 else: return 0 - def addTimes(self,ip): + + def addTimes(self, ip): if ip not in self.ip_time.keys(): self.ip_time[ip] = 0 - self.ip_time[ip] = self.ip_time[ip]+1 + self.ip_time[ip] = self.ip_time[ip] + 1 return self.ip_time[ip] - def addTutorial(self,ip): + def addTutorial(self, ip): if ip not in self.ip_tutorial.keys(): self.ip_tutorial[ip] = 1 return 1 else: - if self.ip_tutorial[ip]>self.tutorialMax: + if self.ip_tutorial[ip] > self.tutorialMax: return 1 else: self.ip_tutorial[ip] = self.ip_tutorial[ip] + 1 return self.ip_tutorial[ip] - def hasNextTutorial(self,ip): + def hasNextTutorial(self, ip): if self.ip_tutorial[ip] == self.tutorialMax: return 0 else: return 1 - def getControl(self,ip): + + def getControl(self, ip): return self.ip_control[ip] - def write_csv(self,path, data): + + def write_csv(self, path, data): with open(path, 'a+', newline='') as f: csv_write = csv.writer(f) - csv_write.writerow([*data, '']) \ No newline at end of file + csv_write.writerow([*data, '']) diff --git a/__pycache__/main.cpython-39.pyc b/__pycache__/main.cpython-39.pyc index 2b11868604d09db673f88204ca2eeee0d74a249a..33b75c96f85c7bc47f60d44eaa84c1f4e8794e8a 100644 GIT binary patch delta 81 zcmbOvyHS=qk(ZZ?0SNdQb2oBNVA8U3wu%WYPAw{qNhwXt$d3sq%FjwoE-8*FPfaS$ jEJ;}lx*alz{D->Y8B(@;u=ttpSAfYQwA5~t<8G8yo`)~lWq7) E0bH667XSbN diff --git a/data/questionare.csv b/data/questionare.csv index ec497c2..d523dc8 100644 --- a/data/questionare.csv +++ b/data/questionare.csv @@ -68,3 +68,4 @@ IP,Style,Frequency,Age,Gender 127.0.0.1,,,,,, 127.0.0.1,,,,,, 127.0.0.1,,,,,, +127.0.0.1,D,B,B,A,, diff --git a/main.py b/main.py index 4b1536b..fbcefb3 100644 --- a/main.py +++ b/main.py @@ -16,9 +16,9 @@ questionarePath = "data/questionare.csv" annotationPath = "data/annotation.csv" -@app.route('/annotation') -def gamepreanno(): - return redirect(url_for('gameanno', id=request.remote_addr)) +@app.route('/') +def gamequestion(): + return render_template('GameQuestion.html') @app.route('/result', methods=['POST', 'GET']) @@ -35,27 +35,26 @@ def gamepreplay(): return redirect(url_for('gametutorial', id=ip)) +@app.route('/gametutorial/') +def gametutorial(id): + return render_template('GameTutorial.html', tutorial=idm.addTutorial(id), next=idm.hasNextTutorial(id)) + + @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('/gametutorial/') -def gametutorial(id): - return render_template('GameTutorial.html', tutorial=idm.addTutorial(id), next=idm.hasNextTutorial(id)) - @app.route('/gametutorial//data') def gametutorialdata(id): return redirect(url_for('gameplay', id=id)) + @app.route('/gameplay/') def gameplay(id): gamelevels = idm.getLevels(id) - return render_template('GamePlay.html', gamelevels=gamelevels, control = idm.getControl(id)) + return render_template('GamePlay.html', gamelevels=gamelevels, control=idm.getControl(id)) + @app.route('/gameplay//data', methods=['POST']) def getJSONData(id): @@ -67,15 +66,20 @@ def getJSONData(id): return "return!" +@app.route('/annotation') +def gamepreanno(): + return redirect(url_for('gameanno', id=request.remote_addr)) + @app.route('/annotation/') def gameanno(id): - print("anno " + id) + if(id != "radioresult"): + 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) - 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('/annotation/radioresult', methods=['POST']) def getRadioData(): @@ -91,11 +95,48 @@ def getRadioData(): # saveFile(evalDataPath,"gameanno",request.json[0]+request.json[1]+request.json[2]) finish = idm.getTimes(ip) - return render_template("GameOver.html",finish = finish) + return render_template("GameOver.html", finish=finish, stage=1) +@app.route('/stage2pre') +def getStage2(): + return redirect(url_for('gameplay2', id=request.remote_addr, w = False)) +@app.route('/stage2game') +def getStage2game(): + return redirect(url_for('gameplay2', id=request.remote_addr, w = True)) + + +@app.route('/gameplay2/') +def gameplay2(id, w): + + return render_template('GamePlay2.html', gamelevel=idm.getLevel(id), control=idm.getControl(id), w=w) + + +@app.route('/annotation2') +def gamepreanno2(): + return redirect(url_for('gameanno2', id=request.remote_addr)) + + +@app.route('/annotation2/') +def gameanno2(id): + print("anno2 " + id) + level = "lvl" + str(idm.getRecent(id)) + return render_template('GameAnnotation2.html', level=level) + + +@app.route('/annotation2/result', methods=['POST']) +def getAnno2result(): + ip = request.remote_addr + + if request.method == 'POST': + print("POST Eval") + result = request.form + # FIXME: do something to save data + finish = idm.getTimes(ip) + + return render_template("GameOver.html", finish=finish, stage=2) def saveFile(path, filename, content): @@ -106,6 +147,10 @@ def saveFile(path, filename, content): f.write(b''.join(struct.pack('B', c) for c in cp)) +def saveFile2(): + print("Save File for Stage2") + + if __name__ == '__main__': app.debug = True app.run() diff --git a/templates/GameAnnotation2.html b/templates/GameAnnotation2.html new file mode 100644 index 0000000..96c6a84 --- /dev/null +++ b/templates/GameAnnotation2.html @@ -0,0 +1,346 @@ + + + + + + + + + + + AI and Games + + + + + + + + + + + + + + + + + + + Close Window + + + + + + + + + + + + + + PEOPLE + + + PUBLICATION + + + ACTIVITY + + + DEMO + + + RESOURCE + + + + + + + + + + + + + + Reviews + + + + + + + Level A Review + Drag Picture To Move + + + + + + + Watch Level A Replay + + + + + Level B Review + Drag Picture To Move + + + + + + + + Watch Level B Replay + + + + + + + + Annotation Questions + + + + + + + + + Practice More + + + + + Play Real Game + + + + + Finish Annotation + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/templates/GameOver.html b/templates/GameOver.html index dbf8065..3b720a9 100644 --- a/templates/GameOver.html +++ b/templates/GameOver.html @@ -160,8 +160,13 @@ Play And Annotate Again! Finish! diff --git a/templates/GamePlay.html b/templates/GamePlay.html index 76c5d70..534548e 100644 --- a/templates/GamePlay.html +++ b/templates/GamePlay.html @@ -55,25 +55,6 @@ color: #c4cbcf; } - .hiddenpart{ - opacity: 0; - max-width: 0; - color:#c4cbcf; - transition: 1.3s ease-out; - } - - .slogan:hover .hiddenpart{ - opacity: 1; - max-width: 10em; - } - .news_prefix{ - display: inline-block; - width: 30px; - height: 30px; - background-image: url("static/img/news_prefix.png"); - background-size: 150px, 30px; - } - svg{ width: 50px; height: 26px; diff --git a/templates/GamePlay2.html b/templates/GamePlay2.html new file mode 100644 index 0000000..534548e --- /dev/null +++ b/templates/GamePlay2.html @@ -0,0 +1,237 @@ + + + + + + + + + + + AI and Games + + + + + + + + + + + + + + + + + + + + + + + + + + + PEOPLE + + + PUBLICATION + + + ACTIVITY + + + DEMO + + + RESOURCE + + + + + + + + + + + + + EDRL Game Demo + + + + + + + + + + Mario Game User Test + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/templates/GameQuestion.html b/templates/GameQuestion.html index 5b91f77..d382b01 100644 --- a/templates/GameQuestion.html +++ b/templates/GameQuestion.html @@ -354,7 +354,11 @@ W - + + diff --git a/templates/GameTutorial.html b/templates/GameTutorial.html index b89b7df..c6c630e 100644 --- a/templates/GameTutorial.html +++ b/templates/GameTutorial.html @@ -159,33 +159,6 @@ + + + + + + + + AI and Games + + + + + + + + + + + + + + + + + + + + + + + + + + + PEOPLE + + + PUBLICATION + + + ACTIVITY + + + DEMO + + + RESOURCE + + + + + + + + + + + + + EDRL Game Demo + + + + + + + + + Mario Game Tutorial + + + + Further description of Tutorial can be done here + Use the way of Play That you selected + + + + + + + + + + + + Play Next Tutorial + + + + Play Real Game + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Drag Picture To Move
+ Further description of Tutorial can be done here + Use the way of Play That you selected +