Browse Source

文档改动

jxing 4 years ago
parent
commit
27dad06ace

+ 47 - 0
docs/dev/data-center/relations/belongs/Sh2Bd.md

@@ -0,0 +1,47 @@
+竖井关联的建筑
+
+# 计算流程
+    
+    根据竖井关联的空间关系来推导
+    
+# 处理流程
+    1. 竖井包含有业务空间, 并且业务空间有所属建筑
+    
+# 函数
+
+```
+
+CREATE OR REPLACE FUNCTION "public"."rel_sh2bd"("project_id" varchar)
+  RETURNS "pg_catalog"."bool" AS $BODY$
+try:
+    # 将下面对数据库的操作作为一个事务, 出异常则自动rollback
+    with plpy.subtransaction():
+        delete_plan = plpy.prepare("delete from  r_sh_in_bd rel where rel.project_id = $1 and sign = 2", ["text"])
+        delete_plan.execute([project_id])
+        join_plan = plpy.prepare("select distinct shsp.sh_id shaft_id, spbd.building_id building_id from relationship.r_sh2sp shsp inner join r_sp_in_bd spbd on shsp.sp_id = spbd.space_id where shsp.project_id = $1 and spbd.project_id = $1", ["text"])
+        rel = join_plan.execute([project_id])
+        for row in rel:
+            shaft_id = row['shaft_id']
+            building_id = row['building_id']
+            try:
+                plan = plpy.prepare("insert into r_sh_in_bd(shaft_id, building_id, project_id, sign) values($1, $2, $3, 2)", ["text", "text", "text"])
+                plan.execute([shaft_id, building_id, project_id])
+            except Exception as ex:
+                pass
+except Exception as e:
+    plpy.warning(e)
+    return False
+else:
+    return True
+$BODY$
+  LANGUAGE plpython3u VOLATILE
+  COST 100
+
+
+select public.rel_sh2bd('Pj1102290002')
+```
+
+## 入参
+    1. 项目id
+## 例子
+    select public.rel_sh2bd('Pj1102290002');

+ 1 - 1
docs/dev/data-center/relations/belongs/Sp2Sp.md

@@ -22,7 +22,7 @@ try:
     with plpy.subtransaction():
         delete_plan = plpy.prepare("delete from r_spatial_connection where project_id = $1 and sign = 2", ["text"])
         delete_plan.execute([project_id])
-        space_data_plan = plpy.prepare("SELECT id, project_id, floor_id, object_type, bim_location, outline FROM zone_space_base where project_id = $1 and outline is not null and floor_id is not null order by floor_id, object_type", ["text"])
+        space_data_plan = plpy.prepare("SELECT sp.id, sp.project_id, rel.floor_id, sp.object_type, sp.bim_location, sp.outline FROM zone_space_base sp inner join r_sp_in_fl rel on rel.space_id = sp.id where sp.project_id = $1 and rel.project_id = $1 and outline is not null order by floor_id, object_type", ["text"])
         space_data = space_data_plan.execute([project_id])
         rel_data = calc_space_adjacent(space_data)
         for single_rel in rel_data:

+ 48 - 0
docs/dev/data-center/relations/belongs/Sp2Sp2.md

