Browse Source

Merge remote-tracking branch 'origin/master'

mengxiangge 5 years ago
parent
commit
8d4d354392

+ 0 - 7
.idea/misc.xml

@@ -1,7 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<project version="4">
-  <component name="JavaScriptSettings">
-    <option name="languageLevel" value="ES6" />
-  </component>
-  <component name="ProjectRootManager" version="2" project-jdk-name="Python 3.6" project-jdk-type="Python SDK" />
-</project>

+ 0 - 8
.idea/modules.xml

@@ -1,8 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<project version="4">
-  <component name="ProjectModuleManager">
-    <modules>
-      <module fileurl="file://$PROJECT_DIR$/.idea/relations.iml" filepath="$PROJECT_DIR$/.idea/relations.iml" />
-    </modules>
-  </component>
-</project>

+ 0 - 12
.idea/relations.iml

@@ -1,12 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<module type="PYTHON_MODULE" version="4">
-  <component name="NewModuleRootManager">
-    <content url="file://$MODULE_DIR$" />
-    <orderEntry type="inheritedJdk" />
-    <orderEntry type="sourceFolder" forTests="false" />
-  </component>
-  <component name="TestRunnerService">
-    <option name="projectConfiguration" value="Twisted Trial" />
-    <option name="PROJECT_TEST_RUNNER" value="Twisted Trial" />
-  </component>
-</module>

+ 0 - 6
.idea/vcs.xml

@@ -1,6 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<project version="4">
-  <component name="VcsDirectoryMappings">
-    <mapping directory="$PROJECT_DIR$" vcs="Git" />
-  </component>
-</project>

+ 0 - 0
pip3


+ 0 - 0
src/grid/__init__.py


+ 88 - 0
src/grid/check_grid.py

@@ -0,0 +1,88 @@
+
+
+def check_grid_upright(model_list, grid_data_dict):
+    grid_data_dict = dict(grid_data_dict)
+    group = []  # 保存结果
+    calc_dict = dict()  # 结构 dict(dict())   key --> modelId, value( key --> name, value --> location )
+    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')
+        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)
+    index = 0
+    group_dict = dict()
+    for model_id_list in group:
+        index = index + 1
+        for tmp_model_id in model_id_list:
+            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)
+    return True
+
+
+def insert_group(group, model_id, calc_dict):
+    # 如果第一次往group里添加元素, 直接添加
+    count = 0
+    for single_group in group:
+        count += len(single_group)
+    if count == 0:
+        group.append([model_id])
+        return
+    # 判断跟组内是否有冲突, 如果有则创建新组添加
+    # 没有冲突则添加到一个组内
+    conflict = False
+    for single_group in group:
+        conflict = False
+        base_data = calc_dict.get(model_id)
+        for compare_model_id in single_group:
+            compare_data = calc_dict.get(compare_model_id)
+            if has_conflict(base_data, compare_data):
+                conflict = True
+                break
+        if not conflict:
+            single_group.append(model_id)
+    if conflict:
+        group.append([model_id])
+
+
+# 返回False是没冲突, True是有冲突
+def has_conflict(base, compare):
+    for name, location in base.items():
+        if name in compare:
+            type1 = location.get('Type')
+            type2 = compare.get(name).get('Type')
+            if type1 in type2:
+                if 'Line' in type1:
+                    if not is_same_line(location.get('Points'), compare.get(name).get('Points')):
+                        return True
+            else:
+                return True
+    return False
+
+
+def is_same_line(line1, line2):
+    line1_point1 = line1[0]
+    line1_point2 = line1[1]
+    line2_point1 = line2[0]
+    line2_point2 = line2[1]
+    try:
+        a1 = (line1_point1.get('Y') - line1_point2.get('Y')) / (line1_point1.get('X') - line1_point2.get('X'))
+        k1 = line1_point1.get('Y') - a1 * line1_point1.get('X')
+    except ZeroDivisionError as error:
+        if line2_point1.get('X') == line2_point2.get('X') == line1_point2.get('X'):
+            return True
+        else:
+            return False
+    try:
+        a2 = (line2_point1.get('Y') - line2_point2.get('Y')) / (line2_point1.get('X') - line2_point2.get('X'))
+        k2 = line2_point1.get('Y') - a2 * line2_point1.get('X')
+    except ZeroDivisionError as error:
+        return False
+
+    return a1 == a2 and k1 == k2

