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
0c29e639
Commit
0c29e639
authored
Jul 06, 2023
by
lcn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bug修复
parent
8441b0f6
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
48 deletions
+45
-48
data_es_dao.py
unify_api/modules/zhiwei_u/dao/data_es_dao.py
+25
-24
scope_operations_service.py
..._api/modules/zhiwei_u/service/scope_operations_service.py
+20
-24
No files found.
unify_api/modules/zhiwei_u/dao/data_es_dao.py
View file @
0c29e639
...
...
@@ -50,23 +50,24 @@ async def query_location_1min_index(date_start, date_end, mtid,
return
results
async
def
get_search_scope
(
cid
,
pid
,
start
,
end
):
where_list
=
[
f
"pid = {pid}"
]
async
def
get_search_scope
(
cid
,
pid
,
start
,
end
,
limit
,
offset
):
where
=
f
" event_mode='scope'"
args
=
()
if
cid
:
where_list
.
append
(
f
"cid in
%
s"
)
where
+=
f
" and cid in
%
s"
args
=
(
cid
,)
if
pid
:
where
+=
f
" and pid = {pid}"
if
start
and
end
:
where_list
.
append
(
f
"event_datetime >= '{start}' and event_datetime <='{end}' "
)
where_str
=
" and "
.
join
(
where_list
)
sql
=
f
"select * from point_1min_event where {where_str} "
\
f
"and event_mode='scope' "
\
f
"ORDER BY event_datetime desc limit 5000"
where
+=
f
" and event_datetime >= '{start}' and event_datetime <="
\
f
"'{end}' "
sql
=
f
"select * from point_1min_event where {where} "
\
f
"ORDER BY event_datetime desc limit {limit} offset {offset}"
total_sql
=
f
"select count(*) count from point_1min_event where {where}"
async
with
MysqlUtil
()
as
conn
:
if
cid
:
data
=
await
conn
.
fetchall
(
sql
,
args
=
(
cid
,))
else
:
data
=
await
conn
.
fetchall
(
sql
)
return
data
data
=
await
conn
.
fetchall
(
sql
,
args
=
args
)
or
[]
total
=
await
conn
.
fetch_value
(
total_sql
,
args
=
args
)
or
0
return
data
,
total
async
def
query_search_scope
(
cid
,
pid
,
page_num
,
page_size
,
...
...
@@ -136,15 +137,15 @@ async def query_search_scope(cid, pid, page_num, page_size,
return
data
,
total
async
def
get_scope_pids
(
pids
,
start
,
end
):
async
def
get_scope_pids
(
pids
,
start
,
end
,
limit
=
20
,
offset
=
0
):
where_str
=
f
"event_mode='scope' and pid in {pids}"
if
start
and
end
:
where_str
=
f
"pid in {pids} and event_datetime>={start} and "
\
f
"event_datetime<={end}"
else
:
where_str
=
f
"pid in {pids}"
sql
=
f
"select * from point_1min_event where {where_str} and "
\
f
"event_mode='scope' "
\
f
"ORDER BY event_datetime desc limit 5000"
where_str
+=
f
" and event_datetime>={start} and event_datetime<={end}"
sql
=
f
"select * from point_1min_event where {where_str} "
\
f
"ORDER BY event_datetime desc limit {limit} offset {offset}"
total_sql
=
f
"select count(*) count from point_1min_event where"
\
f
" {where_str}"
async
with
MysqlUtil
()
as
conn
:
data
=
await
conn
.
fetchall
(
sql
)
return
data
data
=
await
conn
.
fetchall
(
sql
)
or
[]
total
=
await
conn
.
fetch_value
(
total_sql
)
or
0
return
data
,
total
unify_api/modules/zhiwei_u/service/scope_operations_service.py
View file @
0c29e639
...
...
@@ -4,7 +4,8 @@ import io
import
pandas
as
pd
from
pot_libs.qingstor_util.qs_client
import
QsClient
from
unify_api.modules.zhiwei_u.procedures.scope_operations_pds
import
get_event_info_by_event_id
,
get_scope_info_pds
from
unify_api.modules.zhiwei_u.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
...
...
@@ -45,22 +46,17 @@ async def search_scope_service(prod_id, cid, pid, sid, page_num, page_size,
pids_datas
=
await
sid_to_order_dao
(
sid
)
pids
=
[
data
[
"pid"
]
for
data
in
pids_datas
]
# todo databases should be point_1min_scope, not point_1min_event
scope_datas
=
await
get_scope_pids
(
pids
,
start
,
end
)
datas
=
scope_datas
[
start_num
:
start_num
+
page_size
]
total
=
len
(
scope_datas
)
# datas = await query_search_scope_pids(pids, page_num, page_size,
# start, end)
datas
,
total
=
await
get_scope_pids
(
pids
,
start
,
end
,
page_size
,
start_num
)
else
:
if
prod_id
and
not
cid
and
not
pid
:
cid_list
=
await
select_cids_by_prod_id
(
prod_id
)
cid
=
[
c
[
"cid"
]
for
c
in
cid_list
]
elif
cid
:
cid
=
[
cid
]
scope_datas
=
await
get_search_scope
(
cid
,
pid
,
start
,
end
)
datas
=
scope_datas
[
start_num
:
start_num
+
page_size
]
total
=
len
(
scope_datas
)
datas
,
total
=
await
get_search_scope
(
cid
,
pid
,
start
,
end
,
page_size
,
start_num
)
if
not
datas
:
return
SearchScopeResq
(
total
=
0
,
rows
=
[])
pids
,
cids
=
[],
[]
...
...
@@ -93,7 +89,7 @@ async def search_scope_service(prod_id, cid, pid, sid, page_num, page_size,
alarm
=
Alarm
(
check_dt
=
check_dt
,
prod_id
=
company
.
get
(
"product"
),
product
=
config
.
PRODUCT
[
company
.
get
(
"product"
)],
cid
=
cid
,
shortname
=
company
.
get
(
"shortname"
),
pid
=
pid
,
point
=
point
.
get
(
"name"
),
sid
=
point
.
get
(
"sid"
),
pid
=
pid
,
point
=
point
.
get
(
"name"
),
sid
=
point
.
get
(
"sid"
),
message
=
message
,
doc_id
=
doc_id
)
rows
.
append
(
alarm
)
...
...
@@ -108,21 +104,20 @@ async def load_context(url):
async
def
scope_detail_service
(
id
,
wave_range
,
download
=
None
,
user_id
=
None
):
# 1.根据es_id查询point_1min_event对应的point属性
try
:
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
:
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"
)
company
=
await
select_cname_by_cid
(
cid
)
message
=
source
.
get
(
"message"
)
...
...
@@ -130,7 +125,7 @@ async def scope_detail_service(id, wave_range, download=None, user_id=None):
dt
=
time_format
.
convert_to_dt
(
check_dt
)
check_dt
=
time_format
.
convert_dt_to_timestr
(
dt
)
point
=
await
select_sid_by_pid
(
point_id
)
except
Exception
:
log
.
warning
(
f
"query err {id}"
)
raise
DBException
...
...
@@ -138,15 +133,14 @@ async def scope_detail_service(id, wave_range, download=None, user_id=None):
ctnum
,
_
=
await
get_wiring_type
(
point_id
)
if
not
ctnum
:
ctnum
=
3
try
:
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
mysql_results
:
alarm
=
Alarm
(
check_dt
=
check_dt
,
pid
=
point_id
,
cid
=
cid
,
point
=
point_name
,
sid
=
point
[
"sid"
],
message
=
message
,
prod_id
=
company
[
"product"
],
...
...
@@ -166,14 +160,16 @@ async def scope_detail_service(id, wave_range, download=None, user_id=None):
source
=
mysql_results
scope_type
=
source
.
get
(
"fault_type"
)
fault_type
=
config
.
EVENT_TYPE_MAP
.
get
(
scope_type
)
date_time
=
datetime
.
datetime
.
strftime
(
source
.
get
(
"datetime"
),
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
)
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
+
"相"
if
len
(
pos
)
==
1
else
pos
+
"线"
if
len
(
pos
)
==
2
else
''
for
pos
in
position
]
position_tmp
=
[
p
for
p
in
position_tmp
if
p
]
# 去掉空字符串
position_str
=
"|"
.
join
(
position_tmp
)
# 3.曲线数据
res_dic
=
json
.
loads
(
source
.
get
(
"result"
))
location
=
[
d
for
d
in
res_dic
.
values
()][
0
]
.
get
(
"location"
)
...
...
@@ -240,7 +236,7 @@ async def scope_detail_service(id, wave_range, download=None, user_id=None):
else
:
result
=
""
for
r
in
res
:
result
+=
"
%
s :
%0.0
f
%%
;"
%
(
r
[
0
],
r
[
1
]
*
100
)
result
+=
"
%
s :
%0.0
f
%%
;"
%
(
r
[
0
],
r
[
1
]
*
100
)
except
Exception
as
e
:
result
=
""
log
.
error
(
f
"actionFile error:{e}"
)
...
...
@@ -251,7 +247,7 @@ async def scope_detail_service(id, wave_range, download=None, user_id=None):
shortname
=
company
[
"shortname"
],
contin_time
=
int
(
contin_time
*
0.25
),
result
=
result
)
return
ScopeDetailsResponse
(
alarm
=
alarm
,
ctnum
=
ctnum
,
...
...
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