Jelajahi Sumber

Merge remote-tracking branch 'origin/master'

mengxiangge 5 tahun lalu
induk
melakukan
8ecfcd2d27

+ 19 - 7
src/grid/check_grid.py

@@ -1,4 +1,4 @@
-
+import json
 
 def check_grid_upright(model_list, grid_data_dict):
     grid_data_dict = dict(grid_data_dict)
@@ -7,12 +7,13 @@ def check_grid_upright(model_list, grid_data_dict):
     for model_id, all_grid in grid_data_dict.items():
         name_dict = dict()
         for data_row in all_grid:
-            name_dict[data_row.get('name')] = data_row.get('location')
+            name_dict[data_row.get('name')] = str(data_row.get('location')).replace('\'', '"')
+            # name_dict[data_row.get('name')] = data_row.get('location')
         calc_dict[model_id] = name_dict
     for model_id, name_location_dict in calc_dict.items():
         # 判断并插入分组
         insert_group(group, model_id, calc_dict)
-    print(group)
+    # print(group)
     index = 0
     group_dict = dict()
     for model_id_list in group:
@@ -21,10 +22,14 @@ def check_grid_upright(model_list, grid_data_dict):
             group_dict[tmp_model_id] = index
     for floor in model_list:
         if floor.get('fid') in group_dict:
-            floor['group'] = group_dict.get(floor.get('fid'))
-    print(model_list)
+            floor['group_id'] = group_dict.get(floor.get('fid'))
+        else:
+            floor['group_id'] = 0
+    # print(model_list)
     return True
 
+# def process_location(grids):
+#     for name, location in grids.items()
 
 def insert_group(group, model_id, calc_dict):
     # 如果第一次往group里添加元素, 直接添加
@@ -54,12 +59,19 @@ def insert_group(group, model_id, calc_dict):
 # 返回False是没冲突, True是有冲突
 def has_conflict(base, compare):
     for name, location in base.items():
+        if isinstance(location, str):
+            location = json.loads(location)
+            base[name] = location
         if name in compare:
             type1 = location.get('Type')
-            type2 = compare.get(name).get('Type')
+            location2 = compare.get(name)
+            if isinstance(location2, str):
+                location2 = json.loads(location2)
+                compare[name] = location2
+            type2 = location2.get('Type')
             if type1 in type2:
                 if 'Line' in type1:
-                    if not is_same_line(location.get('Points'), compare.get(name).get('Points')):
+                    if not is_same_line(location.get('Points'), location2.get('Points')):
                         return True
             else:
                 return True

+ 8 - 0
src/level/check_level.py

@@ -91,9 +91,11 @@ def check_level_reasonable(model_list, level_data):
     last_model_id = ''
     error = set()
     group = 0
+    elevations = {}
     for row in sorted_arr:
         current_height = row.get('elevation')
         current_model_id = row.get('model_id')
+        elevations[current_model_id] = current_height
         if current_height > last_height:
             last_height = current_height
             last_model_id = current_model_id
@@ -110,7 +112,13 @@ def check_level_reasonable(model_list, level_data):
     for floor_row in model_list:
         model_id = floor_row.get('fid')
         if model_id in error:
+            floor_row['has_error'] = True
             floor_row['error'] = '标高冲突'
+        else:
+            floor_row['has_error'] = False
+            floor_row['error'] = None
+        if model_id in elevations:
+            floor_row['elevation'] = elevations[model_id]
     if len(error) == 0:
         return True
     return False

+ 2 - 1
src/level/test.py

@@ -85,4 +85,5 @@ if __name__ == '__main__':
         single_model_level = [dict(zip(level_keys, item)) for item in single_model_level]
         level_data[item.get('fid')] = single_model_level
 
-    print(check_level_reasonable(model_list, level_data))
+    print(check_level_reasonable(model_list, level_data))
+    print(model_list)

+ 6 - 1
src/saga_mark/check_saga_mark.py

@@ -15,7 +15,7 @@ def check_saga_mark(model_list, level_data):
                     has_saga_mark = True
                     floor_name = row.get('name')[0:len(floor_full_name) - 5]
                     # is_match = re.match(r'^([f|b][0-9]+|rf)(m[0-9]*)?$', floor_name)