+ 92 - 0
src/grid/test.py

@@ -0,0 +1,92 @@
+# -*- coding: utf-8 -*-
+
+import json
+
+import psycopg2
+import sys
+
+from src.grid.check_grid import check_grid_upright
+
+involved_model_keys = [
+    'id',
+    'floor_name',
+    'project_id',
+    'folder_id',
+    'fid',
+    'accept_time',
+    'version',
+    'note',
+    'user_id',
+    'user_name',
+    'log',
+    'url',
+    'md5',
+    'status'
+]
+
+grid_keys = [
+    'id',
+    'model_id',
+    'name',
+    'type',
+    'last_update',
+    'create_time',
+    'revit_id',
+    'source_id',
+    'location',
+]
+
+
+def get_data(sql):
+    global connection, cursor
+    record = []
+    try:
+        connection = psycopg2.connect(
+            database='datacenter',
+            user='postgres',
+            password='123456',
+            host='192.168.20.234',
+            port='5432'
+        )
+        cursor = connection.cursor()
+        cursor.execute(sql)
+        record = cursor.fetchall()
+    except (Exception, psycopg2.Error) as error:
+        print("Error while connecting to PostgreSQL", error)
+    finally:
+        if connection:
+            cursor.close()
+            connection.close()
+            print('PostgreSQL connection is closed')
+    return record
+
+
+def loads(x):
+    x['location'] = json.loads(x['location'])
+    return x
+
+
+def loads_curve(x):
+    x['curve'] = json.loads(x['curve'])
+    return x
+
+
+if __name__ == '__main__':
+
+    involved_model_sql = "select * from revit.model_floor_file_func('Pj1101010015') where folder_id = " \
+                         "'bbe510dbe26011e999b69b669ea08505' and status in (3, 31, 4) "
+    grid_sql = "select * from revit.grid where model_id = "
+    columns_data = get_data(involved_model_sql)
+
+    model_list = [dict(zip(involved_model_keys, item)) for item in columns_data]
+    if len(model_list) < 2:
+        sys.exit()
+    grid_data = dict()
+    for item in model_list:
+        current_grid_sql = grid_sql + '\'{model_id}\''.format(model_id=item.get('fid'))
+        single_model_grid = get_data(current_grid_sql)
+        single_model_grid = [dict(zip(grid_keys, item)) for item in single_model_grid]
+        grid_data[item.get('fid')] = single_model_grid
+
+    print(check_grid_upright(model_list, grid_data))
+

+ 0 - 0
src/level/__init__.py


+ 136 - 0
src/level/check_level.py

