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
f1c2b7ac
Commit
f1c2b7ac
authored
May 30, 2023
by
ZZH
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
remove es 2023-5-30
parent
ebaa57cd
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
7 additions
and
138 deletions
+7
-138
alarm_static_pds.py
..._api/modules/alarm_manager/procedures/alarm_static_pds.py
+1
-60
alarm_static_service.py
...api/modules/alarm_manager/service/alarm_static_service.py
+4
-5
alarm_static.py
unify_api/modules/alarm_manager/views/alarm_static.py
+2
-2
count_info_pds.py
unify_api/modules/home_page/procedures/count_info_pds.py
+0
-71
No files found.
unify_api/modules/alarm_manager/procedures/alarm_static_pds.py
View file @
f1c2b7ac
...
@@ -98,65 +98,6 @@ async def sdu_alarm_content_info(cids, start, end, points):
...
@@ -98,65 +98,6 @@ async def sdu_alarm_content_info(cids, start, end, points):
async
def
risk_distribution
(
start
,
end
,
point_id_list
,
is_new
=
False
):
async
def
risk_distribution
(
start
,
end
,
point_id_list
,
is_new
=
False
):
"""风险分布, 暂时识电u使用"""
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
(
"
%
Y-
%
m-
%
dT
%
H:
%
M:
%
S+08:00"
)
es_end_str
=
end_dt
.
strftime
(
"
%
Y-
%
m-
%
dT
%
H:
%
M:
%
S+08:00"
)
importance_list
=
[
1
]
# 新版sdu, 其中当前时段发生过I或II级报警为风险用户,其余为安全用户
if
is_new
:
importance_list
=
[
1
,
2
]
query_body
=
{
"size"
:
0
,
"query"
:
{
"bool"
:
{
"filter"
:
[
{
"range"
:
{
"datetime"
:
{
"gte"
:
es_start_str
,
"lte"
:
es_end_str
}
}
},
{
"terms"
:
{
"point_id"
:
point_id_list
}
},
{
"terms"
:
{
"importance"
:
importance_list
}
},
# 新版sdu, 限制报警类型
{
"terms"
:
{
"type.keyword"
:
SDU_ALARM_LIST
}}
]
}
},
"aggs"
:
{
"alarm_cnt"
:
{
"terms"
:
{
"field"
:
"point_id"
}
}
}
}
log
.
info
(
"risk_distribution query_body={}"
.
format
(
query_body
))
async
with
EsUtil
()
as
es
:
es_result
=
await
es
.
search_origin
(
body
=
query_body
,
index
=
constants
.
POINT_1MIN_EVENT
)
buckets
=
es_result
[
"aggregations"
][
"alarm_cnt"
][
"buckets"
]
total_user
=
len
(
point_id_list
)
risk_user
=
len
(
buckets
)
security_user
=
total_user
-
risk_user
return
security_user
,
risk_user
async
def
risk_distribution_new15
(
start
,
end
,
point_id_list
,
is_new
=
False
):
li
=
[
f
"event_datetime BETWEEN '{start}' and '{end}'"
,
li
=
[
f
"event_datetime BETWEEN '{start}' and '{end}'"
,
f
"event_type in {tuple(SDU_ALARM_LIST)}"
]
f
"event_type in {tuple(SDU_ALARM_LIST)}"
]
if
is_new
:
if
is_new
:
...
@@ -169,7 +110,7 @@ async def risk_distribution_new15(start, end, point_id_list, is_new=False):
...
@@ -169,7 +110,7 @@ async def risk_distribution_new15(start, end, point_id_list, is_new=False):
li
.
append
(
f
"pid in {tuple(point_id_list)}"
)
li
.
append
(
f
"pid in {tuple(point_id_list)}"
)
mid_sql
=
" and "
.
join
(
li
)
mid_sql
=
" and "
.
join
(
li
)
sql
=
f
"SELECT DISTINCT pid FROM `point_1min_event` where {mid_sql}"
sql
=
f
"SELECT DISTINCT pid FROM `point_1min_event` where {mid_sql}"
log
.
info
(
f
"risk_distribution
_new15
sql:{sql}"
)
log
.
info
(
f
"risk_distribution sql:{sql}"
)
async
with
MysqlUtil
()
as
conn
:
async
with
MysqlUtil
()
as
conn
:
datas
=
await
conn
.
fetchall
(
sql
)
datas
=
await
conn
.
fetchall
(
sql
)
total_user
=
len
(
point_id_list
)
total_user
=
len
(
point_id_list
)
...
...
unify_api/modules/alarm_manager/service/alarm_static_service.py
View file @
f1c2b7ac
...
@@ -8,8 +8,7 @@ from unify_api.modules.alarm_manager.dao.list_static_dao import \
...
@@ -8,8 +8,7 @@ from unify_api.modules.alarm_manager.dao.list_static_dao import \
sdu_alarm_importance_dao
,
sdu_alarm_statistics_dao
,
\
sdu_alarm_importance_dao
,
sdu_alarm_statistics_dao
,
\
sdu_alarm_behavior_dao
,
sdu_alarm_limit_type_dao
sdu_alarm_behavior_dao
,
sdu_alarm_limit_type_dao
from
unify_api.modules.alarm_manager.procedures.alarm_static_pds
import
\
from
unify_api.modules.alarm_manager.procedures.alarm_static_pds
import
\
risk_distribution
,
zdu_summary_info
,
\
sdu_alarm_content_info
,
risk_distribution
,
\
sdu_alarm_content_info
,
risk_distribution_new15
,
\
alarm_content_time_distribution_pds
alarm_content_time_distribution_pds
from
unify_api.modules.common.dao.common_dao
import
points_by_cid
,
\
from
unify_api.modules.common.dao.common_dao
import
points_by_cid
,
\
monitor_point_join
,
points_monitor_by_cid
monitor_point_join
,
points_monitor_by_cid
...
@@ -55,7 +54,7 @@ async def sdu_alarm_statistics_service(cids, start, end, product):
...
@@ -55,7 +54,7 @@ async def sdu_alarm_statistics_service(cids, start, end, product):
)
)
# 2.计算风险分布, 与安电u不同, 安电u发生过I级则为风险用户
# 2.计算风险分布, 与安电u不同, 安电u发生过I级则为风险用户
# 其中当前时段发生过I或II级报警为风险用户,其余为安全用户
# 其中当前时段发生过I或II级报警为风险用户,其余为安全用户
security_user
,
risk_user
=
await
risk_distribution
_new15
(
start
,
end
,
security_user
,
risk_user
=
await
risk_distribution
(
start
,
end
,
point_id_list
,
point_id_list
,
is_new
=
True
)
is_new
=
True
)
rc
=
RiskCount
(
security_user
=
security_user
,
risk_user
=
risk_user
)
rc
=
RiskCount
(
security_user
=
security_user
,
risk_user
=
risk_user
)
...
...
unify_api/modules/alarm_manager/views/alarm_static.py
View file @
f1c2b7ac
...
@@ -12,7 +12,7 @@ from unify_api.modules.alarm_manager.service.alarm_static_service import \
...
@@ -12,7 +12,7 @@ from unify_api.modules.alarm_manager.service.alarm_static_service import \
from
unify_api.modules.home_page.components.security_info_cps
import
\
from
unify_api.modules.home_page.components.security_info_cps
import
\
SecurityCountResp
,
AlarmContentDistributionResp
SecurityCountResp
,
AlarmContentDistributionResp
from
unify_api.modules.home_page.procedures.count_info_pds
import
\
from
unify_api.modules.home_page.procedures.count_info_pds
import
\
electric_use_info_sdu
,
electric_use_info_sdu_new15
electric_use_info_sdu
from
unify_api.utils.time_format
import
last30_day_range
from
unify_api.utils.time_format
import
last30_day_range
...
@@ -83,7 +83,7 @@ async def post_sdu_index_alarm_statistics(req, body: SiasReq) -> SiasResp:
...
@@ -83,7 +83,7 @@ async def post_sdu_index_alarm_statistics(req, body: SiasReq) -> SiasResp:
# 安全和报警统计
# 安全和报警统计
res
=
await
sdu_alarm_statistics_service
([
cid
],
start
,
end
,
product
)
res
=
await
sdu_alarm_statistics_service
([
cid
],
start
,
end
,
product
)
# 安全指数
# 安全指数
alarm_res
=
await
electric_use_info_sdu
_new15
(
cid
)
alarm_res
=
await
electric_use_info_sdu
(
cid
)
electric_use_score
=
round
(
alarm_res
.
electric_use_score
)
electric_use_score
=
round
(
alarm_res
.
electric_use_score
)
return
SiasResp
(
return
SiasResp
(
risk_distribution
=
res
.
risk_distribution
,
risk_distribution
=
res
.
risk_distribution
,
...
...
unify_api/modules/home_page/procedures/count_info_pds.py
View file @
f1c2b7ac
...
@@ -1052,77 +1052,6 @@ async def optimization_count_info(company_id: int):
...
@@ -1052,77 +1052,6 @@ async def optimization_count_info(company_id: int):
async
def
electric_use_info_sdu
(
cid
):
async
def
electric_use_info_sdu
(
cid
):
"""用电安全指数, 识电u"""
start
,
end
=
last30_day_range
()
start_es
=
convert_es_str
(
start
)
end_es
=
convert_es_str
(
end
)
query_body
=
{
"query"
:
{
"bool"
:
{
"filter"
:
[
{
"term"
:
{
"cid"
:
cid
}},
{
"range"
:
{
"datetime"
:
{
"gte"
:
start_es
,
"lte"
:
end_es
,
}}},
{
"terms"
:
{
"type.keyword"
:
SDU_ALARM_LIST
}}
],
}
},
"size"
:
0
,
"aggs"
:
{
"alarm_aggs"
:
{
"terms"
:
{
"field"
:
"importance"
}
}
}
}
log
.
info
(
"cal_score_safe_electric query_body={}"
.
format
(
query_body
))
async
with
EsUtil
()
as
es
:
es_result
=
await
es
.
search_origin
(
body
=
query_body
,
index
=
constants
.
POINT_1MIN_EVENT
)
score_buckets
=
(
es_result
.
get
(
"aggregations"
,
{})
.
get
(
"alarm_aggs"
,
{})
.
get
(
"buckets"
,
[])
)
first_alarm_cnt
=
0
second_alarm_cnt
=
0
third_alarm_cnt
=
0
for
bucket
in
score_buckets
:
if
bucket
[
"key"
]
==
Importance
.
First
.
value
:
first_alarm_cnt
+=
bucket
[
"doc_count"
]
elif
bucket
[
"key"
]
==
Importance
.
Second
.
value
:
second_alarm_cnt
+=
bucket
[
"doc_count"
]
elif
bucket
[
"key"
]
==
Importance
.
Third
.
value
:
third_alarm_cnt
+=
bucket
[
"doc_count"
]
company_point_map
=
await
get_points
([
cid
])
point_len
=
len
(
company_point_map
.
get
(
cid
)
or
{})
alarm_score
=
(
(
first_alarm_cnt
*
2
+
second_alarm_cnt
*
1
+
third_alarm_cnt
*
0.5
)
/
point_len
if
point_len
else
0
)
if
alarm_score
>=
15
:
alarm_score
=
15
electric_use_score
=
get_electric_index
(
alarm_score
)
log
.
info
(
"point_len={} alarm_score={} electric_use_score={}"
.
format
(
point_len
,
alarm_score
,
electric_use_score
)
)
return
ElectricInfo
(
first_alarm_cnt
=
first_alarm_cnt
,
second_alarm_cnt
=
second_alarm_cnt
,
third_alarm_cnt
=
third_alarm_cnt
,
alarm_score
=
alarm_score
,
electric_use_score
=
electric_use_score
,
)
async
def
electric_use_info_sdu_new15
(
cid
):
start
,
end
=
last30_day_range
()
start
,
end
=
last30_day_range
()
first_alarm_cnt
=
0
first_alarm_cnt
=
0
second_alarm_cnt
=
0
second_alarm_cnt
=
0
...
...
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