Support DMA

This commit is contained in:
WQY\qiong
2023-05-14 13:20:54 +08:00
parent 1bc73f5bd5
commit 58fd285d25
9 changed files with 637 additions and 96 deletions

View File

@@ -5871,6 +5871,257 @@ class TestApi:
self.leave(p)
def test_district_metering_area(self):
p = 'test_district_metering_area'
self.enter(p)
dma = get_district_metering_area(p, 'dma')
assert dma == {}
add_district_metering_area(p, ChangeSet({'id': 'dma', 'boundary': [(0.0, 0.0), (1.0, 0.0), (1.0, 1.0)]}))
dma = get_district_metering_area(p, 'dma')
assert dma == {}
add_district_metering_area(p, ChangeSet({'id': 'dma', 'boundary': [(0.0, 0.0), (1.0, 0.0), (1.0, 1.0), (0.0, 0.0)], 'parent': '1'}))
dma = get_district_metering_area(p, 'dma')
assert dma == {}
add_district_metering_area(p, ChangeSet({'id': 'dma', 'boundary': [(0.0, 0.0), (1.0, 0.0), (1.0, 1.0), (0.0, 0.0)]}))
dma = get_district_metering_area(p, 'dma')
assert dma['id'] == 'dma'
assert dma['boundary'] == [(0.0, 0.0), (1.0, 0.0), (1.0, 1.0), (0.0, 0.0)]
assert dma['parent'] == None
assert dma['nodes'] == []
assert dma['level'] == 1
set_district_metering_area(p, ChangeSet({'id': 'dma', 'boundary': [(0.0, 0.0), (1.0, 0.0), (1.0, 1.0), (0.0, 0.0)], 'parent': '1'}))
dma = get_district_metering_area(p, 'dma')
assert dma['id'] == 'dma'
assert dma['boundary'] == [(0.0, 0.0), (1.0, 0.0), (1.0, 1.0), (0.0, 0.0)]
assert dma['parent'] == None
assert dma['nodes'] == []
assert dma['level'] == 1
add_district_metering_area(p, ChangeSet({'id': 'd0', 'boundary': [(0.0, 0.0), (1.0, 0.0), (2.0, 2.0), (0.0, 0.0)]}))
set_district_metering_area(p, ChangeSet({'id': 'dma', 'boundary': [(0.0, 0.0), (1.0, 0.0), (1.0, 1.0), (0.0, 0.0)], 'parent': 'd0'}))
dma = get_district_metering_area(p, 'dma')
assert dma['id'] == 'dma'
assert dma['boundary'] == [(0.0, 0.0), (1.0, 0.0), (1.0, 1.0), (0.0, 0.0)]
assert dma['parent'] == 'd0'
assert dma['nodes'] == []
assert dma['level'] == 2
set_district_metering_area(p, ChangeSet({'id': 'dma', 'boundary': [(0.0, 0.0), (1.0, 0.0), (1.0, 1.0), (0.0, 0.0)], 'nodes': ['1']}))
dma = get_district_metering_area(p, 'dma')
assert dma['id'] == 'dma'
assert dma['boundary'] == [(0.0, 0.0), (1.0, 0.0), (1.0, 1.0), (0.0, 0.0)]
assert dma['parent'] == 'd0'
assert dma['nodes'] == []
assert dma['level'] == 2
add_junction(p, ChangeSet({'id': 'j0', 'x': 0.0, 'y': 10.0, 'elevation': 20.0}))
set_district_metering_area(p, ChangeSet({'id': 'dma', 'boundary': [(0.0, 0.0), (1.0, 0.0), (1.0, 1.0), (0.0, 0.0)], 'nodes': ['j0']}))
dma = get_district_metering_area(p, 'dma')
assert dma['id'] == 'dma'
assert dma['boundary'] == [(0.0, 0.0), (1.0, 0.0), (1.0, 1.0), (0.0, 0.0)]
assert dma['parent'] == 'd0'
assert dma['nodes'] == ['j0']
assert dma['level'] == 2
delete_district_metering_area(p, ChangeSet({'id': 'dma'}))
dma = get_district_metering_area(p, 'dma')
assert dma == {}
add_district_metering_area(p, ChangeSet({'id': 'dma', 'boundary': [(0.0, 0.0), (1.0, 0.0), (1.0, 1.0), (0.0, 0.0)], 'parent': 'd0', 'nodes': ['j0']}))
dma = get_district_metering_area(p, 'dma')
assert dma['id'] == 'dma'
assert dma['boundary'] == [(0.0, 0.0), (1.0, 0.0), (1.0, 1.0), (0.0, 0.0)]
assert dma['parent'] == 'd0'
assert dma['nodes'] == ['j0']
assert dma['level'] == 2
delete_district_metering_area(p, ChangeSet({'id': 'd0'}))
dma = get_district_metering_area(p, 'd0')
assert dma != {}
delete_district_metering_area(p, ChangeSet({'id': 'dma'}))
dma = get_district_metering_area(p, 'dma')
assert dma == {}
delete_district_metering_area(p, ChangeSet({'id': 'd0'}))
dma = get_district_metering_area(p, 'd0')
assert dma == {}
self.leave(p)
def test_district_metering_area_op(self):
p = 'test_district_metering_area_op'
self.enter(p)
cs = add_district_metering_area(p, ChangeSet({'id': 'dma', 'boundary': [(0.0, 0.0), (1.0, 0.0), (1.0, 1.0)]})).operations
assert len(cs) == 0
cs = add_district_metering_area(p, ChangeSet({'id': 'dma', 'boundary': [(0.0, 0.0), (1.0, 0.0), (1.0, 1.0), (0.0, 0.0)], 'parent': '1'})).operations
assert len(cs) == 0
cs = add_district_metering_area(p, ChangeSet({'id': 'dma', 'boundary': [(0.0, 0.0), (1.0, 0.0), (1.0, 1.0), (0.0, 0.0)]})).operations[0]
assert cs['operation'] == API_ADD
assert cs['type'] == 'district_metering_area'
assert cs['id'] == 'dma'
assert cs['boundary'] == [(0.0, 0.0), (1.0, 0.0), (1.0, 1.0), (0.0, 0.0)]
assert cs['parent'] == None
assert cs['nodes'] == []
cs = execute_undo(p).operations[0]
assert cs['operation'] == API_DELETE
assert cs['type'] == 'district_metering_area'
assert cs['id'] == 'dma'
cs = execute_redo(p).operations[0]
assert cs['operation'] == API_ADD
assert cs['type'] == 'district_metering_area'
assert cs['id'] == 'dma'
assert cs['boundary'] == [(0.0, 0.0), (1.0, 0.0), (1.0, 1.0), (0.0, 0.0)]
assert cs['parent'] == None
assert cs['nodes'] == []
cs = set_district_metering_area(p, ChangeSet({'id': 'dma', 'boundary': [(0.0, 0.0), (1.0, 0.0), (1.0, 1.0), (0.0, 0.0)], 'parent': '1'})).operations
assert len(cs) == 0
add_district_metering_area(p, ChangeSet({'id': 'd0', 'boundary': [(0.0, 0.0), (1.0, 0.0), (2.0, 2.0), (0.0, 0.0)]}))
cs = set_district_metering_area(p, ChangeSet({'id': 'dma', 'boundary': [(0.0, 0.0), (1.0, 0.0), (1.0, 1.0), (0.0, 0.0)], 'parent': 'd0'})).operations[0]
assert cs['operation'] == API_UPDATE
assert cs['type'] == 'district_metering_area'
assert cs['id'] == 'dma'
assert cs['boundary'] == [(0.0, 0.0), (1.0, 0.0), (1.0, 1.0), (0.0, 0.0)]
assert cs['parent'] == 'd0'
assert cs['nodes'] == []
cs = execute_undo(p).operations[0]
assert cs['operation'] == API_UPDATE
assert cs['type'] == 'district_metering_area'
assert cs['id'] == 'dma'
assert cs['boundary'] == [(0.0, 0.0), (1.0, 0.0), (1.0, 1.0), (0.0, 0.0)]
assert cs['parent'] == None
assert cs['nodes'] == []
cs = execute_redo(p).operations[0]
assert cs['operation'] == API_UPDATE
assert cs['type'] == 'district_metering_area'
assert cs['id'] == 'dma'
assert cs['boundary'] == [(0.0, 0.0), (1.0, 0.0), (1.0, 1.0), (0.0, 0.0)]
assert cs['parent'] == 'd0'
assert cs['nodes'] == []
cs = set_district_metering_area(p, ChangeSet({'id': 'dma', 'boundary': [(0.0, 0.0), (1.0, 0.0), (1.0, 1.0), (0.0, 0.0)], 'nodes': ['1']})).operations
assert len(cs) == 0
add_junction(p, ChangeSet({'id': 'j0', 'x': 0.0, 'y': 10.0, 'elevation': 20.0}))
cs = set_district_metering_area(p, ChangeSet({'id': 'dma', 'boundary': [(0.0, 0.0), (1.0, 0.0), (1.0, 1.0), (0.0, 0.0)], 'nodes': ['j0']})).operations[0]
assert cs['operation'] == API_UPDATE
assert cs['type'] == 'district_metering_area'
assert cs['id'] == 'dma'
assert cs['boundary'] == [(0.0, 0.0), (1.0, 0.0), (1.0, 1.0), (0.0, 0.0)]
assert cs['parent'] == 'd0'
assert cs['nodes'] == ['j0']
cs = execute_undo(p).operations[0]
assert cs['operation'] == API_UPDATE
assert cs['type'] == 'district_metering_area'
assert cs['id'] == 'dma'
assert cs['boundary'] == [(0.0, 0.0), (1.0, 0.0), (1.0, 1.0), (0.0, 0.0)]
assert cs['parent'] == 'd0'
assert cs['nodes'] == []
cs = execute_redo(p).operations[0]
assert cs['operation'] == API_UPDATE
assert cs['type'] == 'district_metering_area'
assert cs['id'] == 'dma'
assert cs['boundary'] == [(0.0, 0.0), (1.0, 0.0), (1.0, 1.0), (0.0, 0.0)]
assert cs['parent'] == 'd0'
assert cs['nodes'] == ['j0']
cs = delete_district_metering_area(p, ChangeSet({'id': 'xxx'})).operations
assert len(cs) == 0
cs = delete_district_metering_area(p, ChangeSet({'id': 'dma'})).operations[0]
assert cs['operation'] == API_DELETE
assert cs['type'] == 'district_metering_area'
assert cs['id'] == 'dma'
cs = execute_undo(p).operations[0]
assert cs['operation'] == API_ADD
assert cs['type'] == 'district_metering_area'
assert cs['id'] == 'dma'
assert cs['boundary'] == [(0.0, 0.0), (1.0, 0.0), (1.0, 1.0), (0.0, 0.0)]
assert cs['parent'] == 'd0'
assert cs['nodes'] == ['j0']
cs = execute_redo(p).operations[0]
assert cs['operation'] == API_DELETE
assert cs['type'] == 'district_metering_area'
assert cs['id'] == 'dma'
cs = add_district_metering_area(p, ChangeSet({'id': 'dma', 'boundary': [(0.0, 0.0), (1.0, 0.0), (1.0, 1.0), (0.0, 0.0)], 'parent': 'd0', 'nodes': ['j0']})).operations[0]
assert cs['operation'] == API_ADD
assert cs['type'] == 'district_metering_area'
assert cs['id'] == 'dma'
assert cs['boundary'] == [(0.0, 0.0), (1.0, 0.0), (1.0, 1.0), (0.0, 0.0)]
assert cs['parent'] == 'd0'
assert cs['nodes'] == ['j0']
cs = delete_district_metering_area(p, ChangeSet({'id': 'd0'})).operations
assert len(cs) == 0
cs = delete_district_metering_area(p, ChangeSet({'id': 'dma'})).operations[0]
assert cs['operation'] == API_DELETE
assert cs['type'] == 'district_metering_area'
assert cs['id'] == 'dma'
cs = delete_district_metering_area(p, ChangeSet({'id': 'dma'})).operations
assert len(cs) == 0
cs = delete_district_metering_area(p, ChangeSet({'id': 'd0'})).operations[0]
assert cs['operation'] == API_DELETE
assert cs['type'] == 'district_metering_area'
assert cs['id'] == 'd0'
self.leave(p)
def test_district_metering_area_gen(self):
p = 'test_district_metering_area_gen'
read_inp(p, f'./inp/net3.inp', '3')
open_project(p)
cs = generate_district_metering_area(p, 3).operations
assert len(cs) == 3
dmas = get_all_district_metering_area_ids(p)
assert len(dmas) == 3
cs = generate_district_metering_area(p, 3).operations
assert len(cs) == 6
dmas = get_all_district_metering_area_ids(p)
assert len(dmas) == 3
cs = generate_sub_district_metering_area(p, 'DMA_1_1', 2).operations
assert len(cs) == 2
dmas = get_all_district_metering_area_ids(p)
assert len(dmas) == 5
cs = generate_district_metering_area(p, 3).operations
assert len(cs) == 8
dmas = get_all_district_metering_area_ids(p)
assert len(dmas) == 3
self.leave(p)
# 34 service_area