Accept Merge Request #99: (api -> master)
Merge Request: Start simulation Created By: @王琼钰 Accepted By: @王琼钰 URL: https://tjwater.coding.net/p/tjwatercloud/d/TJWaterServer/git/merge/99
This commit is contained in:
43
epanet/epanet.py
Normal file
43
epanet/epanet.py
Normal file
@@ -0,0 +1,43 @@
|
||||
import ctypes
|
||||
import platform
|
||||
import os
|
||||
import sys
|
||||
sys.path.append("..")
|
||||
from api import project
|
||||
from api import parser
|
||||
|
||||
_lib_core = None
|
||||
_lib_output = None
|
||||
|
||||
def _load_epanet():
|
||||
_platform = platform.system()
|
||||
if _platform != "Windows":
|
||||
raise Exception(f'Platform {_platform} unsupported (not yet)')
|
||||
_lib_core = ctypes.CDLL("./epanet2.dll")
|
||||
#version = ctypes.c_int()
|
||||
#lib_core.EN_getversion(ctypes.byref(version))
|
||||
#print(f'Load EPANET {version}')
|
||||
_lib_output = ctypes.CDLL("./epanet-output.dll")
|
||||
|
||||
# readable True => json, False => binary output
|
||||
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())
|
||||
|
||||
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')
|
||||
inp = os.path.join(os.path.join(dir, 'db_inp'), name + '.inp')
|
||||
rpt = os.path.join(os.path.join(dir, 'temp'), name + '.rpt')
|
||||
opt = os.path.join(os.path.join(dir, 'temp'), name + '.opt')
|
||||
command = f'{exe} {inp} {rpt} {opt}'
|
||||
#print(command)
|
||||
result = os.system(command)
|
||||
return ''
|
||||
|
||||
if __name__ == '__main__':
|
||||
_load_epanet()
|
||||
run_project('net3')
|
||||
Reference in New Issue
Block a user