refactor(db)!: finalize pooled WNDB v2 migration
This commit is contained in:
@@ -1,8 +1,11 @@
|
||||
from app.native.wndb.commands.executor import execute_batch_command
|
||||
from app.native.wndb.core.database import ChangeSet
|
||||
from app.native.wndb.gis.region_geometry import Topology, get_nodes_in_region
|
||||
from app.native.wndb.model.demands import get_demand
|
||||
from app.native.wndb.model.elements import get_nodes, is_junction
|
||||
from app.native.wndb.gis.network_views import (
|
||||
get_junction_demands,
|
||||
sum_junction_base_demand,
|
||||
)
|
||||
from app.native.wndb.model.elements import get_nodes
|
||||
|
||||
|
||||
DISTRIBUTION_TYPE_ADD = 'ADD'
|
||||
@@ -28,7 +31,7 @@ def calculate_demand_to_nodes(name: str, demand: float, nodes: list[str]) -> dic
|
||||
|
||||
result: dict[str, float] = {}
|
||||
for node, value in t_nodes.items():
|
||||
if not is_junction(name, node):
|
||||
if value["type"] != "junction":
|
||||
continue
|
||||
demand_per_node = 0.0
|
||||
for link in value['links']:
|
||||
@@ -68,15 +71,19 @@ def distribute_demand_to_nodes(name: str, demand: float, nodes: list[str], type:
|
||||
demand_per_length = demand / length_sum
|
||||
|
||||
cs = ChangeSet()
|
||||
demands_by_junction = get_junction_demands(
|
||||
name,
|
||||
[node for node, value in t_nodes.items() if value["type"] == "junction"],
|
||||
)
|
||||
|
||||
for node, value in t_nodes.items():
|
||||
if not is_junction(name, node):
|
||||
if value["type"] != "junction":
|
||||
continue
|
||||
demand_per_node = 0.0
|
||||
for link in value['links']:
|
||||
demand_per_node += abs(t_links[link]['length']) * demand_per_length * 0.5
|
||||
|
||||
ds = get_demand(name, node)['demands']
|
||||
ds = demands_by_junction.get(node, [])
|
||||
if len(ds) == 0:
|
||||
ds = [{'demand': demand_per_node, 'pattern': None, 'category': None}]
|
||||
elif type == DISTRIBUTION_TYPE_ADD:
|
||||
@@ -92,13 +99,6 @@ def distribute_demand_to_region(name: str, demand: float, region: str, type: str
|
||||
nodes = get_nodes_in_region(name, region)
|
||||
return distribute_demand_to_nodes(name, demand, nodes, type)
|
||||
|
||||
def get_total_base_demand(name:str,region:str)->float:
|
||||
def get_total_base_demand(name: str, region: str) -> float:
|
||||
nodes = get_nodes_in_region(name, region)
|
||||
t_demands=0.0
|
||||
for node in nodes:
|
||||
if not is_junction(name, node):
|
||||
continue
|
||||
ds = get_demand(name, node)['demands']
|
||||
t_demands= t_demands+ds[0]['demand']
|
||||
|
||||
return t_demands
|
||||
return sum_junction_base_demand(name, nodes)
|
||||
|
||||
Reference in New Issue
Block a user