Make use of change set
This commit is contained in:
@@ -2,8 +2,9 @@ from psycopg.rows import dict_row, Row
|
||||
from .connection import g_conn_dict as conn
|
||||
from .s0_base import *
|
||||
from .operation import *
|
||||
from .change_set import ChangeSet
|
||||
|
||||
def add_junction(name: str, id: str, x: float, y: float, elevation: float) -> None:
|
||||
def add_junction(name: str, id: str, x: float, y: float, elevation: float) -> ChangeSet:
|
||||
if is_node(name, id):
|
||||
return
|
||||
|
||||
@@ -19,7 +20,12 @@ def add_junction(name: str, id: str, x: float, y: float, elevation: float) -> No
|
||||
undo += f' delete from _node where id = "{id}";'
|
||||
add_operation(name, redo, undo)
|
||||
|
||||
def delete_junction(name: str, id: str) -> None:
|
||||
change = ChangeSet()
|
||||
change.add('junction', id)
|
||||
return change
|
||||
|
||||
|
||||
def delete_junction(name: str, id: str) -> ChangeSet:
|
||||
if not is_junction(name, id):
|
||||
return
|
||||
|
||||
@@ -52,6 +58,11 @@ def delete_junction(name: str, id: str) -> None:
|
||||
undo += f" insert into coordinates (node, coord) values ('{id}', '{coord}');"
|
||||
add_operation(name, redo, undo)
|
||||
|
||||
change = ChangeSet()
|
||||
change.delete('junction', id)
|
||||
return change
|
||||
|
||||
|
||||
def _get_junction(name: str, id: str) -> Row | None:
|
||||
with conn[name].cursor(row_factory=dict_row) as cur:
|
||||
cur.execute(f"select elevation, demand, pattern from junctions where id = '{id}'")
|
||||
@@ -91,7 +102,7 @@ def get_junction_coord(name: str, id: str) -> dict[str, float] | None:
|
||||
coord = str(row['coord'])
|
||||
return _to_point(coord)
|
||||
|
||||
def set_junction_elevation(name: str, id: str, elevation: float) -> None:
|
||||
def set_junction_elevation(name: str, id: str, elevation: float) -> ChangeSet:
|
||||
if not is_junction(name, id):
|
||||
return
|
||||
|
||||
@@ -106,7 +117,12 @@ def set_junction_elevation(name: str, id: str, elevation: float) -> None:
|
||||
undo = f'update junctions set elevation = {old} where id = "{id}"'
|
||||
add_operation(name, redo, undo)
|
||||
|
||||
def set_junction_demand(name: str, id: str, demand: float) -> None:
|
||||
change = ChangeSet()
|
||||
change.update('junction', id, 'elevation')
|
||||
return change
|
||||
|
||||
|
||||
def set_junction_demand(name: str, id: str, demand: float) -> ChangeSet:
|
||||
if not is_junction(name, id):
|
||||
return
|
||||
|
||||
@@ -121,7 +137,12 @@ def set_junction_demand(name: str, id: str, demand: float) -> None:
|
||||
undo = f'update junctions set demand = {old} where id = "{id}"'
|
||||
add_operation(name, redo, undo)
|
||||
|
||||
def set_junction_pattern(name: str, id: str, pattern: str) -> None:
|
||||
change = ChangeSet()
|
||||
change.update('junction', id, 'demand')
|
||||
return change
|
||||
|
||||
|
||||
def set_junction_pattern(name: str, id: str, pattern: str) -> ChangeSet:
|
||||
if not is_junction(name, id):
|
||||
return
|
||||
if not is_pattern(name, id):
|
||||
@@ -140,7 +161,12 @@ def set_junction_pattern(name: str, id: str, pattern: str) -> None:
|
||||
undo = f'update junctions set pattern = {old} where id = "{id}"'
|
||||
add_operation(name, redo, undo)
|
||||
|
||||
def set_junction_coord(name: str, id: str, x: float, y: float) -> None:
|
||||
change = ChangeSet()
|
||||
change.update('junction', id, 'pattern')
|
||||
return change
|
||||
|
||||
|
||||
def set_junction_coord(name: str, id: str, x: float, y: float) -> ChangeSet:
|
||||
if not is_junction(name, id):
|
||||
return
|
||||
|
||||
@@ -156,3 +182,7 @@ def set_junction_coord(name: str, id: str, x: float, y: float) -> None:
|
||||
redo = sql.replace("'", '"')
|
||||
undo = f'update coordinates set coord = "({old_x},{old_y})" where node = "{id}"'
|
||||
add_operation(name, redo, undo)
|
||||
|
||||
change = ChangeSet()
|
||||
change.update('junction', id, 'coord')
|
||||
return change
|
||||
|
||||
Reference in New Issue
Block a user