Browse Source

修复管网计算的bug

jxing 4 years ago
parent
commit
e582badccd

+ 85 - 14
src/system_relation/graph_model.py

@@ -132,6 +132,54 @@ class FloorGraph:
 				print("Next loop:",connector.source_id)
 		return self.system_graphs
 
+
+	def combine_single_model(self):
+		'''
+		将一层内, 计算连接在一起的构建合并成一个分块
+		:return:
+		'''
+		arr_tmp = []
+		for systemgraph in self.system_graphs:
+			set1 = set()
+			for edge in systemgraph.system_edges:
+				set1.add(str(edge.start_vertex))
+				set1.add(str(edge.end_vertex))
+			arr_tmp.append(set1)
+		# for idx1 in range(0, len(arr_tmp)):
+		# 	for idx2 in range(idx1 + 1, len(arr_tmp)):
+		# 		tmp_set = set.intersection(arr_tmp[idx1], arr_tmp[idx2])
+		# 		if len(tmp_set) > 0:
+		# 			arr_tmp[idx1].union(arr_tmp[idx2])
+		# 			edges1 = self.system_graphs[idx1].system_edges
+		# 			edges2 = self.system_graphs[idx2].system_edges
+		# 			edges1.append(edges2)
+		# 			# self.system_graphs.remove(idx2)
+		# 			del self.system_graphs[idx2]
+		# 			# arr_tmp.remove(arr_tmp[idx2])
+		# 			del arr_tmp[idx2]
+		idx1 = 0
+		while idx1 < len(arr_tmp):
+			merged = False
+			idx2 = idx1 + 1
+			while idx2 < len(arr_tmp):
+				tmp_set = set.intersection(arr_tmp[idx1], arr_tmp[idx2])
+				if len(tmp_set) > 0:
+					arr_tmp[idx1] = arr_tmp[idx1].union(arr_tmp[idx2])
+					edges1 = self.system_graphs[idx1].system_edges
+					edges2 = self.system_graphs[idx2].system_edges
+					edges1.extend(edges2)
+					# self.system_graphs.remove(idx2)
+					del self.system_graphs[idx2]
+					# arr_tmp.remove(arr_tmp[idx2])
+					del arr_tmp[idx2]
+					merged = True
+					break
+				idx2 = idx2 + 1
+			if not merged :
+				idx1 = idx1 + 1
+
+		return self.system_graphs
+
 	def get_path(self, connector, system_graph, graph_next_connectors):
 		"""
 		Get Graph_Edge start with connector,end with triple ,cross,equipment.
@@ -308,19 +356,42 @@ def combine_systemgraph(project_id,floorgraphs):
 			v2 = open_vertical_pipes[j]
 			if systemutils.is_xyz_equal(v1.connector.origin, v2.connector.origin):
 				group_pipes.append(v2)
+
+		# 获取竖管连接的其他楼层竖管
+		if len(group_pipes) < 2:
+			continue
+		for k in range(len(group_pipes)):
+			vertex = group_pipes[k]
+			# systemgraph = systemutils.get_specify_type_parent(vertex, graph_model.SystemGraph)
+			systemgraph = systemutils.get_system_graph_by_vertex(vertex)
+			if not systemgraph:
+				continue
+			if (k == 0):
+				temp_groupedsystemgraphs = graph_model.GroupedSystemGraph(systemgraph)
+			else:
+				prev_vertex = group_pipes[k - 1]
+				temp_groupedsystemgraphs.add_system(systemgraph)
+				temp_groupedsystemgraphs.add_edge(prev_vertex, vertex)
+		if temp_groupedsystemgraphs:
+			projectgraph.groupedsystemgraphs.append(temp_groupedsystemgraphs)
+
+	for floorgraph in floorgraphs:
+		for systemgraph in floorgraph.system_graphs:
+			temp_groupedsystemgraphs = graph_model.GroupedSystemGraph(systemgraph)
+			projectgraph.groupedsystemgraphs.append(temp_groupedsystemgraphs)
 			# combine systemgraph
-			for k in range(len(group_pipes)):
-				vertex = group_pipes[k]
-				systemgraph = systemutils.get_specify_type_parent(vertex, graph_model.SystemGraph)
-				if not systemgraph:
-					continue
-				projectgraph.remove_groupedsystemgraphs(systemgraph)
-				if (k == 0):
-					temp_groupedsystemgraphs = graph_model.GroupedSystemGraph(systemgraph)
-				else:
-					prev_vertex = group_pipes[k - 1]
-					temp_groupedsystemgraphs.add_system(systemgraph)
-					temp_groupedsystemgraphs.add_edge(prev_vertex, vertex)
-			if temp_groupedsystemgraphs:
-				projectgraph.groupedsystemgraphs.append(temp_groupedsystemgraphs)
+			# for k in range(len(group_pipes)):
+			# 	vertex = group_pipes[k]
+			# 	systemgraph = systemutils.get_specify_type_parent(vertex, graph_model.SystemGraph)
+			# 	if not systemgraph:
+			# 		continue
+			# 	projectgraph.remove_groupedsystemgraphs(systemgraph)
+			# 	if (k == 0):
+			# 		temp_groupedsystemgraphs = graph_model.GroupedSystemGraph(systemgraph)
+			# 	else:
+			# 		prev_vertex = group_pipes[k - 1]
+			# 		temp_groupedsystemgraphs.add_system(systemgraph)
+			# 		temp_groupedsystemgraphs.add_edge(prev_vertex, vertex)
+			# if temp_groupedsystemgraphs:
+			# 	projectgraph.groupedsystemgraphs.append(temp_groupedsystemgraphs)
 	return projectgraph

+ 11 - 1
src/system_relation/systemutils.py

@@ -6,7 +6,7 @@
 from functools import cmp_to_key
 import vg
 import json
-from relations.src.system_relation import revit_const
+from relations.src.system_relation import revit_const, graph_model
 
 
 def path2edge(elements):
@@ -116,3 +116,13 @@ def get_specify_type_parent(vertex, type):
 		parent=None
 
 	return parent
+
+
+def get_system_graph_by_vertex(vertex):
+	floor_graph = get_specify_type_parent(vertex, graph_model.FloorGraph)
+	for systemgraph in floor_graph.system_graphs:
+		for edge in systemgraph.system_edges:
+			if edge.start_vertex == vertex or edge.end_vertex == vertex:
+				floor_graph.system_graphs.remove(systemgraph)
+				return systemgraph
+

+ 8 - 3
src/system_relation/test_systemblock.py

@@ -36,13 +36,17 @@ Bd110229000100f824dc594111ea8fa09d5be066de42
 Bd11022900013df921f75b7511eaa6dfc5825970b94b
 Bd110229000134cd447c69a111eaa6dff75d40e4221d
 Bd11022900014c922a1469a111ea8fa0f5eef8d9657e
+
+select * from sys_block('Pj1101080251', 'Bd1101080251530c08b4e86540eba6d93ed783392028', '', '')
+
 '''
 
 if '__main__'==__name__:
-	project_id="Pj1101080002"
-	system_name="空调热水供水管"
+	project_id="Pj1101080251"
+	# system_name="空调热水供水管"
+	system_name="冷、热水供水管"
 	domain="DomainPiping"
-	building_id = 'Bd1101080002a0a394e30d1b4ebda204515c64f3082e'
+	building_id = 'Bd1101080251530c08b4e86540eba6d93ed783392028'
 	models= systemdatautils.get_project_models(project_id,building_id)
 	floorgraphs=[]
 	get_real_model_id(models)
@@ -51,6 +55,7 @@ if '__main__'==__name__:
 		floor_elements = systemdatautils.get_element_data(model.model_id)
 		g = graph_model.FloorGraph(model, system_name, domain, floor_connectors, floor_elements)
 		g.get_floor_graphs()
+		g.combine_single_model()
 		floorgraphs.append(g)
 	projectgraph= graph_model.combine_systemgraph(project_id,floorgraphs)
 	systemdatautils.save_project_data(projectgraph,system_name,domain,building_id)

+ 1 - 1
test.py

@@ -45,7 +45,7 @@ def save_data(sql):
 def get_data(sql):
     record = []
     try:
-        connection = get_test_conn()
+        connection = get_online_conn()
         cursor = connection.cursor()
         print(sql)
         cursor.execute(sql)