123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- # -*- coding: utf-8 -*-
- import json
- 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.234',
- 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:
- connection = psycopg2.connect(
- database='datacenter',
- user='postgres',
- password='123456',
- host='192.168.20.234',
- port='5432'
- )
- cursor = connection.cursor()
- print(sql)
- cursor.execute(sql)
- record = cursor.fetchall()
- except (Exception, psycopg2.Error) as error:
- print("Error while connecting to PostgreSQL", error)
- finally:
- if (connection):
- cursor.close()
- connection.close()
- print('PostgreSQL connection is closed')
- return record
- def loads(x):
- x['location'] = json.loads(x['location'])
- return x
- def loads_curve(x):
- x['curve'] = json.loads(x['curve'])
- return x
- if __name__ == '__main__':
- segment_sql = "SELECT * FROM revit.boundary_segment where model_id = '8544a3c3cd2611e99abc839db1015353'"
- wall_sql = "SELECT * FROM revit.wall where model_id = '8544a3c3cd2611e99abc839db1015353'"
- v_wall_sql = "SELECT * FROM revit.virtual_wall where model_id = '8544a3c3cd2611e99abc839db1015353'"
- columns_sql = "SELECT * FROM revit.column where model_id = '8544a3c3cd2611e99abc839db1015353'"
- segment_data = get_data(segment_sql)
- wall_data = get_data(wall_sql)
- v_wall_data = get_data(v_wall_sql)
- columns_data = get_data(columns_sql)
- SEGMENT_KEYS = [
- 'id',
- 'model_id',
- 'belong',
- 'belong_type',
- 'curve',
- 'space_id',
- 'group_index',
- 'sequence',
- 'reference',
- 'revit_id',
- 'type',
- ]
- WALL_KEYS = [
- 'id',
- 'model_id',
- 'level_id',
- 'width',
- 'location',
- 'outline',
- 'last_update',
- 'create_time',
- 'name',
- 'source_id',
- 'revit_id',
- 'type',
- ]
- V_WALL_KEYS = [
- 'id',
- 'model_id',
- 'location',
- 'outline',
- 'last_update',
- 'create_time',
- 'name',
- 'source_id',
- 'revit_id',
- 'type',
- ]
- COLUMNS_KEYS = [
- 'id',
- 'model_id',
- 'location',
- 'outline',
- 'bounding',
- 'last_update',
- 'create_time',
- 'name',
- 'source_id',
- 'revit_id',
- 'type',
- ]
- segment_data = [dict(zip(SEGMENT_KEYS, item)) for item in segment_data]
- segment_data = list(map(loads_curve, segment_data))
- wall_data = [dict(zip(WALL_KEYS, item)) for item in wall_data]
- wall_data = list(map(loads, wall_data))
- v_wall_data = [dict(zip(V_WALL_KEYS, item)) for item in v_wall_data]
- v_wall_data = list(map(loads, v_wall_data))
- columns_data = [dict(zip(COLUMNS_KEYS, item)) for item in columns_data]
- columns_data = list(map(loads, columns_data))
- test_result = calc_adjacent_relation(
- segments=segment_data,
- walls=wall_data,
- v_walls=v_wall_data,
- columns=columns_data
- )
- for item in test_result:
- print(item)
|