Post success

This commit is contained in:
bigJIU 2022-10-20 22:48:14 +08:00
parent 5f11d14762
commit 8c37071d49
12 changed files with 171 additions and 56 deletions

14
.idea/MarioWeb.iml generated Normal file
View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="Flask">
<option name="enabled" value="true" />
</component>
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="TemplatesService">
<option name="TEMPLATE_CONFIGURATION" value="Jinja2" />
</component>
</module>

View File

@ -1,8 +0,0 @@
<component name="ArtifactManager">
<artifact type="jar" name="Mario-AI-Interface:jar">
<output-path>$USER_HOME$/Documents/MarioGAN/cheerpj_2.3</output-path>
<root id="archive" name="Mario-AI-Interface.jar">
<element id="module-output" name="EDRL-web" />
</root>
</artifact>
</component>

View File

@ -1,9 +0,0 @@
<component name="libraryTable">
<library name="Mario-AI-Interface">
<CLASSES>
<root url="jar://$PROJECT_DIR$/Mario-AI-Interface.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>

4
.idea/misc.xml generated
View File

@ -1,6 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="corretto-1.8" project-jdk-type="JavaSDK"> <component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9" project-jdk-type="Python SDK" />
<output url="file://$PROJECT_DIR$/out" />
</component>
</project> </project>

2
.idea/modules.xml generated
View File

@ -2,7 +2,7 @@
<project version="4"> <project version="4">
<component name="ProjectModuleManager"> <component name="ProjectModuleManager">
<modules> <modules>
<module fileurl="file://$PROJECT_DIR$/EDRL-web.iml" filepath="$PROJECT_DIR$/EDRL-web.iml" /> <module fileurl="file://$PROJECT_DIR$/.idea/MarioWeb.iml" filepath="$PROJECT_DIR$/.idea/MarioWeb.iml" />
</modules> </modules>
</component> </component>
</project> </project>

2
.idea/vcs.xml generated
View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="VcsDirectoryMappings"> <component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" /> <mapping directory="$PROJECT_DIR$" vcs="Git" />
</component> </component>
</project> </project>

82
.idea/workspace.xml generated
View File