@@ -0,0 +1,136 @@
+import functools
+import sys
+
+
+def floor_sort_cmp(x, y):
+    positive = 1
+    negative = -1
+    x_name = x.get('name')[0:len(x.get('name'))-5]
+    y_name = y.get('name')[0:len(y.get('name'))-5]
+    # x 夹层号
+    x_m_num = 1
+    # y 夹层号
+    y_m_num = 1
+    # x 楼层号
+    x_floor_num = 1
+    # y 楼层号
+    y_floor_num = 1
+
+    if x_name.startswith('RFM'):
+        if y_name.startswith('RFM'):
+            if len(x_name) > 3:
+                x_m_num = int(x_name[3:])
+            if len(y_name) > 3:
+                y_m_num = int(y_name[3:])
+            return x_m_num - y_m_num
+        elif y_name.startswith('RF'):
+            return negative
+        else:
+            return positive
+    if x_name.startswith('RF'):
+        return positive
+    if x_name.startswith('F'):
+        if y_name.startswith('RF'):
+            return negative
+        elif y_name.startswith('F'):
+            if 'M' in x_name:
+                x_index = x_name.index('M')
+                x_floor_num = int(x_name[1 : x_index])
+                if not x_name.endswith('M'):
+                    x_m_num = int(x_name[x_index + 1:])
+            else:
+                x_floor_num = int(x_name[1:])
+            if 'M' in y_name:
+                y_index = y_name.index('M')
+                y_floor_num = int(y_name[1:y_index])
+                if not y_name.endswith('M'):
+                    y_m_num = int(y_name[y_index + 1:])
+            else:
+                y_floor_num = int(y_name[1:])
+            if x_floor_num == y_floor_num:
+                return x_m_num - y_m_num
+            else:
+                return x_floor_num - y_floor_num
+        else:
+            return positive
+    if x_name.startswith('B'):
+        if y_name.startswith('B'):
+            if 'M' in x_name:
+                x_index = x_name.index('M')
+                x_floor_num = int(x_name[1 : x_index])
+                if not x_name.endswith('M'):
+                    x_m_num = int(x_name[x_index + 1:])
+            else:
+                x_floor_num = int(x_name[1:])
+            if 'M' in y_name:
+                y_index = y_name.index('M')
+                y_floor_num = int(y_name[1:y_index])
+                if not y_name.endswith('M'):
+                    y_m_num = int(y_name[y_index + 1:])
+            else:
+                y_floor_num = int(y_name[1:])
+            if x_floor_num == y_floor_num:
+                return x_m_num - y_m_num
+            else:
+                return y_floor_num - x_floor_num
+        else:
+            return negative
+    return 1
+
+
+def check_level_reasonable(model_list, level_data):
+    levels = []
+    for model_id, level_rows in level_data.items():
+        if len(level_rows) == 1:
+            levels.append(level_rows[0])
+
+
+    sorted_arr = sorted(levels, key=functools.cmp_to_key(floor_sort_cmp))
+
+    last_height = -999999999
+    last_model_id = ''
+    error = set()
+    group = 0
+    for row in sorted_arr:
+        current_height = row.get('elevation')
+        current_model_id = row.get('model_id')
+        if current_height > last_height:
+            last_height = current_height
+            last_model_id = current_model_id
+            continue
+        else:
+            # 标高有问题
+            group += 1
+            error.add(last_model_id)
+            error.add(current_model_id)
+            last_height = -999999999
+            last_model_id = ''
+            continue
+
+    for floor_row in model_list:
+        model_id = floor_row.get('fid')
+        if model_id in error:
+            floor_row['error'] = '标高冲突'
+    if len(error) == 0:
+        return True
+    return False
+    # arr = ['F1M1-saga', 'F1M2-saga', 'RFM1-saga', 'RFM3-saga', 'RFM2-saga', 'B1-saga', 'B1M-saga', 'B1M2-saga', 'B4-saga', 'F2-saga', 'F2M2-saga', 'RF-saga']
+    # print(sorted(arr, key=functools.cmp_to_key(floor_sort_cmp)))
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

+ 88 - 0
src/level/test.py

@@ -0,0 +1,88 @@
+# -*- coding: utf-8 -*-
+
+import json
+import sys
+
+import psycopg2
+
+from src.level.check_level import check_level_reasonable
+
+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='datacenter',
+            user='postgres',
+            password='123456',
+            host='192.168.20.234',
+            port='5432'
+        )
+        cursor = connection.cursor()
+        cursor.execute(sql)
+        record = cursor.fetchall()
+    except (Exception, psycopg2.Error) as error:
+        print("Error while connecting to PostgreSQL", error)
+    finally:
+        if connection:
+            cursor.close()
+            connection.close()
+            print('PostgreSQL connection is closed')
+
+    return record
+
+
+def loads(x):
+    x['location'] = json.loads(x['location'])
+    return x
+
+
+def loads_curve(x):
+    x['curve'] = json.loads(x['curve'])
+    return x
+
+
+if __name__ == '__main__':
+    involved_model_sql = "select * from revit.model_floor_file_func('Pj1101010015') where folder_id = " \
+                         "'bbe510dbe26011e999b69b669ea08505' and status in (3, 31, 4) "
+    level_sql = "select * from revit.level where name like '%-saga' and model_id = "
+    columns_data = get_data(involved_model_sql)
+    if len(columns_data) == 0:
+        sys.exit()
+    model_list = [dict(zip(involved_model_keys, item)) for item in columns_data]
+    level_data = dict()
+    for item in model_list:
+        current_level_sql = level_sql + '\'{model_id}\''.format(model_id=item.get('fid'))
+        single_model_level = get_data(current_level_sql)
+        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))

