Clean code
This commit is contained in:
@@ -142,11 +142,11 @@ from .s32_region_util import get_nodes_in_boundary, get_nodes_in_region, calcula
|
||||
|
||||
from .s32_region import get_region_schema, get_region, set_region, add_region, delete_region
|
||||
|
||||
from .s32_water_distribution import calculate_demand_to_nodes, calculate_demand_to_region, calculate_demand_to_network
|
||||
|
||||
from .s33_dma import PARTITION_TYPE_RB, PARTITION_TYPE_KWAY
|
||||
from .s33_dma import calculate_district_metering_area_for_nodes, calculate_district_metering_area_for_region, calculate_district_metering_area_for_network
|
||||
|
||||
from .s34_sa import calculate_service_area
|
||||
|
||||
from .s35_vd import calculate_virtual_district
|
||||
|
||||
from .s36_wda_cal import calculate_demand_to_nodes, calculate_demand_to_region, calculate_demand_to_network
|
||||
|
||||
@@ -5822,49 +5822,6 @@ class TestApi:
|
||||
self.leave(p)
|
||||
|
||||
|
||||
# 32 water_distribution
|
||||
|
||||
|
||||
def test_calculate_demand_to_nodes(self):
|
||||
p = 'test_calculate_demand_to_nodes'
|
||||
read_inp(p, f'./inp/net3.inp', '3')
|
||||
open_project(p)
|
||||
|
||||
vds = calculate_virtual_district(p, ['107', '139', '267', '211'])['virtual_districts']
|
||||
result = calculate_demand_to_nodes(p, 100.0, vds[0]['nodes'])
|
||||
assert result == {'10': 17.357291284684024, '101': 22.112211221122113, '103': 6.466202175773133, '105': 8.232489915658233, '107': 4.180418041804181, '109': 7.260726072607261, '111': 3.862608483070529, '115': 6.466202175773133, '117': 5.738907224055739, '119': 0.892311453367559, '120': 3.9665077618873, '257': 2.9275149737195942, '259': 2.1391027991688056, '261': 2.9275149737195942, '263': 5.469991443588803}
|
||||
|
||||
self.leave(p)
|
||||
|
||||
|
||||
def test_calculate_demand_to_region(self):
|
||||
p = 'test_calculate_demand_to_region'
|
||||
read_inp(p, f'./inp/net3.inp', '3')
|
||||
open_project(p)
|
||||
|
||||
vds = calculate_virtual_district(p, ['107', '139', '267', '211'])['virtual_districts']
|
||||
nodes = vds[0]['nodes']
|
||||
boundary = calculate_boundary(p, nodes)
|
||||
boundary = inflate_boundary(p, boundary, 0.1)
|
||||
add_region(p, ChangeSet({'id': 'r', 'boundary': boundary}))
|
||||
|
||||
result = calculate_demand_to_region(p, 100.0, 'r')
|
||||
assert result == {'10': 17.357291284684024, '101': 22.112211221122113, '103': 6.466202175773133, '105': 8.232489915658233, '107': 4.180418041804181, '109': 7.260726072607261, '111': 3.862608483070529, '115': 6.466202175773133, '117': 5.738907224055739, '119': 0.892311453367559, '120': 3.9665077618873, '257': 2.9275149737195942, '259': 2.1391027991688056, '261': 2.9275149737195942, '263': 5.469991443588803}
|
||||
|
||||
self.leave(p)
|
||||
|
||||
|
||||
def test_calculate_demand_to_network(self):
|
||||
p = 'test_calculate_demand_to_network'
|
||||
read_inp(p, f'./inp/net3.inp', '3')
|
||||
open_project(p)
|
||||
|
||||
result = calculate_demand_to_network(p, 100.0)
|
||||
assert result == {'10': 3.2923444181778216, '101': 4.194261304565972, '103': 1.226514223391597, '105': 1.561545046227298, '107': 0.7929449232512782, '109': 1.3772201298574833, '111': 1.7690554866687873, '113': 1.2381069854274345, '115': 1.6902247048250931, '117': 1.088560355165132, '119': 1.9174428407275061, '120': 1.2276734995951808, '121': 1.502421959844527, '123': 10.897196313687157, '125': 2.0240962514572103, '127': 1.141887060529984, '129': 2.3486935884606575, '131': 1.5024219598445272, '139': 1.1129051554403906, '141': 1.6137124753885663, '143': 0.7071584841860814, '145': 1.3238934244926313, '147': 0.7141141414075839, '149': 0.44052495736182123, '15': 0.38256114718263423, '151': 1.3099821100496263, '153': 1.328530529306966, '157': 1.1569576511765725, '159': 1.1384092319192327, '161': 1.0966752885902182, '163': 0.41270232847581145, '164': 0.14838735405871872, '166': 0.11360906795120652, '167': 0.01391131444300488, '169': 0.5949405476791755, '171': 0.48225890069083593, '173': 0.9390137249028294, '179': 0.32459733700344723, '181': 0.06723801980785693, '183': 0.4799403482836684, '184': 1.0734665789944717, '185': 0.4486167052628357, '187': 0.732639375140852, '189': 0.8638926269106031, '191': 0.9807476682318441, '193': 0.8601829430591352, '195': 0.6167349403065497, '197': 0.9135096484239872, '199': 1.2415848140381855, '20': 0.20496003279360525, '201': 0.2434480027525854, '203': 0.02782262888600976, '204': 0.33037053249729426, '205': 1.4780771595692686, '206': 0.22258103108807809, '207': 0.7141141414075839, '208': 0.3234380607998635, '209': 0.48573672930158707, '211': 0.9923404302676815, '213': 1.7331179243576913, '215': 1.378379406061067, '217': 1.2218771185772621, '219': 0.47530324346933345, '225': 0.3616941755181269, '229': 1.1476834415479027, '231': 0.4544362718048261, '237': 0.7836707136226083, '239': 0.22605885969882933, '241': 0.6213720451208846, '243': 0.5100815295768456, '247': 0.42777291912240006, '249': 0.4382064049546538, '251': 0.5912308638277075, '253': 0.2550407647884228, '255': 1.0468264118361172, '257': 0.5552933015166115, '259': 0.405746671254309, '261': 0.5552933015166115, '263': 1.0375522022074473, '265': 0.7813521612154408, '267': 0.9227838580526571, '269': 0.5986502315306435, '271': 0.535585606055688, '273': 0.8346788665802929, '275': 0.9181467532383222, '35': 0.00695565722150244, '40': 0.2988614052838882, '50': 0.23741976649394997, '60': 0.28564565656303353, '601': 0.00046371048143349603, '61': 10.549645307852751}
|
||||
|
||||
self.leave(p)
|
||||
|
||||
|
||||
# 33 district_metering_area
|
||||
|
||||
|
||||
@@ -5962,5 +5919,48 @@ class TestApi:
|
||||
self.leave(p)
|
||||
|
||||
|
||||
# 36 water_distribution
|
||||
|
||||
|
||||
def test_calculate_demand_to_nodes(self):
|
||||
p = 'test_calculate_demand_to_nodes'
|
||||
read_inp(p, f'./inp/net3.inp', '3')
|
||||
open_project(p)
|
||||
|
||||
vds = calculate_virtual_district(p, ['107', '139', '267', '211'])['virtual_districts']
|
||||
result = calculate_demand_to_nodes(p, 100.0, vds[0]['nodes'])
|
||||
assert result == {'10': 17.357291284684024, '101': 22.112211221122113, '103': 6.466202175773133, '105': 8.232489915658233, '107': 4.180418041804181, '109': 7.260726072607261, '111': 3.862608483070529, '115': 6.466202175773133, '117': 5.738907224055739, '119': 0.892311453367559, '120': 3.9665077618873, '257': 2.9275149737195942, '259': 2.1391027991688056, '261': 2.9275149737195942, '263': 5.469991443588803}
|
||||
|
||||
self.leave(p)
|
||||
|
||||
|
||||
def test_calculate_demand_to_region(self):
|
||||
p = 'test_calculate_demand_to_region'
|
||||
read_inp(p, f'./inp/net3.inp', '3')
|
||||
open_project(p)
|
||||
|
||||
vds = calculate_virtual_district(p, ['107', '139', '267', '211'])['virtual_districts']
|
||||
nodes = vds[0]['nodes']
|
||||
boundary = calculate_boundary(p, nodes)
|
||||
boundary = inflate_boundary(p, boundary, 0.1)
|
||||
add_region(p, ChangeSet({'id': 'r', 'boundary': boundary}))
|
||||
|
||||
result = calculate_demand_to_region(p, 100.0, 'r')
|
||||
assert result == {'10': 17.357291284684024, '101': 22.112211221122113, '103': 6.466202175773133, '105': 8.232489915658233, '107': 4.180418041804181, '109': 7.260726072607261, '111': 3.862608483070529, '115': 6.466202175773133, '117': 5.738907224055739, '119': 0.892311453367559, '120': 3.9665077618873, '257': 2.9275149737195942, '259': 2.1391027991688056, '261': 2.9275149737195942, '263': 5.469991443588803}
|
||||
|
||||
self.leave(p)
|
||||
|
||||
|
||||
def test_calculate_demand_to_network(self):
|
||||
p = 'test_calculate_demand_to_network'
|
||||
read_inp(p, f'./inp/net3.inp', '3')
|
||||
open_project(p)
|
||||
|
||||
result = calculate_demand_to_network(p, 100.0)
|
||||
assert result == {'10': 3.2923444181778216, '101': 4.194261304565972, '103': 1.226514223391597, '105': 1.561545046227298, '107': 0.7929449232512782, '109': 1.3772201298574833, '111': 1.7690554866687873, '113': 1.2381069854274345, '115': 1.6902247048250931, '117': 1.088560355165132, '119': 1.9174428407275061, '120': 1.2276734995951808, '121': 1.502421959844527, '123': 10.897196313687157, '125': 2.0240962514572103, '127': 1.141887060529984, '129': 2.3486935884606575, '131': 1.5024219598445272, '139': 1.1129051554403906, '141': 1.6137124753885663, '143': 0.7071584841860814, '145': 1.3238934244926313, '147': 0.7141141414075839, '149': 0.44052495736182123, '15': 0.38256114718263423, '151': 1.3099821100496263, '153': 1.328530529306966, '157': 1.1569576511765725, '159': 1.1384092319192327, '161': 1.0966752885902182, '163': 0.41270232847581145, '164': 0.14838735405871872, '166': 0.11360906795120652, '167': 0.01391131444300488, '169': 0.5949405476791755, '171': 0.48225890069083593, '173': 0.9390137249028294, '179': 0.32459733700344723, '181': 0.06723801980785693, '183': 0.4799403482836684, '184': 1.0734665789944717, '185': 0.4486167052628357, '187': 0.732639375140852, '189': 0.8638926269106031, '191': 0.9807476682318441, '193': 0.8601829430591352, '195': 0.6167349403065497, '197': 0.9135096484239872, '199': 1.2415848140381855, '20': 0.20496003279360525, '201': 0.2434480027525854, '203': 0.02782262888600976, '204': 0.33037053249729426, '205': 1.4780771595692686, '206': 0.22258103108807809, '207': 0.7141141414075839, '208': 0.3234380607998635, '209': 0.48573672930158707, '211': 0.9923404302676815, '213': 1.7331179243576913, '215': 1.378379406061067, '217': 1.2218771185772621, '219': 0.47530324346933345, '225': 0.3616941755181269, '229': 1.1476834415479027, '231': 0.4544362718048261, '237': 0.7836707136226083, '239': 0.22605885969882933, '241': 0.6213720451208846, '243': 0.5100815295768456, '247': 0.42777291912240006, '249': 0.4382064049546538, '251': 0.5912308638277075, '253': 0.2550407647884228, '255': 1.0468264118361172, '257': 0.5552933015166115, '259': 0.405746671254309, '261': 0.5552933015166115, '263': 1.0375522022074473, '265': 0.7813521612154408, '267': 0.9227838580526571, '269': 0.5986502315306435, '271': 0.535585606055688, '273': 0.8346788665802929, '275': 0.9181467532383222, '35': 0.00695565722150244, '40': 0.2988614052838882, '50': 0.23741976649394997, '60': 0.28564565656303353, '601': 0.00046371048143349603, '61': 10.549645307852751}
|
||||
|
||||
self.leave(p)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
pytest.main()
|
||||
|
||||
32
tjnetwork.py
32
tjnetwork.py
@@ -984,9 +984,13 @@ def get_all_scada_elements(name: str) -> list[dict[str, Any]]:
|
||||
# general_region 32
|
||||
############################################################
|
||||
|
||||
# pure geometry function, test point is in polygon
|
||||
def get_nodes_in_boundary(name: str, boundary: list[tuple[float, float]]) -> list[str]:
|
||||
return api.get_nodes_in_boundary(name, boundary)
|
||||
|
||||
# if region is general or wda => get_nodes_in_boundary
|
||||
# if region is dma, sa or vd => get stored nodes in table
|
||||
# TODO: more test
|
||||
def get_nodes_in_region(name: str, region_id: str) -> list[str]:
|
||||
return api.get_nodes_in_region(name, region_id)
|
||||
|
||||
@@ -1002,15 +1006,6 @@ def inflate_boundary(name: str, boundary: list[tuple[float, float]], delta: floa
|
||||
def inflate_region(name: str, region_id: str, delta: float = 0.5) -> list[tuple[float, float]]:
|
||||
return api.inflate_region(name, region_id, delta)
|
||||
|
||||
def calculate_demand_to_nodes(name: str, demand: float, nodes: list[str]) -> dict[str, float]:
|
||||
return api.calculate_demand_to_nodes(name, demand, nodes)
|
||||
|
||||
def calculate_demand_to_region(name: str, demand: float, region: str) -> dict[str, float]:
|
||||
return api.calculate_demand_to_region(name, demand, region)
|
||||
|
||||
def calculate_demand_to_network(name: str, demand: float) -> dict[str, float]:
|
||||
return api.calculate_demand_to_network(name, demand)
|
||||
|
||||
def get_region_schema(name: str) -> dict[str, dict[str, Any]]:
|
||||
return api.get_region_schema(name)
|
||||
|
||||
@@ -1027,7 +1022,7 @@ def add_region(name: str, cs: ChangeSet) -> ChangeSet:
|
||||
def delete_region(name: str, cs: ChangeSet) -> ChangeSet:
|
||||
return api.delete_region(name, cs)
|
||||
|
||||
def get_all_regions(name: str) -> list[str]:
|
||||
def get_all_regions(name: str) -> list[dict[str, Any]]:
|
||||
return []
|
||||
|
||||
|
||||
@@ -1126,3 +1121,20 @@ def get_all_virtual_district(name: str) -> list[dict[str, Any]]:
|
||||
|
||||
def generate_virtual_district(name: str, centers: list[str]) -> ChangeSet:
|
||||
return ChangeSet()
|
||||
|
||||
|
||||
############################################################
|
||||
# water_distribution_area 36
|
||||
############################################################
|
||||
|
||||
def calculate_demand_to_nodes(name: str, demand: float, nodes: list[str]) -> dict[str, float]:
|
||||
return api.calculate_demand_to_nodes(name, demand, nodes)
|
||||
|
||||
# if region is general or wda => get_nodes_in_boundary
|
||||
# if region is dma, sa or vd => get stored nodes in table
|
||||
# TODO: more test
|
||||
def calculate_demand_to_region(name: str, demand: float, region: str) -> dict[str, float]:
|
||||
return api.calculate_demand_to_region(name, demand, region)
|
||||
|
||||
def calculate_demand_to_network(name: str, demand: float) -> dict[str, float]:
|
||||
return api.calculate_demand_to_network(name, demand)
|
||||
|
||||
Reference in New Issue
Block a user