@@ -0,0 +1,48 @@
+业务空间邻接关系
+## 前置条件
+    1. 业务空间有所在楼层
+    2. 业务空间有外轮廓
+## 处理流程
+    1. 查出所有有所在楼层, 并且外轮廓不是null的业务空间
+    2. 根据所在楼层, 业务空间分区来将业务空间分组
+    3. 计算每个分组内的业务空间的相邻关系
+    计算相邻算法:
+    1. 首先判断围成业务空间的线段, 两两空间之间是否有近似平行的线段(线段偏转误差小于1度)
+        1). 近似平行判断: 首先获取两个线段的斜率, 再计算斜率的反正切(即与x轴的角度, 不过是以pi为单位), 再判断两个角度差的绝对值是否小于1度
+    2. 如果有近似平行的线段, 判断是否相互有投影在线段上, 有投影在线段上, 则认为是两平行线段有重合部分, 业务空间有相邻的可能性
+    3. 在判断互相有投影点在对方线段上之后, 判断投影线的长度, 是否小于250mm(墙的最大厚度), 如果小于250mm则认为两空间相邻
+## 函数
+```
+create or replace function public.rel_sp2sp1(project_id character varying) returns boolean
+as
+$$
+from relations.src.business_space_adjacent.adjacent import calc_space_adjacent
+try:
+    # 将下面对数据库的操作作为一个事务, 出异常则自动rollback
+    with plpy.subtransaction():
+        delete_plan = plpy.prepare("delete from r_spatial_connection where project_id = $1 and sign = 2", ["text"])
+        delete_plan.execute([project_id])
+        space_data_plan = plpy.prepare("SELECT id, project_id, floor_id, object_type, bim_location, outline FROM zone_space_base where project_id = $1 and outline is not null and floor_id is not null order by floor_id, object_type", ["text"])
+        space_data = space_data_plan.execute([project_id])
+        rel_data = calc_space_adjacent(space_data)
+        for single_rel in rel_data:
+            delete_duplicate_plan = plpy.prepare("delete from r_spatial_connection where space_id_one = $1 and space_id_two = $2", ["text", "text"])
+            delete_duplicate_plan.execute([single_rel['space_id_one'], single_rel['space_id_two']])
+            insert_plan = plpy.prepare("insert into r_spatial_connection(project_id, location_one, location_two, space_id_one, space_id_two, sign, graph_type, floor_id, zone_type) values($1, $2, $3, $4, $5, 2, 'SpaceNeighborhood', $6, $7)", ["text", "text", "text", "text", "text", "text", "text"])
+            insert_plan.execute([project_id, single_rel['location_one'], single_rel['location_two'], single_rel['space_id_one'], single_rel['space_id_two'], single_rel['floor_id'], single_rel['zone_type']])
+except Exception as e:
+    plpy.warning(e)
+    return False
+else:
+    return True
+$$
+LANGUAGE 'plpython3u' VOLATILE;
+
+
+select public.rel_sp2sp1('Pj1101050001')
+```
+
+## 入参
+    1. 项目id
+## 例子
+    select public.rel_sp2sp1('Pj1102290002');

+ 10 - 7
docs/dev/data-center/relations/belongs/Sy2Bd.md

@@ -11,9 +11,8 @@
 ## 函数
 ~~~
 -- 系统所在建筑
-create or replace function public.rel_sy2bd(project_id character varying) returns boolean
-as
-$$
+CREATE OR REPLACE FUNCTION "public"."rel_sy2bd"("project_id" varchar)
+  RETURNS "pg_catalog"."bool" AS $BODY$
 try:
     # 将下面对数据库的操作作为一个事务, 出异常则自动rollback
     with plpy.subtransaction():
@@ -31,15 +30,19 @@ try:
             sys_set.add(building)
         for sid, sys_set in sy2bd.items():
             for building in sys_set:
-                plan = plpy.prepare("insert into r_sy_in_bd(sys_id, building_id, project_id, sign) values($1, $2, $3, 2)", ["text", "text", "text"])
-                plan.execute([sid, building, project_id])
+                try:
+                    plan = plpy.prepare("insert into r_sy_in_bd(sys_id, building_id, project_id, sign) values($1, $2, $3, 2)", ["text", "text", "text"])
+                    plan.execute([sid, building, project_id])
+                except Exception as ex:
+                    pass
 except Exception as e:
     plpy.warning(e)
     return False
 else:
     return True
-$$
-LANGUAGE 'plpython3u' VOLATILE;
+$BODY$
+  LANGUAGE plpython3u VOLATILE
+  COST 100
 ~~~
 
 ## 入参

+ 13 - 5
docs/dev/data-center/relations/belongs/Sy2Sp.md

