test.py 3.1 KB

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