Update code structure
This commit is contained in:
parent
a1fcf2fd5c
commit
f451920a68
32
.idea/workspace.xml
generated
32
.idea/workspace.xml
generated
@ -3,7 +3,12 @@
|
||||
<component name="ChangeListManager">
|
||||
<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$/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$/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" />
|
||||
</list>
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
@ -40,16 +45,21 @@
|
||||
<option name="hideEmptyMiddlePackages" value="true" />
|
||||
<option name="showLibraryContents" value="true" />
|
||||
</component>
|
||||
<component name="PropertiesComponent">{
|
||||
"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"
|
||||
<component name="PropertiesComponent"><![CDATA[{
|
||||
"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/templates",
|
||||
"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)">
|
||||
<configuration name="MarioWeb" type="PythonConfigurationType" factoryName="Python">
|
||||
<module name="MarioWeb" />
|
||||
@ -162,6 +172,8 @@
|
||||
<workItem from="1668486144158" duration="499000" />
|
||||
<workItem from="1668492153120" duration="654000" />
|
||||
<workItem from="1668520247886" duration="913000" />
|
||||
<workItem from="1669042021967" duration="608000" />
|
||||
<workItem from="1669266954441" duration="4319000" />
|
||||
</task>
|
||||
<servers />
|
||||
</component>
|
||||
@ -181,7 +193,7 @@
|
||||
</component>
|
||||
<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$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="" />
|
||||
</component>
|
||||
</project>
|
54
IDManager.py
54
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, ''])
|
Binary file not shown.
@ -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,,
|
||||
|
|
73
main.py
73
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/<id>')
|
||||
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/<id>')
|
||||
def gametutorial(id):
|
||||
return render_template('GameTutorial.html', tutorial=idm.addTutorial(id), next=idm.hasNextTutorial(id))
|
||||
|
||||
@app.route('/gametutorial/<id>/data')
|
||||
def gametutorialdata(id):
|
||||
return redirect(url_for('gameplay', id=id))
|
||||
|
||||
|
||||
@app.route('/gameplay/<id>')
|
||||
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/<id>/data', methods=['POST'])
|
||||
def getJSONData(id):
|
||||
@ -67,16 +66,21 @@ def getJSONData(id):
|
||||
return "return!"
|
||||
|
||||
|
||||
@app.route('/annotation')
|
||||
def gamepreanno():
|
||||
return redirect(url_for('gameanno', id=request.remote_addr))
|
||||
|
||||
|
||||
@app.route('/annotation/<id>')
|
||||
def gameanno(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)
|
||||
|
||||
|
||||
@app.route('/annotation/radioresult', methods=['POST'])
|
||||
def getRadioData():
|
||||
ip = request.remote_addr
|
||||
@ -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/<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):
|
||||
@ -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()
|
||||
|
346
templates/GameAnnotation2.html
Normal file
346
templates/GameAnnotation2.html
Normal file
File diff suppressed because one or more lines are too long
@ -160,8 +160,13 @@
|
||||
<br>
|
||||
<button onclick='window.location.href = "/again"'>Play And Annotate Again!</button>
|
||||
<button id = "Finish" onclick="
|
||||
if('{{stage}}' == '1'){
|
||||
window.location.href = 'about:blank';
|
||||
window.close();
|
||||
}else{
|
||||
window.location.href = 'about:blank';
|
||||
}
|
||||
|
||||
">Finish!</button>
|
||||
</div>
|
||||
</section>
|
||||
|
@ -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;
|
||||
|
237
templates/GamePlay2.html
Normal file
237
templates/GamePlay2.html
Normal file
File diff suppressed because one or more lines are too long
@ -354,7 +354,11 @@ W
|
||||
|
||||
<!-- Custom JavaScript for this theme -->
|
||||
<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>
|
||||
|
||||
|
||||
|
||||
|
@ -159,33 +159,6 @@
|
||||
<script>
|
||||
//Init Cheerpj Framework
|
||||
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 level = "t"+"{{tutorial}}";
|
||||
|
||||
@ -214,20 +187,7 @@
|
||||
<br>
|
||||
|
||||
<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;"> <button style="border-radius: 5px;"><a href="news/index.html" style="color: black;">More ...</a></button></span> -->
|
||||
</div>
|
||||
|
||||
<!-- <p>more icon-more</p> -->
|
||||
|
235
templates/GameTutorial2.html
Normal file
235
templates/GameTutorial2.html
Normal file
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user