sys_direction.md 2.6 KB

管网系统确定流向

前置条件

  1. 通过管网系统分块计算;
  2. 指定源。

处理方式

  1. 从connected_block表中取出所有关系,构建无向图
  2. 从connected_block_source表中取出所有的源
  3. 由图算法确定流向,构建有方向的图
  4. 更新connected_block表

函数

create or replace function public.sys_direction(project_id character varying,block_id character varying, system_name character varying,domain character varying) returns boolean
as
$$
from relations.src.system_relation import calc_flowdirection, systemdatautils,systemutils

def get_connected_block_data(project_id,block_id,system_name,domain):
  sql ="select * from revit_calc.connected_block " \
		  "where project_id=$1" \
		  "and block_id=$2" \
		  "and mep_system_type=$3" \
		  "and domain=$4" \
		  "order by cast(depth as int) asc"
  join_plan=plpy.prepare(sql,["text","text","text","text"])
  data=join_plan.execute([project_id,block_id,system_name,domain])
  objs=systemutils.sqldata2objlist(data)
  return objs

def get_connected_block_source_data(project_id,block_id,system_name,domain):
  sql = "select * from revit_calc.connected_block_source " \
		  "where project_id=$1" \
		  "and block_id=$2" \
		  "and mep_system_type=$3" \
		  "and domain=$4"
  join_plan=plpy.prepare(sql,["text","text","text","text"])
  data=join_plan.execute([project_id,block_id,system_name,domain])
  objs=systemutils.sqldata2objlist(data)
  return objs

def update_connected_block_data(block_data):
  direction=block_data.direction
  depth=block_data.depth
  plpy.info(depth)
  id=block_data.id
  sql="update revit_calc.connected_block set direction=$1,depth=$2 where id=$3"
  join_plan=plpy.prepare(sql,['int','int','int'])
  join_plan.execute([direction,depth,id])

try:
  # 将下面对数据库的操作作为一个事务, 出异常则自动rollback
  with plpy.subtransaction():
    block_datas=get_connected_block_data(project_id, block_id,system_name,domain)
    source_datas=get_connected_block_source_data(project_id, block_id,system_name,domain)
    block_datas= calc_flowdirection.calc(block_datas, source_datas)
    for block_data in block_datas:
      update_connected_block_data(block_data)
except Exception as e:
    plpy.warning(e)
    return False
else:
    return True
$$
LANGUAGE 'plpython3u' VOLATILE;

select public.sys_direction('Pj1101010015','0','冷冻水供水管','DomainPiping')

输入

1. 项目id
2. 需要计算的块id    
3. 需要计算的系统名称
4. 需要计算的管道系统类型,枚举(水管或风管):DomainPiping,DomainHvac

返回结果

True    成功
False   失败