123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 |
- # -*- 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)
|