Support calculate_demand_to_network

This commit is contained in:
WQY\qiong
2023-05-12 19:47:19 +08:00
parent b75a717f95
commit e6ec0018a0
4 changed files with 25 additions and 9 deletions

View File

@@ -142,7 +142,7 @@ 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
from .s32_water_distribution import calculate_demand_to_nodes, calculate_demand_to_region, calculate_demand_to_network
from .s33_district_metering_area import PARTITION_TYPE_RB, PARTITION_TYPE_KWAY
from .s33_district_metering_area import calculate_district_metering_area

View File

@@ -1,5 +1,5 @@
from .database import ChangeSet
from .s0_base import is_junction
from .s0_base import is_junction, get_nodes
from .s9_demands import get_demand
from .s32_region_util import Topology, get_nodes_in_region
from .batch_exe import execute_batch_command
@@ -43,6 +43,11 @@ def calculate_demand_to_region(name: str, demand: float, region: str) -> dict[st
return calculate_demand_to_nodes(name, demand, nodes)
def calculate_demand_to_network(name: str, demand: float) -> dict[str, float]:
nodes = get_nodes(name)
return calculate_demand_to_nodes(name, demand, nodes)
def distribute_demand_to_nodes(name: str, demand: float, nodes: list[str], type: str = DISTRIBUTION_TYPE_ADD) -> ChangeSet:
if len(nodes) == 0 or demand == 0.0:
return ChangeSet()

View File

@@ -5854,15 +5854,26 @@ class TestApi:
self.leave(p)
# 33 district_metering_area
def test_calculate_district_metering_area(self):
p = 'test_calculate_district_metering_area'
def test_calculate_demand_to_network(self):
p = 'test_calculate_demand_to_network'
read_inp(p, f'./inp/net3.inp', '3')
open_project(p)
dmas = calculate_district_metering_area(p, get_nodes(p), 3)
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
def test_calculate_district_metering_area_for_nodes(self):
p = 'test_calculate_district_metering_area_for_nodes'
read_inp(p, f'./inp/net3.inp', '3')
open_project(p)
dmas = calculate_district_metering_area_for_nodes(p, get_nodes(p), 3)
assert len(dmas) == 3
assert dmas[0] == ['173', '184', '185', '199', '2', '201', '203', '205', '206', '207', '208', '209', '211', '213', '215', '217', '219', '225', '229', '231', '237', '239', '241', '243', '247', '249', '251', '253', '255', '273', '275', '50']
assert dmas[1] == ['1', '10', '101', '103', '109', '111', '113', '161', '163', '164', '166', '167', '169', '171', '179', '181', '183', '187', '189', '191', '193', '195', '197', '204', '265', '267', '269', '271', '35', '40', 'Lake']

View File

@@ -1009,7 +1009,7 @@ def calculate_demand_to_region(name: str, demand: float, region: str) -> dict[st
return api.calculate_demand_to_region(name, demand, region)
def calculate_demand_to_network(name: str, demand: float) -> dict[str, float]:
return {}
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)