-                    is_match = re.match(r'^([F|B][0-9]{1,5}|RF)(M[0-9]{0,5})?$', floor_name)
+                    is_match = re.match(r'^([F|B][1-9][0-9]{0,4}|RF)(M([1-9][0-9]{0,4})?)?$', floor_name)
                     # 如果格式有问题
                     if not is_match:
                         error_model[model_id] = '楼层名称不符合规则'
@@ -25,7 +25,12 @@ def check_saga_mark(model_list, level_data):
             error_model[model_id] = '没有-saga标记'
     for row in model_list:
         if row.get('fid') in error_model:
+            row['has_error'] = True
             row['error'] = error_model.get(row.get('fid'))
+        else:
+            row['has_error'] = False
+            row['error'] = None
+
     if len(error_model) > 0:
         return False
     return True

+ 39 - 79
src/vertical_pipe/test.py

@@ -1,17 +1,46 @@
 # -*- coding: utf-8 -*-
 
 import json
+import sys
 
 import psycopg2
 
-from adjacent import calc_adjacent_relation
+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='postgres',
+            database='datacenter',
             user='postgres',
             password='123456',
             host='192.168.20.234',
@@ -23,7 +52,7 @@ def get_data(sql):
     except (Exception, psycopg2.Error) as error:
         print("Error while connecting to PostgreSQL", error)
     finally:
-        if (connection):
+        if connection:
             cursor.close()
             connection.close()
             print('PostgreSQL connection is closed')
@@ -42,79 +71,10 @@ def loads_curve(x):
 
 
 if __name__ == '__main__':
-    segment_sql = "SELECT * FROM revit.boundary_segment where model_id = '8544a3c3cd2611e99abc839db1015353'"
-    wall_sql = "SELECT * FROM revit.wall where model_id = '8544a3c3cd2611e99abc839db1015353'"
-    v_wall_sql = "SELECT * FROM revit.virtual_wall where model_id = '8544a3c3cd2611e99abc839db1015353'"
-    columns_sql = "SELECT * FROM revit.column where model_id = '8544a3c3cd2611e99abc839db1015353'"
-    segment_data = get_data(segment_sql)
-    wall_data = get_data(wall_sql)
-    v_wall_data = get_data(v_wall_sql)
-    columns_data = get_data(columns_sql)
-    SEGMENT_KEYS = [
-        'id',
-        'model_id',
-        'belong',
-        'belong_type',
-        'curve',
-        'space_id',
-        'group_index',
-        'sequence',
-        'reference',
-        'revit_id',
-        'type',
-    ]
-    WALL_KEYS = [
-        'id',
-        'model_id',
-        'level_id',
-        'width',
-        'location',
-        'outline',
-        'last_update',
-        'create_time',
-        'name',
-        'source_id',
-        'revit_id',
-        'type',
-    ]
-    V_WALL_KEYS = [
-        'id',
-        'model_id',
-        'location',
-        'outline',
-        'last_update',
-        'create_time',
-        'name',
-        'source_id',
-        'revit_id',
-        'type',
-    ]
-    COLUMNS_KEYS = [
-        'id',
-        'model_id',
-        'location',
-        'outline',
-        'bounding',
-        'last_update',
-        'create_time',
-        'name',
-        'source_id',
-        'revit_id',
-        'type',
-    ]
-    segment_data = [dict(zip(SEGMENT_KEYS, item)) for item in segment_data]
-    segment_data = list(map(loads_curve, segment_data))
-    wall_data = [dict(zip(WALL_KEYS, item)) for item in wall_data]
-    wall_data = list(map(loads, wall_data))
-    v_wall_data = [dict(zip(V_WALL_KEYS, item)) for item in v_wall_data]
-    v_wall_data = list(map(loads, v_wall_data))
-    columns_data = [dict(zip(COLUMNS_KEYS, item)) for item in columns_data]
-    columns_data = list(map(loads, columns_data))
-    test_result = calc_adjacent_relation(
-        segments=segment_data,
-        walls=wall_data,
-        v_walls=v_wall_data,
-        columns=columns_data
-    )
-    for item in test_result:
-        print(item)
+    for i in range(0, 100):
+        tmp = -0.5 + i
+        print('var = {}, round = {}'.format(tmp, round(tmp)))
+
+    for i in range(0, 100):
+        tmp = -0.45 + i
+        print('var = {}, round = {}'.format(tmp, round(tmp)))