Make use of change set
This commit is contained in:
@@ -1,13 +1,14 @@
|
|||||||
from psycopg.rows import dict_row
|
from psycopg.rows import dict_row
|
||||||
from .operation import *
|
from .operation import *
|
||||||
from .connection import g_conn_dict as conn
|
from .connection import g_conn_dict as conn
|
||||||
|
from .change_set import ChangeSet
|
||||||
|
|
||||||
def get_title(name: str) -> str:
|
def get_title(name: str) -> str:
|
||||||
with conn[name].cursor(row_factory=dict_row) as cur:
|
with conn[name].cursor(row_factory=dict_row) as cur:
|
||||||
cur.execute(f"select * from title")
|
cur.execute(f"select * from title")
|
||||||
return cur.fetchone()['value']
|
return cur.fetchone()['value']
|
||||||
|
|
||||||
def set_title(name: str, value: str) -> None:
|
def set_title(name: str, value: str) -> ChangeSet:
|
||||||
old = get_title(name)
|
old = get_title(name)
|
||||||
|
|
||||||
with conn[name].cursor() as cur:
|
with conn[name].cursor() as cur:
|
||||||
@@ -17,3 +18,7 @@ def set_title(name: str, value: str) -> None:
|
|||||||
redo = sql.replace("'", '"')
|
redo = sql.replace("'", '"')
|
||||||
undo = f'update title set value = "{old}"'
|
undo = f'update title set value = "{old}"'
|
||||||
add_operation(name, redo, undo)
|
add_operation(name, redo, undo)
|
||||||
|
|
||||||
|
change = ChangeSet()
|
||||||
|
change.update('title', 'null', 'value')
|
||||||
|
return change
|
||||||
|
|||||||
@@ -2,8 +2,9 @@ from psycopg.rows import dict_row, Row
|
|||||||
from .connection import g_conn_dict as conn
|
from .connection import g_conn_dict as conn
|
||||||
from .s0_base import *
|
from .s0_base import *
|
||||||
from .operation 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):
|
if is_node(name, id):
|
||||||
return
|
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}";'
|
undo += f' delete from _node where id = "{id}";'
|
||||||
add_operation(name, redo, undo)
|
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):
|
if not is_junction(name, id):
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -52,6 +58,11 @@ def delete_junction(name: str, id: str) -> None:
|
|||||||
undo += f" insert into coordinates (node, coord) values ('{id}', '{coord}');"
|
undo += f" insert into coordinates (node, coord) values ('{id}', '{coord}');"
|
||||||
add_operation(name, redo, undo)
|
add_operation(name, redo, undo)
|
||||||
|
|
||||||
|
change = ChangeSet()
|
||||||
|
change.delete('junction', id)
|
||||||
|
return change
|
||||||
|
|
||||||
|
|
||||||
def _get_junction(name: str, id: str) -> Row | None:
|
def _get_junction(name: str, id: str) -> Row | None:
|
||||||
with conn[name].cursor(row_factory=dict_row) as cur:
|
with conn[name].cursor(row_factory=dict_row) as cur:
|
||||||
cur.execute(f"select elevation, demand, pattern from junctions where id = '{id}'")
|
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'])
|
coord = str(row['coord'])
|
||||||
return _to_point(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):
|
if not is_junction(name, id):
|
||||||
return
|
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}"'
|
undo = f'update junctions set elevation = {old} where id = "{id}"'
|
||||||
add_operation(name, redo, undo)
|
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):
|
if not is_junction(name, id):
|
||||||
return
|
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}"'
|
undo = f'update junctions set demand = {old} where id = "{id}"'
|
||||||
add_operation(name, redo, undo)
|
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):
|
if not is_junction(name, id):
|
||||||
return
|
return
|
||||||
if not is_pattern(name, id):
|
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}"'
|
undo = f'update junctions set pattern = {old} where id = "{id}"'
|
||||||
add_operation(name, redo, undo)
|
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):
|
if not is_junction(name, id):
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -156,3 +182,7 @@ def set_junction_coord(name: str, id: str, x: float, y: float) -> None:
|
|||||||
redo = sql.replace("'", '"')
|
redo = sql.replace("'", '"')
|
||||||
undo = f'update coordinates set coord = "({old_x},{old_y})" where node = "{id}"'
|
undo = f'update coordinates set coord = "({old_x},{old_y})" where node = "{id}"'
|
||||||
add_operation(name, redo, undo)
|
add_operation(name, redo, undo)
|
||||||
|
|
||||||
|
change = ChangeSet()
|
||||||
|
change.update('junction', id, 'coord')
|
||||||
|
return change
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
from msilib.schema import CheckBox
|
||||||
import api
|
import api
|
||||||
|
|
||||||
|
|
||||||
@@ -128,7 +129,7 @@ def get_patterns(name: str) -> list[str]:
|
|||||||
# title 1.[TITLE]
|
# title 1.[TITLE]
|
||||||
############################################################
|
############################################################
|
||||||
|
|
||||||
def set_title(name: str, title: str) -> None:
|
def set_title(name: str, title: str) -> ChangeSet:
|
||||||
return api.set_title(name, title)
|
return api.set_title(name, title)
|
||||||
|
|
||||||
def get_title(name: str) -> str:
|
def get_title(name: str) -> str:
|
||||||
@@ -139,10 +140,10 @@ def get_title(name: str) -> str:
|
|||||||
# junction 2.[JUNCTIONS]
|
# junction 2.[JUNCTIONS]
|
||||||
############################################################
|
############################################################
|
||||||
|
|
||||||
def add_junction(name: str, junction_id: str, x: float, y: float, elevation: float) -> None:
|
def add_junction(name: str, junction_id: str, x: float, y: float, elevation: float) -> ChangeSet:
|
||||||
return api.add_junction(name, junction_id, x, y, elevation)
|
return api.add_junction(name, junction_id, x, y, elevation)
|
||||||
|
|
||||||
def delete_junction(name: str, junction_id: str) -> None:
|
def delete_junction(name: str, junction_id: str) -> ChangeSet:
|
||||||
return api.delete_junction(name, junction_id)
|
return api.delete_junction(name, junction_id)
|
||||||
|
|
||||||
def get_junction_elevation(name: str, junction_id: str) -> float | None:
|
def get_junction_elevation(name: str, junction_id: str) -> float | None:
|
||||||
@@ -157,14 +158,14 @@ def get_junction_pattern(name: str, junction_id: str) -> str | None:
|
|||||||
def get_junction_coord(name: str, junction_id: str) -> dict[str, float] | None:
|
def get_junction_coord(name: str, junction_id: str) -> dict[str, float] | None:
|
||||||
return api.get_junction_coord(name, junction_id)
|
return api.get_junction_coord(name, junction_id)
|
||||||
|
|
||||||
def set_junction_elevation(name: str, junction_id: str, elevation: float) -> None:
|
def set_junction_elevation(name: str, junction_id: str, elevation: float) -> ChangeSet:
|
||||||
return api.set_junction_elevation(name, junction_id, elevation)
|
return api.set_junction_elevation(name, junction_id, elevation)
|
||||||
|
|
||||||
def set_junction_demand(name: str, junction_id: str, demand: float) -> None:
|
def set_junction_demand(name: str, junction_id: str, demand: float) -> ChangeSet:
|
||||||
return api.set_junction_demand(name, junction_id, demand)
|
return api.set_junction_demand(name, junction_id, demand)
|
||||||
|
|
||||||
def set_junction_pattern(name: str, junction_id: str, pattern: str) -> None:
|
def set_junction_pattern(name: str, junction_id: str, pattern: str) -> ChangeSet:
|
||||||
return api.set_junction_pattern(name, junction_id, pattern)
|
return api.set_junction_pattern(name, junction_id, pattern)
|
||||||
|
|
||||||
def set_junction_coord(name: str, junction_id: str, x: float, y: float) -> None:
|
def set_junction_coord(name: str, junction_id: str, x: float, y: float) -> ChangeSet:
|
||||||
return api.set_junction_coord(name, junction_id, x, y)
|
return api.set_junction_coord(name, junction_id, x, y)
|
||||||
|
|||||||
Reference in New Issue
Block a user