+ 0 - 0
src/saga_mark/__init__.py


+ 31 - 0
src/saga_mark/check_saga_mark.py

@@ -0,0 +1,31 @@
+import re
+
+def check_saga_mark(model_list, level_data):
+    error_model = dict()
+    for model_id, level_arr in level_data.items():
+        has_saga_mark = False
+        for row in level_arr:
+            floor_full_name = row.get('name')
+            if floor_full_name.endswith('-saga'):
+                # 如果重复包含-saga标记
+                if has_saga_mark:
+                    error_model[model_id] = '包含重复-saga标记'
+                    break
+                else:
+                    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)
+                    # 如果格式有问题
+                    if not is_match:
+                        error_model[model_id] = '楼层名称不符合规则'
+                        break
+        # 如果所有楼层都没有包含-saga标记
+        if not has_saga_mark:
+            error_model[model_id] = '没有-saga标记'
+    for row in model_list:
+        if row.get('fid') in error_model:
+            row['error'] = error_model.get(row.get('fid'))
+    if len(error_model) > 0:
+        return False
+    return True

+ 88 - 0
src/saga_mark/test.py

@@ -0,0 +1,88 @@
+# -*- coding: utf-8 -*-
+
+import json
+import sys
+
+import psycopg2
+
+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='datacenter',
+            user='postgres',
+            password='123456',
+            host='192.168.20.234',
+            port='5432'
+        )
+        cursor = connection.cursor()
+        cursor.execute(sql)
+        record = cursor.fetchall()
+    except (Exception, psycopg2.Error) as error:
+        print("Error while connecting to PostgreSQL", error)
+    finally:
+        if connection:
+            cursor.close()
+            connection.close()
+            print('PostgreSQL connection is closed')
+
+    return record
+
+
+def loads(x):
+    x['location'] = json.loads(x['location'])
+    return x
+
+
+def loads_curve(x):
+    x['curve'] = json.loads(x['curve'])
+    return x
+
+
+if __name__ == '__main__':
+    involved_model_sql = "select * from revit.model_floor_file_func('Pj1101010015') where folder_id = " \
+                         "'bbe510dbe26011e999b69b669ea08505' and status in (3, 31, 4) "
+    level_sql = "select * from revit.level where model_id = "
+    columns_data = get_data(involved_model_sql)
+    if len(columns_data) == 0:
+        sys.exit()
+    model_list = [dict(zip(involved_model_keys, item)) for item in columns_data]
+    level_data = dict()
+    for item in model_list:
+        current_level_sql = level_sql + '\'{model_id}\''.format(model_id=item.get('fid'))
+        single_model_level = get_data(current_level_sql)
+        single_model_level = [dict(zip(level_keys, item)) for item in single_model_level]
+        level_data[item.get('fid')] = single_model_level
+
+    print(check_saga_mark(model_list, level_data))

+ 0 - 0
src/vertical_pipe/__init__.py


+ 0 - 0
src/vertical_pipe/check_vertical_pipe.py


+ 120 - 0
src/vertical_pipe/test.py

@@ -0,0 +1,120 @@
+# -*- coding: utf-8 -*-
+
+import json
+
+import psycopg2
+
+from adjacent import calc_adjacent_relation
+
+
+def get_data(sql):
+    record = []
+    try:
+        connection = psycopg2.connect(
+            database='postgres',
+            user='postgres',
+            password='123456',
+            host='192.168.20.234',
+            port='5432'
+        )
+        cursor = connection.cursor()
+        cursor.execute(sql)
+        record = cursor.fetchall()
+    except (Exception, psycopg2.Error) as error:
+        print("Error while connecting to PostgreSQL", error)
+    finally:
+        if (connection):
+            cursor.close()
+            connection.close()
+            print('PostgreSQL connection is closed')
+
+    return record
+
+
+def loads(x):
+    x['location'] = json.loads(x['location'])
+    return x
+
+
+def loads_curve(x):
+    x['curve'] = json.loads(x['curve'])
+    return 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)