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
6d640792
Commit
6d640792
authored
Sep 07, 2022
by
peng.xiaozhe
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
首页 报警排名rank-type-ranking
parent
1c264a88
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
107 additions
and
2 deletions
+107
-2
common_cps.py
unify_api/modules/common/procedures/common_cps.py
+29
-0
count_info_pds.py
unify_api/modules/home_page/procedures/count_info_pds.py
+3
-2
count_info_proxy_pds.py
..._api/modules/home_page/procedures/count_info_proxy_pds.py
+75
-0
No files found.
unify_api/modules/common/procedures/common_cps.py
View file @
6d640792
...
...
@@ -164,6 +164,35 @@ async def proxy_safe_run_info(cids, start_time_str=None, end_time_str=None):
async
def
alarm_time_distribution
(
company_ids
,
start
,
end
):
sql
=
f
"""
SELECT
HOUR (pevent.event_datetime) event_hour,
COUNT(*) event_count
FROM
point_1min_event pevent
WHERE
cid IN
%
s
AND pevent.event_datetime >= '{start}'
AND pevent.event_datetime <= '{end}'
GROUP BY
HOUR (pevent.event_datetime)
"""
async
with
MysqlUtil
()
as
conn
:
datas
=
await
conn
.
fetchall
(
sql
,
args
=
(
company_ids
,
))
time_distribution_map
=
{
"day_alarm_cnt"
:
0
,
"night_alarm_cnt"
:
0
,
"morning_alarm_cnt"
:
0
}
for
data
in
datas
:
hour
=
int
(
data
[
"event_hour"
])
if
hour
>=
6
and
hour
<
18
:
time_distribution_map
[
"day_alarm_cnt"
]
+=
data
[
"event_count"
]
elif
hour
>=
18
and
hour
<=
23
:
time_distribution_map
[
"night_alarm_cnt"
]
+=
data
[
"event_count"
]
else
:
time_distribution_map
[
"morning_alarm_cnt"
]
+=
data
[
"event_count"
]
return
time_distribution_map
async
def
alarm_time_distribution_old
(
company_ids
,
start
,
end
):
start_dt
=
datetime
.
strptime
(
start
,
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
)
end_dt
=
datetime
.
strptime
(
end
,
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
)
es_start_str
=
datetime
(
year
=
start_dt
.
year
,
month
=
start_dt
.
month
,
day
=
start_dt
.
day
)
.
strftime
(
...
...
unify_api/modules/home_page/procedures/count_info_pds.py
View file @
6d640792
...
...
@@ -13,7 +13,8 @@ from pot_libs.mysql_util.mysql_util import MysqlUtil
from
unify_api
import
constants
from
unify_api.constants
import
Importance
,
EVENT_TYPE_MAP
,
SDU_ALARM_LIST
from
unify_api.modules.alarm_manager.dao.list_static_dao
import
\
sdu_alarm_importance_dao
,
alarm_aggs_importance
sdu_alarm_importance_dao
,
alarm_aggs_importance
,
\
sdu_alarm_importance_dao_new15
from
unify_api.modules.common.dao.common_dao
import
monitor_point_join
,
\
monitor_by_cid
from
unify_api.modules.common.procedures.common_utils
import
get_electric_index
...
...
@@ -1681,7 +1682,7 @@ async def cid_alarm_importance_count(cid, start, end):
"""计算工厂报警数, 按报警等级"""
monitor_point_list
=
await
monitor_point_join
(
cid
)
point_list
=
[
i
[
"pid"
]
for
i
in
monitor_point_list
]
es_res
=
await
sdu_alarm_importance_dao
(
start
,
end
,
point_list
)
es_res
=
await
sdu_alarm_importance_dao
_new15
(
start
,
end
,
point_list
)
es_res_key
=
{
i
[
"key"
]:
i
for
i
in
es_res
}
res_list
=
[]
...
...
unify_api/modules/home_page/procedures/count_info_proxy_pds.py
View file @
6d640792
...
...
@@ -23,6 +23,7 @@ from unify_api.modules.common.procedures.points import get_points
from
unify_api.modules.home_page.procedures.count_info_pds
import
\
datetime_to_timestamp
from
unify_api.utils.es_query_body
import
agg_statistics
from
unify_api.utils.time_format
import
last30_day_range_today
async
def
proxy_alarm_score
(
cids
):
...
...
@@ -129,6 +130,80 @@ async def security_level_count(cids):
async
def
alarm_percentage_count
(
cids
):
start
,
end
=
last30_day_range_today
()
importance_sql
=
f
"""
SELECT
COUNT(*) doc_count,
importance
FROM
point_1min_event pevent
WHERE
cid =
%
s
AND pevent.event_datetime >= '{start}'
AND pevent.event_datetime <= '{end}'
GROUP BY
pevent.importance
"""
event_type_sql
=
f
"""
SELECT
COUNT(*) doc_count,
event_type
FROM
point_1min_event pevent
WHERE
cid =
%
s
AND pevent.event_datetime >= '{start}'
AND pevent.event_datetime <= '{end}'
GROUP BY
pevent.event_type;
"""
async
with
MysqlUtil
()
as
conn
:
event_type_data
=
await
conn
.
fetchall
(
event_type_sql
,
args
=
(
cids
,))
importance_data
=
await
conn
.
fetchall
(
importance_sql
,
args
=
(
cids
,))
first_alarm_cnt
,
second_alarm_cnt
,
third_alarm_cnt
=
0
,
0
,
0
for
bucket
in
importance_data
:
if
bucket
[
"importance"
]
==
Importance
.
First
.
value
:
first_alarm_cnt
+=
bucket
[
"doc_count"
]
elif
bucket
[
"importance"
]
==
Importance
.
Second
.
value
:
second_alarm_cnt
+=
bucket
[
"doc_count"
]
elif
bucket
[
"importance"
]
==
Importance
.
Third
.
value
:
third_alarm_cnt
+=
bucket
[
"doc_count"
]
temperature_cnt
,
residual_current_cnt
,
electric_param_cnt
=
0
,
0
,
0
for
bucket
in
event_type_data
:
if
bucket
[
"event_type"
]
in
[
"overTemp"
,
"overTempRange1min"
,
"overTempRange15min"
,
"overTempTrendDaily"
,
"overTempTrendQuarterly"
,
]:
temperature_cnt
+=
bucket
[
"doc_count"
]
elif
bucket
[
"event_type"
]
in
[
"overResidualCurrent"
,
]:
residual_current_cnt
+=
bucket
[
"doc_count"
]
else
:
electric_param_cnt
+=
bucket
[
"doc_count"
]
time_distribution_map
=
await
alarm_time_distribution
(
cids
,
start
,
end
)
alarm_percentage_map
=
{
"first_alarm_cnt"
:
first_alarm_cnt
,
"second_alarm_cnt"
:
second_alarm_cnt
,
"third_alarm_cnt"
:
third_alarm_cnt
,
"temperature_cnt"
:
temperature_cnt
,
"residual_current_cnt"
:
residual_current_cnt
,
"electric_param_cnt"
:
electric_param_cnt
,
"day_alarm_cnt"
:
time_distribution_map
[
"day_alarm_cnt"
],
"night_alarm_cnt"
:
time_distribution_map
[
"night_alarm_cnt"
],
"morning_alarm_cnt"
:
time_distribution_map
[
"morning_alarm_cnt"
],
}
return
alarm_percentage_map
async
def
alarm_percentage_count_old
(
cids
):
now
=
datetime
.
now
()
end_timestamp
=
datetime_to_timestamp
(
now
)
start_timestamp
=
datetime_to_timestamp
(
...
...
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