@ -1,14 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="ArtifactsWorkspaceSettings">
<artifacts-to-build>
<artifact name="Mario-AI-Interface:jar" />
</artifacts-to-build>
</component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="4b9312b1-50a2-48ef-899f-df123ed058fa" name="Changes" comment=""> <list default="true" id="c32bfd4e-6189-47f3-9d6c-c1825d3d7e5f" name="Changes" comment="">
<change beforePath="$PROJECT_DIR$/.gitignore" beforeDir="false" afterPath="$PROJECT_DIR$/.gitignore" afterDir="false" /> <change afterPath="$PROJECT_DIR$/.idea/MarioWeb.iml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/artifacts/Mario_AI_Interface_jar.xml" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/libraries/Mario_AI_Interface.xml" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/misc.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/misc.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/modules.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/modules.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/vcs.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/vcs.xml" afterDir="false" />
<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$/Flask/main.py" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/play.html" beforeDir="false" afterPath="$PROJECT_DIR$/play.html" afterDir="false" /> <change beforePath="$PROJECT_DIR$/play.html" beforeDir="false" afterPath="$PROJECT_DIR$/play.html" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
@ -22,30 +23,74 @@
<component name="MarkdownSettingsMigration"> <component name="MarkdownSettingsMigration">
<option name="stateVersion" value="1" /> <option name="stateVersion" value="1" />
</component> </component>
<component name="ProjectId" id="2C9ZsKKfAPfUnaEwule1gMjJzDj" /> <component name="ProjectId" id="2GOqJL6AbAwn9o8a0bcSOREMSll" />
<component name="ProjectViewState"> <component name="ProjectViewState">
<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"><![CDATA[{ <component name="PropertiesComponent"><![CDATA[{
"keyToString": { "keyToString": {
"RunOnceActivity.OpenProjectViewOnStart": "true",
"RunOnceActivity.ShowReadmeOnStart": "true",
"SHARE_PROJECT_CONFIGURATION_FILES": "true",
"WebServerToolWindowFactoryState": "false", "WebServerToolWindowFactoryState": "false",
"last_opened_file_path": "C:/Users/duaho/Documents/MarioGAN/cheerpj_2.3", "last_opened_file_path": "C:/Users/duaho/Projects/website materials/MarioWeb",
"nodejs_package_manager_path": "npm", "nodejs_package_manager_path": "npm"
"project.structure.last.edited": "Artifacts",
"project.structure.proportion": "0.15",
"project.structure.side.proportion": "0.2"
} }
}]]></component> }]]></component>
<component name="RunManager" selected="Flask server.Flask (main.py)">
<configuration name="MarioWeb" type="PythonConfigurationType" factoryName="Python">
<module name="MarioWeb" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" />
<envs>
<env name="PYTHONUNBUFFERED" value="1" />
</envs>
<option name="SDK_HOME" value="" />
<option name="WORKING_DIRECTORY" value="" />
<option name="IS_MODULE_SDK" value="false" />
<option name="ADD_CONTENT_ROOTS" value="true" />
<option name="ADD_SOURCE_ROOTS" value="true" />
<EXTENSION ID="PythonCoverageRunConfigurationExtension" runner="coverage.py" />
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/main.py" />
<option name="PARAMETERS" value="" />
<option name="SHOW_COMMAND_LINE" value="false" />
<option name="EMULATE_TERMINAL" value="false" />
<option name="MODULE_MODE" value="false" />
<option name="REDIRECT_INPUT" value="false" />
<option name="INPUT_FILE" value="" />
<method v="2" />
</configuration>
<configuration name="Flask (main.py)" type="Python.FlaskServer" temporary="true" nameIsGenerated="true">
<module name="MarioWeb" />
<option name="target" value="$PROJECT_DIR$/main.py" />
<option name="targetType" value="PATH" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" />
<option name="SDK_HOME" value="" />
<option name="WORKING_DIRECTORY" value="" />
<option name="IS_MODULE_SDK" value="true" />
<option name="ADD_CONTENT_ROOTS" value="true" />
<option name="ADD_SOURCE_ROOTS" value="true" />
<EXTENSION ID="PythonCoverageRunConfigurationExtension" runner="coverage.py" />
<option name="launchJavascriptDebuger" value="false" />
<method v="2" />
</configuration>
<recent_temporary>
<list>
<item itemvalue="Flask server.Flask (main.py)" />
</list>
</recent_temporary>
</component>
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" /> <component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
<component name="TaskManager"> <component name="TaskManager">
<task active="true" id="Default" summary="Default task"> <task active="true" id="Default" summary="Default task">
<changelist id="4b9312b1-50a2-48ef-899f-df123ed058fa" name="Changes" comment="" /> <changelist id="c32bfd4e-6189-47f3-9d6c-c1825d3d7e5f" name="Changes" comment="" />
<created>1658216972707</created> <created>1666269904844</created>
<option name="number" value="Default" /> <option name="number" value="Default" />
<option name="presentableId" value="Default" /> <option name="presentableId" value="Default" />
<updated>1658216972707</updated> <updated>1666269904844</updated>
<workItem from="1666267203057" duration="1289000" /> <workItem from="1666269906002" duration="7106000" />
</task> </task>
<servers /> <servers />
</component> </component>
@ -63,4 +108,7 @@
</map> </map>
</option> </option>
</component> </component>
<component name="com.intellij.coverage.CoverageDataManagerImpl">
<SUITE FILE_PATH="coverage/MarioWeb$Flask__main_py_.coverage" NAME="Flask (main.py) Coverage Results" MODIFIED="1666277231897" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="" />
</component>
</project> </project>

View File

@ -1,16 +0,0 @@
# This is a sample Python script.
# Press Shift+F10 to execute it or replace it with your code.
# Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings.
def print_hi(name):
# Use a breakpoint in the code line below to debug your script.
print(f'Hi, {name}') # Press Ctrl+F8 to toggle the breakpoint.
# Press the green button in the gutter to run the script.
if __name__ == '__main__':
print_hi('PyCharm')
# See PyCharm help at https://www.jetbrains.com/help/pycharm/

Binary file not shown.

22
main.py Normal file
View File

@ -0,0 +1,22 @@
from flask import Flask, render_template, request, redirect, url_for
app = Flask(__name__,static_folder='')
@app.route('/')
def index():
py2htmlstr = 'py2html test str'
return render_template('play.html',py2htmlstr = py2htmlstr)
@app.route('/dataPage')
def dataPage(data):
return data
@app.route('/',methods = ['POST'])
def getData():
if request.method == 'POST':
print("POST")
print(request.json)
return redirect(url_for('dataPage',data = request.json))
if __name__ == '__main__':
app.run(debug=True)

View File

@ -4,14 +4,26 @@
<meta charset="utf-8"> <meta charset="utf-8">
<title>CheerpJ test</title> <title>CheerpJ test</title>
<script src="https://cjrtnc.leaningtech.com/2.3/loader.js"></script> <script src="https://cjrtnc.leaningtech.com/2.3/loader.js"></script>
<script src="https://cdn.bootcss.com/FileSaver.js/1.3.8/FileSaver.js"></script>
</head> </head>
<body> <body>
</body> </body>
<br />{{ py2htmlstr }}
<script> <script>
function showPreloadProgress(loadedFiles, totalFiles) function showPreloadProgress(loadedFiles, totalFiles)
{ {
console.log("Percentage loaded "+(loadedFiles*100/totalFiles)); console.log("Percentage loaded "+(loadedFiles*100/totalFiles));
} }
function saveHandler(){
let data = {
name:"hanmeimei",
age:88
}
var content = JSON.stringify(data);
var blob = new Blob([content], {type: "text/plain;charset=utf-8"});
saveAs(blob, "save.json");
}
var cheerpjListener = {preloadProgress:showPreloadProgress}; var cheerpjListener = {preloadProgress:showPreloadProgress};
cheerpjInit({listener:cheerpjListener}); cheerpjInit({listener:cheerpjListener});
//cheerpjInit(); //cheerpjInit();
@ -24,7 +36,7 @@
var returnVal = cjCall("Play", "otherMain", "0", "f_l", "0");// var returnVal = cjCall("Play", "otherMain", "0", "f_l", "0");//
returnVal.then(function(e) { returnVal.then(function(e) {
console.log("the return val is ready"); console.log("the return val is ready");
console.log(returnVal.data[0]); console.log(returnVal);
}).catch(e => console.log("Critical failure: " + e.message)); }).catch(e => console.log("Critical failure: " + e.message));
//console.log(returnVal); //console.log(returnVal);

54
templates/play.html Normal file
View File

@ -0,0 +1,54 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>CheerpJ test</title>
<script src="https://cjrtnc.leaningtech.com/2.3/loader.js"></script>
</head>
<body>
</body>
<br />{{ py2htmlstr }}
<script>
function showPreloadProgress(loadedFiles, totalFiles)
{
console.log("Percentage loaded "+(loadedFiles*100/totalFiles));
}
//上传测井数据表到服务器数据库
function PostToServer(data) {
var httpRequest = new XMLHttpRequest();//第一步:建立所需的对象
httpRequest.open("POST",""); //调用AddDataToServer
httpRequest.setRequestHeader("Content-Type", "application/json"); //设置请求头信息
httpRequest.onreadystatechange = function () {
if (httpRequest.readyState == 4 && httpRequest.status == 200) {
alert('添加成功');
}
}
console.log(typeof Array.from(data));
console.log(Array.from(data));
httpRequest.send(JSON.stringify(Array.from(data))); //设置为发送给服务器数据
//httpRequest.send((""+data));
}
var cheerpjListener = {preloadProgress:showPreloadProgress};
cheerpjInit({listener:cheerpjListener});
//cheerpjInit();
cheerpjCreateDisplay(800,600);
//cheerpjRunMain("Play", "/app/Mario-AI-Interface.jar", "0", "f_l", "0");
console.log("done");
cheerpjRunJar("/app/Mario-AI-Interface.jar");
var returnVal = cjCall("Play", "otherMain", "0", "f_l", "0");//
returnVal.then(function(e) {
console.log("the return val is ready");
console.log(returnVal.value);
PostToServer(returnVal.value);
}).catch(e => console.log("Critical failure: " + e.message));
//console.log(returnVal);
// cheerpjRunJar("/app/Mario-AI-Interface.jar");
// var actionSequenceInBytes = cjCall("MarioProxy", "play", "0", "f_l", "0");
</script>
</html>