Commit d2c161bf authored by lcn's avatar lcn

bug修复

parent 4c7a3d80
...@@ -20,8 +20,7 @@ from unify_api.modules.electric.procedures.electric_util import \ ...@@ -20,8 +20,7 @@ from unify_api.modules.electric.procedures.electric_util import \
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.utils.time_format import CST, YMD_Hms, timestamp2dts
time_pick_transf
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 (
...@@ -77,12 +76,12 @@ async def elec_current_storeys_service(storeys): ...@@ -77,12 +76,12 @@ async def elec_current_storeys_service(storeys):
"ua": "", "ia": "", "ub": "", "ib": "", "uc": "", "ic": "", "ua": "", "ia": "", "ub": "", "ib": "", "uc": "", "ic": "",
"pttl": "", "qttl": "", "freq": "", "costtl": "", "lf": "", "pttl": "", "qttl": "", "freq": "", "costtl": "", "lf": "",
"sdu_i": "", "sdu_u": "", } "sdu_i": "", "sdu_u": "", }
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
...@@ -149,7 +148,7 @@ async def qual_current_storeys_service(storeys): ...@@ -149,7 +148,7 @@ async def qual_current_storeys_service(storeys):
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
...@@ -230,7 +229,7 @@ async def elec_card_level_service(point_list): ...@@ -230,7 +229,7 @@ async def elec_card_level_service(point_list):
"costtl_threshold": COSTTL_THRESHOLD, "costtl_threshold": COSTTL_THRESHOLD,
"lf_threshold": LF_THRESHOLD, "lf_threshold": LF_THRESHOLD,
} }
ret_data[m_type].append(res_dic) ret_data[m_type].append(res_dic)
return EclResp(inline=ret_data["inline"], return EclResp(inline=ret_data["inline"],
transformer=ret_data["transformer"], transformer=ret_data["transformer"],
...@@ -264,15 +263,15 @@ async def qual_current_level_service(point_list): ...@@ -264,15 +263,15 @@ async def qual_current_level_service(point_list):
# 初始化返回dic # 初始化返回dic
rt_ele = get_sdu_i_and_u(rt_ele, ctnum) rt_ele = get_sdu_i_and_u(rt_ele, ctnum)
time_str = timestamp2dts(rt_ele["ts"], YMD_Hms) time_str = timestamp2dts(rt_ele["ts"], YMD_Hms)
fdia = round_2(rt_ele.get("fdia")) fdia = round_2(rt_ele.get("fdia"))
fdib = round_2(rt_ele.get("fdib")) fdib = round_2(rt_ele.get("fdib"))
fdic = round_2(rt_ele.get("fdic")) fdic = round_2(rt_ele.get("fdic"))
thdia = round_4(rt_ele.get("thdia")) thdia = round_4(rt_ele.get("thdia"))
thdib = round_4(rt_ele.get("thdib")) thdib = round_4(rt_ele.get("thdib"))
thdic = round_4(rt_ele.get("thdic")) thdic = round_4(rt_ele.get("thdic"))
res_dic = { res_dic = {
"name": m_name, "name": m_name,
"point_id": point_id, "point_id": point_id,
...@@ -280,7 +279,7 @@ async def qual_current_level_service(point_list): ...@@ -280,7 +279,7 @@ async def qual_current_level_service(point_list):
"real_time": time_str, "real_time": time_str,
# 电流/电压谐波畸变率 # 电流/电压谐波畸变率
"thdia": thdia, "thdib": thdib, "thdic": thdic, "thdia": thdia, "thdib": thdib, "thdic": thdic,
"thdua": round_4(rt_ele.get("thdua")), "thdua": round_4(rt_ele.get("thdua")),
"thdub": round_4(rt_ele.get("thdub")), "thdub": round_4(rt_ele.get("thdub")),
"thduc": round_4(rt_ele.get("thduc")), "thduc": round_4(rt_ele.get("thduc")),
...@@ -297,7 +296,7 @@ async def qual_current_level_service(point_list): ...@@ -297,7 +296,7 @@ async def qual_current_level_service(point_list):
"uc_dev": round_4(rt_ele.get("uc_dev")), "uc_dev": round_4(rt_ele.get("uc_dev")),
"uab_dev": round_4(rt_ele.get("uab_dev")), "uab_dev": round_4(rt_ele.get("uab_dev")),
"ucb_dev": round_4(rt_ele.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)),
...@@ -317,7 +316,7 @@ async def qual_current_level_service(point_list): ...@@ -317,7 +316,7 @@ async def qual_current_level_service(point_list):
"real_time": "", "real_time": "",
# 电流/电压谐波畸变率 # 电流/电压谐波畸变率
"thdia": "", "thdib": "", "thdic": "", "thdia": "", "thdib": "", "thdic": "",
"thdua": "", "thdub": "", "thduc": "", "thdua": "", "thdub": "", "thduc": "",
"thduab": "", "thducb": "", "thduab": "", "thducb": "",
# 基波电流 # 基波电流
...@@ -333,7 +332,7 @@ async def qual_current_level_service(point_list): ...@@ -333,7 +332,7 @@ async def qual_current_level_service(point_list):
"thdib_virtual": "", "thdib_virtual": "",
"thdic_virtual": "", "thdic_virtual": "",
} }
ret_data[m_type].append(res_dic) ret_data[m_type].append(res_dic)
return QclResp(inline=ret_data["inline"], return QclResp(inline=ret_data["inline"],
transformer=ret_data["transformer"], transformer=ret_data["transformer"],
...@@ -347,14 +346,12 @@ async def elec_index_service(cid, point_id, start, end): ...@@ -347,14 +346,12 @@ async def elec_index_service(cid, point_id, start, end):
ctnum = await load_point_ctnum(point_id) ctnum = await load_point_ctnum(point_id)
ctnum = ctnum if ctnum == 2 else 3 ctnum = ctnum if ctnum == 2 else 3
now = str(datetime.now()) now = str(datetime.now())
intervel, _ = time_pick_transf(start, end) if start[:10] == now[:10] and end[:10] == now[:10]:
if intervel == 86400:
table_name = "point_1day_electric"
redi_table_name = "location_1day_aiao"
else:
table_name = "point_15min_electric" table_name = "point_15min_electric"
redi_table_name = "location_15min_aiao" redi_table_name = "location_15min_aiao"
else:
table_name = "point_1day_electric"
redi_table_name = "location_1day_aiao"
if ctnum == 2: if ctnum == 2:
common_items = ["lf_mean", "lf_min", "lf_max", "pttl_mean", "pttl_min", common_items = ["lf_mean", "lf_min", "lf_max", "pttl_mean", "pttl_min",
"pttl_max", "qttl_mean", "qttl_min", "qttl_max", "pttl_max", "qttl_mean", "qttl_min", "qttl_max",
...@@ -463,7 +460,7 @@ async def elec_index_service(cid, point_id, start, end): ...@@ -463,7 +460,7 @@ async def elec_index_service(cid, point_id, start, end):
mean_item_name = f"{item}_mean" mean_item_name = f"{item}_mean"
avg_value = df[mean_item_name].mean() avg_value = df[mean_item_name].mean()
if not pd.isna(avg_value): if not pd.isna(avg_value):
avg_value = round(avg_value, 2) if avg_value else "" avg_value = round(avg_value, 4) if avg_value else ""
else: else:
avg_value = "" avg_value = ""
elec_index = ElecIndex( elec_index = ElecIndex(
...@@ -517,7 +514,7 @@ async def elec_current_service(point_id): ...@@ -517,7 +514,7 @@ async def elec_current_service(point_id):
if not p_info or not p_info["mtid"]: if not p_info or not p_info["mtid"]:
msg = f"没有监测点:{point_id} monitor信息,请联系运维人员!" msg = f"没有监测点:{point_id} monitor信息,请联系运维人员!"
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_rt_ele, ts = None, now_ts d_rt_ele, ts = None, now_ts
try: try:
...@@ -532,27 +529,27 @@ async def elec_current_service(point_id): ...@@ -532,27 +529,27 @@ async def elec_current_service(point_id):
for k in rt_ele_hr.keys(): for k in rt_ele_hr.keys():
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_rt_ele, 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_rt_ele, 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_rt_ele, 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_rt_ele is None: if d_rt_ele is None:
return time_str, None return time_str, None
# 识电U只有一项有数据,返回具体的项 # 识电U只有一项有数据,返回具体的项
ctnum = d_rt_ele.get("ctnum") or 3 ctnum = d_rt_ele.get("ctnum") or 3
return time_str, get_sdu_i_and_u(d_rt_ele, ctnum) return time_str, get_sdu_i_and_u(d_rt_ele, ctnum)
...@@ -564,27 +561,27 @@ async def batch_load_rt_ele(mtids): ...@@ -564,27 +561,27 @@ async def batch_load_rt_ele(mtids):
try: try:
db = SETTING.mysql_db db = SETTING.mysql_db
keys = [f"real_time:electric:{db}:{mtid}" for mtid in mtids] keys = [f"real_time:electric:{db}:{mtid}" for mtid in mtids]
i_size = 500 i_size = 500
lst_rt_ele = [] lst_rt_ele = []
for i in range(math.ceil(len(mtids) / i_size)): for i in range(math.ceil(len(mtids) / i_size)):
pipe = await RedisUtils().client.pipeline() pipe = await RedisUtils().client.pipeline()
for key in keys[i_size * i:i_size * (i + 1)]: for key in keys[i_size * i:i_size * (i + 1)]:
await pipe.get(key) await pipe.get(key)
lst_rt_ele += await pipe.execute() lst_rt_ele += await pipe.execute()
for rt_ele in lst_rt_ele: for rt_ele in lst_rt_ele:
if rt_ele is None: if rt_ele is None:
continue continue
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_rt_ele[rt_ele["mtid"]] = rt_ele d_rt_ele[rt_ele["mtid"]] = rt_ele
except Exception as e: except Exception as e:
log.error(f"batch load real time electric error, mtids:{mtids}") log.error(f"batch load real time electric error, mtids:{mtids}")
log.exception(e) log.exception(e)
return d_rt_ele return d_rt_ele
...@@ -595,22 +592,22 @@ async def batch_load_rt_ele_with_hr(mtids): ...@@ -595,22 +592,22 @@ async def batch_load_rt_ele_with_hr(mtids):
db = SETTING.mysql_db db = SETTING.mysql_db
keys = [f"real_time:electric:{db}:{mtid}" for mtid in mtids] keys = [f"real_time:electric:{db}:{mtid}" for mtid in mtids]
key_hrs = [f"real_time:electric_hr:{db}:{mtid}" for mtid in mtids] key_hrs = [f"real_time:electric_hr:{db}:{mtid}" for mtid in mtids]
i_size = 500 i_size = 500
lst_rt_ele, lst_rt_ele_hr = [], [] lst_rt_ele, lst_rt_ele_hr = [], []
for i in range(math.ceil(len(mtids) / i_size)): for i in range(math.ceil(len(mtids) / i_size)):
pipe = await RedisUtils().client.pipeline() pipe = await RedisUtils().client.pipeline()
for key in keys[i_size * i:i_size * (i + 1)]: for key in keys[i_size * i:i_size * (i + 1)]:
await pipe.get(key) await pipe.get(key)
lst_rt_ele += await pipe.execute() lst_rt_ele += await pipe.execute()
pipe = await RedisUtils().client.pipeline() pipe = await RedisUtils().client.pipeline()
for key in key_hrs[i_size * i:i_size * (i + 1)]: for key in key_hrs[i_size * i:i_size * (i + 1)]:
await pipe.get(key) await pipe.get(key)
lst_rt_ele_hr += await pipe.execute() lst_rt_ele_hr += await pipe.execute()
for i, mtid in enumerate(mtids): for i, mtid in enumerate(mtids):
rt_ele, rt_ele_hr = lst_rt_ele[i], lst_rt_ele_hr[i] rt_ele, rt_ele_hr = lst_rt_ele[i], lst_rt_ele_hr[i]
if rt_ele and rt_ele_hr: if rt_ele and rt_ele_hr:
...@@ -618,36 +615,36 @@ async def batch_load_rt_ele_with_hr(mtids): ...@@ -618,36 +615,36 @@ async def batch_load_rt_ele_with_hr(mtids):
if rt_ele["mtid"] != mtid or rt_ele_hr["mtid"] != mtid: if rt_ele["mtid"] != mtid or rt_ele_hr["mtid"] != mtid:
log.error(f"batch_load_rt_ele error, mtid:{mtid}") log.error(f"batch_load_rt_ele error, mtid:{mtid}")
continue continue
if now_ts - rt_ele["ts"] <= REAL_EXP_TIME: if now_ts - rt_ele["ts"] <= REAL_EXP_TIME:
if now_ts - rt_ele_hr["ts"] <= REAL_EXP_TIME: if now_ts - rt_ele_hr["ts"] <= REAL_EXP_TIME:
for k in rt_ele_hr.keys(): for k in rt_ele_hr.keys():
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_rt_ele[mtid] = rt_ele d_rt_ele[mtid] = rt_ele
elif rt_ele: elif rt_ele:
rt_ele = json.loads(rt_ele) rt_ele = json.loads(rt_ele)
if rt_ele["mtid"] != mtid: if rt_ele["mtid"] != mtid:
log.error(f"load_rt_ele error, mtid:{mtid}") log.error(f"load_rt_ele error, mtid:{mtid}")
continue continue
if now_ts - rt_ele["ts"] <= REAL_EXP_TIME: if now_ts - rt_ele["ts"] <= REAL_EXP_TIME:
d_rt_ele[mtid] = rt_ele d_rt_ele[mtid] = rt_ele
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 rt_ele_hr["mtid"] != mtid: if rt_ele_hr["mtid"] != mtid:
log.error(f"load_rt_ele_hr error, mtid:{mtid}") log.error(f"load_rt_ele_hr error, mtid:{mtid}")
continue continue
if now_ts - rt_ele_hr["ts"] <= REAL_EXP_TIME: if now_ts - rt_ele_hr["ts"] <= REAL_EXP_TIME:
d_rt_ele[mtid] = rt_ele_hr d_rt_ele[mtid] = rt_ele_hr
except Exception as e: except Exception as e:
log.error(f"batch load real time electric error, mtids:{mtids}") log.error(f"batch load real time electric error, mtids:{mtids}")
log.exception(e) log.exception(e)
return d_rt_ele return d_rt_ele
......
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