test.py 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. # -*- coding: utf-8 -*-
  2. import json
  3. import psycopg2
  4. from adjacent import calc_adjacent_relation
  5. def get_data(sql):
  6. record = []
  7. try:
  8. connection = psycopg2.connect(
  9. database='datacenter',
  10. user='postgres',
  11. password='123456',
  12. host='192.168.20.235',
  13. port='5432'
  14. )
  15. cursor = connection.cursor()
  16. print(sql)
  17. cursor.execute(sql)
  18. record = cursor.fetchall()
  19. except (Exception, psycopg2.Error) as error:
  20. print("Error while connecting to PostgreSQL", error)
  21. finally:
  22. if (connection):
  23. cursor.close()
  24. connection.close()
  25. print('PostgreSQL connection is closed')
  26. return record
  27. def loads(x):
  28. x['location'] = json.loads(x['location'])
  29. return x
  30. def loads_curve(x):
  31. x['curve'] = json.loads(x['curve'])
  32. return x
  33. if __name__ == '__main__':
  34. segment_sql = "SELECT * FROM revit.boundary_segment where model_id = '8544a3c3cd2611e99abc839db1015353'"
  35. wall_sql = "SELECT * FROM revit.wall where model_id = '8544a3c3cd2611e99abc839db1015353'"
  36. v_wall_sql = "SELECT * FROM revit.virtual_wall where model_id = '8544a3c3cd2611e99abc839db1015353'"
  37. columns_sql = "SELECT * FROM revit.column where model_id = '8544a3c3cd2611e99abc839db1015353'"
  38. segment_data = get_data(segment_sql)
  39. wall_data = get_data(wall_sql)
  40. v_wall_data = get_data(v_wall_sql)
  41. columns_data = get_data(columns_sql)
  42. SEGMENT_KEYS = [
  43. 'id',
  44. 'model_id',
  45. 'belong',
  46. 'belong_type',
  47. 'curve',
  48. 'space_id',
  49. 'group_index',
  50. 'sequence',
  51. 'reference',
  52. 'revit_id',
  53. 'type',
  54. ]
  55. WALL_KEYS = [
  56. 'id',
  57. 'model_id',
  58. 'level_id',
  59. 'width',
  60. 'location',
  61. 'outline',
  62. 'last_update',
  63. 'create_time',
  64. 'name',
  65. 'source_id',
  66. 'revit_id',
  67. 'type',
  68. ]
  69. V_WALL_KEYS = [
  70. 'id',
  71. 'model_id',
  72. 'location',
  73. 'outline',
  74. 'last_update',
  75. 'create_time',
  76. 'name',
  77. 'source_id',
  78. 'revit_id',
  79. 'type',
  80. ]
  81. COLUMNS_KEYS = [
  82. 'id',
  83. 'model_id',
  84. 'location',
  85. 'outline',
  86. 'bounding',
  87. 'last_update',
  88. 'create_time',
  89. 'name',
  90. 'source_id',
  91. 'revit_id',
  92. 'type',
  93. ]
  94. segment_data = [dict(zip(SEGMENT_KEYS, item)) for item in segment_data]
  95. segment_data = list(map(loads_curve, segment_data))
  96. wall_data = [dict(zip(WALL_KEYS, item)) for item in wall_data]
  97. wall_data = list(map(loads, wall_data))
  98. v_wall_data = [dict(zip(V_WALL_KEYS, item)) for item in v_wall_data]
  99. v_wall_data = list(map(loads, v_wall_data))
  100. columns_data = [dict(zip(COLUMNS_KEYS, item)) for item in columns_data]
  101. columns_data = list(map(loads, columns_data))
  102. test_result = calc_adjacent_relation(
  103. segments=segment_data,
  104. walls=wall_data,
  105. v_walls=v_wall_data,
  106. columns=columns_data
  107. )
  108. for item in test_result:
  109. print(item)