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