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
d9f4a706
Commit
d9f4a706
authored
Jun 16, 2023
by
ZZH
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
real time aiao 2023-6-16
parent
6348a28e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
39 additions
and
38 deletions
+39
-38
count_info_pds.py
unify_api/modules/home_page/procedures/count_info_pds.py
+39
-38
No files found.
unify_api/modules/home_page/procedures/count_info_pds.py
View file @
d9f4a706
...
...
@@ -129,7 +129,7 @@ async def normal_rate_of_location(cid):
"""获取温度和漏电流达标率"""
d_stats
=
{
"residual_current"
:
{
"total"
:
0
,
"normal"
:
0
},
"temperature"
:
{
"total"
:
0
,
"normal"
:
0
},
}
sql
=
"select l.lid, l.
item, l.
ad_type type, s.threshold from "
\
sql
=
"select l.lid, l.ad_type type, s.threshold from "
\
"location l left join soe_config_record s on l.lid=s.lid "
\
"where l.cid =
%
s and s.enable=1 and l.ad_type in
%
s "
\
"and s.etype in
%
s;"
...
...
@@ -137,50 +137,51 @@ async def normal_rate_of_location(cid):
locs
=
await
conn
.
fetchall
(
sql
,
(
cid
,
(
"residual_current"
,
"temperature"
),
(
"overTemp"
,
"overResidualCurrent"
)))
loc_infos
=
{
loc
[
"lid"
]:
loc
for
loc
in
locs
}
lids
=
list
(
loc_infos
.
keys
())
if
not
lids
:
return
"100
%
"
,
"100
%
"
location_map
=
{
loc
[
"lid"
]:
loc
for
loc
in
locs
}
lids
=
list
(
location_map
.
keys
())
adio_currents
=
[]
if
lids
:
prefix
=
f
"real_time:adio:{SETTING.mysql_db}"
keys
=
[
f
"{prefix}:{lid}"
for
lid
in
lids
]
adio_currents
=
await
RedisUtils
()
.
mget
(
keys
)
log
.
info
(
f
"adio_currents:{adio_currents}"
)
adio_infos
=
{}
for
index
,
item_byte
in
enumerate
(
adio_currents
):
if
item_byte
:
adio_infos
[
lids
[
index
]]
=
json
.
loads
(
item_byte
.
decode
())
for
lid
,
d_loc
in
location_map
.
items
():
d_adio
=
adio_infos
.
get
(
lid
)
d_stats
[
d_loc
[
"type"
]][
"total"
]
+=
1
if
d_adio
and
d_adio
.
get
(
"value"
):
time_now
=
int
(
time
.
time
())
real_tt
=
d_adio
.
get
(
"timestamp"
,
0
)
if
(
time_now
-
real_tt
)
>
constants
.
REAL_EXP_TIME
:
# 超过4小时的值不统计在normal里
log
.
warn
(
f
"adio_current location_id={lid} has expire!"
)
rt_rlts
=
await
RedisUtils
()
.
mget
(
keys
)
rt_adios
=
[
json
.
loads
(
r
)
for
r
in
rt_rlts
if
r
]
d_rt_adio
=
{
adio
[
"lid"
]:
adio
for
adio
in
rt_adios
}
now_ts
=
pendulum
.
now
(
tz
=
CST
)
.
int_timestamp
for
lid
,
d_loc
in
loc_infos
.
items
():
d_stats
[
d_loc
[
"type"
]][
"total"
]
+=
1
if
lid
not
in
d_rt_adio
:
continue
if
(
isinstance
(
d_loc
[
"threshold"
],
float
)
and
d_adio
[
"value"
]
<
d_loc
[
"threshold"
]):
d_stats
[
d_loc
[
"type"
]][
"normal"
]
+=
1
if
not
isinstance
(
d_loc
[
"threshold"
],
(
float
,
int
)):
continue
if
d_stats
[
"temperature"
][
"total"
]
==
0
:
temp_qr
=
"100
%
"
else
:
norm
=
d_stats
[
"temperature"
][
"normal"
]
total
=
d_stats
[
"temperature"
][
"total"
]
temp_qr
=
str
(
round
((
norm
/
total
)
*
100
,
))
+
"
%
"
try
:
d_adio
=
d_rt_adio
[
lid
]
if
(
now_ts
-
d_adio
[
"ts"
])
>
constants
.
REAL_EXP_TIME
:
log
.
warn
(
f
"adio_current location_id={lid} has expire!"
)
continue
if
d_stats
[
"residual_current"
][
"total"
]
==
0
:
rc_qr
=
"100
%
"
else
:
norm
=
d_stats
[
"residual_current"
][
"normal"
]
total
=
d_stats
[
"residual_current"
][
"total"
]
rc_qr
=
str
(
round
((
norm
/
total
)
*
100
))
+
"
%
"
return
temp_qr
,
rc_qr
if
d_adio
[
"v"
]
<
d_loc
[
"threshold"
]:
d_stats
[
d_loc
[
"type"
]][
"normal"
]
+=
1
except
Exception
as
e
:
log
.
exception
(
f
"parse real time adio:{d_adio} exc, e:{e}"
)
if
d_stats
[
"temperature"
][
"total"
]
==
0
:
temp_qr
=
"100
%
"
else
:
norm
=
d_stats
[
"temperature"
][
"normal"
]
total
=
d_stats
[
"temperature"
][
"total"
]
temp_qr
=
str
(
round
((
norm
/
total
)
*
100
,
))
+
"
%
"
if
d_stats
[
"residual_current"
][
"total"
]
==
0
:
rc_qr
=
"100
%
"
else
:
norm
=
d_stats
[
"residual_current"
][
"normal"
]
total
=
d_stats
[
"residual_current"
][
"total"
]
rc_qr
=
str
(
round
((
norm
/
total
)
*
100
))
+
"
%
"
return
temp_qr
,
rc_qr
async
def
real_time_load
(
cid
,
end_dt
=
None
):
...
...
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