Commit 5c6c1e29 authored by lcn's avatar lcn

bug修复

parent 354b291f
...@@ -20,3 +20,11 @@ async def elec_current_data(mtids, cid): ...@@ -20,3 +20,11 @@ async def elec_current_data(mtids, cid):
if data["mtid"] in mtids: if data["mtid"] in mtids:
res_map[data["mtid"]] = data res_map[data["mtid"]] = data
return res_map 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
...@@ -5,7 +5,11 @@ ...@@ -5,7 +5,11 @@
import time import time
import json import json
from dataclasses import fields from dataclasses import fields
import pendulum
from pot_libs.settings import SETTING 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.procedures.points import get_meter_by_point
from unify_api.modules.common.service.td_engine_service import \ from unify_api.modules.common.service.td_engine_service import \
get_td_engine_data get_td_engine_data
...@@ -17,6 +21,8 @@ from pot_libs.utils.exc_util import ( ...@@ -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.components.common_cps import CidPointsReq
from unify_api.modules.common.procedures import health_score 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 ( from unify_api.modules.electric.service.electric_service import (
elec_current_storeys_service, qual_current_storeys_service, elec_current_storeys_service, qual_current_storeys_service,
elec_card_level_service, qual_current_level_service, elec_index_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: ...@@ -510,18 +516,32 @@ async def post_qual_current(req, body: PageRequest) -> QualCurrentResponse:
raise BusinessException( raise BusinessException(
message="没有该监测点的monitor信息,请联系运维人员!") message="没有该监测点的monitor信息,请联系运维人员!")
mtid = meter_info["mtid"] 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" url = f"{SETTING.stb_url}db_electric?tz={CST}"
sql = f"select last_row(*) from mt{mtid}_ele where pid={point_id}" 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) is_succ, results = await get_td_engine_data(url, sql)
if is_succ: is_succ2, results2 = await get_td_engine_data(url, hr_sql)
head = parse_td_columns(results) if not is_succ:
if not results["data"]: raise BusinessException(message="数据查询失败!")
results["data"] = ['' for i in range(len(head))] res = trans_electric_tdengine_data(results)
res = dict(zip(head, results["data"][0])) if is_succ2:
ctnum = res.get("ctnum") or 3 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 = json.loads(res.get("harmonic")) if res.get(
"harmonic") else {} "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 = {}, {} voltage_harmonic_dict, current_harmonic_dict = {}, {}
for k in [field.name for field in fields(VoltageHarmonicRate)]: for k in [field.name for field in fields(VoltageHarmonicRate)]:
if k in harmonic.keys(): if k in harmonic.keys():
...@@ -563,8 +583,6 @@ async def post_qual_current(req, body: PageRequest) -> QualCurrentResponse: ...@@ -563,8 +583,6 @@ async def post_qual_current(req, body: PageRequest) -> QualCurrentResponse:
current_harmonic=current_harmonic, current_harmonic=current_harmonic,
**{k: v for k, v in res.items() if k in ret_items}, **{k: v for k, v in res.items() if k in ret_items},
) )
else:
raise BusinessException(message="数据查询失败!")
@summary("用电监测-实时监测-楼层") @summary("用电监测-实时监测-楼层")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment