Commit 2fb841ab authored by lcn's avatar lcn

bug修复

parent 7129b651
......@@ -61,7 +61,7 @@ async def get_es_aiao_15min_data(query_body):
async with EsUtil() as es:
es_results = await es.search_origin(body=query_body,
index=constants.LOCATION_15MIN_AIAO)
return es_results.get("aggregations", {})
......@@ -72,7 +72,7 @@ async def get_es_point_15min_data(query_body):
async with EsUtil() as es:
es_results = await es.search_origin(body=query_body,
index=constants.POINT_15MIN_INDEX)
return es_results.get("aggregations", {})
......@@ -86,17 +86,17 @@ async def get_es_point_1min_data(query_body, start):
str(int(start[5:7]))
es_results = await es.search_origin(body=query_body,
index=p_database)
return es_results.get("hits", {}).get("hits", {})
async def get_aiao_1min_pds(slots, temp_res_data, res_curr_th):
temp, res, s_value, a_value, b_value, c_value, n_value = [], [], {
"item": "漏电流", "threhold": res_curr_th}, {"item": "A相"}, {
"item": "B相"}, {
"item": "C相"}, {
"item": "N相"}
"item": "B相"}, {
"item": "C相"}, {
"item": "N相"}
temp1, temp2, temp3, temp4, res_curr = {}, {}, {}, {}, {}
[temp1.update({i.get("ts"): i.get("temp1")}) for i in temp_res_data]
[temp2.update({i.get("ts"): i.get("temp2")}) for i in temp_res_data]
......@@ -104,7 +104,7 @@ async def get_aiao_1min_pds(slots, temp_res_data, res_curr_th):
[temp4.update({i.get("ts"): i.get("temp4")}) for i in temp_res_data]
[res_curr.update({i.get("ts"): i.get("residual_current")}) for i in
temp_res_data]
a_slot, b_slot, c_slot, n_slot, res_slot = [], [], [], [], []
[a_slot.append(temp1.get(i, "")) for i in slots]
[b_slot.append(temp2.get(i, "")) for i in slots]
......@@ -121,17 +121,15 @@ async def get_aiao_1min_pds(slots, temp_res_data, res_curr_th):
temp.append(c_value)
temp.append(n_value)
res.append(s_value)
return temp, res
async def get_aiao_data_pds(slots, temp_res_data, res_curr_th):
temp, res, s_value, a_value, b_value, c_value, n_value = [], [], {
"item": "漏电流", "threhold": res_curr_th}, {"item": "A相"}, {
"item": "B相"}, {
"item": "C相"}, {
"item": "N相"}
"item": "B相"}, {"item": "C相"}, {"item": "N线"}
temp1, temp2, temp3, temp4, res_curr = {}, {}, {}, {}, {}
for i in temp_res_data:
if i.get('ad_field') == 'temp1':
......@@ -144,7 +142,7 @@ async def get_aiao_data_pds(slots, temp_res_data, res_curr_th):
temp4.update({i.get("create_time"): i.get("value_avg")})
else:
res_curr.update({i.get("create_time"): i.get("value_avg")})
a_slot, b_slot, c_slot, n_slot, res_slot = [], [], [], [], []
[a_slot.append(temp1.get(i, "")) for i in slots]
[b_slot.append(temp2.get(i, "")) for i in slots]
......@@ -169,8 +167,8 @@ async def get_point_1min_chart_pds(ctnum, slots, data):
i, v, power, ia_value, ib_value, ic_value, ua_value, ub_value, uc_value, pttl_value, qttl_value \
= [], [], [], {"item": "ia"}, {"item": "ib"}, {"item": "ic"}, {
"item": "ua"}, {"item": "ub"}, {"item": "uc"}, {"item": "pttl"}, {
"item": "qttl"}
"item": "qttl"}
ia_dict, ib_dict, ic_dict, pttl_dict, qttl_dict, ua_dict, ub_dict, uc_dict \
= {}, {}, {}, {}, {}, {}, {}, {}
[ia_dict.update({i.get("ts"): i.get("ia")}) for i in data]
......@@ -181,10 +179,10 @@ async def get_point_1min_chart_pds(ctnum, slots, data):
[ua_dict.update({i.get("ts"): i.get("ua")}) for i in data]
[ub_dict.update({i.get("ts"): i.get("ub")}) for i in data]
[uc_dict.update({i.get("ts"): i.get("uc")}) for i in data]
ia_list, ib_list, ic_list, pttl_list, qttl_list, ua_list, ub_list, uc_list \
= [], [], [], [], [], [], [], []
[ia_list.append(ia_dict.get(i, "")) for i in slots]
[ib_list.append(ia_dict.get(i, "")) for i in slots]
[ic_list.append(ia_dict.get(i, "")) for i in slots]
......@@ -213,7 +211,7 @@ async def get_point_1min_chart_pds(ctnum, slots, data):
i, v, power, ia_value, ic_value, uab_value, ucb_value, pttl_value, qttl_value \
= [], [], [], {"item": "ia"}, {"item": "ic"}, {
"item": "uab"}, {"item": "ucb"}, {"item": "pttl"}, {"item": "qttl"}
ia_dict, ic_dict, pttl_dict, qttl_dict, uab_dict, ucb_dict, \
= {}, {}, {}, {}, {}, {}
[ia_dict.update({i.get("ts"): i.get("ia")}) for i in data]
......@@ -222,10 +220,10 @@ async def get_point_1min_chart_pds(ctnum, slots, data):
[qttl_dict.update({i.get("ts"): i.get("qttl")}) for i in data]
[uab_dict.update({i.get("ts"): i.get("ua")}) for i in data]
[ucb_dict.update({i.get("ts"): i.get("ub")}) for i in data]
ia_list, ic_list, pttl_list, qttl_list, uab_list, ucb_list \
= [], [], [], [], [], []
[ia_list.append(ia_dict.get(i, "")) for i in slots]
[ic_list.append(ia_dict.get(i, "")) for i in slots]
[pttl_list.append(ia_dict.get(i, "")) for i in slots]
......@@ -252,8 +250,8 @@ async def get_point_data_chart_pds(ctnum, slots, data):
i, v, power, ia_value, ib_value, ic_value, ua_value, ub_value, uc_value, pttl_value, qttl_value \
= [], [], [], {"item": "ia"}, {"item": "ib"}, {"item": "ic"}, {
"item": "ua"}, {"item": "ub"}, {"item": "uc"}, {"item": "pttl"}, {
"item": "qttl"}
"item": "qttl"}
ia_dict, ib_dict, ic_dict, pttl_dict, qttl_dict, ua_dict, ub_dict, uc_dict \
= {}, {}, {}, {}, {}, {}, {}, {}
[ia_dict.update({i.get("create_time"): i.get("ia_mean")}) for i in
......@@ -272,10 +270,10 @@ async def get_point_data_chart_pds(ctnum, slots, data):
data]
[uc_dict.update({i.get("create_time"): i.get("uc_mean")}) for i in
data]
ia_list, ib_list, ic_list, pttl_list, qttl_list, ua_list, ub_list, uc_list \
= [], [], [], [], [], [], [], []
[ia_list.append(ia_dict.get(i, "")) for i in slots]
[ib_list.append(ia_dict.get(i, "")) for i in slots]
[ic_list.append(ia_dict.get(i, "")) for i in slots]
......@@ -304,7 +302,7 @@ async def get_point_data_chart_pds(ctnum, slots, data):
i, v, power, ia_value, ic_value, uab_value, ucb_value, pttl_value, qttl_value \
= [], [], [], {"item": "ia"}, {"item": "ic"}, {
"item": "uab"}, {"item": "ucb"}, {"item": "pttl"}, {"item": "qttl"}
ia_dict, ic_dict, pttl_dict, qttl_dict, uab_dict, ucb_dict, \
= {}, {}, {}, {}, {}, {}
[ia_dict.update({i.get("create_time"): i.get("ia_mean")}) for i in
......@@ -319,10 +317,10 @@ async def get_point_data_chart_pds(ctnum, slots, data):
data]
[ucb_dict.update({i.get("create_time"): i.get("ub_mean")}) for i in
data]
ia_list, ic_list, pttl_list, qttl_list, uab_list, ucb_list \
= [], [], [], [], [], []
[ia_list.append(ia_dict.get(i, "")) for i in slots]
[ic_list.append(ia_dict.get(i, "")) for i in slots]
[pttl_list.append(ia_dict.get(i, "")) for i in slots]
......@@ -495,7 +493,7 @@ def cal_aiao_value(location_datas, datas, mtid=None):
mean_value = round(mean_value, 2)
else:
mean_value = ""
if mtid:
mtid = str(mtid)
electric_index = dict(
......
......@@ -8,7 +8,7 @@ from unify_api.modules.electric.procedures.electric_util import (
get_wiring_type
)
from unify_api.modules.anshiu.components.fine_monitor_cps import (
ElectricIndexParam
ElectricIndexParam
)
from unify_api.modules.anshiu.procedures.fine_monitor_pds import (
get_threshold_by_location, get_aiao_1min_pds,
......@@ -43,7 +43,7 @@ async def get_adio_chart_data(location_group, location_info, date_start,
# 取时间间隔为1min的数据
temp_res_data = await get_aiao_1min_dao(mtid, date_start, date_end)
temp, res = await get_aiao_1min_pds(slots, temp_res_data, res_curr_th)
return temp, res
......@@ -52,16 +52,16 @@ async def get_point_chart_data(point_id, date_start, date_end, intervel,
'''
获取电气量
'''
# 获取当前监测点的接表法
ctnum, mtid = await get_wiring_type(point_id)
if ctnum not in [2, 3]:
log.error(
f"elec_index point_id={point_id} ctnum={ctnum} 找不到ctnum , 监测点已经拆除")
# 返回的数值不在2,3中的,一般是装置点已经拆除。默认先给一个默认值3
ctnum = 3
if ctnum == 2:
stats_items = [
"pttl_mean",
......@@ -82,24 +82,24 @@ async def get_point_chart_data(point_id, date_start, date_end, intervel,
"ib_mean",
"ic_mean",
]
if 15 * 60 >= intervel > 60:
elec_data = await get_point_15min_chart_dao(mtid, stats_items,
date_start,
date_end)
power, i, u = await get_point_data_chart_pds(ctnum, slots, elec_data)
i, v, power = await get_point_data_chart_pds(ctnum, slots, elec_data)
elif intervel == 86400:
elec_data = await get_point_1day_chart_dao(mtid, stats_items,
date_start,
date_end)
power, i, u = await get_point_data_chart_pds(ctnum, slots, elec_data)
i, v, power = await get_point_data_chart_pds(ctnum, slots, elec_data)
else:
elec_data = await get_point_1min_chart_dao(mtid, ctnum, date_start,
date_end)
power, i, u = await get_point_1min_chart_pds(ctnum, slots, elec_data)
return power, i, u, ctnum
i, v, power = await get_point_1min_chart_pds(ctnum, slots, elec_data)
return power, i, v, ctnum
async def electric_index_list_service(mtid, start_time, end_time,
......@@ -117,19 +117,19 @@ async def electric_index_list_service(mtid, start_time, end_time,
monitor = await get_fields_by_mtid(mtid)
if not monitor:
return -1, general_param, electric_quality, safe_param
time_diff = get_time_diff(start_time, end_time)
if time_diff <= 24 * 3600:
table_name = "point_15min_electric"
aiao_table_name = "location_15min_aiao"
else:
table_name = "point_1day_electric"
aiao_table_name = "location_1day_aiao"
# 字段是否需要组装mtid(前端下载要求的)
is_merge_mtid = mtid if param_types else None
if monitor.get("m_type") == 126:
pt_info = await get_fields_by_mtid(mtid, "pt_info", "pt_id")
if not pt_info:
......@@ -147,7 +147,7 @@ async def electric_index_list_service(mtid, start_time, end_time,
if not monitor_info:
return -1, general_param, electric_quality, safe_param
ctnum = monitor_info.get("ctnum") or 3
datas, locations_datas, aiao_datas = [], [], []
if (not param_types or 'general_param' in param_types or
'electric_quality' in param_types):
......@@ -158,7 +158,7 @@ async def electric_index_list_service(mtid, start_time, end_time,
if not param_types or 'safe_param' in param_types:
locations_datas, aiao_datas = await electric_index_location_dao(
aiao_table_name, mtid, start_time, end_time)
# 2,封装信息
if ctnum == 2:
general_param_field = GENERAL_PARAM_FIELD_2
......@@ -185,7 +185,7 @@ async def electric_index_list_service(mtid, start_time, end_time,
is_merge_mtid)
if not param_types:
safe_param = electric_index_list_return_data(safe_param)
# 3,返回信息
return ctnum, general_param, electric_quality, safe_param
......@@ -217,12 +217,12 @@ async def electric_index_export_service(cid, mtids, start_time, end_time,
ctnums.append(ctnum)
if len(set(ctnums)) > 1:
return -1, [], [], []
general_param, electric_quality, safe_param = [], [], []
# 常规参数
if 'general_param' in param_types:
general_param = electric_index_export_return_data(general_param_list)
# 用电质量
if 'electric_quality' in param_types:
electric_quality = electric_index_export_return_data(
......@@ -230,7 +230,7 @@ async def electric_index_export_service(cid, mtids, start_time, end_time,
# 安全参数
if 'safe_param' in param_types:
safe_param = electric_index_export_return_data(safe_param_list)
# 2,返回信息
return 1, general_param, electric_quality, safe_param
......
......@@ -5,12 +5,12 @@ from unify_api.constants import CST
from unify_api.modules.common.service.td_engine_service import \
get_td_engine_data
from unify_api.utils.taos_new import parse_td_columns, td3_tbl_compate
from unify_api.utils.time_format import get_15min_ago
async def elec_current_data(mtids, cid):
res_map = {}
last_15min_time = pendulum.now(tz=CST).subtract(minutes=15).format(
"YYYY-MM-DD HH:mm:ss")
last_15min_time = get_15min_ago()
url = f"{SETTING.stb_url}db_electric?tz=Asia/Shanghai"
table_name = ["mt{}_ele".format(mtid) for mtid in mtids]
......
......@@ -24,6 +24,7 @@ from unify_api.modules.electric.components.electric import (
ElecIndexResponse, ElecIndex, EscResp, QcsResp, EclResp, QclResp,
)
from unify_api.utils.taos_new import parse_td_columns
from unify_api.utils.time_format import get_15min_ago
async def elec_current_storeys_service(storeys):
......@@ -587,9 +588,10 @@ async def elec_current_service(point_id):
raise BusinessException(
message="没有该监测点的monitor信息,请联系运维人员!")
mtid = meter_info["mtid"]
last_15min_time = get_15min_ago()
# 获取子表中的实时数据
url = f"{SETTING.stb_url}db_electric?tz=Asia/Shanghai"
sql = f"select last_row(*) from mt{mtid}_ele where pid={point_id}"
sql = f"select last_row(*) from mt{mtid}_ele where ts>='{last_15min_time}'"
is_succ, results = await get_td_engine_data(url, sql)
if not is_succ or not results or results.get("code") > 0:
return '', {}
......
......@@ -411,7 +411,7 @@ def get_datetime_str(timestamp):
'''
if not timestamp:
timestamp = time.time()
time_array = time.localtime(timestamp)
return time.strftime("%Y-%m-%d %H:%M:%S", time_array)
......@@ -713,7 +713,7 @@ def get_last_3month_start_end(date=None):
:param dt: datetime obj
:return:
"""
if not date:
dt = get_current_date_time()
else:
......@@ -775,7 +775,7 @@ def get_this_year_start_end(date=None):
:param dt: datetime obj
:return:
"""
if not date:
dt = get_current_date_time()
else:
......@@ -791,7 +791,7 @@ def get_last_year_start_end(date=None):
:param dt: datetime obj
:return:
"""
if not date:
dt = get_current_date_time()
else:
......@@ -807,7 +807,7 @@ def get_last_month_start_end(date=None):
:param dt: datetime obj
:return:
"""
if not date:
dt = get_current_date_time()
else:
......@@ -915,7 +915,7 @@ def get_current_start_n_end_dt(date_type, include_end_day=False):
start_year += 1
start_month = start_month - 12
start = datetime.datetime(start_year, start_month, 1)
elif date_type == "season":
season_number = int((current_dt.month - 1) / 3)
start = datetime.datetime(current_dt.year, season_number * 3 + 1, 1)
......@@ -1026,7 +1026,7 @@ def get_previous_slot(slots, date_type, compare_type=None):
return get_slots_between_date(
start - datetime.timedelta(days=days),
end - datetime.timedelta(days=days), date_type)
elif date_type == "hour":
hours = int((end - start).total_seconds() / 3600) + 1
return get_slots_between_date(start - datetime.timedelta(hours=hours),
......@@ -1074,8 +1074,8 @@ def get_slots_between_date(start, end, interval_type, growth_type=None):
while start <= end:
date_dts.append([start, start + datetime.timedelta(days=1)])
start += datetime.timedelta(days=1)
elif interval_type == "month":
start_months = start.year * 12 + start.month
end_months = end.year * 12 + end.month
......@@ -1187,7 +1187,7 @@ def deco_convert_date_to_dt(f):
if kwarg in kwargs and kwargs[kwarg]:
kwargs[kwarg] = convert_to_dt(kwargs[kwarg])
return f(*args, **kwargs)
return deco
......@@ -1463,7 +1463,7 @@ def get_time_duration_by_str(duration_str):
days = int(duration_str / (60 * 60 * 24))
if days > 0:
return_str += "%s天" % str(days)
hours = int(duration_str % (60 * 60 * 24) / (60 * 60))
if hours > 0:
return_str += "%s时" % str(hours)
......@@ -1487,3 +1487,7 @@ def get_time_diff(start, end):
end_f = my_pendulum.from_format(end, YMD_Hms)
diff = end_f.int_timestamp - start_f.int_timestamp
return diff
def get_15min_ago(time_fmt="YYYY-MM-DD HH:mm:ss"):
return my_pendulum.now(tz=CST).subtract(minutes=15).format(time_fmt)
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