test.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. # -*- coding: utf-8 -*-
  2. import json
  3. import sys
  4. import psycopg2
  5. from src.saga_mark.check_saga_mark import check_saga_mark
  6. involved_model_keys = [
  7. 'id',
  8. 'floor_name',
  9. 'project_id',
  10. 'folder_id',
  11. 'fid',
  12. 'accept_time',
  13. 'version',
  14. 'note',
  15. 'user_id',
  16. 'user_name',
  17. 'log',
  18. 'url',
  19. 'md5',
  20. 'status'
  21. ]
  22. level_keys = [
  23. 'id',
  24. 'model_id',
  25. 'name',
  26. 'elevation',
  27. 'last_update',
  28. 'create_time',
  29. 'type',
  30. 'revit_id',
  31. 'source_id',
  32. ]
  33. def get_data(sql):
  34. global connection, cursor
  35. record = []
  36. try:
  37. connection = psycopg2.connect(
  38. database='datacenter',
  39. user='postgres',
  40. password='123456',
  41. host='192.168.20.234',
  42. port='5432'
  43. )
  44. cursor = connection.cursor()
  45. cursor.execute(sql)
  46. record = cursor.fetchall()
  47. except (Exception, psycopg2.Error) as error:
  48. print("Error while connecting to PostgreSQL", error)
  49. finally:
  50. if connection:
  51. cursor.close()
  52. connection.close()
  53. print('PostgreSQL connection is closed')
  54. return record
  55. def loads(x):
  56. x['location'] = json.loads(x['location'])
  57. return x
  58. def loads_curve(x):
  59. x['curve'] = json.loads(x['curve'])
  60. return x
  61. if __name__ == '__main__':
  62. involved_model_sql = "select * from revit.model_floor_file_func('Pj1101010015') where folder_id = " \
  63. "'bbe510dbe26011e999b69b669ea08505' and status in (3, 31, 4) "
  64. level_sql = "select * from revit.level where model_id = "
  65. columns_data = get_data(involved_model_sql)
  66. if len(columns_data) == 0:
  67. sys.exit()
  68. model_list = [dict(zip(involved_model_keys, item)) for item in columns_data]
  69. level_data = dict()
  70. for item in model_list:
  71. current_level_sql = level_sql + '\'{model_id}\''.format(model_id=item.get('fid'))
  72. single_model_level = get_data(current_level_sql)
  73. single_model_level = [dict(zip(level_keys, item)) for item in single_model_level]
  74. level_data[item.get('fid')] = single_model_level
  75. print(check_saga_mark(model_list, level_data))