diff --git a/api/s10_status.py b/api/s10_status.py index cf07ccb..33b2a7d 100644 --- a/api/s10_status.py +++ b/api/s10_status.py @@ -84,9 +84,9 @@ def inp_in_status(line: str) -> str: link = str(tokens[0]) value = tokens[1].upper() if value == LINK_STATUS_OPEN or value == LINK_STATUS_CLOSED or value == LINK_STATUS_ACTIVE: - return f"insert into status (link, status, setting) values ('{link}', '{value}', null);" + return str(f"insert into status (link, status, setting) values ('{link}', '{value}', null);") else: - return f"insert into status (link, status, setting) values ('{link}', null, {float(value)});" + return str(f"insert into status (link, status, setting) values ('{link}', null, {float(value)});") def inp_out_status(name: str) -> list[str]: diff --git a/api/s12_curves.py b/api/s12_curves.py index 1ea6456..eb37982 100644 --- a/api/s12_curves.py +++ b/api/s12_curves.py @@ -151,7 +151,7 @@ def delete_curve(name: str, cs: ChangeSet) -> ChangeSet: def inp_in_curve(line: str) -> str: tokens = line.split() - return f"insert into curves (id, x, y) values ('{tokens[0]}', {float(tokens[1])}, {float(tokens[2])});" + return str(f"insert into curves (id, x, y) values ('{tokens[0]}', {float(tokens[1])}, {float(tokens[2])});") def inp_out_curve(name: str) -> list[str]: diff --git a/api/s13_controls.py b/api/s13_controls.py index b3cf9b7..7b43f2b 100644 --- a/api/s13_controls.py +++ b/api/s13_controls.py @@ -45,7 +45,7 @@ def set_control(name: str, cs: ChangeSet) -> ChangeSet: def inp_in_control(line: str) -> str: - return f"insert into controls (line) values ('{line}');" + return str(f"insert into controls (line) values ('{line}');") def inp_out_control(name: str) -> list[str]: diff --git a/api/s14_rules.py b/api/s14_rules.py index b7f9e9a..b210f71 100644 --- a/api/s14_rules.py +++ b/api/s14_rules.py @@ -41,7 +41,7 @@ def set_rule(name: str, cs: ChangeSet) -> ChangeSet: def inp_in_rule(line: str) -> str: - return f"insert into rules (line) values ('{line}');" + return str(f"insert into rules (line) values ('{line}');") def inp_out_rule(name: str) -> list[str]: diff --git a/api/s15_energy.py b/api/s15_energy.py index cc04c6c..3abb998 100644 --- a/api/s15_energy.py +++ b/api/s15_energy.py @@ -153,7 +153,7 @@ def inp_in_energy(line: str) -> str: if key == 'efficiency': key = 'effic' - return f"insert into energy_pump_{key} (pump, {key}) values ('{pump}', {value});" + return str(f"insert into energy_pump_{key} (pump, {key}) values ('{pump}', {value});") else: line = line.upper().strip() @@ -165,9 +165,9 @@ def inp_in_energy(line: str) -> str: if line.startswith('GLOBAL EFFICIENCY'): value = line.removeprefix('GLOBAL EFFICIENCY').strip() - return f"update energy set value = '{value}' where key = '{key}';" + return str(f"update energy set value = '{value}' where key = '{key}';") - return '' + return str('') def inp_out_energy(name: str) -> list[str]: diff --git a/api/s16_emitters.py b/api/s16_emitters.py index 0bf06ad..8f510a9 100644 --- a/api/s16_emitters.py +++ b/api/s16_emitters.py @@ -78,7 +78,7 @@ def inp_in_emitter(line: str) -> str: junction = str(tokens[0]) coefficient = float(tokens[1]) - return f"insert into emitters (junction, coefficient) values ('{junction}', {coefficient});" + return str(f"insert into emitters (junction, coefficient) values ('{junction}', {coefficient});") def inp_out_emitter(name: str) -> list[str]: diff --git a/api/s17_quality.py b/api/s17_quality.py index 1087863..539b205 100644 --- a/api/s17_quality.py +++ b/api/s17_quality.py @@ -75,7 +75,7 @@ def inp_in_quality(line: str) -> str: node = str(tokens[0]) quality = float(tokens[1]) - return f"insert into quality (node, quality) values ('{node}', {quality});" + return str(f"insert into quality (node, quality) values ('{node}', {quality});") def inp_out_quality(name: str) -> list[str]: diff --git a/api/s18_sources.py b/api/s18_sources.py index 42cfb3f..0abaeda 100644 --- a/api/s18_sources.py +++ b/api/s18_sources.py @@ -121,8 +121,7 @@ def inp_in_source(line: str) -> str: pattern = str(tokens[3]) if num_without_desc >= 4 else None pattern = f"'{pattern}'" if pattern != None else 'null' - return f"insert into sources (node, s_type, strength, pattern) values ('{node}', '{s_type}', {strength}, {pattern});" - + return str(f"insert into sources (node, s_type, strength, pattern) values ('{node}', '{s_type}', {strength}, {pattern});") def inp_out_source(name: str) -> list[str]: diff --git a/api/s19_reactions.py b/api/s19_reactions.py index 8ebf7a7..bf0faf5 100644 --- a/api/s19_reactions.py +++ b/api/s19_reactions.py @@ -201,21 +201,21 @@ def inp_in_reaction(line: str) -> str: pipe = tokens[1] key = token0.lower() value = tokens[2] - return f"insert into reactions_pipe_{key} (pipe, value) values ('{pipe}', {value});" + return str(f"insert into reactions_pipe_{key} (pipe, value) values ('{pipe}', {value});") elif token0 == 'TANK': tank = tokens[1] value = tokens[2] - return f"insert into reactions_tank (tank, value) values ('{tank}', {value});" + return str(f"insert into reactions_tank (tank, value) values ('{tank}', {value});") else: line = line.upper().strip() for key in get_reaction_schema('').keys(): if line.startswith(key): value = line.removeprefix(key).strip() - return f"update reactions set value = '{value}' where key = '{key}';" + return str(f"update reactions set value = '{value}' where key = '{key}';") - return '' + return str('') def inp_out_reaction(name: str) -> list[str]: diff --git a/api/s1_title.py b/api/s1_title.py index a038857..3ec5d6a 100644 --- a/api/s1_title.py +++ b/api/s1_title.py @@ -29,10 +29,10 @@ def set_title(name: str, cs: ChangeSet) -> ChangeSet: def inp_in_title(section: list[str]) -> str: if section == []: - return '' + return str('') title = '\n'.join(section) - return f"update title set value = '{title}';" + return str(f"update title set value = '{title}';") def inp_out_title(name: str) -> list[str]: diff --git a/api/s20_mixing.py b/api/s20_mixing.py index db4c8d3..5bef359 100644 --- a/api/s20_mixing.py +++ b/api/s20_mixing.py @@ -129,7 +129,7 @@ def inp_in_mixing(line: str) -> str: value = float(tokens[3]) if num_without_desc >= 4 else None value = value if value != None else 'null' - return f"insert into mixing (tank, model, value) values ('{tank}', '{model}', {value});" + return str(f"insert into mixing (tank, model, value) values ('{tank}', '{model}', {value});") def inp_out_mixing(name: str) -> list[str]: diff --git a/api/s24_coordinates.py b/api/s24_coordinates.py index 6c36216..bf313cf 100644 --- a/api/s24_coordinates.py +++ b/api/s24_coordinates.py @@ -3,16 +3,16 @@ from .database import * def sql_update_coord(node: str, x: float, y: float) -> str: coord = f"st_geomfromtext('point({x} {y})')" - return f"update coordinates set coord = {coord} where node = '{node}';" + return str(f"update coordinates set coord = {coord} where node = '{node}';") def sql_insert_coord(node: str, x: float, y: float) -> str: coord = f"st_geomfromtext('point({x} {y})')" - return f"insert into coordinates (node, coord) values ('{node}', {coord});" + return str(f"insert into coordinates (node, coord) values ('{node}', {coord});") def sql_delete_coord(node: str) -> str: - return f"delete from coordinates where node = '{node}';" + return str(f"delete from coordinates where node = '{node}';") def from_postgis_point(coord: str) -> dict[str, float]: @@ -43,7 +43,7 @@ def inp_in_coord(line: str) -> str: tokens = line.split() node = tokens[0] coord = f"st_geomfromtext('point({tokens[1]} {tokens[2]})')" - return f"insert into coordinates (node, coord) values ('{node}', {coord});" + return str(f"insert into coordinates (node, coord) values ('{node}', {coord});") def inp_out_coord(name: str) -> list[str]: diff --git a/api/s25_vertices.py b/api/s25_vertices.py index 3660ce9..0bd7647 100644 --- a/api/s25_vertices.py +++ b/api/s25_vertices.py @@ -99,7 +99,7 @@ def inp_in_vertex(line: str) -> str: link = tokens[0] x = float(tokens[1]) y = float(tokens[2]) - return f"insert into vertices (link, x, y) values ('{link}', {x}, {y});" + return str(f"insert into vertices (link, x, y) values ('{link}', {x}, {y});") def inp_out_vertex(name: str) -> list[str]: diff --git a/api/s26_labels.py b/api/s26_labels.py index c7e7193..3bb0596 100644 --- a/api/s26_labels.py +++ b/api/s26_labels.py @@ -112,7 +112,7 @@ def inp_in_label(line: str) -> str: node = str(tokens[3]) if num >= 4 else None node = f"'{node}'" if node != None else 'null' - return f"insert into labels (x, y, label, node) values ({x}, {y}, '{label}', {node});" + return str(f"insert into labels (x, y, label, node) values ({x}, {y}, '{label}', {node});") def inp_out_label(name: str) -> list[str]: diff --git a/api/s27_backdrop.py b/api/s27_backdrop.py index 18f938a..bedc8fa 100644 --- a/api/s27_backdrop.py +++ b/api/s27_backdrop.py @@ -28,10 +28,10 @@ def set_backdrop(name: str, cs: ChangeSet) -> ChangeSet: def inp_in_backdrop(section: list[str]) -> str: if section == []: - return '' + return str('') content = '\n'.join(section) - return f"update backdrop set content = '{content}';" + return str(f"update backdrop set content = '{content}';") def inp_out_backdrop(name: str) -> list[str]: diff --git a/api/s2_junctions.py b/api/s2_junctions.py index 84164ea..723addb 100644 --- a/api/s2_junctions.py +++ b/api/s2_junctions.py @@ -158,7 +158,7 @@ def inp_in_junction(line: str, demand_outside: bool) -> str: if demand != None and demand_outside == False: sql += f"insert into demands (junction, demand, pattern) values ('{id}', {demand}, {pattern});" - return sql + return str(sql) def inp_out_junction(name: str) -> list[str]: diff --git a/api/s32_region_util.py b/api/s32_region_util.py index d95862b..4fdb46d 100644 --- a/api/s32_region_util.py +++ b/api/s32_region_util.py @@ -22,14 +22,14 @@ def to_postgis_polygon(boundary: list[tuple[float, float]]) -> str: polygon = '' for pt in boundary: polygon += f'{pt[0]} {pt[1]},' - return f'polygon(({polygon[:-1]}))' + return str(f'polygon(({polygon[:-1]}))') def to_postgis_linestring(boundary: list[tuple[float, float]]) -> str: line = '' for pt in boundary: line += f'{pt[0]} {pt[1]},' - return f'linestring({line[:-1]})' + return str(f'linestring({line[:-1]})') def get_nodes_in_boundary(name: str, boundary: list[tuple[float, float]]) -> list[str]: diff --git a/api/s3_reservoirs.py b/api/s3_reservoirs.py index 992b50b..b75630b 100644 --- a/api/s3_reservoirs.py +++ b/api/s3_reservoirs.py @@ -148,7 +148,7 @@ def inp_in_reservoir(line: str) -> str: pattern = f"'{pattern}'" if pattern != None else 'null' desc = str(tokens[-1]) if has_desc else None - return f"insert into _node (id, type) values ('{id}', 'reservoir');insert into reservoirs (id, head, pattern) values ('{id}', {head}, {pattern});" + return str(f"insert into _node (id, type) values ('{id}', 'reservoir');insert into reservoirs (id, head, pattern) values ('{id}', {head}, {pattern});") def inp_out_reservoir(name: str) -> list[str]: diff --git a/api/s4_tanks.py b/api/s4_tanks.py index 837c9af..ca47c1f 100644 --- a/api/s4_tanks.py +++ b/api/s4_tanks.py @@ -191,7 +191,7 @@ def inp_in_tank(line: str) -> str: overflow = f"'{overflow}'" if overflow != None else 'null' desc = str(tokens[-1]) if has_desc else None - return f"insert into _node (id, type) values ('{id}', 'tank');insert into tanks (id, elevation, init_level, min_level, max_level, diameter, min_vol, vol_curve, overflow) values ('{id}', {elevation}, {init_level}, {min_level}, {max_level}, {diameter}, {min_vol}, {vol_curve}, {overflow});" + return str(f"insert into _node (id, type) values ('{id}', 'tank');insert into tanks (id, elevation, init_level, min_level, max_level, diameter, min_vol, vol_curve, overflow) values ('{id}', {elevation}, {init_level}, {min_level}, {max_level}, {diameter}, {min_vol}, {vol_curve}, {overflow});") def inp_out_tank(name: str) -> list[str]: diff --git a/api/s5_pipes.py b/api/s5_pipes.py index 248e607..2a1499a 100644 --- a/api/s5_pipes.py +++ b/api/s5_pipes.py @@ -164,7 +164,7 @@ def inp_in_pipe(line: str) -> str: status = str(tokens[7].upper()) if num_without_desc >= 8 else PIPE_STATUS_OPEN desc = str(tokens[-1]) if has_desc else None - return f"insert into _link (id, type) values ('{id}', 'pipe');insert into pipes (id, node1, node2, length, diameter, roughness, minor_loss, status) values ('{id}', '{node1}', '{node2}', {length}, {diameter}, {roughness}, {minor_loss}, '{status}');" + return str(f"insert into _link (id, type) values ('{id}', 'pipe');insert into pipes (id, node1, node2, length, diameter, roughness, minor_loss, status) values ('{id}', '{node1}', '{node2}', {length}, {diameter}, {roughness}, {minor_loss}, '{status}');") def inp_out_pipe(name: str) -> list[str]: diff --git a/api/s6_pumps.py b/api/s6_pumps.py index d57a2c4..6bced9c 100644 --- a/api/s6_pumps.py +++ b/api/s6_pumps.py @@ -158,7 +158,7 @@ def inp_in_pump(line: str) -> str: pattern = f"'{pattern}'" if pattern != None else 'null' desc = str(tokens[-1]) if has_desc else None - return f"insert into _link (id, type) values ('{id}', 'pump');insert into pumps (id, node1, node2, power, head, speed, pattern) values ('{id}', '{node1}', '{node2}', {power}, {head}, {speed}, {pattern});" + return str(f"insert into _link (id, type) values ('{id}', 'pump');insert into pumps (id, node1, node2, power, head, speed, pattern) values ('{id}', '{node1}', '{node2}', {power}, {head}, {speed}, {pattern});") def inp_out_pump(name: str) -> list[str]: diff --git a/api/s7_valves.py b/api/s7_valves.py index 7268d47..e257740 100644 --- a/api/s7_valves.py +++ b/api/s7_valves.py @@ -160,7 +160,7 @@ def inp_in_valve(line: str) -> str: minor_loss = float(tokens[6]) if len(tokens) >= 7 else 0.0 desc = str(tokens[-1]) if has_desc else None - return f"insert into _link (id, type) values ('{id}', 'valve');insert into valves (id, node1, node2, diameter, v_type, setting, minor_loss) values ('{id}', '{node1}', '{node2}', {diameter}, '{v_type}', '{setting}', {minor_loss});" + return str(f"insert into _link (id, type) values ('{id}', 'valve');insert into valves (id, node1, node2, diameter, v_type, setting, minor_loss) values ('{id}', '{node1}', '{node2}', {diameter}, '{v_type}', '{setting}', {minor_loss});") def inp_out_valve(name: str) -> list[str]: diff --git a/api/s8_tags.py b/api/s8_tags.py index 9f72610..32ad588 100644 --- a/api/s8_tags.py +++ b/api/s8_tags.py @@ -104,10 +104,10 @@ def inp_in_tag(line: str) -> str: tag = str(tokens[2]) if t_type == TAG_TYPE_NODE: - return f"insert into tags_node (id, tag) values ('{id}', '{tag}');" + return str(f"insert into tags_node (id, tag) values ('{id}', '{tag}');") elif t_type == TAG_TYPE_LINK: - return f"insert into tags_link (id, tag) values ('{id}', '{tag}');" - return '' + return str(f"insert into tags_link (id, tag) values ('{id}', '{tag}');") + return str('') def inp_out_tag(name: str) -> list[str]: diff --git a/api/s9_demands.py b/api/s9_demands.py index de3de41..f53a5a1 100644 --- a/api/s9_demands.py +++ b/api/s9_demands.py @@ -79,7 +79,7 @@ def inp_in_demand(line: str) -> str: category = str(tokens[3]) if num_without_desc >= 4 else None category = f"'{category}'" if category != None else 'null' - return f"insert into demands (junction, demand, pattern, category) values ('{junction}', {demand}, {pattern}, {category});" + return str(f"insert into demands (junction, demand, pattern, category) values ('{junction}', {demand}, {pattern}, {category});") def inp_out_demand(name: str) -> list[str]: diff --git a/build_pyd.py b/build_pyd.py index 03e01de..ba50311 100644 --- a/build_pyd.py +++ b/build_pyd.py @@ -1,4 +1,8 @@ from distutils.core import setup from Cython.Build import cythonize -setup(ext_modules=cythonize("tjnetwork.py")) \ No newline at end of file +setup(ext_modules=cythonize([ + "tjnetwork.py", + "api/*.py", + "epanet/*.py" + ])) \ No newline at end of file