Accept Merge Request #103: (api -> master)
Merge Request: Fix path issue, since api dir is different from internal Created By: @王琼钰 Accepted By: @王琼钰 URL: https://tjwater.coding.net/p/tjwatercloud/d/TJWaterServer/git/merge/103
This commit is contained in:
@@ -21,4 +21,5 @@ def db2inp():
|
|||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
#inp2db()
|
#inp2db()
|
||||||
#db2inp()
|
#db2inp()
|
||||||
|
print(run_project('net3'))
|
||||||
pass
|
pass
|
||||||
@@ -19,7 +19,7 @@ class Output:
|
|||||||
def __init__(self, path: str) -> None:
|
def __init__(self, path: str) -> None:
|
||||||
self._path = path
|
self._path = path
|
||||||
|
|
||||||
self._lib = ctypes.CDLL(os.path.join(os.getcwd(), 'epanet-output.dll'))
|
self._lib = ctypes.CDLL(os.path.join(os.getcwd(), 'epanet', 'epanet-output.dll'))
|
||||||
|
|
||||||
self._handle = ctypes.c_void_p()
|
self._handle = ctypes.c_void_p()
|
||||||
self._check(self._lib.ENR_init(ctypes.byref(self._handle)))
|
self._check(self._lib.ENR_init(ctypes.byref(self._handle)))
|
||||||
@@ -27,6 +27,11 @@ class Output:
|
|||||||
self._check(self._lib.ENR_open(self._handle, ctypes.c_char_p(self._path.encode())))
|
self._check(self._lib.ENR_open(self._handle, ctypes.c_char_p(self._path.encode())))
|
||||||
|
|
||||||
|
|
||||||
|
def __del__(self):
|
||||||
|
# throw exception in destructor ? :)
|
||||||
|
self._check(self._lib.ENR_close(ctypes.byref(self._handle)))
|
||||||
|
|
||||||
|
|
||||||
def _check(self, result):
|
def _check(self, result):
|
||||||
if result != 0:
|
if result != 0:
|
||||||
msg = ctypes.c_char_p()
|
msg = ctypes.c_char_p()
|
||||||
@@ -108,7 +113,6 @@ class Output:
|
|||||||
return { 'nodes' : nodes, 'links': links }
|
return { 'nodes' : nodes, 'links': links }
|
||||||
|
|
||||||
|
|
||||||
# { pump_index, link_index, utilization, avg.efficiency, avg.kW/flow, avg.kwatts, max.kwatts, cost/day }
|
|
||||||
def energy_usage(self) -> list[dict[str, Any]]:
|
def energy_usage(self) -> list[dict[str, Any]]:
|
||||||
size = self.net_size()['pump']
|
size = self.net_size()['pump']
|
||||||
usages = []
|
usages = []
|
||||||
@@ -126,6 +130,18 @@ class Output:
|
|||||||
return usages
|
return usages
|
||||||
|
|
||||||
|
|
||||||
|
def reactions(self) -> dict[str, float]:
|
||||||
|
values = ctypes.POINTER(ctypes.c_float)()
|
||||||
|
length = ctypes.c_int()
|
||||||
|
self._check(self._lib.ENR_getNetReacts(self._handle, ctypes.byref(values), ctypes.byref(length)))
|
||||||
|
assert length.value == 4
|
||||||
|
category = ['bulk', 'wall', 'tank', 'source']
|
||||||
|
d = {}
|
||||||
|
for i in range(4):
|
||||||
|
d[category[i]] = values[i]
|
||||||
|
return d
|
||||||
|
|
||||||
|
|
||||||
def dump(self, cache: bool = True) -> str:
|
def dump(self, cache: bool = True) -> str:
|
||||||
data = {}
|
data = {}
|
||||||
data |= { 'version' : self.version() }
|
data |= { 'version' : self.version() }
|
||||||
@@ -134,17 +150,13 @@ class Output:
|
|||||||
data |= { 'times' : self.times() }
|
data |= { 'times' : self.times() }
|
||||||
data |= { 'element_name' : self.element_name() }
|
data |= { 'element_name' : self.element_name() }
|
||||||
data |= { 'energy_usage' : self.energy_usage() }
|
data |= { 'energy_usage' : self.energy_usage() }
|
||||||
|
data |= { 'reactions' : self.reactions() }
|
||||||
if cache:
|
if cache:
|
||||||
with open(self._path + '.json', 'w') as f:
|
with open(self._path + '.json', 'w') as f:
|
||||||
json.dump(data, f)
|
json.dump(data, f)
|
||||||
return json.dumps(data)
|
return json.dumps(data)
|
||||||
|
|
||||||
|
|
||||||
def __del__(self):
|
|
||||||
# throw exception in destructor ? :)
|
|
||||||
self._check(self._lib.ENR_close(ctypes.byref(self._handle)))
|
|
||||||
|
|
||||||
|
|
||||||
def dump_output(path: str) -> str:
|
def dump_output(path: str) -> str:
|
||||||
opt = Output(path)
|
opt = Output(path)
|
||||||
return opt.dump()
|
return opt.dump()
|
||||||
@@ -154,7 +166,7 @@ def run_project(name: str) -> str:
|
|||||||
if not project.have_project(name):
|
if not project.have_project(name):
|
||||||
raise Exception(f'Not found project [{name}]')
|
raise Exception(f'Not found project [{name}]')
|
||||||
|
|
||||||
dir = os.path.dirname(os.getcwd())
|
dir = os.path.abspath(os.getcwd())
|
||||||
|
|
||||||
db_inp = os.path.join(os.path.join(dir, 'db_inp'), name + '.db.inp')
|
db_inp = os.path.join(os.path.join(dir, 'db_inp'), name + '.db.inp')
|
||||||
parser.dump_inp(name, db_inp)
|
parser.dump_inp(name, db_inp)
|
||||||
@@ -175,7 +187,7 @@ def run_project(name: str) -> str:
|
|||||||
|
|
||||||
|
|
||||||
def run_inp(name: str) -> str:
|
def run_inp(name: str) -> str:
|
||||||
dir = os.path.dirname(os.getcwd())
|
dir = os.path.abspath(os.getcwd())
|
||||||
|
|
||||||
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'), name + '.inp')
|
inp = os.path.join(os.path.join(dir, 'inp'), name + '.inp')
|
||||||
|
|||||||
Reference in New Issue
Block a user