Browse Source

Merge remote-tracking branch 'origin/master'

jxing 5 years ago
parent
commit
a8f0114ab4
2 changed files with 230 additions and 0 deletions
  1. 145 0
      datacenter/docs/sys_calc/sys_block.md
  2. 85 0
      datacenter/docs/sys_calc/sys_direction.md

+ 145 - 0
datacenter/docs/sys_calc/sys_block.md

@@ -0,0 +1,145 @@
+管网系统设备分块
+## 前置条件
+1. 项目下的模型文件已上传;
+2. 所有管网已正确连接;
+3. 相邻层立管开放端口坐标位置相等(距离差值不能超过0.01)
+4. (非强制)通过模型检查:连接件检查、系统类型名称检查、管网及相关设备检查、管段检查
+
+## 处理方式
+
+1. 获取所有当前项目project_id下的的有模型文件models; 表:revit.model_folder、revit.model_floor、revit.model_file
+2. 遍历models,获取model层的系统图systemGraphs;
+    1. 获取model下且domain、systemName符合条件的connector,connectors,表:revit.connector
+    2. 获取model下所有的设备、部件、其它、风管、水管,表:revit.equipment、revit.component、revit.other、revit.pipe、revit.duct
+    3. 获取model层的系统图数据,存在systemGraphs中。
+3. 获取systemGraphs中所有的开放立管,按开放立管对连接的系统图systemGraphs进行合并;
+4. 删除本项目下project_id、指定系统类型systemName,指定域domain,所有数据,表revit_calc.connected_block
+4. 将合并后的数据存入数据库,表:revit_calc.connected_block。
+
+
+# 函数
+```
+create or replace function public.sys_block(project_id character varying,building_id character varying,system_name character varying,domain character varying) returns boolean
+as
+$$
+from relations.src.system_relation import systemutils, graph_model
+
+def get_models(project_id,building_id):
+  sql ="select " \
+		"id,name,local_id,local_name,sequence_id,model_id,building_id,project_id " \
+		"from floor " \
+		"where project_id=$1 " \
+		"and ($2 is null or building_id=$2) " \
+		"order by sequence_id desc"
+  join_plan=plpy.prepare(sql,["text","text"])
+  data=join_plan.execute([project_id,building_id])
+  models=systemutils.sqldata2objlist(data)
+  return models
+
+def get_connectors(model_id, system_name, domain):
+  sql = "SELECT * FROM revit.connector where model_id=$1 and mep_system_type=$2 and domain=$3"
+  join_plan=plpy.prepare(sql,["text","text","text"])
+  data=join_plan.execute([model_id, system_name, domain])
+  floor_connectors=systemutils.sqldata2objlist(data)
+  return floor_connectors
+def get_elements(model_id):
+  floor_elements=[]
+  sql="select * from revit.equipment where model_id=$1"
+  join_plan=plpy.prepare(sql,["text"])
+  data=join_plan.execute([model_id])
+  floor_elements.extend(systemutils.sqldata2objlist(data))
+
+  sql="select * from revit.component where model_id=$1"
+  join_plan=plpy.prepare(sql,["text"])
+  data=join_plan.execute([model_id])
+  floor_elements.extend(systemutils.sqldata2objlist(data))
+
+  sql="select * from revit.other where model_id=$1"
+  join_plan=plpy.prepare(sql,["text"])
+  data=join_plan.execute([model_id])
+  floor_elements.extend(systemutils.sqldata2objlist(data))
+
+  sql="select * from revit.join_object where model_id=$1"
+  join_plan=plpy.prepare(sql,["text"])
+  data=join_plan.execute([model_id])
+  floor_elements.extend(systemutils.sqldata2objlist(data))
+
+  sql="select * from revit.pipe where model_id=$1"
+  join_plan=plpy.prepare(sql,["text"])
+  data=join_plan.execute([model_id])
+  floor_elements.extend(systemutils.sqldata2objlist(data))
+
+  sql="select * from revit.duct where model_id=$1"
+  join_plan=plpy.prepare(sql,["text"])
+  data=join_plan.execute([model_id])
+  floor_elements.extend(systemutils.sqldata2objlist(data))
+  return floor_elements
+def delete_block_data(project_id,building_id,system_name,domain):
+  sql="delete from revit_calc.connected_block " \
+		  "where project_id=$1"\
+		  "and mep_system_type=$2" \
+		  "and domain=$3" \
+		  "and ($4 is null or building_id=$4)"
+  join_plan=plpy.prepare(sql,["text","text","text","text"])
+  join_plan.execute([project_id,system_name,domain,building_id])
+def save_edge_data(edge,block_id,system_name,domain,building_id):
+  vertex1=edge.start_vertex
+  vertex2=edge.end_vertex
+  c1=vertex1.system_data
+  c2=vertex2.system_data
+  floor1 = vertex1.get_parent_floor()
+  floor2 = vertex2.get_parent_floor()
+  model1= floor1.model
+  model2 = floor2.model
+  sql="insert into revit_calc.connected_block" \
+    "(id1,type1,model_id1,id2,type2,model_id2,block_id,project_id,mep_system_type,domain,building_id) values " \
+    "($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11)"
+  join_plan=plpy.prepare(sql,["text","text","text","text","text","text","text","text","text","text","text"])
+  join_plan.execute([c1.id,c1.type,model1.model_id,c2.id,c2.type,model2.model_id,block_id,model1.project_id,floor1.system_name,floor1.domain,building_id])
+
+try:
+  # 将下面对数据库的操作作为一个事务, 出异常则自动rollback
+  with plpy.subtransaction():
+    models=get_models(project_id,building_id)
+    floorgraphs=[]
+    for model in models:
+      floor_connectors=get_connectors(model.model_id, system_name, domain)
+      floor_elements=get_elements(model.model_id)
+      g= graph_model.FloorGraph(model, system_name, domain,floor_connectors,floor_elements)
+      g.get_floor_graphs()
+      floorgraphs.append(g)
+    projectgraph= graph_model.combine_systemgraph(project_id,floorgraphs)
+
+    delete_block_data(project_id,building_id, system_name, domain)
+    block_id=0
+    for g in projectgraph.groupedsystemgraphs:
+      for s in g.systemgraphs:
+        for e in s.system_edges:
+          save_edge_data(e, block_id,system_name,domain,building_id)
+      for e in g.connectedges:
+        save_edge_data(e,block_id,system_name,domain,building_id)
+      block_id+=1
+except Exception as e:
+    plpy.warning(e)
+    return False
+else:
+    return True
+$$
+LANGUAGE 'plpython3u' VOLATILE;
+
+select public.sys_block('Pj1101010015','Bd11010100153c05821ed8fd11e9b8f2d79d0a5b4bf6','冷冻水供水管','DomainPiping')
+```
+
+## 输入
+    1. 项目id
+    2. 需要计算的building_id,如果没有提供时请传入null,不能传""
+    3. 需要计算的系统名称
+    4. 需要计算的管道系统类型,枚举(水管或风管):DomainPiping,DomainHvac
+## 返回结果
+    True    成功
+    False   失败
+    
+## 结果展示
+![原模型图](https://note.youdao.com/yws/public/resource/4f363b5153dec1221ac59c1569282496/xmlnote/6B97DC93F07E4E909EC35C8A4836CA16/12986)
+![抽象后的图](https://note.youdao.com/yws/public/resource/4f363b5153dec1221ac59c1569282496/xmlnote/ADDD4317DDDF450DAA69D4084DDBC615/12984)
+![确定完流向的图](https://note.youdao.com/yws/public/resource/4f363b5153dec1221ac59c1569282496/xmlnote/C1C1B1EC272E4A66B06C298972636A87/13650)

+ 85 - 0
datacenter/docs/sys_calc/sys_direction.md

@@ -0,0 +1,85 @@
+管网系统确定流向
+## 前置条件
+
+1. 通过管网系统分块计算;
+2. 指定源。
+
+## 处理方式
+
+1. 从connected_block表中取出所有关系,构建无向图
+2. 从connected_block_source表中取出所有的源
+3. 由图算法确定流向,构建有方向的图
+4. 更新connected_block表
+
+
+# 函数
+```
+create or replace function public.sys_direction(project_id character varying,building_id character varying,block_id character varying, system_name character varying,domain character varying,is_source boolean default true) returns boolean
+as
+$$
+from relations.src.system_relation import calc_flowdirection, systemdatautils,systemutils
+
+def get_connected_block_data(project_id,building_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" \
+		  "and ($5 is null or building_id=$5)" \
+		  "order by cast(depth as int) asc"
+  join_plan=plpy.prepare(sql,["text","text","text","text","text"])
+  data=join_plan.execute([project_id,block_id,system_name,domain,building_id])
+  objs=systemutils.sqldata2objlist(data)
+  return objs
+
+def get_connected_block_source_data(project_id,building_id,block_id,system_name,domain,is_source):
+  sql = "select * from revit_calc.connected_block_source " \
+		  "where project_id=$1" \
+		  "and block_id=$2" \
+		  "and mep_system_type=$3" \
+		  "and domain=$4" \
+		  "and ($5 is null or building_id=$5)" \
+		  "and is_source=$6"
+  join_plan=plpy.prepare(sql,["text","text","text","text","text","boolean"])
+  data=join_plan.execute([project_id,block_id,system_name,domain,building_id,is_source])
+  objs=systemutils.sqldata2objlist(data)
+  return objs
+
+def update_connected_block_data(block_data):
+  direction=block_data.direction
+  depth=block_data.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,building_id, block_id,system_name,domain)
+    source_datas=get_connected_block_source_data(project_id,building_id, block_id,system_name,domain,is_source)
+    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','Bd11010100153c05821ed8fd11e9b8f2d79d0a5b4bf6','0','冷冻水供水管','DomainPiping',true)
+```
+
+## 输入
+    1. 项目id
+    2. 需要计算的building_id,如果没有提供时请传入null,不能传""
+    3. 需要计算的块id    
+    4. 需要计算的系统名称
+    5. 需要计算的管道系统类型,枚举(水管或风管):DomainPiping,DomainHvac    
+    6. 跟据源或端计算:bool。true表示源,false表示端
+## 返回结果
+    True    成功
+    False   失败
+