Update code structure

This commit is contained in:
bigJIU 2022-11-24 14:49:02 +08:00
parent a1fcf2fd5c
commit f451920a68
12 changed files with 953 additions and 109 deletions

32
.idea/workspace.xml generated
View File

@ -3,7 +3,12 @@
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="c32bfd4e-6189-47f3-9d6c-c1825d3d7e5f" name="Changes" comment=""> <list default="true" id="c32bfd4e-6189-47f3-9d6c-c1825d3d7e5f" name="Changes" comment="">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/IDManager.py" beforeDir="false" afterPath="$PROJECT_DIR$/IDManager.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/data/questionare.csv" beforeDir="false" afterPath="$PROJECT_DIR$/data/questionare.csv" afterDir="false" /> <change beforePath="$PROJECT_DIR$/data/questionare.csv" beforeDir="false" afterPath="$PROJECT_DIR$/data/questionare.csv" afterDir="false" />
<change beforePath="$PROJECT_DIR$/main.py" beforeDir="false" afterPath="$PROJECT_DIR$/main.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/templates/GameOver.html" beforeDir="false" afterPath="$PROJECT_DIR$/templates/GameOver.html" afterDir="false" />
<change beforePath="$PROJECT_DIR$/templates/GamePlay.html" beforeDir="false" afterPath="$PROJECT_DIR$/templates/GamePlay.html" afterDir="false" />
<change beforePath="$PROJECT_DIR$/templates/GameQuestion.html" beforeDir="false" afterPath="$PROJECT_DIR$/templates/GameQuestion.html" afterDir="false" />
<change beforePath="$PROJECT_DIR$/templates/GameTutorial.html" beforeDir="false" afterPath="$PROJECT_DIR$/templates/GameTutorial.html" afterDir="false" /> <change beforePath="$PROJECT_DIR$/templates/GameTutorial.html" beforeDir="false" afterPath="$PROJECT_DIR$/templates/GameTutorial.html" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
@ -40,16 +45,21 @@
<option name="hideEmptyMiddlePackages" value="true" /> <option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" /> <option name="showLibraryContents" value="true" />
</component> </component>
<component name="PropertiesComponent">{ <component name="PropertiesComponent"><![CDATA[{
&quot;keyToString&quot;: { "keyToString": {
&quot;RunOnceActivity.OpenProjectViewOnStart&quot;: &quot;true&quot;, "RunOnceActivity.OpenProjectViewOnStart": "true",
&quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;, "RunOnceActivity.ShowReadmeOnStart": "true",
&quot;SHARE_PROJECT_CONFIGURATION_FILES&quot;: &quot;true&quot;, "SHARE_PROJECT_CONFIGURATION_FILES": "true",
&quot;WebServerToolWindowFactoryState&quot;: &quot;false&quot;, "WebServerToolWindowFactoryState": "false",
&quot;last_opened_file_path&quot;: &quot;C:/Users/duaho/Projects/website materials/MarioWeb/Mario-AI-Interface&quot;, "last_opened_file_path": "C:/Users/duaho/Projects/website materials/MarioWeb/templates",
&quot;nodejs_package_manager_path&quot;: &quot;npm&quot; "nodejs_package_manager_path": "npm"
} }
}</component> }]]></component>
<component name="RecentsManager">
<key name="CopyFile.RECENT_KEYS">
<recent name="C:\Users\duaho\Projects\website materials\MarioWeb\templates" />
</key>
</component>
<component name="RunManager" selected="Flask server.Flask (main.py)"> <component name="RunManager" selected="Flask server.Flask (main.py)">
<configuration name="MarioWeb" type="PythonConfigurationType" factoryName="Python"> <configuration name="MarioWeb" type="PythonConfigurationType" factoryName="Python">
<module name="MarioWeb" /> <module name="MarioWeb" />
@ -162,6 +172,8 @@
<workItem from="1668486144158" duration="499000" /> <workItem from="1668486144158" duration="499000" />
<workItem from="1668492153120" duration="654000" /> <workItem from="1668492153120" duration="654000" />
<workItem from="1668520247886" duration="913000" /> <workItem from="1668520247886" duration="913000" />
<workItem from="1669042021967" duration="608000" />
<workItem from="1669266954441" duration="4319000" />
</task> </task>
<servers /> <servers />
</component> </component>
@ -181,7 +193,7 @@
</component> </component>
<component name="com.intellij.coverage.CoverageDataManagerImpl"> <component name="com.intellij.coverage.CoverageDataManagerImpl">
<SUITE FILE_PATH="coverage/MarioWeb$test.coverage" NAME="test Coverage Results" MODIFIED="1668079935841" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" /> <SUITE FILE_PATH="coverage/MarioWeb$test.coverage" NAME="test Coverage Results" MODIFIED="1668079935841" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" />
<SUITE FILE_PATH="coverage/MarioWeb$Flask__main_py_.coverage" NAME="Flask (main.py) Coverage Results" MODIFIED="1668520582987" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="" /> <SUITE FILE_PATH="coverage/MarioWeb$Flask__main_py_.coverage" NAME="Flask (main.py) Coverage Results" MODIFIED="1669267399800" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="" />
<SUITE FILE_PATH="coverage/MarioWeb$Flask__main_py___1_.coverage" NAME="Flask (main.py) (1) Coverage Results" MODIFIED="1668079945407" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="" /> <SUITE FILE_PATH="coverage/MarioWeb$Flask__main_py___1_.coverage" NAME="Flask (main.py) (1) Coverage Results" MODIFIED="1668079945407" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="" />
</component> </component>
</project> </project>

