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
8dd52daa
Commit
8dd52daa
authored
May 11, 2023
by
peng.xiaozhe
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix:scope-detail接口升级
parent
d01ffbff
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
56 additions
and
40 deletions
+56
-40
scope_operations_pds.py
...y_api/modules/zhiwei_u/procedures/scope_operations_pds.py
+29
-0
scope_operations_service.py
..._api/modules/zhiwei_u/service/scope_operations_service.py
+27
-40
No files found.
unify_api/modules/zhiwei_u/procedures/scope_operations_pds.py
0 → 100644
View file @
8dd52daa
from
pot_libs.mysql_util.mysql_util
import
MysqlUtil
async
def
get_event_info_by_event_id
(
event_id
):
"""获取报警信息"""
sql
=
f
"""
SELECT
mtid, name, pid point_id, UNIX_TIMESTAMP(event_datetime) time,
cid, message, event_datetime datetime
FROM point_1min_event
WHERE event_id = "{event_id}"
"""
async
with
MysqlUtil
()
as
conn
:
data
=
await
conn
.
fetchone
(
sql
)
return
data
if
data
else
{}
async
def
get_scope_info_pds
(
mtid
,
create_time
):
"""获取报警西南西"""
sql
=
f
"""
SELECT
fault_type, create_time datetime, index_loc result, url context_url
FROM point_1min_scope
WHERE mtid = "{mtid}"
AND create_time = "{create_time}"
"""
async
with
MysqlUtil
()
as
conn
:
data
=
await
conn
.
fetchone
(
sql
)
return
data
if
data
else
{}
unify_api/modules/zhiwei_u/service/scope_operations_service.py
View file @
8dd52daa
import
datetime
import
json
import
io
import
pandas
as
pd
from
pot_libs.qingstor_util.qs_client
import
QsClient
from
procedures.scope_operations_pds
import
get_event_info_by_event_id
,
get_scope_info_pds
from
unify_api.modules.zhiwei_u.fault_foreast.actionFile
import
actionFilemin
from
unify_api.modules.zhiwei_u
import
config
from
unify_api.utils
import
time_format
...
...
@@ -99,28 +103,27 @@ async def search_scope_service(prod_id, cid, pid, sid, page_num, page_size,
return
SearchScopeResq
(
total
=
total
,
rows
=
rows
)
async
def
load_context
(
url
):
async
with
QsClient
()
as
client
:
context_bytes
=
await
client
.
get_file
(
key
=
url
)
context
=
json
.
loads
(
context_bytes
.
decode
(
"utf-8"
))
return
context
async
def
scope_detail_service
(
id
,
wave_range
,
download
=
None
,
user_id
=
None
):
# 1.根据es_id查询point_1min_event对应的point属性
es_id
=
Equal
(
field
=
"_id"
,
value
=
id
)
filter
=
Filter
(
equals
=
[
es_id
],
ranges
=
[],
in_groups
=
[],
keywords
=
[])
query_request
=
PageRequest
(
page_size
=
1
,
page_num
=
1
,
filter
=
filter
,
sort
=
None
)
query_body
=
EsQuery
.
query
(
query_request
)
try
:
async
with
EsUtil
()
as
es
:
es_results
=
await
es
.
search_origin
(
body
=
query_body
,
index
=
config
.
SCOPE_DATABASE
)
except
:
log
.
error
(
"es query error"
)
mysql_results
=
await
get_event_info_by_event_id
(
id
)
except
Exception
as
e
:
log
.
error
(
f
"query error {e}"
)
return
ScopeDetailsResponse
()
.
db_error
()
try
:
es_results
=
es_results
[
"hits"
][
"hits"
][
0
]
source
=
es_results
.
get
(
"_source"
,
{})
source
=
mysql_results
point_name
=
source
.
get
(
"name"
)
point_id
=
source
.
get
(
"point_id"
)
mtid
=
source
.
get
(
"mtid"
)
cmp_time
=
source
.
get
(
"time"
)
cid
=
source
.
get
(
"cid"
)
...
...
@@ -132,37 +135,20 @@ async def scope_detail_service(id, wave_range, download=None, user_id=None):
point
=
await
select_sid_by_pid
(
point_id
)
except
Exception
:
log
.
warning
(
"can not find data on es(index:
%
s):
%
s"
%
(
config
.
POINT_1MIN_SCOPE
,
query_body
))
log
.
warning
(
f
"query err {id}"
)
raise
DBException
# 4.接线法:二表/三表
ctnum
,
_
=
await
get_wiring_type
(
point_id
)
if
not
ctnum
:
ctnum
=
3
# 2.用point_1min_event的ponint_id、cmp_time查询point_1min_scope
point_equal
=
Equal
(
field
=
"point_id"
,
value
=
point_id
)
time_equal
=
Equal
(
field
=
"time"
,
value
=
cmp_time
)
filter
=
Filter
(
equals
=
[
point_equal
,
time_equal
],
ranges
=
[],
in_groups
=
[],
keywords
=
[])
query_request
=
PageRequest
(
page_size
=
1
,
page_num
=
1
,
filter
=
filter
,
sort
=
None
)
query_body
=
EsQuery
.
query
(
query_request
)
try
:
async
with
EsUtil
()
as
es
:
es_results
=
await
es
.
search_origin
(
body
=
query_body
,
index
=
config
.
POINT_1MIN_SCOPE
)
mysql_results
=
await
get_scope_info_pds
(
mtid
,
check_dt
)
except
Exception
as
e
:
log
.
error
(
f
"es query error {e}"
)
return
ScopeDetailsResponse
()
.
db_error
()
if
not
es_results
:
log
.
warning
(
"can not find data on es(index:
%
s):
%
s"
%
(
config
.
POINT_1MIN_SCOPE
,
query_body
))
return
ScopeDetailsResponse
()
.
db_error
()
if
not
es_results
[
"hits"
][
"hits"
]:
if
not
mysql_results
:
alarm
=
Alarm
(
check_dt
=
check_dt
,
pid
=
point_id
,
cid
=
cid
,
point
=
point_name
,
sid
=
point
[
"sid"
],
message
=
message
,
...
...
@@ -180,12 +166,13 @@ async def scope_detail_service(id, wave_range, download=None, user_id=None):
date_time
=
""
,
contents
=
{}
)
es_results
=
es_results
[
"hits"
][
"hits"
][
0
]
scope_type
=
es_results
.
get
(
"_source"
,
{})
.
get
(
"fault_type"
)
source
=
mysql_results
scope_type
=
source
.
get
(
"fault_type"
)
fault_type
=
config
.
EVENT_TYPE_MAP
.
get
(
scope_type
)
date_time
=
time_format
.
esstr_to_dtstr
(
es_results
[
"_source"
]
.
get
(
"datetime"
))
position
=
list
(
json
.
loads
(
es_results
[
"_source"
]
.
get
(
"result"
))
.
keys
())
# date_time = time_format.esstr_to_dtstr(
# source.get("datetime"))
date_time
=
datetime
.
datetime
.
strftime
(
source
.
get
(
"datetime"
),
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
)
position
=
list
(
json
.
loads
(
source
.
get
(
"result"
))
.
keys
())
position_tmp
=
[
pos
+
"相"
if
len
(
pos
)
==
1
else
pos
+
"线"
if
len
(
pos
)
==
2
else
''
for
pos
in
position
]
...
...
@@ -193,9 +180,9 @@ async def scope_detail_service(id, wave_range, download=None, user_id=None):
position_str
=
"|"
.
join
(
position_tmp
)
# 3.曲线数据
res_dic
=
json
.
loads
(
es_results
[
"_source"
]
.
get
(
"result"
))
res_dic
=
json
.
loads
(
source
.
get
(
"result"
))
location
=
[
d
for
d
in
res_dic
.
values
()][
0
]
.
get
(
"location"
)
wave_data
=
json
.
loads
(
es_results
[
"_source"
]
.
get
(
"context
"
))
wave_data
=
await
load_context
(
source
.
get
(
"context_url
"
))
length
=
wave_data
.
get
(
"ia"
)
or
wave_data
.
get
(
"ileak_rms"
)
contin_time
=
len
(
length
)
if
wave_range
==
"100ms"
:
...
...
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