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
4bb601d6
Commit
4bb601d6
authored
Aug 19, 2022
by
lcn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改tdengine写法
parent
e7df191b
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
41 additions
and
21 deletions
+41
-21
td_engine_service.py
unify_api/modules/common/service/td_engine_service.py
+1
-2
electric_pds.py
unify_api/modules/electric/procedures/electric_pds.py
+6
-3
electric_service.py
unify_api/modules/electric/service/electric_service.py
+1
-1
electric.py
unify_api/modules/electric/views/electric.py
+1
-1
count_info_pds.py
unify_api/modules/home_page/procedures/count_info_pds.py
+9
-3
health_index_service.py
unify_api/modules/home_page/service/health_index_service.py
+9
-2
open_data_service.py
unify_api/modules/shidianu/service/open_data_service.py
+14
-9
No files found.
unify_api/modules/common/service/td_engine_service.py
View file @
4bb601d6
...
...
@@ -29,8 +29,7 @@ def test_td_engine():
url
=
f
"{SETTING.stb_url}db_electric"
print
(
token
)
h
=
{
"Authorization"
:
f
"Basic {token}"
}
sql
=
f
"select last_row(*) from electric_stb where cpyid =204 "
\
f
"group by tbname"
sql
=
f
"select last_row(*) from mt1332_ele where pid=1395"
r
=
requests
.
post
(
url
,
data
=
sql
,
headers
=
h
)
print
(
r
.
status_code
)
print
(
r
.
content
)
...
...
unify_api/modules/electric/procedures/electric_pds.py
View file @
4bb601d6
...
...
@@ -230,9 +230,12 @@ async def qual_current_data(point_mid):
async
def
elec_current_data_new15
(
mtids
):
res_map
=
{}
url
=
f
"{SETTING.stb_url}db_electric"
table_name
=
[
f
"mt{mtid}_ele"
for
mtid
in
mtids
]
sql
=
f
'select last_row(*) from electric_stb '
\
f
'where TBNAME IN {tuple(table_name)} group by tbname'
sql
=
f
""
for
mtid
in
mtids
:
table_name
=
f
"mt{mtid}_ele"
if
len
(
sql
)
>
0
:
sql
+=
" union all "
sql
+=
f
"select last_row(*) from {table_name}"
is_succ
,
results
=
await
get_td_engine_data
(
url
,
sql
)
if
is_succ
:
head
=
[
re
.
findall
(
r'last_row\((.*)\)'
,
i
)[
0
]
if
"("
in
i
else
i
...
...
unify_api/modules/electric/service/electric_service.py
View file @
4bb601d6
...
...
@@ -875,7 +875,7 @@ async def elec_current_service_new15(point_id):
mtid
=
meter_info
[
"mtid"
]
# 获取子表中的实时数据
url
=
f
"{SETTING.stb_url}db_electric"
sql
=
f
"select last(*) from mt{mtid}_ele where pid={point_id}"
sql
=
f
"select last
_row
(*) from mt{mtid}_ele where pid={point_id}"
is_succ
,
results
=
await
get_td_engine_data
(
url
,
sql
)
if
not
is_succ
:
return
''
,{}
...
...
unify_api/modules/electric/views/electric.py
View file @
4bb601d6
...
...
@@ -879,7 +879,7 @@ async def post_qual_current(req, body: PageRequest) -> QualCurrentResponse:
mtid
=
meter_info
[
"mtid"
]
# 获取子表中的实时数据
url
=
f
"{SETTING.stb_url}db_electric"
sql
=
f
"select last(*) from mt{mtid}_ele where pid={point_id}"
sql
=
f
"select last
_row
(*) from mt{mtid}_ele where pid={point_id}"
is_succ
,
results
=
await
get_td_engine_data
(
url
,
sql
)
log
.
info
(
f
"is_succ:{is_succ}"
)
if
is_succ
:
...
...
unify_api/modules/home_page/procedures/count_info_pds.py
View file @
4bb601d6
...
...
@@ -14,7 +14,8 @@ from unify_api import constants
from
unify_api.constants
import
Importance
,
EVENT_TYPE_MAP
,
SDU_ALARM_LIST
from
unify_api.modules.alarm_manager.dao.list_static_dao
import
\
sdu_alarm_importance_dao
,
alarm_aggs_importance
from
unify_api.modules.common.dao.common_dao
import
monitor_point_join
from
unify_api.modules.common.dao.common_dao
import
monitor_point_join
,
\
monitor_by_cid
from
unify_api.modules.common.procedures.common_utils
import
get_electric_index
from
unify_api.modules.common.procedures.points
import
get_points
,
\
proxy_points
,
get_points_num
...
...
@@ -549,8 +550,13 @@ async def current_load_new15(cid):
from
unify_api.modules.common.service.td_engine_service
import
\
get_td_engine_data
url
=
f
"{SETTING.stb_url}db_electric"
sql
=
f
"select last_row(*) from electric_stb where cpyid ={cid} "
\
f
"group by tbname"
monitors
=
await
monitor_by_cid
(
cid
)
sql
=
f
""
for
monitor
in
monitors
:
table_name
=
f
"mt{monitor.get('mtid')}_ele"
if
len
(
sql
)
>
0
:
sql
+=
" union all "
sql
+=
f
"select last_row(*) from {table_name}"
is_succ
,
results
=
await
get_td_engine_data
(
url
,
sql
)
now_tt
=
int
(
time
.
time
())
if
is_succ
:
...
...
unify_api/modules/home_page/service/health_index_service.py
View file @
4bb601d6
import
json
import
time
import
re
from
unify_api.modules.common.dao.common_dao
import
monitor_by_cid
from
unify_api.utils.common_utils
import
round_2
from
pot_libs.logger
import
log
from
pot_libs.settings
import
SETTING
...
...
@@ -187,8 +189,13 @@ async def health_ctl_rate_service_new15(cid):
real_tt
=
now_ts
total
=
0
url
=
f
"{SETTING.stb_url}db_electric"
sql
=
f
"select last_row(*) from electric_stb where cpyid ={cid} "
\
f
"group by tbname"
monitors
=
await
monitor_by_cid
(
cid
)
sql
=
f
""
for
monitor
in
monitors
:
table_name
=
f
"mt{monitor.get('mtid')}_ele"
if
len
(
sql
)
>
0
:
sql
+=
" union all "
sql
+=
f
"select last_row(*) from {table_name}"
is_succ
,
results
=
await
get_td_engine_data
(
url
,
sql
)
time_str
=
time_format
.
get_datetime_str
(
real_tt
)
if
is_succ
:
...
...
unify_api/modules/shidianu/service/open_data_service.py
View file @
4bb601d6
...
...
@@ -9,8 +9,8 @@ from unify_api.modules.shidianu.components.open_data_cps import (
)
from
unify_api.modules.alarm_manager.components.list_alarm
import
\
ListAlarmResponse
,
Alarm
from
unify_api.modules.common.dao.common_dao
import
meter_by_mids
,
\
monitor_point_storey_join_in
from
unify_api.modules.common.dao.common_dao
import
meter_by_mids
,
\
monitor_point_storey_join_in
,
points_monitor_by_cid
from
unify_api.modules.common.procedures.points
import
point_to_mid
from
unify_api.modules.shidianu.dao.open_data_dao
import
\
get_user_product_auth
,
result_longgang_by_cid
,
monitor_point_company
...
...
@@ -87,9 +87,9 @@ async def basic_info_longgang_service(user_id, page_size, page_num):
async
def
stb_data_longgang_service
(
user_id
,
type
):
db_name
=
{
"soe"
:
"db_soe"
,
"electric"
:
"db_electric"
,
"appliance"
:
"db_appliance"
"soe"
:
{
"super"
:
"db_soe"
,
"suffix"
:
"soe"
}
,
"electric"
:
{
"super"
:
"db_electric"
,
"suffix"
:
"ele"
}
,
"appliance"
:
{
"super"
:
"db_appliance"
,
"suffix"
:
"app"
}
}
if
type
not
in
db_name
.
keys
():
return
success_res
(
code
=
4002
,
msg
=
"type错误"
)
...
...
@@ -105,10 +105,15 @@ async def stb_data_longgang_service(user_id, type):
return
success_res
(
code
=
4001
,
msg
=
"您没有权限访问"
)
token
=
get_token
()
stb_url
=
f
"{SETTING.stb_url}{db_name[type]}"
table_name
=
f
"{type}_stb"
sql
=
f
"select last_row(*) from {table_name} "
\
f
"where cpyid in {tuple(cids)} group by tbname"
stb_url
=
f
"{SETTING.stb_url}{db_name[type]['super']}"
monitor_datas
=
await
points_monitor_by_cid
(
cids
)
sql
=
f
""
for
monitor_data
in
monitor_datas
:
table_name
=
f
"mt{monitor_data.get('mtid')}_{db_name[type]['suffix']}"
if
len
(
sql
)
>
0
:
sql
+=
" union all "
sql
+=
f
"select last_row(*) from {table_name}"
resp_str
,
status
=
await
AioHttpUtils
()
.
post_data
(
stb_url
,
data
=
sql
,
timeout
=
50
,
headers
=
{
"Authorization"
:
f
"Basic {token}"
}
...
...
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