Commit 54b0d9c6 authored by ZZH's avatar ZZH

fix lf_dev 2023-8-2

parent 20a1acad
...@@ -53,15 +53,15 @@ async def post_elec_history(req, body: PageRequest) -> ElecHistoryResponse: ...@@ -53,15 +53,15 @@ async def post_elec_history(req, body: PageRequest) -> ElecHistoryResponse:
except: except:
log.error("param error, ranges is NULL") log.error("param error, ranges is NULL")
raise ParamException(message="param error, ranges is NULL") raise ParamException(message="param error, ranges is NULL")
try: try:
intervel, slots = time_format.time_pick_transf(date_start, date_end) intervel, slots = time_format.time_pick_transf(date_start, date_end)
except: except:
log.error("param error, date format error") log.error("param error, date format error")
raise ParamException(message="param error, date format error") raise ParamException(message="param error, date format error")
point_id = filed_value_from_list(body.filter.equals, "point_id") point_id = filed_value_from_list(body.filter.equals, "point_id")
if point_id <= 0 or not point_id: if point_id <= 0 or not point_id:
log.warning("param exception, equals is NULL, no point_id") log.warning("param exception, equals is NULL, no point_id")
raise ParamException( raise ParamException(
...@@ -162,12 +162,12 @@ async def post_elec_current(req, body: PageRequest) -> ElecCurrentResponse: ...@@ -162,12 +162,12 @@ async def post_elec_current(req, body: PageRequest) -> ElecCurrentResponse:
for k, v in res.items(): for k, v in res.items():
if isinstance(v, (str, int)): if isinstance(v, (str, int)):
continue continue
res[k] = add_random_change(v) res[k] = add_random_change(v)
except Exception as e: except Exception as e:
log.error(f"post_elec_current service error:{str(e)}") log.error(f"post_elec_current service error:{str(e)}")
raise BusinessException(message=f"{str(e)}") raise BusinessException(message=f"{str(e)}")
return ElecCurrentResponse(real_time=time_str, return ElecCurrentResponse(real_time=time_str,
**{k: v for k, v in res.items() **{k: v for k, v in res.items()
if k in [field.name for field in if k in [field.name for field in
...@@ -181,7 +181,7 @@ async def post_elec_index(req, body: PageRequest) -> ElecIndexResponse: ...@@ -181,7 +181,7 @@ async def post_elec_index(req, body: PageRequest) -> ElecIndexResponse:
cid = req.json.get("cid") cid = req.json.get("cid")
# 1. 获取point_id # 1. 获取point_id
point_id = filed_value_from_list(body.filter.equals, "point_id") point_id = filed_value_from_list(body.filter.equals, "point_id")
if not point_id or point_id <= 0: if not point_id or point_id <= 0:
msg = "param exception, equals is NULL, no point_id" msg = "param exception, equals is NULL, no point_id"
log.warning(msg) log.warning(msg)
...@@ -208,20 +208,20 @@ async def post_qual_history(req, body: PageRequest) -> QualHistoryResponse: ...@@ -208,20 +208,20 @@ async def post_qual_history(req, body: PageRequest) -> QualHistoryResponse:
except: except:
log.error("param error, ranges is NULL") log.error("param error, ranges is NULL")
raise ParamException(message="param error, ranges is NULL") raise ParamException(message="param error, ranges is NULL")
try: try:
intervel, slots = time_format.time_pick_transf(date_start, date_end) intervel, slots = time_format.time_pick_transf(date_start, date_end)
except: except:
log.error("param error, date format error") log.error("param error, date format error")
raise ParamException(message="param error, date format error") raise ParamException(message="param error, date format error")
point_id = filed_value_from_list(body.filter.equals, "point_id") point_id = filed_value_from_list(body.filter.equals, "point_id")
if not point_id or point_id <= 0: if not point_id or point_id <= 0:
msg = "param exception, equals is NULL, no point_id" msg = "param exception, equals is NULL, no point_id"
log.warning(msg) log.warning(msg)
raise ParamException(message=msg) raise ParamException(message=msg)
return await qual_history_service(date_start, date_end, intervel, slots, return await qual_history_service(date_start, date_end, intervel, slots,
point_id) point_id)
...@@ -272,15 +272,15 @@ async def qual_history_service(start, end, intervel, slots, pid): ...@@ -272,15 +272,15 @@ async def qual_history_service(start, end, intervel, slots, pid):
if slot in datas.keys(): if slot in datas.keys():
for stats_item in stats_items: for stats_item in stats_items:
value = datas[slot].get(stats_item, "") value = datas[slot].get(stats_item, "")
if value and stats_item == "freq_dev_mean": # if value and stats_item == "freq_dev_mean":
# 如果频率偏差保留两位小数之后为0了,那么直接返回0,防止出现-0.00 的情况 # 如果频率偏差保留两位小数之后为0了,那么直接返回0,防止出现-0.00 的情况
if abs(value) < 0.05: # if abs(value) < 0.05:
value = 0 # value = 0
elec_data[stats_item].append(value) elec_data[stats_item].append(value)
else: else:
for stats_item in stats_items: for stats_item in stats_items:
elec_data[stats_item].append("") elec_data[stats_item].append("")
voltage_dev = VoltageDev( voltage_dev = VoltageDev(
**{ **{
k.rsplit("_", 1)[0]: v k.rsplit("_", 1)[0]: v
...@@ -343,7 +343,7 @@ async def qual_history_service(start, end, intervel, slots, pid): ...@@ -343,7 +343,7 @@ async def qual_history_service(start, end, intervel, slots, pid):
): ):
sdu_i = "ic" sdu_i = "ic"
sdu_u = "uc" sdu_u = "uc"
return QualHistoryResponse( return QualHistoryResponse(
ctnum=ctnum, ctnum=ctnum,
voltage_dev=voltage_dev, voltage_dev=voltage_dev,
...@@ -367,35 +367,35 @@ async def post_qual_current(req, body: PageRequest) -> QualCurrentResponse: ...@@ -367,35 +367,35 @@ async def post_qual_current(req, body: PageRequest) -> QualCurrentResponse:
except Exception as e: except Exception as e:
log.warning(f"param exception, equals is NULL, no pid, e:{e}") log.warning(f"param exception, equals is NULL, no pid, e:{e}")
raise ParamException(message="param exception, equals is NULL, no pid") raise ParamException(message="param exception, equals is NULL, no pid")
if point_id <= 0 or not point_id or cid <= 0: if point_id <= 0 or not point_id or cid <= 0:
log.warning("param exception, equals is NULL, no point_id") log.warning("param exception, equals is NULL, no point_id")
raise ParamException(message="param exception, equals is NULL, no pid") raise ParamException(message="param exception, equals is NULL, no pid")
try: try:
time_str, d_rt_ele = await elec_current_service(point_id) time_str, d_rt_ele = await elec_current_service(point_id)
if d_rt_ele is None: if d_rt_ele is None:
d_rt_ele = {} d_rt_ele = {}
# 加些随机变化(防止数据一直不变化) # 加些随机变化(防止数据一直不变化)
for k, v in d_rt_ele.items(): for k, v in d_rt_ele.items():
if isinstance(v, (str, int)): if isinstance(v, (str, int)):
continue continue
d_rt_ele[k] = add_random_change(v) d_rt_ele[k] = add_random_change(v)
except Exception as e: except Exception as e:
log.error(f"post_qual_current service error:{str(e)}") log.error(f"post_qual_current service error:{str(e)}")
raise BusinessException(message=f"{str(e)}") raise BusinessException(message=f"{str(e)}")
d_vol_harm, d_cur_harm = {}, {} d_vol_harm, d_cur_harm = {}, {}
for k in [field.name for field in fields(VoltageHarmonicRate)]: for k in [field.name for field in fields(VoltageHarmonicRate)]:
d_vol_harm[k] = d_rt_ele.get(k) or "" d_vol_harm[k] = d_rt_ele.get(k) or ""
voltage_harmonic = VoltageHarmonicRate(**d_vol_harm) voltage_harmonic = VoltageHarmonicRate(**d_vol_harm)
for k in [field.name for field in fields(CurrentHarmonicRate)]: for k in [field.name for field in fields(CurrentHarmonicRate)]:
d_cur_harm[k] = d_rt_ele.get(k) or "" d_cur_harm[k] = d_rt_ele.get(k) or ""
current_harmonic = CurrentHarmonicRate(**d_cur_harm) current_harmonic = CurrentHarmonicRate(**d_cur_harm)
health_index = await health_score.load_health_index(cid, point_id) health_index = await health_score.load_health_index(cid, point_id)
ret_items = ["ua_dev", "ub_dev", "uc_dev", "uab_dev", "ucb_dev", ret_items = ["ua_dev", "ub_dev", "uc_dev", "uab_dev", "ucb_dev",
"freq_dev", "ubl", "ibl", "sdu_i", "sdu_u"] "freq_dev", "ubl", "ibl", "sdu_i", "sdu_u"]
......
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