12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- import networkx as nx
- import matplotlib.pyplot as plt
- def show_system(system_graph):
- '''
- Show one system by pyplot.
- :param system_graph:
- :return:
- '''
- g=nx.Graph()
- for e in system_graph.system_edges:
- #g.add_edge(e.start_vertex.system_data.source_id,e.end_vertex.system_data.source_id)
- g.add_edge(e.start_vertex, e.end_vertex)
- nx.draw_shell(g,with_labels=True)
- plt.show()
- def show_floor(floor_graph):
- '''
- Show all system in this floor
- :param floor_graph:
- :return:
- '''
- for s in floor_graph.system_graphs:
- show_system(s)
- def show_project(project_graph):
- '''
- Show all grouped system in project.
- :param project_graph:
- :return:
- '''
- for g in project_graph.groupedsystemgraphs:
- show_groupedsystem(g)
- def show_groupedsystem(grouped_system_graph):
- '''
- Show one grouped system.
- :param grouped_system_graph:
- :return:
- '''
- g=nx.Graph()
- for s in grouped_system_graph.systemgraphs:
- for e in s.system_edges:
- g.add_edge(e.start_vertex, e.end_vertex)
- for e in grouped_system_graph.connectedges:
- g.add_edge(e.start_vertex, e.end_vertex)
- nx.draw_spring(g,with_labels=True,font_size=8,with_label=True)
- plt.show()
- from systemrelation import systemdatautils
- def show_connected_block(project_id,block_id):
- '''
- show connected block.
- :param project_id:
- :param block_id:
- :return:
- '''
- block_datas=systemdatautils.get_connected_block_data(project_id,block_id)
- g=nx.DiGraph()
- 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)
- direction=block_data.direction
- if direction==1 or direction==0:
- g.add_edge(v1,v2)
- if direction==-1 or direction==0:
- g.add_edge(v2,v1)
- 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):
- '''
- get graphvertex display info
- :param model_dic:
- :param floor_data_dic:
- :param project_id:
- :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]
- model_dic=dict(zip(ids,models))
- model=model_dic[model_id]
- if model_id not in floor_data_dic:
- datas=systemdatautils.get_element_data(model_id)
- floor_data_dic[model_id]=datas
- floor_datas = floor_data_dic[model_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)
- return str0
|