Commit bc388b75 authored by wang.wenrong's avatar wang.wenrong

Merge branch 'wwr' into 'develop'

adu_alarm_sort

See merge request !25
parents dd334441 17784beb
......@@ -312,3 +312,32 @@ async def wx_list_alarm_zdu_dao(cid, points, start, end):
async with EsUtil() as es:
es_re = await es.search_origin(body=query_body, index=index)
return es_re
async def zdu_alarm_sort_dao(cid, start, end, page_size, page_num):
sql = f"""
SELECT
pt.`name`,
a.event_count
FROM
point pt
RIGHT JOIN (
SELECT
pid,
COUNT(*) event_count
FROM
point_1min_event
WHERE
cid = {cid}
AND event_datetime > "{start}"
AND event_datetime < "{end}"
AND event_type in {tuple(SDU_ALARM_LIST)}
GROUP BY
pid
ORDER BY
event_count DESC
) a ON pt.pid = a.pid limit {(page_num-1)*page_size}, {page_size}
"""
async with MysqlUtil() as conn:
data = await conn.fetchall(sql, args=())
return data
......@@ -22,6 +22,8 @@ from unify_api.modules.home_page.components.security_info_cps import \
from unify_api.modules.home_page.procedures.security_info_pds import \
alarm_content_time_distribution, alarm_count_info_new15
from unify_api.utils.common_utils import round_1, division_two
from unify_api.modules.alarm_manager.dao.list_alarm_dao import \
zdu_alarm_sort_dao
async def sdu_alarm_statistics_service(cids, start, end, product):
......@@ -32,7 +34,8 @@ async def sdu_alarm_statistics_service(cids, start, end, product):
raise ParamException(message=f"{cids}没有points")
point_id_list = [i["pid"] for i in points]
# 1.调用函数获取报警统计信息
alarm_info_map = await new_alarm_content_info_new15(cids, start, end, points)
alarm_info_map = await new_alarm_content_info_new15(cids, start, end,
points)
ele_overload, illegal_ele_app, power_quality, illegal_app_dic, \
total_alarm_cnt, alarm_points_cnt = (
alarm_info_map["ele_overload"],
......@@ -398,7 +401,7 @@ async def sdu_index_alarm_ranking_service_new15(cid, start, end, product):
im2 = v.get("im2") or 0
im3 = v.get("im3") or 0
alarm_dic = {
"name": point_name, "value": im1+im2+im3,
"name": point_name, "value": im1 + im2 + im3,
"im1": im1, "im2": im2, "im3": im3
}
alarm_ranking.append(alarm_dic)
......@@ -486,35 +489,11 @@ async def zdu_summary_service(cid, start, end, product):
)
async def zdu_alarm_sort_service(cid, start, end, page_size, page_num):
async def zdu_alarm_sort_service_2(cid, start, end, page_size, page_num):
"""报警统计-报警排名-智电u"""
# 获取point信息
points = await points_by_cid([cid])
# point_id_list = [i["pid"] for i in points]
points_map = {i["pid"]: i["name"] for i in points}
# 1.调用函数获取报警统计信息
buckets = await sdu_alarm_statistics_dao(cid, start, end, is_sdu=False)
# point报警统计
points_dic = {}
for bucket in buckets:
# 2.2 point报警数量
if bucket["point_cnt"]["buckets"]:
for item in bucket["point_cnt"]["buckets"]:
point_t = item["key"]
# point和point_name映射
point_name = points_map[point_t]
if point_name not in points_dic:
points_dic[point_name] = item["doc_count"]
else:
points_dic[point_name] += item["doc_count"]
# point报警统计
points_alarm_list = []
for key, val in points_dic.items():
points_alarm_list.append({"name": key, "value": val})
points_alarm_list.sort(key=lambda x: x["value"], reverse=True)
points_alarm_list_size = points_alarm_list[
(page_num - 1) * page_size: page_num * page_size]
points_alarm_list = await zdu_alarm_sort_dao(cid, start, end, page_size,
page_num)
return ZasResp(
total=len(points_alarm_list),
alarm_ranking=points_alarm_list_size
total=len(points_alarm_list) if points_alarm_list else 0,
alarm_ranking=points_alarm_list
)
......@@ -11,7 +11,7 @@ from unify_api.modules.alarm_manager.service.alarm_static_service import \
sdu_app_statistics_sort_service, sdu_electric_behave_service, \
sdu_index_alarm_ranking_service, zdu_level_distribution_service, \
zdu_content_distribution_service, zdu_summary_service, \
zdu_alarm_sort_service, sdu_alarm_statistics_sort_service_new15, \
zdu_alarm_sort_service_2, sdu_alarm_statistics_sort_service_new15, \
sdu_app_statistics_sort_service_new15, \
sdu_index_alarm_ranking_service_new15
from unify_api.modules.home_page.components.security_info_cps import \
......@@ -218,4 +218,4 @@ async def post_zdu_alarm_sort(req, body: ZasReq) -> ZasResp:
end = body.end
page_size = body.page_size
page_num = body.page_num
return await zdu_alarm_sort_service(cid, start, end, page_size, page_num)
return await zdu_alarm_sort_service_2(cid, start, end, page_size, page_num)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment