Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
U
unify_api2
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
chaonan
unify_api2
Commits
240befd7
Commit
240befd7
authored
Apr 23, 2023
by
wang.wenrong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
zdu-summary
parent
61200aa0
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
47 additions
and
64 deletions
+47
-64
list_alarm_dao.py
unify_api/modules/alarm_manager/dao/list_alarm_dao.py
+25
-3
list_static_dao.py
unify_api/modules/alarm_manager/dao/list_static_dao.py
+17
-50
alarm_static_service.py
...api/modules/alarm_manager/service/alarm_static_service.py
+5
-11
No files found.
unify_api/modules/alarm_manager/dao/list_alarm_dao.py
View file @
240befd7
...
@@ -346,7 +346,7 @@ async def zdu_alarm_sort_dao(cid, start, end, page_size, page_num):
...
@@ -346,7 +346,7 @@ async def zdu_alarm_sort_dao(cid, start, end, page_size, page_num):
return
data
return
data
async
def
alarm_content_time_distribution_dao
(
cid
,
start
,
end
,):
async
def
alarm_content_time_distribution_dao
(
cid
,
start
,
end
,
):
"""
"""
智电温度漏电流电参数分布
智电温度漏电流电参数分布
"""
"""
...
@@ -371,4 +371,26 @@ async def alarm_content_time_distribution_dao(cid, start, end,):
...
@@ -371,4 +371,26 @@ async def alarm_content_time_distribution_dao(cid, start, end,):
"""
"""
async
with
MysqlUtil
()
as
conn
:
async
with
MysqlUtil
()
as
conn
:
elec_data
=
await
conn
.
fetchall
(
sql
,
)
elec_data
=
await
conn
.
fetchall
(
sql
,
)
return
elec_data
return
elec_data
if
elec_data
else
[]
async
def
zdu_summary_dao
(
cid
,
start
,
end
):
sql
=
f
"""
SELECT
pid,
count(*) coun
FROM
point_1min_event
WHERE
cid = {cid}
AND event_datetime BETWEEN '{start}'
AND '{end}' AND pid is not null
GROUP BY
pid
"""
async
with
MysqlUtil
()
as
conn
:
summary_data
=
await
conn
.
fetchall
(
sql
,
)
total_alarm_cnt
=
sum
([
i
.
get
(
'coun'
)
for
i
in
summary_data
])
alarm_points
=
len
(
summary_data
)
return
total_alarm_cnt
,
alarm_points
unify_api/modules/alarm_manager/dao/list_static_dao.py
View file @
240befd7
...
@@ -187,7 +187,7 @@ async def sdu_alarm_limit_type_dao_new15(start, end, points):
...
@@ -187,7 +187,7 @@ async def sdu_alarm_limit_type_dao_new15(start, end, points):
f
"event_datetime BETWEEN '{start}' and '{end}' "
\
f
"event_datetime BETWEEN '{start}' and '{end}' "
\
f
"and event_type in {tuple(SDU_ALARM_LIST)} GROUP BY pid, event_type"
f
"and event_type in {tuple(SDU_ALARM_LIST)} GROUP BY pid, event_type"
async
with
MysqlUtil
()
as
conn
:
async
with
MysqlUtil
()
as
conn
:
datas
=
await
conn
.
fetchall
(
sql
,
args
=
(
points
,
))
datas
=
await
conn
.
fetchall
(
sql
,
args
=
(
points
,))
return
datas
return
datas
...
@@ -366,54 +366,21 @@ async def zdu_alarm_aggs_date_impotent(cid, start, end):
...
@@ -366,54 +366,21 @@ async def zdu_alarm_aggs_date_impotent(cid, start, end):
"""zdu求安全运行
"""zdu求安全运行
根据每日聚合,再根据等级聚合
根据每日聚合,再根据等级聚合
"""
"""
start_dt
=
datetime
.
strptime
(
start
,
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
)
sql
=
f
"""
end_dt
=
datetime
.
strptime
(
end
,
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
)
SELECT DISTINCT
es_start_str
=
datetime
(
year
=
start_dt
.
year
,
month
=
start_dt
.
month
,
DATE_FORMAT( event_datetime, '
%
m-
%
d' ) dat
day
=
start_dt
.
day
)
.
strftime
(
FROM
"
%
Y-
%
m-
%
dT
%
H:
%
M:
%
S+08:00"
)
point_1min_event
es_end_str
=
end_dt
.
strftime
(
"
%
Y-
%
m-
%
dT
%
H:
%
M:
%
S+08:00"
)
WHERE
query_body
=
{
cid = {cid}
"size"
:
0
,
AND event_datetime BETWEEN '{start}'
"query"
:
{
AND '{end}'
"bool"
:
{
AND importance !=1
"must"
:
[
{
"""
"term"
:
{
async
with
MysqlUtil
()
as
conn
:
"cid"
:
cid
datas
=
await
conn
.
fetchall
(
sql
)
}
return
len
(
datas
)
if
datas
else
0
},
{
"range"
:
{
"datetime"
:
{
"gte"
:
es_start_str
,
"lte"
:
es_end_str
}
}
}
]
}
},
"aggs"
:
{
"date_day"
:
{
"date_histogram"
:
{
"field"
:
"datetime"
,
"interval"
:
"day"
,
"time_zone"
:
"+08:00"
,
"format"
:
"yyyy-MM-dd"
,
"min_doc_count"
:
0
,
"extended_bounds"
:
{
"min"
:
start_dt
.
strftime
(
"
%
Y-
%
m-
%
d"
),
"max"
:
end_dt
.
strftime
(
"
%
Y-
%
m-
%
d"
)},
},
"aggs"
:
{
"important_cnt"
:
{
"terms"
:
{
"field"
:
"importance"
}}}
}
}
}
log
.
info
(
"query_body={}"
.
format
(
query_body
))
async
with
EsUtil
()
as
es
:
es_result
=
await
es
.
search_origin
(
body
=
query_body
,
index
=
constants
.
POINT_1MIN_EVENT
)
return
es_result
[
"aggregations"
][
"date_day"
][
"buckets"
]
async
def
sdu_alarm_aggs_date_importance
(
cid
):
# todo: 扬尘es待改
async
def
sdu_alarm_aggs_date_importance
(
cid
):
# todo: 扬尘es待改
...
...
unify_api/modules/alarm_manager/service/alarm_static_service.py
View file @
240befd7
...
@@ -24,7 +24,7 @@ from unify_api.modules.home_page.procedures.security_info_pds import \
...
@@ -24,7 +24,7 @@ from unify_api.modules.home_page.procedures.security_info_pds import \
alarm_count_info_new15
alarm_count_info_new15
from
unify_api.utils.common_utils
import
round_1
,
division_two
from
unify_api.utils.common_utils
import
round_1
,
division_two
from
unify_api.modules.alarm_manager.dao.list_alarm_dao
import
\
from
unify_api.modules.alarm_manager.dao.list_alarm_dao
import
\
zdu_alarm_sort_dao
,
alarm_content_time_distribution_dao
zdu_alarm_sort_dao
,
alarm_content_time_distribution_dao
,
zdu_summary_dao
async
def
sdu_alarm_statistics_service
(
cids
,
start
,
end
,
product
):
async
def
sdu_alarm_statistics_service
(
cids
,
start
,
end
,
product
):
...
@@ -464,23 +464,17 @@ async def zdu_content_distribution_service(cid, start, end, product):
...
@@ -464,23 +464,17 @@ async def zdu_content_distribution_service(cid, start, end, product):
async
def
zdu_summary_service
(
cid
,
start
,
end
,
product
):
async
def
zdu_summary_service
(
cid
,
start
,
end
,
product
):
"""报警统计-统计概况信息-智电u"""
"""报警统计-统计概况信息-智电u"""
# 1. 报警总数, 报警监测点数, 平均报警 = 报警总数除以报警监测点
# 1. 报警总数, 报警监测点数, 平均报警 = 报警总数除以报警监测点
total_alarm_cnt
,
alarm_points
=
await
zdu_summary_info
(
cid
,
start
,
end
)
# total_alarm_cnt, alarm_points = await zdu_summary_info(cid, start, end)
total_alarm_cnt
,
alarm_points
=
await
zdu_summary_dao
(
cid
,
start
,
end
)
# 2. 安全运行, 本月累计安全运行天数,从月初算起, 未出现一级报警则加一天
# 2. 安全运行, 本月累计安全运行天数,从月初算起, 未出现一级报警则加一天
es_buckets
=
await
zdu_alarm_aggs_date_impotent
(
cid
,
start
,
end
)
safe_run
=
await
zdu_alarm_aggs_date_impotent
(
cid
,
start
,
end
)
total_day
=
len
(
es_buckets
)
has_alarm
=
0
for
bucket
in
es_buckets
:
inner_buckets
=
bucket
[
"important_cnt"
][
"buckets"
]
for
ib
in
inner_buckets
:
if
ib
[
"key"
]
==
1
:
has_alarm
+=
1
# 3. 时段分布, 白天/黑夜/凌晨
# 3. 时段分布, 白天/黑夜/凌晨
time_distribution_map
=
await
alarm_time_distribution
([
cid
],
start
,
end
)
time_distribution_map
=
await
alarm_time_distribution
([
cid
],
start
,
end
)
return
ZsResp
(
return
ZsResp
(
total_alarm_cnt
=
total_alarm_cnt
,
total_alarm_cnt
=
total_alarm_cnt
,
alarm_points_cnt
=
alarm_points
,
alarm_points_cnt
=
alarm_points
,
aver_alarm
=
round_1
(
division_two
(
total_alarm_cnt
,
alarm_points
)),
aver_alarm
=
round_1
(
division_two
(
total_alarm_cnt
,
alarm_points
)),
safe_run
=
total_day
-
has_alarm
,
safe_run
=
safe_run
,
time_interval_distribution
=
TimeCount
(
time_interval_distribution
=
TimeCount
(
daytime_cnt
=
time_distribution_map
[
"day_alarm_cnt"
],
daytime_cnt
=
time_distribution_map
[
"day_alarm_cnt"
],
night_cnt
=
time_distribution_map
[
"night_alarm_cnt"
],
night_cnt
=
time_distribution_map
[
"night_alarm_cnt"
],
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment