Commit 17784beb authored by wang.wenrong's avatar wang.wenrong

adu_alarm_sort

parent d59ec61e
......@@ -16,7 +16,7 @@ async def new_list_alarm_dao(cid, points, page_num, page_size, start, end,
#
# if product == Product.RecognitionElectric.value: # 识电u
alarm_list = SDU_ALARM_LIST
query_body = {
"from": (page_num - 1) * page_size,
"size": page_size,
......@@ -126,12 +126,12 @@ async def new_list_alarm_dao_new15(cid, points, start, end, importance, offset,
async def wx_list_alarm_dao(cids, product, start, end):
"""小程序消息列表, 取当前范围最新40条"""
# alarm_list = list(EVENT_TYPE_MAP.keys()) # 安电u
#
# if product == Product.RecognitionElectric.value: # 识电u
alarm_list = SDU_ALARM_LIST
query_body = {
"size": 40,
"query": {
......@@ -171,7 +171,7 @@ async def wx_list_alarm_dao(cids, product, start, end):
}
}
)
log.info(f"index:{index}--query_body:{query_body}")
async with EsUtil() as es:
es_re = await es.search_origin(body=query_body, index=index)
......@@ -181,7 +181,7 @@ async def wx_list_alarm_dao(cids, product, start, end):
async def list_alarm_zdu_dao(cid, points, page_num, page_size, start, end,
importance, event_type):
"""智电u, es报警信息分页列表, 可根据报警等级筛选"""
query_body = {
"from": (page_num - 1) * page_size,
"size": page_size,
......@@ -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