View File

@ -1,5 +1,7 @@
import random import random
import csv import csv
class idManager(): class idManager():
levelNum = 200 levelNum = 200
timeMin = 2 timeMin = 2
@ -9,68 +11,84 @@ class idManager():
ip_control = {} ip_control = {}
ip_time = {} ip_time = {}
ip_tutorial = {} ip_tutorial = {}
def __int__(self): def __int__(self):
self.levelNum = 200 self.levelNum = 200
def getLevels(self, ip):
def getLevels(self,ip):
if ip not in self.ip_dic.keys(): if ip not in self.ip_dic.keys():
self.ip_dic[ip] = [] 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]: 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]) self.ip_dic[ip].append(levels[0])
while levels[1] in self.ip_dic[ip]: while levels[1] in self.ip_dic[ip]:
levels[1] = random.randint(1, self.levelNum) levels[1] = random.randint(1, self.levelNum)
self.ip_dic[ip].append(levels[1]) self.ip_dic[ip].append(levels[1])
self.ip_recent[ip] = [levels[0],levels[1]] self.ip_recent[ip] = [levels[0], levels[1]]
return ["lvl"+str(levels[0]),"lvl"+str(levels[1])] return ["lvl" + str(levels[0]), "lvl" + str(levels[1])]
#return ["test1","test2"] # return ["test1","test2"]
def getRecent(self,ip): def getRecent(self, ip):
return self.ip_recent[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": if content == "A":
self.ip_control[ip] = 0 self.ip_control[ip] = 0
else: else:
self.ip_control[ip] = 1 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]) print(self.ip_time[ip])
if ip not in self.ip_time.keys(): if ip not in self.ip_time.keys():
return 0 return 0
else: else:
if self.ip_time[ip]>=self.timeMin: if self.ip_time[ip] >= self.timeMin:
return 1 return 1
else: else:
return 0 return 0
def addTimes(self,ip):
def addTimes(self, ip):
if ip not in self.ip_time.keys(): if ip not in self.ip_time.keys():
self.ip_time[ip] = 0 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] return self.ip_time[ip]
def addTutorial(self,ip): def addTutorial(self, ip):
if ip not in self.ip_tutorial.keys(): if ip not in self.ip_tutorial.keys():
self.ip_tutorial[ip] = 1 self.ip_tutorial[ip] = 1
return 1 return 1
else: else:
if self.ip_tutorial[ip]>self.tutorialMax: if self.ip_tutorial[ip] > self.tutorialMax:
return 1 return 1
else: else:
self.ip_tutorial[ip] = self.ip_tutorial[ip] + 1 self.ip_tutorial[ip] = self.ip_tutorial[ip] + 1
return self.ip_tutorial[ip] return self.ip_tutorial[ip]
def hasNextTutorial(self,ip): def hasNextTutorial(self, ip):
if self.ip_tutorial[ip] == self.tutorialMax: if self.ip_tutorial[ip] == self.tutorialMax:
return 0 return 0
else: else:
return 1 return 1
def getControl(self,ip):
def getControl(self, ip):
return self.ip_control[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: with open(path, 'a+', newline='') as f:
csv_write = csv.writer(f) csv_write = csv.writer(f)
csv_write.writerow([*data, '']) csv_write.writerow([*data, ''])

Binary file not shown.

View File

@ -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,,,,,,
127.0.0.1,,,,,, 127.0.0.1,,,,,,
127.0.0.1,D,B,B,A,,

1 IP,Style,Frequency,Age,Gender
68 127.0.0.1,,,,,,
69 127.0.0.1,,,,,,
70 127.0.0.1,,,,,,
71 127.0.0.1,D,B,B,A,,

73
main.py
View File

@ -16,9 +16,9 @@ questionarePath = "data/questionare.csv"
annotationPath = "data/annotation.csv" annotationPath = "data/annotation.csv"
@app.route('/annotation') @app.route('/')
def gamepreanno(): def gamequestion():
return redirect(url_for('gameanno', id=request.remote_addr)) return render_template('GameQuestion.html')
@app.route('/result', methods=['POST', 'GET']) @app.route('/result', methods=['POST', 'GET'])
@ -35,27 +35,26 @@ def gamepreplay():
return redirect(url_for('gametutorial', id=ip)) return redirect(url_for('gametutorial', id=ip))
@app.route('/gametutorial/<id>')
def gametutorial(id):
return render_template('GameTutorial.html', tutorial=idm.addTutorial(id), next=idm.hasNextTutorial(id))
@app.route('/again') @app.route('/again')
def gamepreplayAgain(): def gamepreplayAgain():
return redirect(url_for('gameplay', id=request.remote_addr)) return redirect(url_for('gameplay', id=request.remote_addr))
@app.route('/')
def gamequestion():
return render_template('GameQuestion.html')
@app.route('/gametutorial/<id>')
def gametutorial(id):
return render_template('GameTutorial.html', tutorial=idm.addTutorial(id), next=idm.hasNextTutorial(id))
@app.route('/gametutorial/<id>/data') @app.route('/gametutorial/<id>/data')
def gametutorialdata(id): def gametutorialdata(id):
return redirect(url_for('gameplay', id=id)) return redirect(url_for('gameplay', id=id))
@app.route('/gameplay/<id>') @app.route('/gameplay/<id>')
def gameplay(id): def gameplay(id):
gamelevels = idm.getLevels(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/<id>/data', methods=['POST']) @app.route('/gameplay/<id>/data', methods=['POST'])
def getJSONData(id): def getJSONData(id):
@ -67,16 +66,21 @@ def getJSONData(id):
return "return!" return "return!"
@app.route('/annotation')
def gamepreanno():
return redirect(url_for('gameanno', id=request.remote_addr))
@app.route('/annotation/<id>') @app.route('/annotation/<id>')
def gameanno(id): def gameanno(id):
if(id != "radioresult"):
print("anno " + id) print("anno " + id)
gamelevels = idm.getRecent(id) gamelevels = idm.getRecent(id)
level1 = "lvl" + str(gamelevels[0]) level1 = "lvl" + str(gamelevels[0])
level2 = "lvl" + str(gamelevels[1]) level2 = "lvl" + str(gamelevels[1])
return render_template('GameAnnotation.html', level1=level1, level2=level2) return render_template('GameAnnotation.html', level1=level1, level2=level2)
@app.route('/annotation/radioresult', methods=['POST']) @app.route('/annotation/radioresult', methods=['POST'])
def getRadioData(): def getRadioData():
ip = request.remote_addr ip = request.remote_addr
@ -91,11 +95,48 @@ def getRadioData():
# saveFile(evalDataPath,"gameanno",request.json[0]+request.json[1]+request.json[2]) # saveFile(evalDataPath,"gameanno",request.json[0]+request.json[1]+request.json[2])
finish = idm.getTimes(ip) 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/<id>')
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/<id>')
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): 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)) f.write(b''.join(struct.pack('B', c) for c in cp))
def saveFile2():
print("Save File for Stage2")
if __name__ == '__main__': if __name__ == '__main__':
app.debug = True app.debug = True
app.run() app.run()

File diff suppressed because one or more lines are too long

View File

@ -160,8 +160,13 @@
<br> <br>
<button onclick='window.location.href = "/again"'>Play And Annotate Again!</button> <button onclick='window.location.href = "/again"'>Play And Annotate Again!</button>
<button id = "Finish" onclick=" <button id = "Finish" onclick="
if('{{stage}}' == '1'){
window.location.href = 'about:blank'; window.location.href = 'about:blank';
window.close(); window.close();
}else{
window.location.href = 'about:blank';
}
">Finish!</button> ">Finish!</button>
</div> </div>
</section> </section>

View File

@ -55,25 +55,6 @@
color: #c4cbcf; 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{ svg{
width: 50px; width: 50px;
height: 26px; height: 26px;

237
templates/GamePlay2.html Normal file

File diff suppressed because one or more lines are too long

View File

@ -354,7 +354,11 @@ W
<!-- Custom JavaScript for this theme --> <!-- Custom JavaScript for this theme -->
<script src="../templates/Web/scrolling-nav.js"></script> <script src="../templates/Web/scrolling-nav.js"></script>
<script src="https://cjrtnc.leaningtech.com/2.3/loader.js"></script>
<script>
cheerpjInit();
cheerpjRunMain("Play", "/app/Mario-AI-Interface.jar", "0", "f_l");
</script>

