|
@@ -927,3 +927,309 @@ except Exception as e:
|
|
|
$BODY$
|
|
|
LANGUAGE plpython3u VOLATILE
|
|
|
COST 100
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+CREATE OR REPLACE FUNCTION "public"."sys_block"("project_id" varchar, "building_id" varchar, "system_name" varchar, "domain" varchar)
|
|
|
+RETURNS "pg_catalog"."bool"
|
|
|
+AS $BODY$
|
|
|
+
|
|
|
+from relations.src.system_relation import systemutils, graph_model
|
|
|
+
|
|
|
+# 获取楼层上的ModelId信息点
|
|
|
+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])
|
|
|
+
|
|
|
+
|
|
|
+def get_real_model_id(models):
|
|
|
+ sql_str = ""
|
|
|
+ for model in models:
|
|
|
+ sql_str += '\'' + model.model_id + '\','
|
|
|
+ if sql_str.endswith(','):
|
|
|
+ sql_str = sql_str[0:-1]
|
|
|
+ real_model_id_plan = plpy.prepare("select mid.id, file.id fid, file.status from (select id, current_model_id from revit.model_floor where id in ({0})) mid left join revit.model_file file on mid.current_model_id = file.id".format(sql_str), [])
|
|
|
+ real_model_ids = real_model_id_plan.execute([])
|
|
|
+ floor_model_dict = dict()
|
|
|
+ for row in real_model_ids:
|
|
|
+ floor_id = row.get('id')
|
|
|
+ model_id = row.get('fid')
|
|
|
+ status = row.get('status')
|
|
|
+ if status == 4:
|
|
|
+ floor_model_dict[floor_id] = model_id
|
|
|
+ for model in models:
|
|
|
+ if model.model_id not in floor_model_dict:
|
|
|
+ del models[model.model_id]
|
|
|
+ else:
|
|
|
+ model.model_id = floor_model_dict[model.model_id]
|
|
|
+
|
|
|
+
|
|
|
+try:
|
|
|
+ # 将下面对数据库的操作作为一个事务, 出异常则自动rollback
|
|
|
+ with plpy.subtransaction():
|
|
|
+ models = get_models(project_id, building_id)
|
|
|
+ floorgraphs = []
|
|
|
+ plpy.info(len(models))
|
|
|
+ get_real_model_id(models)
|
|
|
+ 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)
|
|
|
+ plpy.info("reached")
|
|
|
+ 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
|
|
|
+$BODY$
|
|
|
+LANGUAGE plpython3u VOLATILE
|
|
|
+COST 100
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+CREATE OR REPLACE FUNCTION "public"."sys_direction"("project_id" varchar, "building_id" varchar, "block_id" varchar, "system_name" varchar, "domain" varchar, "is_source" bool=true)
|
|
|
+ RETURNS "pg_catalog"."bool" AS $BODY$
|
|
|
+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"
|
|
|
+ plpy.info(sql+str(direction)+str(depth)+str(id))
|
|
|
+ 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
|
|
|
+$BODY$
|
|
|
+ LANGUAGE plpython3u VOLATILE
|
|
|
+ COST 100
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+CREATE OR REPLACE FUNCTION "pointconfig"."rel_description_param_key"("word" _varchar)
|
|
|
+ RETURNS "pg_catalog"."text" AS $BODY$
|
|
|
+
|
|
|
+import json
|
|
|
+from kwextraction.extraction import extractor
|
|
|
+
|
|
|
+
|
|
|
+def get_key_words(text_list):
|
|
|
+ return extractor(text_list)
|
|
|
+
|
|
|
+try:
|
|
|
+ arr = list()
|
|
|
+ for item in get_key_words(word):
|
|
|
+ item.pop('str')
|
|
|
+ arr.append(item)
|
|
|
+ return json.dumps(arr, sort_keys=True, indent=0, ensure_ascii=False)
|
|
|
+except Exception as e:
|
|
|
+ plpy.warning(e)
|
|
|
+ return "error"
|
|
|
+$BODY$
|
|
|
+ LANGUAGE plpython3u VOLATILE
|
|
|
+ COST 100
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|