12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- # -*- coding: utf-8 -*-
- import json
- import sys
- import psycopg2
- from src.saga_mark.check_saga_mark import check_saga_mark
- involved_model_keys = [
- 'id',
- 'floor_name',
- 'project_id',
- 'folder_id',
- 'fid',
- 'accept_time',
- 'version',
- 'note',
- 'user_id',
- 'user_name',
- 'log',
- 'url',
- 'md5',
- 'status'
- ]
- level_keys = [
- 'id',
- 'model_id',
- 'name',
- 'elevation',
- 'last_update',
- 'create_time',
- 'type',
- 'revit_id',
- 'source_id',
- ]
- def get_data(sql):
- global connection, cursor
- record = []
- try:
- connection = psycopg2.connect(
- database='datacenter',
- user='postgres',
- password='123456',
- host='192.168.20.234',
- port='5432'
- )
- cursor = connection.cursor()
- 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__':
- involved_model_sql = "select * from revit.model_floor_file_func('Pj1101010015') where folder_id = " \
- "'bbe510dbe26011e999b69b669ea08505' and status in (3, 31, 4) "
- level_sql = "select * from revit.level where model_id = "
- columns_data = get_data(involved_model_sql)
- if len(columns_data) == 0:
- sys.exit()
- model_list = [dict(zip(involved_model_keys, item)) for item in columns_data]
- level_data = dict()
- for item in model_list:
- current_level_sql = level_sql + '\'{model_id}\''.format(model_id=item.get('fid'))
- single_model_level = get_data(current_level_sql)
- single_model_level = [dict(zip(level_keys, item)) for item in single_model_level]
- level_data[item.get('fid')] = single_model_level
- print(check_saga_mark(model_list, level_data))
|