View File

@ -159,33 +159,6 @@
<script> <script>
//Init Cheerpj Framework //Init Cheerpj Framework
cheerpjInit(); cheerpjInit();
/*
function cheerpjCreateDisplay(w, h, oldElem)
{
// Create a div element that will contain all Java Windows
var element = document.createElement("div");
cjDisplay = element;
element.id="cheerpjDisplay";
if(oldElem && w<0 && h<0)
{
// Compute the sizes from the parent
element.style.width="100%";
element.style.height="100%";
}
else
{
element.style.width=w+"px";
element.style.height=h+"px";
}
element.classList.add("cheerpjLoading");
element.classList.add("bordered");
if(oldElem)
oldElem.appendChild(element);
else
document.body.appendChild(element);
cheerpjSetStatus(cjStatus, element);
return element;
}*/
var divElement = document.getElementById("GameWindow"); var divElement = document.getElementById("GameWindow");
var level = "t"+"{{tutorial}}"; var level = "t"+"{{tutorial}}";
@ -214,20 +187,7 @@
<br> <br>
<div style="padding-left:2%; padding-top: 10px;"> <div style="padding-left:2%; padding-top: 10px;">
<!-- <button style=" display:inline-block; border-radius: 5px; width: 120px; background-color: white; border-width: 0.1px;">
<a href="news/index.html" style="color: black; vertical-align:middle;">MORE</a>
<svg class="icon" aria-hidden="true">
<use xlink:href="#icon-more"></use>
</svg>
</button> -->
<!-- <button style=" display:inline-block; border-radius: 5px; width: 80px; background-color: white; border-width: 0.1px;">
<a href="http://aingames.cn/news/index.html" style="color: black;">MORE <i class="icon-forward"></i> </a>
</button> -->
<!-- <span style="vertical-align:middle;"> &nbsp;<button style="border-radius: 5px;"><a href="news/index.html" style="color: black;">More ...</a></button></span> -->
</div> </div>
<!-- <p>more icon-more</p> --> <!-- <p>more icon-more</p> -->

File diff suppressed because one or more lines are too long