# -*- coding: utf-8 -*- import json import psycopg2 #from business_space_adjacent import calc_adjacent_relation def get_online_conn(): return psycopg2.connect( database='datacenter', user='postgres', password='123qwe!@#', host='47.94.89.44', port='5432' ) def get_test_conn(): return psycopg2.connect( database='datacenter', user='postgres', password='123456', host='172.16.44.234', port='5432' ) def save_data(sql): record = [] try: connection = get_test_conn() 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 = get_online_conn() 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__': foo = [2, 18, 9, 22, 17, 24, 8, 12, 27] my_map = dict() i = 1 print(i if (i %2 == 0) else i/2 for i in foo) # 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)