Support database simulation

This commit is contained in:
WQY\qiong
2022-11-19 10:09:58 +08:00
parent 7b0e79fb9a
commit ec062ace48
2 changed files with 20 additions and 10 deletions

0
db_inp/db Normal file
View File

View File

@@ -1,11 +1,15 @@
import ctypes import ctypes
import platform import platform
import os import os
import sys
sys.path.append("..")
from api import project
from api import parser
_lib_core = None _lib_core = None
_lib_output = None _lib_output = None
def load_epanet(): def _load_epanet():
_platform = platform.system() _platform = platform.system()
if _platform != "Windows": if _platform != "Windows":
raise Exception(f'Platform {_platform} unsupported (not yet)') raise Exception(f'Platform {_platform} unsupported (not yet)')
@@ -15,19 +19,25 @@ def load_epanet():
#print(f'Load EPANET {version}') #print(f'Load EPANET {version}')
_lib_output = ctypes.CDLL("./epanet-output.dll") _lib_output = ctypes.CDLL("./epanet-output.dll")
# readable True => json, False => binary output # readable True => json, False => binary output
def run_epanet(project: str, readable: bool = True) -> str: def run_project(name: str, readable: bool = True) -> str:
if not project.have_project(name):
raise Exception("No such project!")
dir = os.path.dirname(os.getcwd()) dir = os.path.dirname(os.getcwd())
db_inp = os.path.join(os.path.join(dir, 'db_inp'), name + '.inp')
parser.dump_inp(name, db_inp)
exe = os.path.join(os.path.join(dir, 'epanet'), 'runepanet.exe') exe = os.path.join(os.path.join(dir, 'epanet'), 'runepanet.exe')
inp = os.path.join(os.path.join(dir, 'inp'), project + '.inp') inp = os.path.join(os.path.join(dir, 'db_inp'), name + '.inp')
rpt = os.path.join(os.path.join(dir, 'temp'), project + '.rpt') rpt = os.path.join(os.path.join(dir, 'temp'), name + '.rpt')
opt = os.path.join(os.path.join(dir, 'temp'), project + '.opt') opt = os.path.join(os.path.join(dir, 'temp'), name + '.opt')
command = f'{exe} {inp} {rpt} {opt}' command = f'{exe} {inp} {rpt} {opt}'
print(command) #print(command)
os.popen(command) result = os.system(command)
return '' return ''
if __name__ == '__main__': if __name__ == '__main__':
load_epanet() _load_epanet()
run_epanet('net3') run_project('net3')