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
5c6c1e29
Commit
5c6c1e29
authored
Jun 09, 2023
by
lcn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bug修复
parent
354b291f
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
98 additions
and
72 deletions
+98
-72
electric_pds.py
unify_api/modules/electric/procedures/electric_pds.py
+8
-0
electric.py
unify_api/modules/electric/views/electric.py
+90
-72
No files found.
unify_api/modules/electric/procedures/electric_pds.py
View file @
5c6c1e29
...
...
@@ -20,3 +20,11 @@ async def elec_current_data(mtids, cid):
if
data
[
"mtid"
]
in
mtids
:
res_map
[
data
[
"mtid"
]]
=
data
return
res_map
def
trans_electric_tdengine_data
(
results
):
head
=
parse_td_columns
(
results
)
if
not
results
[
"data"
]:
results
[
"data"
]
=
[
''
for
i
in
range
(
len
(
head
))]
res
=
dict
(
zip
(
head
,
results
[
"data"
][
0
]))
return
res
unify_api/modules/electric/views/electric.py
View file @
5c6c1e29
...
...
@@ -5,7 +5,11 @@
import
time
import
json
from
dataclasses
import
fields
import
pendulum
from
pot_libs.settings
import
SETTING
from
unify_api.constants
import
CST
from
unify_api.modules.common.procedures.points
import
get_meter_by_point
from
unify_api.modules.common.service.td_engine_service
import
\
get_td_engine_data
...
...
@@ -17,6 +21,8 @@ from pot_libs.utils.exc_util import (
)
from
unify_api.modules.common.components.common_cps
import
CidPointsReq
from
unify_api.modules.common.procedures
import
health_score
from
unify_api.modules.electric.procedures.electric_pds
import
\
trans_electric_tdengine_data
from
unify_api.modules.electric.service.electric_service
import
(
elec_current_storeys_service
,
qual_current_storeys_service
,
elec_card_level_service
,
qual_current_level_service
,
elec_index_service
,
...
...
@@ -510,18 +516,32 @@ async def post_qual_current(req, body: PageRequest) -> QualCurrentResponse:
raise
BusinessException
(
message
=
"没有该监测点的monitor信息,请联系运维人员!"
)
mtid
=
meter_info
[
"mtid"
]
# 过期时间
last_ts
=
pendulum
.
now
(
tz
=
CST
)
.
subtract
(
seconds
=
constants
.
REAL_EXP_TIME
)
.
format
(
"YYYY-MM-DD HH:mm:ss"
)
# 获取子表中的实时数据
url
=
f
"{SETTING.stb_url}db_electric?tz=Asia/Shanghai"
sql
=
f
"select last_row(*) from mt{mtid}_ele where pid={point_id}"
url
=
f
"{SETTING.stb_url}db_electric?tz={CST}"
sql
=
f
"select last_row(*) from mt{mtid}_ele where ts>='{last_ts}'"
hr_sql
=
f
"select last_row(*) from mt{mtid}_ele where ts>='{last_ts}' "
\
f
"and harmonic is not null "
is_succ
,
results
=
await
get_td_engine_data
(
url
,
sql
)
if
is_succ
:
head
=
parse_td_columns
(
results
)
if
not
results
[
"data"
]:
results
[
"data"
]
=
[
''
for
i
in
range
(
len
(
head
))]
res
=
dict
(
zip
(
head
,
results
[
"data"
][
0
]))
ctnum
=
res
.
get
(
"ctnum"
)
or
3
is_succ2
,
results2
=
await
get_td_engine_data
(
url
,
hr_sql
)
if
not
is_succ
:
raise
BusinessException
(
message
=
"数据查询失败!"
)
res
=
trans_electric_tdengine_data
(
results
)
if
is_succ2
:
res2
=
trans_electric_tdengine_data
(
results2
)
harmonic
=
json
.
loads
(
res2
.
get
(
"harmonic"
))
if
res2
.
get
(
"harmonic"
)
else
{}
else
:
harmonic
=
json
.
loads
(
res
.
get
(
"harmonic"
))
if
res
.
get
(
"harmonic"
)
else
{}
ctnum
=
res
.
get
(
"ctnum"
)
or
3
# 加些随机变化(防止数据一直不变化)
for
k
in
res
.
keys
():
res
[
k
]
=
add_random_change
(
res
[
k
])
voltage_harmonic_dict
,
current_harmonic_dict
=
{},
{}
for
k
in
[
field
.
name
for
field
in
fields
(
VoltageHarmonicRate
)]:
if
k
in
harmonic
.
keys
():
...
...
@@ -563,8 +583,6 @@ async def post_qual_current(req, body: PageRequest) -> QualCurrentResponse:
current_harmonic
=
current_harmonic
,
**
{
k
:
v
for
k
,
v
in
res
.
items
()
if
k
in
ret_items
},
)
else
:
raise
BusinessException
(
message
=
"数据查询失败!"
)
@
summary
(
"用电监测-实时监测-楼层"
)
...
...
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