Support SA
This commit is contained in:
@@ -2,18 +2,13 @@ import sys
|
||||
import json
|
||||
from queue import Queue
|
||||
from .database import *
|
||||
from .s0_base import get_node_links, get_link_nodes
|
||||
from .s0_base import get_node_links, get_link_nodes, get_nodes
|
||||
|
||||
sys.path.append('..')
|
||||
from epanet.epanet import run_project
|
||||
|
||||
def calculate_service_area(name: str, time_index: int = 0) -> dict[str, Any]:
|
||||
inp = json.loads(run_project(name))
|
||||
|
||||
time_count = len(inp['node_results'][0]['result'])
|
||||
if time_index >= time_count:
|
||||
return {}
|
||||
|
||||
def _calculate_service_area(name: str, inp, time_index: int = 0) -> dict[str, list[str]]:
|
||||
sources : dict[str, list[str]] = {}
|
||||
for node_result in inp['node_results']:
|
||||
result = node_result['result'][time_index]
|
||||
@@ -43,6 +38,8 @@ def calculate_service_area(name: str, time_index: int = 0) -> dict[str, Any]:
|
||||
elif node2 == cursor and link_flows[link] < 0:
|
||||
queue.put(node1)
|
||||
|
||||
return sources
|
||||
|
||||
# calculation concentration
|
||||
concentration_map: dict[str, dict[str, float]] = {}
|
||||
node_wip: list[str] = []
|
||||
@@ -85,6 +82,8 @@ def calculate_service_area(name: str, time_index: int = 0) -> dict[str, Any]:
|
||||
break
|
||||
if ready:
|
||||
for link_node in up_link_nodes:
|
||||
if link_node[1] not in concentration_map.keys():
|
||||
continue
|
||||
for source, concentration in concentration_map[link_node[1]].items():
|
||||
concentration_map[node][source] += concentration * abs(link_flows[link_node[0]])
|
||||
|
||||
@@ -117,3 +116,17 @@ def calculate_service_area(name: str, time_index: int = 0) -> dict[str, Any]:
|
||||
sas.append({ 'source': source, 'nodes': nodes })
|
||||
|
||||
return { 'service_areas' : sas, 'concentrations': concentration_map }
|
||||
|
||||
|
||||
def calculate_service_area(name: str) -> list[dict[str, list[str]]]:
|
||||
inp = json.loads(run_project(name))
|
||||
|
||||
result: list[dict[str, list[str]]] = []
|
||||
|
||||
time_count = len(inp['node_results'][0]['result'])
|
||||
|
||||
for i in range(time_count):
|
||||
sas = _calculate_service_area(name, inp, i)
|
||||
result.append(sas)
|
||||
|
||||
return result
|
||||
|
||||
Reference in New Issue
Block a user