@@ -13,38 +13,46 @@
 create or replace function public.rel_sy2sp(project_id character varying) returns boolean
 as
 $$
+CREATE OR REPLACE FUNCTION "public"."rel_sy2sp"("project_id" varchar)
+  RETURNS "pg_catalog"."bool" AS $BODY$
 try:
     input_tables = ['r_eq_in_sp_zone_air_conditioning', 'r_eq_in_sp_zone_clean', 'r_eq_in_sp_zone_domestic_water_supply', 'r_eq_in_sp_zone_fire', 'r_eq_in_sp_zone_function',
         'r_eq_in_sp_zone_general', 'r_eq_in_sp_zone_heating', 'r_eq_in_sp_zone_lighting', 'r_eq_in_sp_zone_network', 'r_eq_in_sp_zone_power_supply', 'r_eq_in_sp_zone_security', 'r_eq_in_sp_zone_tenant']
+    input_tables = ['relationship.r_eq2sp']
     output_tables = ['r_sy_in_sp_zone_air_conditioning', 'r_sy_in_sp_zone_clean', 'r_sy_in_sp_zone_domestic_water_supply',
         'r_sy_in_sp_zone_fire', 'r_sy_in_sp_zone_function', 'r_sy_in_sp_zone_general', 'r_sy_in_sp_zone_heating', 'r_sy_in_sp_zone_lighting',
         'r_sy_in_sp_zone_network', 'r_sy_in_sp_zone_power_supply', 'r_sy_in_sp_zone_security', 'r_sy_in_sp_zone_tenant']
+    output_tables = ['relationship.r_sy2sp']
     # 将下面对数据库的操作作为一个事务, 出异常则自动rollback
     with plpy.subtransaction():
         for i in range(len(output_tables)):
-            delete_plan = plpy.prepare("delete from {0} where project_id = $1 and sign = 2".format(output_tables[i]), ["text"])
+            delete_plan = plpy.prepare("delete from {0} where project_id = $1 and sign = 2 and type = 'sy2sp'".format(output_tables[i]), ["text"])
             delete_plan.execute([project_id])
-            join_plan = plpy.prepare("select sy.sys_id, rel.space_id from r_sy_eq sy inner join {0} rel on sy.equip_id = rel.equip_id where rel.project_id = $1 and sy.project_id = $1".format(input_tables[i]), ["text"])
+            join_plan = plpy.prepare("select sy.sys_id, rel.sp_id space_id, zone_type from r_sy_eq sy inner join {0} rel on sy.equip_id = rel.eq_id where rel.project_id = $1 and sy.project_id = $1 and rel.type = 'eq2sp_in'".format(input_tables[i]), ["text"])
             rel = join_plan.execute([project_id])
             sy2sp = dict()
+            zone_type_map = dict()
             for row in rel:
                 sys = row['sys_id']
                 space = row['space_id']
+                space_zone = row['zone_type']
+                zone_type_map[space] = space_zone
                 if sys not in sy2sp:
                     sy2sp[sys] = set()
                 space_set = sy2sp[sys]
                 space_set.add(space)
             for sid, space_set in sy2sp.items():
                 for space in space_set:
-                    plan = plpy.prepare("insert into {0}(sys_id, space_id, project_id, sign) values($1, $2, $3, 2)".format(output_tables[i]), ["text", "text", "text"])
+                    plan = plpy.prepare("insert into {0}(sy_id, sp_id, project_id, type, zone_type, sign) values($1, $2, $3, 'sy2sp', '{1}', 2)".format(output_tables[i], zone_type_map[space]), ["text", "text", "text"])
                     plan.execute([sid, space, project_id])
 except Exception as e:
     plpy.warning(e)
     return False
 else:
     return True
-$$
-LANGUAGE 'plpython3u' VOLATILE;
+$BODY$
+  LANGUAGE plpython3u VOLATILE
+  COST 100
 ```
 
 ## 输入