Commit 5b9cfac6 authored by ZZH's avatar ZZH

change shidianu real time ele qua load from redis 2023-6-25

parent fbacfff2
...@@ -13,35 +13,25 @@ from unify_api.modules.common.procedures.points import points_by_storeys, \ ...@@ -13,35 +13,25 @@ from unify_api.modules.common.procedures.points import points_by_storeys, \
get_meter_by_point get_meter_by_point
from unify_api.modules.electric.dao.electric_dao import \ from unify_api.modules.electric.dao.electric_dao import \
monitor_point_join_by_points, get_electric_datas_dao monitor_point_join_by_points, get_electric_datas_dao
from unify_api.modules.electric.procedures.electric_pds import \
elec_current_data
from unify_api.utils import time_format
from unify_api.utils.common_utils import round_2, round_4, multiplication_two from unify_api.utils.common_utils import round_2, round_4, multiplication_two
from unify_api.modules.electric.procedures.electric_util import \ from unify_api.modules.electric.procedures.electric_util import \
get_wiring_type, load_point_ctnum load_point_ctnum
from datetime import datetime from datetime import datetime
from unify_api.constants import REAL_EXP_TIME from unify_api.constants import REAL_EXP_TIME
from unify_api.utils.time_format import CST, YMD_Hms, timestamp2dts
from unify_api.modules.common.procedures.location_temp_rcurrent import \ from unify_api.modules.common.procedures.location_temp_rcurrent import \
location_stats_statics location_stats_statics
from unify_api.modules.electric.components.electric import ( from unify_api.modules.electric.components.electric import (
ElecIndexResponse, ElecIndex, EscResp, QcsResp, EclResp, QclResp, ElecIndexResponse, ElecIndex, EscResp, QcsResp, EclResp, QclResp,
) )
from unify_api.utils.time_format import CST, YMD_Hms, timestamp2dts
async def elec_current_storeys_service(storeys): async def elec_current_storeys_service(storeys):
"""用电监测-实时监测-楼层""" """用电监测-实时监测-楼层"""
# 1.根据storeys获取points信息 # 1.根据storeys获取points信息
point_list = await points_by_storeys(storeys) point_list = await points_by_storeys(storeys)
# mtids
mtids = [i.get("mtid") for i in point_list] mtids = [i.get("mtid") for i in point_list]
cid = point_list[0]["cid"] if len(point_list) > 0 else 0 d_rt_ele = await batch_load_rt_ele(mtids)
# 2.获取mid, ctnum
# point_mid = await batch_get_wiring_type(points)
# # 3. 获取redis数据
# res = await elec_current_data(point_mid)
res = await elec_current_data(mtids, cid)
# 4. 返回数据
elec_data = {} elec_data = {}
for info in point_list: for info in point_list:
storey_name = info.get("storey_name") storey_name = info.get("storey_name")
...@@ -50,32 +40,30 @@ async def elec_current_storeys_service(storeys): ...@@ -50,32 +40,30 @@ async def elec_current_storeys_service(storeys):
room_name = info.get("room_name") room_name = info.get("room_name")
mtid = info.get("mtid") mtid = info.get("mtid")
ctnum = info.get("ctnum") ctnum = info.get("ctnum")
# 初始化返回dic rt_ele = d_rt_ele.get(mtid, None)
if res.get(mtid): if rt_ele:
# 识电U只有一项有数据,返回具体的项 # 识电U只有一项有数据,返回具体的项
res[mtid] = get_sdu_i_and_u(res[mtid], ctnum) rt_ele = get_sdu_i_and_u(rt_ele, ctnum)
time_str = res[mtid]["ts"][:-4] time_str = timestamp2dts(rt_ele["ts"], YMD_Hms)
res_dic = { res_dic = {
"room_name": room_name, "room_name": room_name,
"storey_id": storey_id, "storey_id": storey_id,
"point_id": point_id, "point_id": point_id,
"ctnum": ctnum, "ctnum": ctnum,
"real_time": time_str, "real_time": time_str,
"ua": round_2(res[mtid].get("ua")), "ua": round_2(rt_ele.get("ua")),
"ia": round_2(res[mtid].get("ia")), "ia": round_2(rt_ele.get("ia")),
"ub": round_2(res[mtid].get("ub")), "ub": round_2(rt_ele.get("ub")),
"ib": round_2(res[mtid].get("ib")), "ib": round_2(rt_ele.get("ib")),
"uc": round_2(res[mtid].get("uc")), "uc": round_2(rt_ele.get("uc")),
"ic": round_2(res[mtid].get("ic")), "ic": round_2(rt_ele.get("ic")),
"pttl": round_2(res[mtid].get("pttl")), "pttl": round_2(rt_ele.get("pttl")),
"qttl": round_2(res[mtid].get("qttl")), "qttl": round_2(rt_ele.get("qttl")),
"freq": round_2(res[mtid].get("freq")), "freq": round_2(rt_ele.get("freq")),
"costtl": round_2(res[mtid].get("costtl")), "costtl": round_2(rt_ele.get("costtl")),
"lf": round_2(res[mtid].get("lf")), "lf": round_2(rt_ele.get("lf")),
"sdu_i": res[mtid].get("sdu_i"), "sdu_i": rt_ele.get("sdu_i"),
"sdu_u": res[mtid].get("sdu_u"), "sdu_u": rt_ele.get("sdu_u"), }
}
# redis数据过期,或者没有数据
else: else:
res_dic = { res_dic = {
"room_name": room_name, "room_name": room_name,
...@@ -83,25 +71,15 @@ async def elec_current_storeys_service(storeys): ...@@ -83,25 +71,15 @@ async def elec_current_storeys_service(storeys):
"storey_id": storey_id, "storey_id": storey_id,
"ctnum": ctnum, "ctnum": ctnum,
"real_time": "", "real_time": "",
"ua": "", "ua": "", "ia": "", "ub": "", "ib": "", "uc": "", "ic": "",
"ia": "", "pttl": "", "qttl": "", "freq": "", "costtl": "", "lf": "",
"ub": "", "sdu_i": "", "sdu_u": "", }
"ib": "",
"uc": "",
"ic": "",
"pttl": "",
"qttl": "",
"freq": "",
"costtl": "",
"lf": "",
"sdu_i": "",
"sdu_u": "",
}
# 组装返回格式为dic
if storey_name in elec_data: if storey_name in elec_data:
elec_data[storey_name].append(res_dic) elec_data[storey_name].append(res_dic)
else: else:
elec_data[storey_name] = [res_dic] elec_data[storey_name] = [res_dic]
# 转换成list格式, 可以按照storey_name排序 # 转换成list格式, 可以按照storey_name排序
if elec_data: if elec_data:
# 房间排序, 并返回数据转化为list # 房间排序, 并返回数据转化为list
...@@ -119,15 +97,8 @@ async def qual_current_storeys_service(storeys): ...@@ -119,15 +97,8 @@ async def qual_current_storeys_service(storeys):
"""电能质量-实时参数-楼层""" """电能质量-实时参数-楼层"""
# 1.根据storeys获取points信息 # 1.根据storeys获取points信息
point_list = await points_by_storeys(storeys) point_list = await points_by_storeys(storeys)
# 获取point_id列表
# points = [i.get("point_id") for i in point_list]
# # 2.获取mid, ctnum
# point_mid = await batch_get_wiring_type(points)
# # 3. 获取redis数据
# res = await qual_current_data(point_mid)
mtids = [point["mtid"] for point in point_list if point["mtid"]] mtids = [point["mtid"] for point in point_list if point["mtid"]]
cid = point_list[0]["cid"] if len(point_list) > 0 else 0 d_rt_ele = await batch_load_rt_ele_with_hr(mtids)
res = await elec_current_data(mtids, cid)
# 4. 返回数据 # 4. 返回数据
qual_data = {} qual_data = {}
for info in point_list: for info in point_list:
...@@ -137,10 +108,10 @@ async def qual_current_storeys_service(storeys): ...@@ -137,10 +108,10 @@ async def qual_current_storeys_service(storeys):
room_name = info.get("room_name") room_name = info.get("room_name")
mtid = info.get("mtid") mtid = info.get("mtid")
ctnum = info.get("ctnum") if info.get("ctnum") == 2 else 3 ctnum = info.get("ctnum") if info.get("ctnum") == 2 else 3
# 初始化返回dic rt_ele = d_rt_ele.get(mtid, None)
if res.get(mtid): if rt_ele:
res[mtid] = get_sdu_i_and_u(res[mtid], ctnum) rt_ele = get_sdu_i_and_u(rt_ele, ctnum)
time_str = res[mtid]["ts"][:-4] time_str = timestamp2dts(rt_ele["ts"], YMD_Hms)
res_dic = { res_dic = {
"room_name": room_name, "room_name": room_name,
"storey_id": storey_id, "storey_id": storey_id,
...@@ -148,20 +119,18 @@ async def qual_current_storeys_service(storeys): ...@@ -148,20 +119,18 @@ async def qual_current_storeys_service(storeys):
"ctnum": ctnum, "ctnum": ctnum,
"real_time": time_str, "real_time": time_str,
# 电流/电压谐波畸变率 # 电流/电压谐波畸变率
"thdia": round_4(res[mtid].get("thdia")), "thdia": round_4(rt_ele.get("thdia")),
"thdib": round_4(res[mtid].get("thdib")), "thdib": round_4(rt_ele.get("thdib")),
"thdic": round_4(res[mtid].get("thdic")), "thdic": round_4(rt_ele.get("thdic")),
"thdua": round_4(res[mtid].get("thdua")), "thdua": round_4(rt_ele.get("thdua")),
"thdub": round_4(res[mtid].get("thdub")), "thdub": round_4(rt_ele.get("thdub")),
"thduc": round_4(res[mtid].get("thduc")), "thduc": round_4(rt_ele.get("thduc")),
# 电压偏差 # 电压偏差
"ua_dev": round_4(res[mtid].get("ua_dev")), "ua_dev": round_4(rt_ele.get("ua_dev")),
"ub_dev": round_4(res[mtid].get("ub_dev")), "ub_dev": round_4(rt_ele.get("ub_dev")),
"uc_dev": round_4(res[mtid].get("uc_dev")), "uc_dev": round_4(rt_ele.get("uc_dev")),
"sdu_i": res[mtid].get("sdu_i"), "sdu_i": rt_ele.get("sdu_i"),
"sdu_u": res[mtid].get("sdu_u"), "sdu_u": rt_ele.get("sdu_u"), }
}
# redis数据过期,或者没有数据
else: else:
res_dic = { res_dic = {
"room_name": room_name, "room_name": room_name,
...@@ -169,144 +138,111 @@ async def qual_current_storeys_service(storeys): ...@@ -169,144 +138,111 @@ async def qual_current_storeys_service(storeys):
"point_id": point_id, "point_id": point_id,
"ctnum": ctnum, "ctnum": ctnum,
"real_time": "", "real_time": "",
"thdia": "", "thdia": "", "thdib": "", "thdic": "",
"thdib": "", "thdua": "", "thdub": "", "thduc": "",
"thdic": "", "ua_dev": "", "ub_dev": "", "uc_dev": "",
"thdua": "", "sdu_i": "", "sdu_u": "", }
"thdub": "",
"thduc": "",
"ua_dev": "",
"ub_dev": "",
"uc_dev": "",
"sdu_i": "",
"sdu_u": "",
}
# 组装返回格式为dic
if storey_name in qual_data: if storey_name in qual_data:
qual_data[storey_name].append(res_dic) qual_data[storey_name].append(res_dic)
else: else:
qual_data[storey_name] = [res_dic] qual_data[storey_name] = [res_dic]
# 转换成list格式, 可以按照storey_name排序 # 转换成list格式, 可以按照storey_name排序
if qual_data: if qual_data:
# 房间排序, 并返回数据转化为list # 房间排序, 并返回数据转化为list
qual_list = [{"name": key, "storey_id": value[0]["storey_id"], lst_qual = [{"name": key, "storey_id": value[0]["storey_id"],
"room_data": sorted(value, "room_data": sorted(value, key=lambda i: i["room_name"])}
key=lambda i: i["room_name"])} for key, value in qual_data.items()]
for key, value in qual_data.items()]
# 楼层排序 # 楼层排序
qual_list = sorted(qual_list, key=lambda x: x["storey_id"]) lst_qual = sorted(lst_qual, key=lambda x: x["storey_id"])
else: else:
qual_list = [] lst_qual = []
return QcsResp(qual_data=qual_list) return QcsResp(qual_data=lst_qual)
async def elec_card_level_service(point_list): async def elec_card_level_service(point_list):
"""用电监测-卡片信息-level""" """用电监测-卡片信息-level"""
# 1. 获取每个point_id的详细信息 # 1. 获取每个point_id的详细信息
monitor_point_list = await monitor_point_join_by_points(point_list) d_point_info = await monitor_point_join_by_points(point_list)
# # 2.获取mid, ctnum mtids = [p_info["mtid"] for p_info in d_point_info if p_info["mtid"]]
# point_mid = await batch_get_wiring_type(point_list) d_rt_ele = await batch_load_rt_ele(mtids)
# # 3. 获取redis数据
# res_redis = await elec_current_data(point_mid)
mtids = [monitor["mtid"] for monitor in monitor_point_list if
monitor["mtid"]]
cid = monitor_point_list[0]["cid"] if len(monitor_point_list) > 0 else 0
results = await elec_current_data(mtids, cid)
# 4. 返回数据 # 4. 返回数据
ret_data = { ret_data = {"inline": [],
"inline": [], "transformer": [],
"transformer": [], "feeder": [],
"feeder": [], "power_dist": [],
"power_dist": [], "device": []
"device": [] }
} for info in d_point_info:
for info in monitor_point_list:
m_name = info.get("name") m_name = info.get("name")
m_type = POINT_LEVEL_MAP[info.get("m_type")] m_type = POINT_LEVEL_MAP[info.get("m_type")]
point_id = info.get("pid") point_id = info.get("pid")
mtid = info.get("mtid") mtid = info.get("mtid")
ctnum = info.get("ctnum") if info.get("ctnum") == 2 else 3 ctnum = info.get("ctnum") if info.get("ctnum") == 2 else 3
# 初始化返回dic rt_ele = d_rt_ele.get(mtid, None)
if results.get(mtid): if rt_ele:
time_str = results[mtid]["ts"][:-4] rt_ele = get_sdu_i_and_u(rt_ele, ctnum)
time_str = timestamp2dts(rt_ele["ts"], YMD_Hms)
res_dic = { res_dic = {
"name": m_name, "name": m_name,
"point_id": point_id, "point_id": point_id,
"ctnum": ctnum, "ctnum": ctnum,
"real_time": time_str, "real_time": time_str,
"ua": round_2(results[mtid].get("ua")), "ua": round_2(rt_ele.get("ua")),
"ia": round_2(results[mtid].get("ia")), "ia": round_2(rt_ele.get("ia")),
"ub": round_2(results[mtid].get("ub")), "ub": round_2(rt_ele.get("ub")),
"ib": round_2(results[mtid].get("ib")), "ib": round_2(rt_ele.get("ib")),
"uc": round_2(results[mtid].get("uc")), "uc": round_2(rt_ele.get("uc")),
"ic": round_2(results[mtid].get("ic")), "ic": round_2(rt_ele.get("ic")),
"pttl": round_2(results[mtid].get("pttl")), "pttl": round_2(rt_ele.get("pttl")),
"qttl": round_2(results[mtid].get("qttl")), "qttl": round_2(rt_ele.get("qttl")),
"freq": round_2(results[mtid].get("freq")), "freq": round_2(rt_ele.get("freq")),
"costtl": round_2(results[mtid].get("costtl")), "costtl": round_2(rt_ele.get("costtl")),
"lf": round_2(results[mtid].get("lf")), "lf": round_2(rt_ele.get("lf")),
"sdu_i": results[mtid].get("sdu_i"), "sdu_i": rt_ele.get("sdu_i"),
"sdu_u": results[mtid].get("sdu_u"), "sdu_u": rt_ele.get("sdu_u"),
# 增加电压偏差,用于判断是否超过阈值标红 # 增加电压偏差,用于判断是否超过阈值标红
"ua_dev": round_4(results[mtid].get("ua_dev")), "ua_dev": round_4(rt_ele.get("ua_dev")),
"ub_dev": round_4(results[mtid].get("ub_dev")), "ub_dev": round_4(rt_ele.get("ub_dev")),
"uc_dev": round_4(results[mtid].get("uc_dev")), "uc_dev": round_4(rt_ele.get("uc_dev")),
"uab_dev": round_4(results[mtid].get("uab_dev")), "uab_dev": round_4(rt_ele.get("uab_dev")),
"ucb_dev": round_4(results[mtid].get("ucb_dev")), "ucb_dev": round_4(rt_ele.get("ucb_dev")),
# 增加阈值 # 增加阈值
"u_threshold": U_THRESHOLD, "u_threshold": U_THRESHOLD,
"costtl_threshold": COSTTL_THRESHOLD, "costtl_threshold": COSTTL_THRESHOLD,
"lf_threshold": LF_THRESHOLD, "lf_threshold": LF_THRESHOLD,
} }
# redis数据过期,或者没有数据
else: else:
res_dic = { res_dic = {
"name": m_name, "name": m_name,
"point_id": point_id, "point_id": point_id,
"ctnum": ctnum, "ctnum": ctnum,
"real_time": "", "real_time": "",
"ua": "", "ua": "", "ia": "", "ub": "", "ib": "", "uc": "", "ic": "",
"ia": "", "pttl": "", "qttl": "", "freq": "", "costtl": "", "lf": "",
"ub": "", "sdu_i": "", "sdu_u": "",
"ib": "", "ua_dev": "", "ub_dev": "", "uc_dev": "",
"uc": "", "uab_dev": "", "ucb_dev": "",
"ic": "", "u_threshold": U_THRESHOLD,
"pttl": "", "costtl_threshold": COSTTL_THRESHOLD,
"qttl": "", "lf_threshold": LF_THRESHOLD,
"freq": "",
"costtl": "",
"lf": "",
"sdu_i": "",
"sdu_u": "",
# 增加电压偏差,用于判断是否超过阈值标红
"ua_dev": "",
"ub_dev": "",
"uc_dev": "",
} }
ret_data[m_type].append(res_dic) ret_data[m_type].append(res_dic)
return EclResp( return EclResp(inline=ret_data["inline"],
inline=ret_data["inline"], transformer=ret_data["transformer"],
transformer=ret_data["transformer"], feeder=ret_data["feeder"],
feeder=ret_data["feeder"], power_dist=ret_data["power_dist"],
power_dist=ret_data["power_dist"], device=ret_data["device"],
device=ret_data["device"], )
)
async def qual_current_level_service(point_list): async def qual_current_level_service(point_list):
"""电能质量-卡片信息-level""" """电能质量-卡片信息-level"""
# 1. 获取每个point_id的详细信息 # 1. 获取每个point_id的详细信息
monitor_point_list = await monitor_point_join_by_points(point_list) d_point_info = await monitor_point_join_by_points(point_list)
# # 2.获取mid, ctnum mtids = [p_info["mtid"] for p_info in d_point_info if p_info["mtid"]]
# point_mid = await batch_get_wiring_type(point_list) d_rt_ele = await batch_load_rt_ele_with_hr(mtids)
# # 3. 获取redis数据
# res_redis = await qual_current_data(point_mid)
mtids = [monitor["mtid"] for monitor in monitor_point_list if
monitor["mtid"]]
cid = monitor_point_list[0]["cid"] if len(monitor_point_list) > 0 else 0
res = await elec_current_data(mtids, cid)
# 4. 返回数据
ret_data = { ret_data = {
"inline": [], "inline": [],
"transformer": [], "transformer": [],
...@@ -314,23 +250,25 @@ async def qual_current_level_service(point_list): ...@@ -314,23 +250,25 @@ async def qual_current_level_service(point_list):
"power_dist": [], "power_dist": [],
"device": [] "device": []
} }
for info in monitor_point_list: for info in d_point_info:
m_name = info.get("name") m_name = info.get("name")
m_type = POINT_LEVEL_MAP[info.get("m_type")] m_type = POINT_LEVEL_MAP[info.get("m_type")]
point_id = info.get("pid") point_id = info.get("pid")
mtid = info.get("mtid") mtid = info.get("mtid")
ctnum = info.get("ctnum") if info.get("ctnum") == 2 else 3 ctnum = info.get("ctnum") if info.get("ctnum") == 2 else 3
# 初始化返回dic rt_ele = d_rt_ele.get(mtid, None)
if res.get(mtid): if rt_ele:
time_str = res[mtid]["ts"][:-4] # 初始化返回dic
rt_ele = get_sdu_i_and_u(rt_ele, ctnum)
time_str = timestamp2dts(rt_ele["ts"], YMD_Hms)
fdia = round_2(res[mtid].get("fdia")) fdia = round_2(rt_ele.get("fdia"))
fdib = round_2(res[mtid].get("fdib")) fdib = round_2(rt_ele.get("fdib"))
fdic = round_2(res[mtid].get("fdic")) fdic = round_2(rt_ele.get("fdic"))
thdia = round_4(res[mtid].get("thdia")) thdia = round_4(rt_ele.get("thdia"))
thdib = round_4(res[mtid].get("thdib")) thdib = round_4(rt_ele.get("thdib"))
thdic = round_4(res[mtid].get("thdic")) thdic = round_4(rt_ele.get("thdic"))
res_dic = { res_dic = {
"name": m_name, "name": m_name,
...@@ -338,28 +276,25 @@ async def qual_current_level_service(point_list): ...@@ -338,28 +276,25 @@ async def qual_current_level_service(point_list):
"ctnum": ctnum, "ctnum": ctnum,
"real_time": time_str, "real_time": time_str,
# 电流/电压谐波畸变率 # 电流/电压谐波畸变率
"thdia": thdia, "thdia": thdia, "thdib": thdib, "thdic": thdic,
"thdib": thdib,
"thdic": thdic, "thdua": round_4(rt_ele.get("thdua")),
"thdub": round_4(rt_ele.get("thdub")),
"thdua": round_4(res[mtid].get("thdua")), "thduc": round_4(rt_ele.get("thduc")),
"thdub": round_4(res[mtid].get("thdub")), "thduab": round_4(rt_ele.get("thduab")),
"thduc": round_4(res[mtid].get("thduc")), "thducb": round_4(rt_ele.get("thducb")),
"thduab": round_4(res[mtid].get("thduab")),
"thducb": round_4(res[mtid].get("thducb")),
# 基波电流 # 基波电流
"fdia": fdia, "fdia": fdia, "fdib": fdib, "fdic": fdic,
"fdib": fdib,
"fdic": fdic,
# 三相不平衡 # 三相不平衡
"ubl": round_4(res[mtid].get("ubl")), "ubl": round_4(rt_ele.get("ubl")),
"ibl": round_4(res[mtid].get("ibl")), "ibl": round_4(rt_ele.get("ibl")),
# 电压偏差 # 电压偏差
"ua_dev": round_4(res[mtid].get("ua_dev")), "ua_dev": round_4(rt_ele.get("ua_dev")),
"ub_dev": round_4(res[mtid].get("ub_dev")), "ub_dev": round_4(rt_ele.get("ub_dev")),
"uc_dev": round_4(res[mtid].get("uc_dev")), "uc_dev": round_4(rt_ele.get("uc_dev")),
"uab_dev": round_4(res[mtid].get("uab_dev")), "uab_dev": round_4(rt_ele.get("uab_dev")),
"ucb_dev": round_4(res[mtid].get("ucb_dev")), "ucb_dev": round_4(rt_ele.get("ucb_dev")),
# 电流总谐波有效值 = 基波电流 * 电流总谐波畸变率 # 电流总谐波有效值 = 基波电流 * 电流总谐波畸变率
"thdia_virtual": round_2(multiplication_two(fdia, thdia)), "thdia_virtual": round_2(multiplication_two(fdia, thdia)),
"thdib_virtual": round_2(multiplication_two(fdib, thdib)), "thdib_virtual": round_2(multiplication_two(fdib, thdib)),
...@@ -371,7 +306,6 @@ async def qual_current_level_service(point_list): ...@@ -371,7 +306,6 @@ async def qual_current_level_service(point_list):
"thdi_threshold": THDI_THRESHOLD, # 电流总谐波畸变 "thdi_threshold": THDI_THRESHOLD, # 电流总谐波畸变
"u_threshold": U_THRESHOLD, # 电压偏差 "u_threshold": U_THRESHOLD, # 电压偏差
} }
# redis数据过期,或者没有数据
else: else:
res_dic = { res_dic = {
"name": m_name, "name": m_name,
...@@ -379,28 +313,18 @@ async def qual_current_level_service(point_list): ...@@ -379,28 +313,18 @@ async def qual_current_level_service(point_list):
"ctnum": ctnum, "ctnum": ctnum,
"real_time": "", "real_time": "",
# 电流/电压谐波畸变率 # 电流/电压谐波畸变率
"thdia": "", "thdia": "", "thdib": "", "thdic": "",
"thdib": "",
"thdic": "", "thdua": "", "thdub": "", "thduc": "",
"thduab": "", "thducb": "",
"thdua": "",
"thdub": "",
"thduc": "",
"thduab": "",
"thducb": "",
# 基波电流 # 基波电流
"fdia": "", "fdia": "", "fdib": "", "fdic": "",
"fdib": "",
"fdic": "",
# 三相不平衡 # 三相不平衡
"ubl": "", "ubl": "",
"ibl": "", "ibl": "",
# 电压偏差 # 电压偏差
"ua_dev": "", "ua_dev": "", "ub_dev": "", "uc_dev": "",
"ub_dev": "", "uab_dev": "", "ucb_dev": "",
"uc_dev": "",
"uab_dev": "",
"ucb_dev": "",
# 电流总谐波有效值 = 基波电流 * 电流总谐波畸变率 # 电流总谐波有效值 = 基波电流 * 电流总谐波畸变率
"thdia_virtual": "", "thdia_virtual": "",
"thdib_virtual": "", "thdib_virtual": "",
...@@ -408,13 +332,12 @@ async def qual_current_level_service(point_list): ...@@ -408,13 +332,12 @@ async def qual_current_level_service(point_list):
} }
ret_data[m_type].append(res_dic) ret_data[m_type].append(res_dic)
return QclResp( return QclResp(inline=ret_data["inline"],
inline=ret_data["inline"], transformer=ret_data["transformer"],
transformer=ret_data["transformer"], feeder=ret_data["feeder"],
feeder=ret_data["feeder"], power_dist=ret_data["power_dist"],
power_dist=ret_data["power_dist"], device=ret_data["device"],
device=ret_data["device"], )
)
async def elec_index_service(cid, point_id, start, end): async def elec_index_service(cid, point_id, start, end):
...@@ -591,7 +514,7 @@ async def elec_current_service(point_id): ...@@ -591,7 +514,7 @@ async def elec_current_service(point_id):
raise BusinessException(message=msg) raise BusinessException(message=msg)
now_ts = pendulum.now(tz=CST).int_timestamp now_ts = pendulum.now(tz=CST).int_timestamp
d_ele_rt, ts = None, now_ts d_rt_ele, ts = None, now_ts
try: try:
mtid = p_info["mtid"] mtid = p_info["mtid"]
key = f"real_time:electric:{SETTING.mysql_db}:{mtid}" key = f"real_time:electric:{SETTING.mysql_db}:{mtid}"
...@@ -605,35 +528,103 @@ async def elec_current_service(point_id): ...@@ -605,35 +528,103 @@ async def elec_current_service(point_id):
if k not in rt_ele.keys(): if k not in rt_ele.keys():
rt_ele[k] = rt_ele_hr[k] rt_ele[k] = rt_ele_hr[k]
d_ele_rt, ts = rt_ele, rt_ele["ts"] d_rt_ele, ts = rt_ele, rt_ele["ts"]
elif rt_ele: elif rt_ele:
rt_ele = json.loads(rt_ele) rt_ele = json.loads(rt_ele)
if now_ts - rt_ele["ts"] <= REAL_EXP_TIME: if now_ts - rt_ele["ts"] <= REAL_EXP_TIME:
d_ele_rt, ts = rt_ele, rt_ele["ts"] d_rt_ele, ts = rt_ele, rt_ele["ts"]
elif rt_ele_hr: elif rt_ele_hr:
rt_ele_hr = json.loads(rt_ele_hr) rt_ele_hr = json.loads(rt_ele_hr)
if now_ts - rt_ele_hr["ts"] <= REAL_EXP_TIME: if now_ts - rt_ele_hr["ts"] <= REAL_EXP_TIME:
d_ele_rt, ts = rt_ele_hr, rt_ele_hr["ts"] d_rt_ele, ts = rt_ele_hr, rt_ele_hr["ts"]
except Exception as e: except Exception as e:
log.error(f"parse real time electric error, pid:{point_id}") log.error(f"parse real time electric error, pid:{point_id}")
log.exception(e) log.exception(e)
time_str = timestamp2dts(ts, YMD_Hms) time_str = timestamp2dts(ts, YMD_Hms)
if d_ele_rt is None: if d_rt_ele is None:
return time_str, None return time_str, None
# 识电U只有一项有数据,返回具体的项 # 识电U只有一项有数据,返回具体的项
ctnum = d_ele_rt.get("ctnum") or 3 ctnum = d_rt_ele.get("ctnum") or 3
return time_str, get_sdu_i_and_u(d_ele_rt, ctnum) return time_str, get_sdu_i_and_u(d_rt_ele, ctnum)
async def batch_load_rt_ele(mtids):
now_ts = pendulum.now(tz=CST).int_timestamp
d_rt_ele = {mtid: {} for mtid in mtids}
try:
db = SETTING.mysql_db
keys = [f"real_time:electric:{db}:{mtid}" for mtid in mtids]
for rt_ele in await RedisUtils().mget(keys):
if rt_ele is None:
continue
rt_ele = json.loads(rt_ele)
if now_ts - rt_ele["ts"] <= REAL_EXP_TIME:
d_rt_ele[rt_ele["mtid"]] = rt_ele
except Exception as e:
log.error(f"batch load real time electric error, mtids:{mtids}")
log.exception(e)
return d_rt_ele
async def batch_load_rt_ele_with_hr(mtids):
now_ts = pendulum.now(tz=CST).int_timestamp
d_rt_ele = {mtid: {} for mtid in mtids}
try:
db = SETTING.mysql_db
keys = [f"real_time:electric:{db}:{mtid}" for mtid in mtids]
key_hrs = [f"real_time:electric_hr:{db}:{mtid}" for mtid in mtids]
lst_rt_ele = await RedisUtils().mget(keys)
lst_rt_ele_hr = await RedisUtils().mget(key_hrs)
for i, mtid in enumerate(mtids):
rt_ele, rt_ele_hr = lst_rt_ele[i], lst_rt_ele_hr[i]
if rt_ele and rt_ele_hr:
rt_ele, rt_ele_hr = json.loads(rt_ele), json.loads(rt_ele_hr)
if rt_ele["mtid"] != mtid or rt_ele_hr["mtid"] != mtid:
log.error(f"batch_load_rt_ele error, mtid:{mtid}")
continue
if now_ts - rt_ele["ts"] <= REAL_EXP_TIME:
if now_ts - rt_ele_hr["ts"] <= REAL_EXP_TIME:
for k in rt_ele_hr.keys():
if k not in rt_ele.keys():
rt_ele[k] = rt_ele_hr[k]
d_rt_ele[mtid] = rt_ele
elif rt_ele:
rt_ele = json.loads(rt_ele)
if rt_ele["mtid"] != mtid:
log.error(f"load_rt_ele error, mtid:{mtid}")
continue
if now_ts - rt_ele["ts"] <= REAL_EXP_TIME:
d_rt_ele[mtid] = rt_ele
elif rt_ele_hr:
rt_ele_hr = json.loads(rt_ele_hr)
if rt_ele_hr["mtid"] != mtid:
log.error(f"load_rt_ele_hr error, mtid:{mtid}")
continue
if now_ts - rt_ele_hr["ts"] <= REAL_EXP_TIME:
d_rt_ele[mtid] = rt_ele_hr
except Exception as e:
log.error(f"batch load real time electric error, mtids:{mtids}")
log.exception(e)
return d_rt_ele
def get_sdu_i_and_u(res, ctnum): def get_sdu_i_and_u(res, ctnum):
''' """获取识电U的相序字段"""
获取识电U的相序字段
'''
res["sdu_i"] = None res["sdu_i"] = None
res["sdu_u"] = None res["sdu_u"] = None
meter_sn = res.get("meter_sn", "").lower() meter_sn = res.get("meter_sn", "").lower()
......
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