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
444ec2cc
Commit
444ec2cc
authored
May 09, 2023
by
wang.wenrong
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'wwr' into 'develop'
安识U-精细监测 See merge request
!34
parents
4a5aa641
7cbc839a
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
502 additions
and
282 deletions
+502
-282
fine_monitor_dao.py
unify_api/modules/anshiu/dao/fine_monitor_dao.py
+161
-13
fine_monitor_pds.py
unify_api/modules/anshiu/procedures/fine_monitor_pds.py
+264
-1
fine_monitor_serv.py
unify_api/modules/anshiu/service/fine_monitor_serv.py
+54
-254
fine_monitor.py
unify_api/modules/anshiu/views/fine_monitor.py
+17
-14
common_utils.py
unify_api/utils/common_utils.py
+4
-0
taos_new.py
unify_api/utils/taos_new.py
+2
-0
No files found.
unify_api/modules/anshiu/dao/fine_monitor_dao.py
View file @
444ec2cc
...
...
@@ -2,27 +2,175 @@ from pot_libs.settings import SETTING
from
unify_api.utils.common_utils
import
make_tdengine_data_as_list
from
unify_api.utils.taos_new
import
get_td_table_name
,
get_td_engine_data
from
unify_api.utils.exc_util
import
BusinessException
from
pot_libs.mysql_util.mysql_util
import
MysqlUtil
async
def
get_aiao_1min_data
(
monitor_info
,
start_time
,
end_time
,
su_table
):
async
def
get_aiao_1min_dao
(
mtid
,
start_time
,
end_time
):
# 查1min温度漏电流
sid_data
=
await
get_sid_by_mtid_dao
(
mtid
)
sid
=
sid_data
[
'sid'
]
.
lower
()
su_table
=
"new_adio_stb"
td_mt_table
=
get_td_table_name
(
su_table
,
mtid
)
url
=
f
"{SETTING.stb_url}db_adio"
# td的精度过高,采用 >= start and < end的形式查询
sql
=
f
"select last_row( ts, temp1, temp2, temp3, temp4, residual_current) "
\
f
"from adio_stb where TBNAME = '{td_mt_table}' and "
\
f
"ts >= '{start_time}' AND ts <'{end_time}' "
\
f
"Interval(60s) order by ts asc"
is_succ
,
results
=
await
get_td_engine_data
(
url
,
sql
)
if
not
results
:
su_table
=
"old_adio_stb"
td_mt_table
=
get_td_table_name
(
su_table
,
sid
)
sql
=
f
"select last_row( ts, temp1, temp2, temp3, temp4, residual_current) "
\
f
"from adio_stb where TBNAME = '{td_mt_table}' and "
\
f
"ts >= '{start_time}' AND ts <'{end_time}' "
\
f
"Interval(60s) order by ts asc"
is_succ
,
results
=
await
get_td_engine_data
(
url
,
sql
)
if
not
is_succ
:
raise
BusinessException
()
td_datas
=
make_tdengine_data_as_list
(
results
)
if
not
td_datas
:
return
""
return
td_datas
async
def
get_sid_by_mtid_dao
(
mtid
):
# 查15min温度漏电流
sql
=
f
"""
SELECT
sid
FROM
monitor
WHERE
mtid = {mtid}
"""
async
with
MysqlUtil
()
as
conn
:
data
=
await
conn
.
fetchone
(
sql
,
)
return
data
async
def
get_aiao_15min_dao
(
mtid
,
start_time
,
end_time
):
# 查15min温度漏电流
sql
=
f
"""
SELECT
DATE_FORMAT(create_time,'
%
H:
%
i') create_time,
value_avg,
ad_field
FROM
location_15min_aiao
WHERE
create_time > "{start_time}"
AND create_time < "{end_time}"
AND mtid = {mtid}
"""
:param monitor_info: pass
:param start_time: 开始时间
:param end_time: 结束时间
:param su_table: 超级表名
:return select_val对应在数据库中对应的值
async
with
MysqlUtil
()
as
conn
:
data
=
await
conn
.
fetchall
(
sql
,
)
return
data
async
def
get_aiao_1day_dao
(
mtid
,
start_time
,
end_time
):
sql
=
f
"""
SELECT
DATE_FORMAT(create_time,'
%
m-
%
d') create_time,
value_avg,
ad_field
FROM
location_1day_aiao
WHERE
create_time > "{start_time}"
AND create_time < "{end_time}"
AND mtid = {mtid}
"""
mtid
=
monitor_info
[
"mtid"
]
async
with
MysqlUtil
()
as
conn
:
data
=
await
conn
.
fetchall
(
sql
,
)
return
data
async
def
get_point_1min_chart_dao
(
mtid
,
ctnum
,
start_time
,
end_time
):
if
ctnum
==
2
:
stats_items
=
[
"pttl"
,
"qttl"
,
"uab"
,
"ucb"
,
"ia"
,
"ic"
,
]
else
:
stats_items
=
[
"pttl"
,
"qttl"
,
"ua"
,
"ub"
,
"uc"
,
"ia"
,
"ib"
,
"ic"
,
]
# 查1min温度漏电流
sid_data
=
await
get_sid_by_mtid_dao
(
mtid
)
sid
=
sid_data
[
'sid'
]
.
lower
()
su_table
=
"new_electric_stb"
td_mt_table
=
get_td_table_name
(
su_table
,
mtid
)
url
=
f
"{SETTING.stb_url}db_
adio
"
url
=
f
"{SETTING.stb_url}db_
electric
"
# td的精度过高,采用 >= start and < end的形式查询
sql
=
f
" select temp1, temp2, temp3, temp4 from {su_table} "
\
f
" where TBNAME = '{td_mt_table}' "
\
f
" and ts >= '{start_time}' AND ts <'{end_time}' "
stats_items
.
insert
(
0
,
'ts'
)
sql
=
f
"select last_row({','.join(stats_items)}) "
\
f
"from electric_stb where TBNAME = '{td_mt_table}' and "
\
f
"ts >= '{start_time}' AND ts <'{end_time}' "
\
f
"Interval(60s) order by ts asc"
is_succ
,
results
=
await
get_td_engine_data
(
url
,
sql
)
if
not
results
:
su_table
=
"old_electric_stb"
td_mt_table
=
get_td_table_name
(
su_table
,
sid
)
sql
=
f
"select last_row( {','.join(stats_items)}) "
\
f
"from electric_stb where TBNAME = '{td_mt_table}' and "
\
f
"ts >= '{start_time}' AND ts <'{end_time}' "
\
f
"Interval(60s) order by ts asc"
is_succ
,
results
=
await
get_td_engine_data
(
url
,
sql
)
if
not
is_succ
:
raise
BusinessException
()
td_datas
=
make_tdengine_data_as_list
(
results
)
if
not
td_datas
:
return
""
return
td_datas
[
0
]
return
td_datas
async
def
get_point_15min_chart_dao
(
mtid
,
stats_items
,
date_start
,
date_end
):
# 查15min温度漏电流
sql
=
f
"""
SELECT
DATE_FORMAT(create_time,'
%
H:
%
i') create_time,
{','.join(stats_items)}
FROM
point_15min_electric
WHERE
create_time > "{date_start}"
AND create_time < "{date_end}"
AND mtid = {mtid}
"""
async
with
MysqlUtil
()
as
conn
:
data
=
await
conn
.
fetchall
(
sql
,
)
return
data
async
def
get_point_1day_chart_dao
(
mtid
,
stats_items
,
date_start
,
date_end
):
sql
=
f
"""
SELECT
DATE_FORMAT(create_time,'
%
m-
%
d') create_time,
{','.join(stats_items)}
FROM
point_1day_electric
WHERE
create_time > "{date_start}"
AND create_time < "{date_end}"
AND mtid = {mtid}
"""
async
with
MysqlUtil
()
as
conn
:
data
=
await
conn
.
fetchall
(
sql
,
)
return
data
unify_api/modules/anshiu/procedures/fine_monitor_pds.py
View file @
444ec2cc
This diff is collapsed.
Click to expand it.
unify_api/modules/anshiu/service/fine_monitor_serv.py
View file @
444ec2cc
This diff is collapsed.
Click to expand it.
unify_api/modules/anshiu/views/fine_monitor.py
View file @
444ec2cc
...
...
@@ -9,7 +9,7 @@ from unify_api.modules.anshiu.components.fine_monitor_cps import (
FineMonitorInfoResp
)
from
unify_api.modules.anshiu.procedures.fine_monitor_pds
import
(
get_location_by_ids
,
get_threshold_by_location
get_location_by_ids
,
get_threshold_by_location
,
get_mtid_by_location_ids
)
from
unify_api.modules.anshiu.service.fine_monitor_serv
import
(
get_adio_chart_data
,
get_point_chart_data
,
get_adio_info_data
,
...
...
@@ -43,7 +43,7 @@ async def post_fine_monitor_chart(request,
# 获取location表的信息
try
:
location_info
=
await
get_
location_by
_ids
(
location_group
)
location_info
=
await
get_
mtid_by_location
_ids
(
location_group
)
except
Exception
as
e
:
log
.
error
(
'get_fine_monitor_chart_error '
+
e
)
return
FineMonitorChartResp
.
db_error
()
...
...
@@ -54,16 +54,19 @@ async def post_fine_monitor_chart(request,
intervel
,
slots
)
# 电力数据 power_list、电流曲线、电压曲线
power_list
,
i_list
,
v_list
,
ctnum
=
await
get_point_chart_data
(
point_id
,
start_timestamp
,
end_timestamp
,
\
intervel
,
slots
)
power_list
,
i_list
,
v_list
,
ctnum
=
await
get_point_chart_data
(
point_id
,
date_start
,
date_end
,
intervel
,
slots
)
# 获取温度与漏电流的曲线数据
# 获取用电数据
return
FineMonitorChartResp
(
time_slots
=
slots
,
temperature
=
temperature_list
,
residual_current
=
residual_currents_list
,
power
=
power_list
,
i
=
i_list
,
v
=
v_list
,
ctnum
=
ctnum
)
power
=
power_list
,
i
=
i_list
,
v
=
v_list
,
ctnum
=
ctnum
)
@
summary
(
"精细监测-指标统计"
)
...
...
unify_api/utils/common_utils.py
View file @
444ec2cc
import
argparse
from
dataclasses
import
dataclass
import
pendulum
from
chinese_calendar
import
is_workday
,
is_holiday
from
datetime
import
datetime
import
re
...
...
@@ -178,5 +180,7 @@ def make_tdengine_data_as_list(tdengine_data):
meta
[
0
]
for
meta
in
tdengine_data
[
"column_meta"
]]
result
=
[]
for
res
in
tdengine_data
[
"data"
]:
res
[
0
]
=
pendulum
.
parse
(
res
[
0
])
.
format
(
"HH:mm"
)
result
.
append
(
dict
(
zip
(
head
,
res
)))
return
result
unify_api/utils/taos_new.py
View file @
444ec2cc
...
...
@@ -154,6 +154,8 @@ def get_td_table_name(topic, id):
"smoke_soe_stb"
:
"smoke_soe_stb
%
s"
,
# 烟感报警
"old_adio_stb"
:
"s_
%
s_a"
,
# 安电--旧 这里是%s是sid
"new_adio_stb"
:
"mt
%
s_adi"
,
# 安电——新
"old_electric_stb"
:
"s_
%
s_a"
,
"new_electric_stb"
:
"mt
%
s_ele"
,
}
table_name
=
topic_map
.
get
(
topic
)
...
...
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