Procházet zdrojové kódy

mxg:add is_source param to sys_direction calc

mengxiangge před 5 roky
rodič
revize
0246436ab1

+ 3 - 2
src/system_relation/calc_flowdirection.py

@@ -18,7 +18,7 @@ def calc(block_datas,source_datas):
 	g = nx.Graph()
 	for item in block_datas:
 		item.direction=None
-		g.add_edge(item.id1,item.id2);
+		g.add_edge(item.id1,item.id2)
 	G = g.to_directed()
 	# get leaves
 	leaves=list(v for v,d in G.out_degree() if d==1)
@@ -26,6 +26,7 @@ def calc(block_datas,source_datas):
 	try:
 		for i in range(len(roots)):
 			root=roots[i]
+			sign=1 if source_datas[i].is_source else -1
 			for leaf in leaves:
 				paths = nx.all_simple_paths(G, root, leaf)
 				for path in paths:
@@ -34,7 +35,7 @@ def calc(block_datas,source_datas):
 						continue
 					# set path direction
 					for j in range(len(path) - 1):
-						G_new.add_edge(path[j], path[j + 1],weight=(j))
+						G_new.add_edge(path[j], path[j + 1],weight=(j*sign))
 			# add source direct to source path.
 			for j in range(i + 1, len(roots)):
 				next_root=roots[j]

+ 10 - 7
src/system_relation/systemdatautils.py

@@ -28,12 +28,13 @@ def get_project_models(project_id,building_id):
 		"id,name,local_id,local_name,sequence_id,model_id,building_id,project_id " \
 		"from floor " \
 		"where project_id='%s' " \
-		"order by sequence_id desc"\
-		%(project_id)
-
-		#"and ('%s' is null or building_id='%s') " \
+		"and ('%s' is null or building_id='%s') " \
+		"order by sequence_id desc" \
+		% (project_id, building_id, building_id)
 		# "order by sequence_id desc"\
-		# %(project_id,building_id,building_id)
+		# %(project_id)
+
+
 	COMPONENT_KEYS = [
 		'id',
 		'name',
@@ -289,7 +290,7 @@ def get_connected_block_data(project_id,building_id,block_id,system_name,domain)
 	element_data.extend(get_dicdata(sql, KEYS))
 	element_data = list(map(systemutils.dic2obj, element_data))
 	return element_data
-def get_connected_block_source_data(project_id,building_id,block_id,system_name,domain):
+def get_connected_block_source_data(project_id,building_id,block_id,system_name,domain,is_source):
 	'''
 	Get all the connected_block source .
 	:param project_id:
@@ -303,7 +304,8 @@ def get_connected_block_source_data(project_id,building_id,block_id,system_name,
 		  "and mep_system_type='%s'" \
 		  "and domain='%s'" \
 		  "and ('%s' is null or building_id='%s')" \
-		  % (project_id,block_id,system_name,domain,building_id,building_id)
+		  "and is_source=%s" \
+		  % (project_id,block_id,system_name,domain,building_id,building_id,is_source)
 	KEYS = [
 		'id',
 		'project_id',
@@ -313,6 +315,7 @@ def get_connected_block_source_data(project_id,building_id,block_id,system_name,
 		'mep_system_type',
 		'domain',
 		'building_id',
+		'is_source',
 	]
 	element_data.extend(get_dicdata(sql, KEYS))
 	element_data = list(map(systemutils.dic2obj, element_data))

+ 7 - 7
src/system_relation/systemgraph_display.py

@@ -62,8 +62,8 @@ def show_connected_block(block_datas):
 	model_dic = {}
 	floor_data_dic = {}
 	for block_data in block_datas:
-		v1=get_connected_info(model_dic,floor_data_dic,block_data.project_id,block_data.model_id1,block_data.type1,block_data.id1)
-		v2 = get_connected_info(model_dic,floor_data_dic,block_data.project_id,block_data.model_id2, block_data.type2, block_data.id2)
+		v1=get_connected_info(model_dic,floor_data_dic,block_data,block_data.model_id1,block_data.type1,block_data.id1)
+		v2 = get_connected_info(model_dic,floor_data_dic,block_data,block_data.model_id2, block_data.type2, block_data.id2)
 		direction=block_data.direction
 		if direction==1 or direction==0:
 			g.add_edge(v1,v2)
@@ -72,20 +72,20 @@ def show_connected_block(block_datas):
 	nx.draw_planar(g, with_labels=True, font_size=8, with_label=True)
 	plt.show()
 
-def get_connected_info(model_dic,floor_data_dic,project_id,model_id,type,id):
+def get_connected_info(model_dic,floor_data_dic,block_data,model_id,type,id):
 	'''
 	get graphvertex display info
 	:param model_dic:
 	:param floor_data_dic:
-	:param project_id:
+	:param block_data:
 	:param model_id:
 	:param type:
 	:param id:
 	:return:
 	'''
 	if model_id not in model_dic:
-		models = systemdatautils.get_project_models(project_id)
-		ids=[i.file_id for i in models]
+		models = systemdatautils.get_project_models(block_data.project_id,block_data.building_id)
+		ids=[i.model_id for i in models]
 		model_dic=dict(zip(ids,models))
 	model=model_dic[model_id]
 	if model_id not in floor_data_dic:
@@ -95,5 +95,5 @@ def get_connected_info(model_dic,floor_data_dic,project_id,model_id,type,id):
 	datas=list(i for i in floor_datas if i.type==type and i.id==id)
 	str0=id
 	if datas:
-		str0=str(model.floor_name)+':'+str(datas[0].source_id)
+		str0=str(model.local_name)+':'+str(datas[0].source_id)
 	return str0

+ 2 - 1
src/system_relation/test_flowdirection.py

@@ -7,8 +7,9 @@ if __name__=="__main__":
 	system_name = "冷冻水供水管"
 	domain = "DomainPiping"
 	building_id = 'Bd11010100153c05821ed8fd11e9b8f2d79d0a5b4bf6'
+	is_source=True
 	block_datas= systemdatautils.get_connected_block_data(project_id,building_id, block_id,system_name,domain)
-	source_datas= systemdatautils.get_connected_block_source_data(project_id,building_id, block_id,system_name,domain)
+	source_datas= systemdatautils.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)
 	systemdatautils.update_connected_block_data(block_datas)
 	systemgraph_display.show_connected_block(block_datas)