Browse Source

mxg:save calc result to db

mengxiangge 5 năm trước cách đây
mục cha
commit
6652d63409
4 tập tin đã thay đổi với 45 bổ sung5 xóa
  1. 5 4
      systemrelation/graph_model.py
  2. 4 1
      systemrelation/system_test.py
  3. 14 0
      systemrelation/systemdatautils.py
  4. 22 0
      test.py

+ 5 - 4
systemrelation/graph_model.py

@@ -59,15 +59,16 @@ class FloorGraph:
 	May contain one or more SystemGraph.
 	"""
 
-	def __init__(self, floor_id, system_name, domain):
-		self.floor_id = floor_id
+	def __init__(self, project_id,model_id, system_name, domain):
+		self.project_id=project_id
+		self.model_id = model_id
 		self.system_name = system_name
 		self.domain = domain
-		floor_connectors = systemdatautils.get_connectors_data(floor_id, system_name, domain)
+		floor_connectors = systemdatautils.get_connectors_data(model_id, system_name, domain)
 		floor_connectors = systemutils.sort_connectors(floor_connectors)
 		floor_connectors = list(map(systemutils.add_attr_is_used, floor_connectors))
 		self.connector_data = (floor_connectors)
-		self.element_data = systemutils.list_to_dict(systemdatautils.get_element_data(floor_id))
+		self.element_data = systemutils.list_to_dict(systemdatautils.get_element_data(model_id))
 		self.system_graphs = []
 
 	def get_floor_graphs(self):

+ 4 - 1
systemrelation/system_test.py

@@ -1,10 +1,13 @@
 from systemrelation import graph_model
 from systemrelation import systemgraph_display
+from systemrelation import systemdatautils
 
 if '__main__'==__name__:
+	project_id=""
 	model_id="0ebf6b7ae97211e9a27c57c0742fab4c"
 	system_name="冷冻水供水管"
 	domain="DomainPiping"
-	g=graph_model.FloorGraph(model_id,system_name,domain)
+	g=graph_model.FloorGraph(project_id,model_id,system_name,domain)
 	g.get_floor_graphs()
+	systemdatautils.save_floor_graph_data(g)
 	systemgraph_display.show_floor(g)

+ 14 - 0
systemrelation/systemdatautils.py

@@ -144,6 +144,20 @@ def get_connectors_data(model_id, system_name, domain):
 	connector_data.extend(get_dicdata(connector_sql, CONNECTOR_KEYS))
 	connector_data=list(map(systemutils.dic2obj,connector_data))
 	return connector_data
+def save_floor_graph_data(floor_graph):
+	block_id=0
+	for s in floor_graph.system_graphs:
+		sava_system_graph_data(s,block_id,floor_graph.project_id)
+		block_id+=1
+def sava_system_graph_data(system_graph,block_id,project_id):
+	for e in system_graph.system_edges:
+		save_connected_block(e.start_vertex.system_data,e.end_vertex.system_data,block_id,project_id)
+def save_connected_block(vertex1,vertex2,block_id,project_id):
+	sql="insert into revit.connected_block" \
+		"(id1,type1,model_id1,id2,type2,model_id2,block_id,project_id) values " \
+		"('%s','%s','%s','%s','%s','%s','%s','%s')"\
+		%(vertex1.id,vertex1.type,vertex1.model_id,vertex2.id,vertex2.type,vertex2.model_id,block_id,project_id)
+	data = test.save_data(sql)
 if '__main__'==__name__:
 	model_id="cf4e11a0e25811e999b6dbc4c75fa946"
 	system_name="喷淋管"

+ 22 - 0
test.py

@@ -6,7 +6,29 @@ import psycopg2
 
 from adjacent import calc_adjacent_relation
 
+def save_data(sql):
+    record = []
+    try:
+        connection = psycopg2.connect(
+            database='datacenter',
+            user='postgres',
+            password='123456',
+            host='192.168.20.235',
+            port='5432'
+        )
+        cursor = connection.cursor()
+        print(sql)
+        cursor.execute(sql)
+    except (Exception, psycopg2.Error) as error:
+        print("Error while connecting to PostgreSQL", error)
+    finally:
+        if (connection):
+            cursor.close()
+            connection.commit()
+            connection.close()
+            print('PostgreSQL connection is closed')
 
+    return record
 def get_data(sql):
     record = []
     try: