test.py 4.1 KB

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