Accept Merge Request #94: (api -> master)
Merge Request: Support to dump inp Created By: @王琼钰 Accepted By: @王琼钰 URL: https://tjwater.coding.net/p/tjwatercloud/d/TJWaterServer/git/merge/94
This commit is contained in:
@@ -2,7 +2,7 @@ from .project import list_project, have_project, create_project, delete_project
|
||||
from .project import is_project_open, get_project_open_count, open_project, close_project
|
||||
from .project import copy_project
|
||||
|
||||
from .api_parser import read_inp
|
||||
from .api_parser import read_inp, dump_inp
|
||||
|
||||
from .operation import API_ADD, API_UPDATE, API_DELETE
|
||||
from .operation import ChangeSet
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
from typing import Any
|
||||
import os
|
||||
from .project import *
|
||||
from .s1_title import *
|
||||
from .s2_junctions import *
|
||||
@@ -213,8 +214,116 @@ def read_inp(project: str, inp: str):
|
||||
create_project(project)
|
||||
open_project(project)
|
||||
|
||||
execute_batch_command(project, cs)
|
||||
execute_batch_commands(project, cs)
|
||||
|
||||
|
||||
def dump_inp(name: str, inp: str):
|
||||
pass
|
||||
def dump_inp(project: str, inp: str):
|
||||
if not have_project(project):
|
||||
return
|
||||
|
||||
if not is_project_open(project):
|
||||
open_project(project)
|
||||
|
||||
dir = os.getcwd()
|
||||
path = os.path.join(dir, inp)
|
||||
|
||||
if os.path.exists(path):
|
||||
os.remove(path)
|
||||
|
||||
file = open(path, mode='w')
|
||||
|
||||
for name in section_name:
|
||||
if name == 'TITLE':
|
||||
file.write(f'[{name}]\n')
|
||||
else:
|
||||
file.write(f'\n[{name}]\n')
|
||||
|
||||
if name == 'TITLE':
|
||||
file.write('\n'.join(inp_out_title(project)))
|
||||
|
||||
elif name == 'JUNCTIONS': # + coords
|
||||
file.write('\n'.join(inp_out_junction(project)))
|
||||
|
||||
elif name == 'RESERVOIRS': # + coords
|
||||
file.write('\n'.join(inp_out_reservoir(project)))
|
||||
|
||||
elif name == 'TANKS': # + coords
|
||||
file.write('\n'.join(inp_out_tank(project)))
|
||||
|
||||
elif name == 'PIPES':
|
||||
file.write('\n'.join(inp_out_pipe(project)))
|
||||
|
||||
elif name == 'PUMPS':
|
||||
file.write('\n'.join(inp_out_pump(project)))
|
||||
|
||||
elif name == 'VALVES':
|
||||
file.write('\n'.join(inp_out_valve(project)))
|
||||
|
||||
elif name == 'TAGS':
|
||||
file.write('\n'.join(inp_out_tag(project)))
|
||||
|
||||
elif name == 'DEMANDS':
|
||||
file.write('\n'.join(inp_out_demand(project)))
|
||||
|
||||
elif name == 'STATUS':
|
||||
file.write('\n'.join(inp_out_status(project)))
|
||||
|
||||
elif name == 'PATTERNS':
|
||||
file.write('\n'.join(inp_out_pattern(project)))
|
||||
|
||||
elif name == 'CURVES':
|
||||
file.write('\n'.join(inp_out_curve(project)))
|
||||
|
||||
elif name == 'CONTROLS':
|
||||
file.write('\n'.join(inp_out_control(project)))
|
||||
|
||||
elif name == 'RULES':
|
||||
file.write('\n'.join(inp_out_rule(project)))
|
||||
|
||||
elif name == 'ENERGY':
|
||||
file.write('\n'.join(inp_out_energy(project)))
|
||||
|
||||
elif name == 'EMITTERS':
|
||||
file.write('\n'.join(inp_out_emitter(project)))
|
||||
|
||||
elif name == 'QUALITY':
|
||||
file.write('\n'.join(inp_out_quality(project)))
|
||||
|
||||
elif name == 'SOURCES':
|
||||
file.write('\n'.join(inp_out_source(project)))
|
||||
|
||||
elif name == 'REACTIONS':
|
||||
file.write('\n'.join(inp_out_reaction(project)))
|
||||
|
||||
elif name == 'MIXING':
|
||||
file.write('\n'.join(inp_out_mixing(project)))
|
||||
|
||||
elif name == 'TIMES':
|
||||
file.write('\n'.join(inp_out_time(project)))
|
||||
|
||||
elif name == 'REPORT':
|
||||
file.write('\n'.join(inp_out_report(project)))
|
||||
|
||||
elif name == 'OPTIONS':
|
||||
file.write('\n'.join(inp_out_option(project)))
|
||||
|
||||
elif name == 'COORDINATES':
|
||||
file.write('\n'.join(inp_out_coord(project)))
|
||||
|
||||
elif name == 'VERTICES':
|
||||
file.write('\n'.join(inp_out_vertex(project)))
|
||||
|
||||
elif name == 'LABELS':
|
||||
file.write('\n'.join(inp_out_label(project)))
|
||||
|
||||
elif name == 'BACKDROP':
|
||||
file.write('\n'.join(inp_out_backdrop(project)))
|
||||
|
||||
elif name == 'END':
|
||||
pass # :)
|
||||
|
||||
file.write('\n')
|
||||
|
||||
file.close()
|
||||
|
||||
close_project(project)
|
||||
|
||||
@@ -170,7 +170,8 @@ def inp_out_energy(name: str) -> list[str]:
|
||||
for obj in objs:
|
||||
key = obj['key']
|
||||
value = obj['value']
|
||||
lines.append(f'{key} {value}')
|
||||
if value.strip() != '':
|
||||
lines.append(f'{key} {value}')
|
||||
|
||||
objs = read_all(name, f"select * from energy_pump_price")
|
||||
for obj in objs:
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
from .operation import *
|
||||
|
||||
|
||||
def inp_out_report(name: str) -> list[str]:
|
||||
lines = []
|
||||
objs = read_all(name, f"select * from report")
|
||||
for obj in objs:
|
||||
key = obj['key']
|
||||
value = obj['value']
|
||||
lines.append(f'{key} {value}')
|
||||
return lines
|
||||
|
||||
@@ -110,12 +110,19 @@ def inp_in_option(section: list[str]) -> ChangeSet:
|
||||
for s in section:
|
||||
if s.startswith(';'):
|
||||
continue
|
||||
|
||||
line = s.upper().strip()
|
||||
for key in get_option_schema('').keys():
|
||||
if line.startswith(key):
|
||||
value = line.removeprefix(key).strip()
|
||||
cs |= { key : value }
|
||||
|
||||
tokens = s.strip().split()
|
||||
if tokens[0].upper() == 'QUALITY':
|
||||
value = tokens[1]
|
||||
if len(tokens) > 2:
|
||||
value += f' {tokens[2]}'
|
||||
cs |= { 'QUALITY' : value }
|
||||
else:
|
||||
line = s.upper().strip()
|
||||
for key in get_option_schema('').keys():
|
||||
if line.startswith(key):
|
||||
value = line.removeprefix(key).strip()
|
||||
cs |= { key : value }
|
||||
return ChangeSet(cs)
|
||||
|
||||
|
||||
|
||||
@@ -165,7 +165,7 @@ def inp_out_pipe(name: str) -> list[str]:
|
||||
diameter = obj['diameter']
|
||||
roughness = obj['roughness']
|
||||
minor_loss = obj['minor_loss']
|
||||
status = obj['vol_curve']
|
||||
status = obj['status']
|
||||
desc = ';'
|
||||
lines.append(f'{id} {node1} {node2} {length} {diameter} {roughness} {minor_loss} {status} {desc}')
|
||||
return lines
|
||||
|
||||
@@ -126,6 +126,9 @@ def copy_project(source: str, new: str) -> None:
|
||||
def read_inp(name: str, inp: str) -> None:
|
||||
return api.read_inp(name, inp)
|
||||
|
||||
def dump_inp(name: str, inp: str) -> None:
|
||||
return api.dump_inp(name, inp)
|
||||
|
||||
|
||||
############################################################
|
||||
# operation
|
||||
|
||||
Reference in New Issue
Block a user