Skip to content
Snippets Groups Projects
Commit ec2020b7 authored by Duc Bui Tien's avatar Duc Bui Tien
Browse files

add modules conf save and load

parent 31f98303
No related branches found
No related tags found
No related merge requests found
......@@ -4,7 +4,7 @@
<option name="autoReloadType" value="SELECTIVE" />
</component>
<component name="ChangeListManager">
<list default="true" id="ade4f2dd-968a-4099-9236-831254f6eb55" name="Changes" comment="add get_modulePath">
<list default="true" id="ade4f2dd-968a-4099-9236-831254f6eb55" name="Changes" comment="refactor convergence endpoints &#10;update modules endpoints">
<change afterPath="$PROJECT_DIR$/xmlConfigReader.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/main.py" beforeDir="false" afterPath="$PROJECT_DIR$/main.py" afterDir="false" />
......@@ -76,8 +76,8 @@
<recent name="C:\Users\d_bui\PycharmProjects\fastApiUnicado" />
</key>
</component>
<component name="RunManager" selected="Python.xmlConfigReader">
<configuration name="test_main | #5" type="HttpClient.HttpRequestRunConfigurationType" factoryName="HTTP Request" temporary="true" nameIsGenerated="true" path="$PROJECT_DIR$/test_main.http" index="5" requestIdentifier="#5" runType="Run single request">
<component name="RunManager" selected="FastAPI.fastApiUnicado">
<configuration name="test_main | #4" type="HttpClient.HttpRequestRunConfigurationType" factoryName="HTTP Request" temporary="true" nameIsGenerated="true" path="$PROJECT_DIR$/test_main.http" index="4" requestIdentifier="#4" runType="Run single request">
<method v="2" />
</configuration>
<configuration name="test_main | #6" type="HttpClient.HttpRequestRunConfigurationType" factoryName="HTTP Request" temporary="true" nameIsGenerated="true" path="$PROJECT_DIR$/test_main.http" index="6" requestIdentifier="#6" runType="Run single request">
......@@ -149,11 +149,11 @@
</configuration>
<recent_temporary>
<list>
<item itemvalue="HTTP Request.test_main | #4" />
<item itemvalue="Python.xmlConfigReader" />
<item itemvalue="Python.test" />
<item itemvalue="HTTP Request.test_main | #8" />
<item itemvalue="HTTP Request.test_main | #6" />
<item itemvalue="HTTP Request.test_main | #5" />
</list>
</recent_temporary>
</component>
......@@ -233,7 +233,16 @@
<workItem from="1719577095693" duration="43000" />
<workItem from="1719577148084" duration="603000" />
<workItem from="1719995851952" duration="466000" />
<workItem from="1719996576928" duration="3299000" />
<workItem from="1719996576928" duration="7097000" />
<workItem from="1720075595422" duration="8540000" />
<workItem from="1720173999845" duration="3367000" />
<workItem from="1720591643068" duration="596000" />
<workItem from="1720594508888" duration="4366000" />
<workItem from="1720765983827" duration="2471000" />
<workItem from="1721116263498" duration="2729000" />
<workItem from="1721286344593" duration="5576000" />
<workItem from="1721769527434" duration="238000" />
<workItem from="1721974616129" duration="2742000" />
</task>
<task id="LOCAL-00001" summary="add update_Modules">
<option name="closed" value="true" />
......@@ -259,7 +268,15 @@
<option name="project" value="LOCAL" />
<updated>1710427169439</updated>
</task>
<option name="localTasksCounter" value="4" />
<task id="LOCAL-00004" summary="refactor convergence endpoints &#10;update modules endpoints">
<option name="closed" value="true" />
<created>1720008890021</created>
<option name="number" value="00004" />
<option name="presentableId" value="LOCAL-00004" />
<option name="project" value="LOCAL" />
<updated>1720008890021</updated>
</task>
<option name="localTasksCounter" value="5" />
<servers />
</component>
<component name="TypeScriptGeneratedFilesManager">
......@@ -292,11 +309,12 @@
<MESSAGE value="add update_Modules" />
<MESSAGE value="prototyp config, graph und log endpoints" />
<MESSAGE value="add get_modulePath" />
<option name="LAST_COMMIT_MESSAGE" value="add get_modulePath" />
<MESSAGE value="refactor convergence endpoints &#10;update modules endpoints" />
<option name="LAST_COMMIT_MESSAGE" value="refactor convergence endpoints &#10;update modules endpoints" />
</component>
<component name="com.intellij.coverage.CoverageDataManagerImpl">
<SUITE FILE_PATH="coverage/fastApiUnicado$test.coverage" NAME="test Coverage Results" MODIFIED="1711008069985" 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/fastApiUnicado$xmlConfigReader.coverage" NAME="xmlConfigReader Coverage Results" MODIFIED="1720007025187" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="false" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" />
<SUITE FILE_PATH="coverage/fastApiUnicado$fastApiUnicado.coverage" NAME="fastApiUnicado Coverage Results" MODIFIED="1719384363003" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="false" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="" />
<SUITE FILE_PATH="coverage/fastApiUnicado$xmlConfigReader.coverage" NAME="xmlConfigReader Coverage Results" MODIFIED="1720078308255" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="false" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$" />
<SUITE FILE_PATH="coverage/fastApiUnicado$fastApiUnicado.coverage" NAME="fastApiUnicado Coverage Results" MODIFIED="1721977726034" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="false" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="" />
</component>
</project>
\ No newline at end of file
import json
from fastapi import FastAPI
from fastapi.responses import FileResponse
import os
......@@ -6,6 +8,7 @@ from subprocess import Popen, PIPE
from fastapi.middleware.cors import CORSMiddleware
from pydantic import BaseModel
import xmltodict
from fastapi.encoders import jsonable_encoder
app = FastAPI()
......@@ -31,6 +34,10 @@ class Convergence(BaseModel):
class Modules(BaseModel):
groups: list = []
class Conf(BaseModel):
name: str;
controll_settings: dict = {}
def search_modules(dict, name, root):
list = []
for i in range(len(root.findall(f"ProgramSettings/{name}/Program/Name"))):
......@@ -55,7 +62,7 @@ async def start_module(module: str):
@app.get("/convergence")
async def get_modules():
async def get_conv_modules():
tree = ET.parse('newProject/convergenceLoop/convergenceLoop_conf.xml')
root = tree.getroot()
dict = {}
......@@ -66,6 +73,13 @@ async def get_modules():
tree.write("test.xml")
return dict
@app.get("/modules")
async def get_modules():
with open("test", "r") as fp:
modules= json.load(fp)
return modules
@app.put("/convergence/update")
async def update_convergence(item: Convergence):
......@@ -81,7 +95,10 @@ async def update_convergence(item: Convergence):
@app.put("/modules/update")
async def update_modules(item:Modules):
print(item)
print(jsonable_encoder(item))
with open("test", "w") as fp:
json.dump(jsonable_encoder(item), fp)
return item
......@@ -94,9 +111,13 @@ async def get_module_config(module: str):
@app.get("/modules/{module}/config")
async def get_module_config(module: str):
tree = ET.parse("xml_configs/"+module+"_config.xml")
tree = ET.parse("xml_configs/"+module+"_conf.xml")
root = tree.getroot()
config = xmltodict.XmlDictConfig(root)
config = json.dumps(xmltodict.XmlDictConfig(root))
return config
@app.put("/modules/config/update")
async def update_module_config(config: Conf):
print(config)
return config
@app.get("/graph/")
......
......@@ -15,7 +15,7 @@ Accept: application/json
###
GET http://127.0.0.1:8000/modules/test/config
GET http://127.0.0.1:8000/modules/initialSizing/config
Accept: application/json
###
......
from pydantic import BaseModel
import xmltodict
import os
import xml.etree.ElementTree as ET
import json
tree = ET.parse("xml_configs/initialSizing_conf.xml")
root = tree.getroot()
config = xmltodict.XmlDictConfig(root)
print(config)
print(json.dumps(config,sort_keys=True, indent=4))
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment