Commit e9a86df4 authored by lcn's avatar lcn

bug修复

parent 43ef9b36
......@@ -8,12 +8,19 @@ from unify_api.modules.zhiwei_u.components.scope_operations_cps import \
from pot_libs.mysql_util.mysql_util import MysqlUtil
async def scope_by_sql(mid_sql):
sql = f"select * from point_1min_scope where {mid_sql} order by " \
f"create_time desc limit 500"
async def scope_by_sql(mid_sql, offset, limit):
scope_event_type = ['over_gap_cur', 'over_gap_i', 'over_gap_pttl',
'over_gap_u', 'over_res_cur', 'over_rms_i',
'over_rms_pttl', 'over_rms_u', 'under_rms_u']
sql = f"select * from point_1min_scope where {mid_sql} " \
f"and fault_type in %s" \
f"order by create_time desc limit {limit} offset {offset}"
count_sql = f"select count(*) count from point_1min_scope where" \
f" {mid_sql} and fault_type in %s"
async with MysqlUtil() as conn:
data = await conn.fetchall(sql)
return data
data = await conn.fetchall(sql, args=(scope_event_type,))
count = await conn.fetch_value(count_sql, args=(scope_event_type,))
return data, count
async def detail_data_by_es(pid, create_time):
......
......@@ -18,7 +18,7 @@ from pot_libs.common.components.responses import success_res
from unify_api.utils.response_code import RET
async def scope_record_service(cid, point_id, page_num, page_size, start, end):
async def scope_record_service(cid, point_id, offset, limit, start, end):
li = [f"cid={cid}"]
if point_id:
if len(point_id) == 1:
......@@ -28,53 +28,50 @@ async def scope_record_service(cid, point_id, page_num, page_size, start, end):
if start and end:
li.append(f"create_time BETWEEN '{start}' and '{end}'")
mid_sql = " and ".join(li)
datas = await scope_by_sql(mid_sql)
total = len(datas)
datas, total = await scope_by_sql(mid_sql, offset, limit)
# 获取监测点名称
point_dict = await get_point_dict(cid)
# 动态漏电流阈值
rows = []
if datas:
start = (page_num - 1) * page_size
datas = datas[start: start + page_num]
for data in datas:
# 漏电流
if data["fault_type"] in ("over_res_cur", "overResidualCurrent"):
probability = 1
record_type_name = "漏电流"
reason = "漏电流越限"
threhold = await get_threhold(data["cid"], data["sid"])
log.info(f"scope_record_service threhold:{threhold}")
for data in datas:
# 漏电流
if data["fault_type"] in ("over_res_cur", "overResidualCurrent"):
probability = 1
record_type_name = "漏电流"
reason = "漏电流越限"
threhold = await get_threhold(data["cid"], data["sid"])
log.info(f"scope_record_service threhold:{threhold}")
else:
try:
# 获取url地址数据,后续再接上
context = json.load(data.get("url"))
ctnum = 2 if "uab" in context else 3
result = actionFile(context, ctnum)
except:
result = None
log.info(f"actionFile:{result}")
if isinstance(result, list):
# record_type_name, probability, reason = result[0]
record_type_name, probability, _ = result[0]
probability = round(float(probability), 4)
else:
try:
# 获取url地址数据,后续再接上
context = json.load(data.get("url"))
ctnum = 2 if "uab" in context else 3
result = actionFile(context, ctnum)
except:
result = None
log.info(f"actionFile:{result}")
if isinstance(result, list):
# record_type_name, probability, reason = result[0]
record_type_name, probability, _ = result[0]
probability = round(float(probability), 4)
else:
# record_type_name, probability, reason = "不存在故障", "",
# result
record_type_name, probability = "不存在故障", ""
fault_type = await get_trigger_params_dao(data["fault_type"])
reason = fault_type.get("name")
dt = data["create_time"]
check_dt = time_format.convert_dt_to_timestr(dt)
check_timestamp = int(time_format.convert_dt_to_timestamp(dt))
sr = ScopeRecord(trigger_time=check_dt, point_id=data["pid"],
point_name=point_dict.get(data["pid"]),
record_type=data["fault_type"],
record_type_name=record_type_name,
probability=probability, reason=reason,
scope_id="{}_{}".format(data["pid"],
check_timestamp))
rows.append(sr)
# record_type_name, probability, reason = "不存在故障", "",
# result
record_type_name, probability = "不存在故障", ""
fault_type = await get_trigger_params_dao(data["fault_type"])
reason = fault_type.get("name")
dt = data["create_time"]
check_dt = time_format.convert_dt_to_timestr(dt)
check_timestamp = int(time_format.convert_dt_to_timestamp(dt))
sr = ScopeRecord(trigger_time=check_dt, point_id=data["pid"],
point_name=point_dict.get(data["pid"]),
record_type=data["fault_type"],
record_type_name=record_type_name,
probability=probability, reason=reason,
scope_id="{}_{}".format(data["pid"],
check_timestamp))
rows.append(sr)
return ScopeRecordResp(rows=rows, total=total)
......
......@@ -14,7 +14,8 @@ async def post_scope_record(req, body: ScopeRecordReq) -> ScopeRecordResp:
end = body.end
page_size = body.page_size
page_num = body.page_num
return await scope_record_service(cid, point_id, page_num, page_size,
return await scope_record_service(cid, point_id,
(page_num - 1) * page_size, page_size,
start, end)
......
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