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
36127263
Commit
36127263
authored
Jun 16, 2023
by
ZZH
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix temp rc qr 2023-6-16
parent
1cbb81b3
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
39 additions
and
62 deletions
+39
-62
count_info_pds.py
unify_api/modules/home_page/procedures/count_info_pds.py
+39
-62
No files found.
unify_api/modules/home_page/procedures/count_info_pds.py
View file @
36127263
...
@@ -127,80 +127,57 @@ async def electric_use_info(cid):
...
@@ -127,80 +127,57 @@ async def electric_use_info(cid):
async
def
normal_rate_of_location
(
cid
):
async
def
normal_rate_of_location
(
cid
):
"""获取温度和漏电流达标率"""
"""获取温度和漏电流达标率"""
location_map
=
{}
d_stats
=
{
"residual_current"
:
{
"total"
:
0
,
"normal"
:
0
},
location_sql
=
"select l.lid, l.item, l.ad_type type, s.threshold from "
\
"temperature"
:
{
"total"
:
0
,
"normal"
:
0
},
}
sql
=
"select l.lid, l.item, l.ad_type type, s.threshold from "
\
"location l left join soe_config_record s on l.lid=s.lid "
\
"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 "
\
"where l.cid =
%
s and s.enable=1 and l.ad_type in
%
s "
\
"and s.etype in
%
s
"
"and s.etype in
%
s;
"
async
with
MysqlUtil
()
as
conn
:
async
with
MysqlUtil
()
as
conn
:
loc
ations
=
await
conn
.
fetchall
(
loc
s
=
await
conn
.
fetchall
(
sql
,
(
cid
,
location_sql
,
args
=
(
cid
,
(
"residual_current"
,
"temperature"
),
(
"residual_current"
,
"temperature"
),
(
"overTemp"
,
"overResidualCurrent"
)))
(
"overTemp"
,
"overResidualCurrent"
)))
for
location
in
locations
:
location_map
[
location
[
"lid"
]]
=
location
location_map
=
{
loc
[
"lid"
]:
loc
for
loc
in
locs
}
count_info_map
=
{
lids
=
list
(
location_map
.
keys
())
"residual_current"
:
{
"total"
:
0
,
"normal"
:
0
},
"temperature"
:
{
"total"
:
0
,
"normal"
:
0
},
}
location_ids
=
list
(
location_map
.
keys
())
adio_currents
=
[]
adio_currents
=
[]
if
l
ocation_
ids
:
if
lids
:
adio_currents
=
await
RedisUtils
()
.
hmget
(
"adio_current"
,
adio_currents
=
await
RedisUtils
()
.
hmget
(
"adio_current"
,
*
lids
)
*
location_ids
)
adio_info
_map
=
{}
adio_info
s
=
{}
for
index
,
item_byte
in
enumerate
(
adio_currents
):
for
index
,
item_byte
in
enumerate
(
adio_currents
):
if
item_byte
:
if
item_byte
:
item
=
json
.
loads
(
item_byte
.
decode
())
adio_infos
[
lids
[
index
]]
=
json
.
loads
(
item_byte
.
decode
())
adio_info_map
[
location_ids
[
index
]]
=
item
for
l
ocation_id
,
location_info
in
location_map
.
items
():
for
l
id
,
d_loc
in
location_map
.
items
():
audio_info
=
adio_info_map
.
get
(
location_
id
)
d_adio
=
adio_infos
.
get
(
l
id
)
count_info_map
[
location_info
[
"type"
]][
"total"
]
+=
1
d_stats
[
d_loc
[
"type"
]][
"total"
]
+=
1
if
audio_info
and
audio_inf
o
.
get
(
"value"
):
if
d_adio
and
d_adi
o
.
get
(
"value"
):
time_now
=
int
(
time
.
time
())
time_now
=
int
(
time
.
time
())
real_tt
=
audio_inf
o
.
get
(
"timestamp"
,
0
)
real_tt
=
d_adi
o
.
get
(
"timestamp"
,
0
)
if
(
time_now
-
real_tt
)
>
constants
.
REAL_EXP_TIME
:
if
(
time_now
-
real_tt
)
>
constants
.
REAL_EXP_TIME
:
# 超过4小时的值不统计在normal里
# 超过4小时的值不统计在normal里
log
.
warn
(
f
"adio_current location_id={l
ocation_
id} has expire!"
)
log
.
warn
(
f
"adio_current location_id={lid} has expire!"
)
continue
continue
if
(
isinstance
(
location_info
[
"threshold"
],
float
)
and
audio_info
[
"value"
]
<
location_info
[
"threshold"
]
):
count_info_map
[
location_info
[
"type"
]][
"normal"
]
+=
1
if
count_info_map
[
"temperature"
][
"total"
]
==
0
:
temperature_qr
=
"100
%
"
else
:
temperature_qr
=
(
str
(
round
(
(
count_info_map
[
"temperature"
][
"normal"
]
/
count_info_map
[
"temperature"
][
"total"
]
)
*
100
,
)
)
+
"
%
"
)
if
count_info_map
[
"residual_current"
][
"total"
]
==
0
:
if
(
isinstance
(
d_loc
[
"threshold"
],
float
)
and
residual_current_qr
=
"100
%
"
d_adio
[
"value"
]
<
d_loc
[
"threshold"
]):
d_stats
[
d_loc
[
"type"
]][
"normal"
]
+=
1
if
d_stats
[
"temperature"
][
"total"
]
==
0
:
temp_qr
=
"100
%
"
else
:
else
:
residual_current_qr
=
(
norm
=
d_stats
[
"temperature"
][
"normal"
]
str
(
total
=
d_stats
[
"temperature"
][
"total"
]
round
(
temp_qr
=
str
(
round
((
norm
/
total
)
*
100
,
))
+
"
%
"
(
count_info_map
[
"residual_current"
][
"normal"
]
/
count_info_map
[
"residual_current"
][
"total"
]
)
*
100
)
)
+
"
%
"
)
return
temperature_qr
,
residual_current_qr
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
):
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