Clean repo
This commit is contained in:
207
demo.py
207
demo.py
@@ -1,57 +1,184 @@
|
||||
from tjnetwork import *
|
||||
|
||||
JUNCTION = 0
|
||||
RESERVOIR = 1
|
||||
TANK = 2
|
||||
PIPE = 1
|
||||
NODE_COUNT = 0
|
||||
LINK_COUNT = 2
|
||||
|
||||
create_project("net1")
|
||||
open_project("net1")
|
||||
def demo_snapshot():
|
||||
p = "demo_snapshot"
|
||||
|
||||
add_node("net1", "node-1", JUNCTION)
|
||||
print(p)
|
||||
|
||||
undo("net1")
|
||||
redo("net1")
|
||||
if is_project_open(p):
|
||||
close_project(p)
|
||||
|
||||
add_node("net1", "node-2", RESERVOIR)
|
||||
add_node("net1", "node-3", TANK)
|
||||
if have_project(p):
|
||||
delete_project(p)
|
||||
|
||||
set_node_coord("net1", "node-3", 10.0, 10.0)
|
||||
create_project(p)
|
||||
open_project(p)
|
||||
|
||||
delete_node("net1", "node-3")
|
||||
undo("net1")
|
||||
add_junction(p, 'j-1', 10.0, 20.0, 30.0)
|
||||
add_junction(p, 'j-2', 10.0, 20.0, 30.0)
|
||||
add_junction(p, 'j-3', 10.0, 20.0, 30.0)
|
||||
add_junction(p, 'j-4', 10.0, 20.0, 30.0)
|
||||
take_snapshot(p, "1-2-3-4")
|
||||
|
||||
set_node_coord("net1", "node-1", 10.0, 10.0)
|
||||
undo("net1")
|
||||
redo("net1")
|
||||
undo(p)
|
||||
undo(p)
|
||||
undo(p)
|
||||
undo(p)
|
||||
|
||||
set_node_coord("net1", "node-2", 20.0, 20.0)
|
||||
add_junction(p, 'j-5', 10.0, 20.0, 30.0)
|
||||
add_junction(p, 'j-6', 10.0, 20.0, 30.0)
|
||||
add_junction(p, 'j-7', 10.0, 20.0, 30.0)
|
||||
add_junction(p, 'j-8', 10.0, 20.0, 30.0)
|
||||
take_snapshot(p, "5-6-7-8")
|
||||
|
||||
add_link("net1", "link-1", PIPE, "node-1", "node-2")
|
||||
print("before checkout, it should be 5, 6, 7, 8")
|
||||
print(get_nodes(p))
|
||||
|
||||
add_link("net1", "link-2", PIPE, "node-1", "node-3")
|
||||
undo("net1")
|
||||
redo("net1")
|
||||
pick_snapshot(p, "1-2-3-4")
|
||||
|
||||
add_link("net1", "link-3", PIPE, "node-2", "node-3")
|
||||
undo("net1")
|
||||
print("after checkout, it should be 1, 2, 3, 4")
|
||||
print(get_nodes(p))
|
||||
|
||||
# this could fail since link-1 & link-2 ref node-1
|
||||
delete_node("net1", "node-1")
|
||||
close_project(p)
|
||||
delete_project(p)
|
||||
|
||||
node_count = get_count("net1", NODE_COUNT)
|
||||
print(node_count.value)
|
||||
for i in range(1, node_count.value + 1):
|
||||
node_id = get_node_id("net1", i)
|
||||
print(node_id.value)
|
||||
|
||||
link_count = get_count("net1", LINK_COUNT)
|
||||
print(link_count.value)
|
||||
for i in range(1, link_count.value + 1):
|
||||
link_id = get_link_id("net1", i)
|
||||
print(link_id.value)
|
||||
def demo_transaction():
|
||||
p = "demo_transaction"
|
||||
|
||||
close_project("net1")
|
||||
delete_project("net1")
|
||||
print(p)
|
||||
|
||||
if is_project_open(p):
|
||||
close_project(p)
|
||||
|
||||
if have_project(p):
|
||||
delete_project(p)
|
||||
|
||||
create_project(p)
|
||||
open_project(p)
|
||||
|
||||
add_junction(p, 'j-1', 10.0, 20.0, 30.0)
|
||||
take_snapshot(p, "1")
|
||||
add_junction(p, 'j-2', 10.0, 20.0, 30.0)
|
||||
take_snapshot(p, "2")
|
||||
|
||||
start_transaction(p)
|
||||
|
||||
add_junction(p, 'j-3', 10.0, 20.0, 30.0)
|
||||
take_snapshot(p, "3")
|
||||
add_junction(p, 'j-4', 10.0, 20.0, 30.0)
|
||||
take_snapshot(p, "4")
|
||||
|
||||
print("before rollback, it should be 1, 2, 3, 4")
|
||||
print(get_nodes(p))
|
||||
|
||||
print("after rollback, it should be 1, 2")
|
||||
abort_transaction(p)
|
||||
|
||||
print(get_nodes(p))
|
||||
|
||||
print(f"have snapshot 1: {have_snapshot(p, '1')}")
|
||||
print(f"have snapshot 2: {have_snapshot(p, '2')}")
|
||||
print(f"have snapshot 3: {have_snapshot(p, '3')}")
|
||||
print(f"have snapshot 4: {have_snapshot(p, '4')}")
|
||||
|
||||
close_project(p)
|
||||
delete_project(p)
|
||||
|
||||
|
||||
def demo_1_title():
|
||||
p = "demo_1_title"
|
||||
|
||||
print(p)
|
||||
|
||||
if is_project_open(p):
|
||||
close_project(p)
|
||||
|
||||
if have_project(p):
|
||||
delete_project(p)
|
||||
|
||||
create_project(p)
|
||||
open_project(p)
|
||||
|
||||
print(get_title(p)) #
|
||||
|
||||
set_title(p, "title")
|
||||
print(get_title(p)) # title
|
||||
|
||||
set_title(p, "test")
|
||||
print(get_title(p)) # test
|
||||
|
||||
undo(p)
|
||||
print(get_title(p)) # title
|
||||
|
||||
undo(p)
|
||||
print(get_title(p)) #
|
||||
|
||||
close_project(p)
|
||||
delete_project(p)
|
||||
|
||||
|
||||
def demo_2_junctions():
|
||||
p = "demo_2_junctions"
|
||||
|
||||
print(p)
|
||||
|
||||
if is_project_open(p):
|
||||
close_project(p)
|
||||
|
||||
if have_project(p):
|
||||
delete_project(p)
|
||||
|
||||
create_project(p)
|
||||
open_project(p)
|
||||
|
||||
j = 'j-1'
|
||||
print(get_junction_coord(p, j)) # None
|
||||
print(get_junction_elevation(p, j)) # None
|
||||
print(get_junction_demand(p, j)) # None
|
||||
print(get_junction_pattern(p, j)) # None
|
||||
|
||||
add_junction(p, j, 10.0, 20.0, 30.0)
|
||||
print(get_junction_coord(p, j)) # {'x': 10.0, 'y': 20.0}
|
||||
print(get_junction_elevation(p, j)) # 30.0
|
||||
print(get_junction_demand(p, j)) # NULL
|
||||
print(get_junction_pattern(p, j)) # NULL
|
||||
|
||||
set_junction_demand(p, j, 100.0)
|
||||
print(get_junction_demand(p, j)) # 100.0
|
||||
|
||||
undo(p)
|
||||
print(get_junction_demand(p, j)) # NULL
|
||||
|
||||
undo(p)
|
||||
print(get_junction_coord(p, j)) # None
|
||||
print(get_junction_elevation(p, j)) # None
|
||||
print(get_junction_demand(p, j)) # None
|
||||
print(get_junction_pattern(p, j)) # None
|
||||
|
||||
add_junction(p, j, 10.0, 20.0, 30.0)
|
||||
print(get_junction_coord(p, j)) # {'x': 10.0, 'y': 20.0}
|
||||
print(get_junction_elevation(p, j)) # 30.0
|
||||
print(get_junction_demand(p, j)) # NULL
|
||||
print(get_junction_pattern(p, j)) # NULL
|
||||
|
||||
set_junction_coord(p, j, 100.0, 200.0)
|
||||
print(get_junction_coord(p, j)) # {'x': 100.0, 'y': 200.0}
|
||||
|
||||
undo(p)
|
||||
print(get_junction_coord(p, j)) # {'x': 10.0, 'y': 20.0}
|
||||
|
||||
redo(p)
|
||||
print(get_junction_coord(p, j)) # {'x': 100.0, 'y': 200.0}
|
||||
|
||||
close_project(p)
|
||||
delete_project(p)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
demo_snapshot()
|
||||
demo_transaction()
|
||||
demo_1_title()
|
||||
demo_2_junctions()
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user