Commit 9e9cc857 authored by wang.wenrong's avatar wang.wenrong

Merge branch 'wwr' into 'develop'

anshiU

See merge request !12
parents 153e0c79 6c602d2a
......@@ -9,9 +9,9 @@ async def get_location_by_ids(location_ids):
根据location_id获取各项温度信息
'''
async with MysqlUtil() as conn:
sql = "select id,item,type from location where id in %s"
sql = "select lid,item,ad_type from location where lid in %s"
result = await conn.fetchall(sql, args=(tuple(location_ids),))
location_info = {res.get('id'): res for res in result}
location_info = {res.get('lid'): res for res in result}
return location_info
......@@ -21,8 +21,8 @@ async def get_threshold_by_location(location_ids, type='overResidualCurrent',
根据location_id获取阈值
'''
async with MysqlUtil() as conn:
sql = "select threshold from alarm_setting where location_id in %s " \
"and type = %s limit 1 "
sql = "select threshold from soe_config_record where lid in %s " \
"and etype = %s limit 1 "
settings = await conn.fetchall(sql, args=(tuple(location_ids), type))
if settings:
return settings[0]["threshold"]
......
......@@ -25,7 +25,7 @@ async def get_adio_chart_data(location_group, location_info,
start_timestamp,
end_timestamp, intervel, slots):
'''
获取环境(温度与漏电流)的曲线数据
获取环境(温度与漏电流)的曲线数据 todo:es获取liudianliu
'''
# 工况标准,取其中一个漏电流阈值
......
......@@ -155,12 +155,12 @@ async def list_point(cid):
async def point_to_mid(points):
"""获取所有poin_id和mid对应关系"""
sql = "SELECT pid, mid FROM change_meter_record WHERE pid IN %s " \
"order by pid, start_time"
sql = "SELECT pid, mtid FROM point WHERE pid IN %s " \
"order by pid, create_time"
async with MysqlUtil() as conn:
change_meter_records = await conn.fetchall(sql, args=(tuple(points),))
point_mid_map = {
i["pid"]: i["mid"] for i in change_meter_records
i["pid"]: i["mtid"] for i in change_meter_records
}
point_mid = dict(filter(lambda x: x[1] is not None, point_mid_map.items()))
return point_mid, len(point_mid)
......
......@@ -49,7 +49,7 @@ async def get_user_hardware_info(company_id, page_num, page_size):
points = [point for point in points if point["pid"] in point_mid_map]
meter_change_sql = (
"select pid, mid from `change_meter_record` where pid in %s order by pid, start_time"
"select pid, mtid from `point` where pid in %s order by pid, create_time"
)
meter_changes = []
if point_ids:
......@@ -59,21 +59,35 @@ async def get_user_hardware_info(company_id, page_num, page_size):
for i in meter_changes:
point_meter_map[i["pid"]] = i
meter_ids = [i["mid"] for i in point_meter_map.values()]
meter_ids = [i["mtid"] for i in point_meter_map.values()]
meters, meter_param_records = [], []
if meter_ids:
async with MysqlUtil() as conn:
meter_sql = "select mid, sid from `meter` where mid in %s"
meter_sql = "select mtid, sid from `monitor` where mtid in %s"
meters = await conn.fetchall(meter_sql, args=(tuple(meter_ids),))
async with MysqlUtil() as conn:
meter_param_record_sql = "select mid, ptr, ctr, ctnum, voltage_side, vc, tc, bureau_number, td_type from `meter_param_record` where mid in %s order by mid, start_time"
meter_param_record_sql ="""SELECT
mtid,
ptr,
ctr,
ctnum,
voltage_side,
vc,
tc
FROM
`point`
WHERE
mtid IN % s
ORDER BY
mtid,
create_time"""
meter_param_records = await conn.fetchall(
meter_param_record_sql, args=(tuple(meter_ids),)
)
meter_map = {m["mid"]: m for m in meters}
meterparam_map = {m["mid"]: m for m in meter_param_records}
meter_map = {m["mtid"]: m for m in meters}
meterparam_map = {m["mtid"]: m for m in meter_param_records}
log.info("meter_ids = {}".format(meter_ids))
log.info("meter_map = {}".format(meter_map))
......@@ -81,14 +95,14 @@ async def get_user_hardware_info(company_id, page_num, page_size):
# 组装point_id和meter_param的对应关系
point_meterparam_map = defaultdict(dict)
for point_id, meter_change in point_meter_map.items():
if meter_change["mid"] not in meterparam_map:
log.warn(f"mid={meter_change['mid']}沒有meter_param_records")
if meter_change["mtid"] not in meterparam_map:
log.warn(f"mtid={meter_change['mtid']}沒有meter_param_records")
continue
point_meterparam_map[point_id] = meterparam_map[meter_change["mid"]]
point_meterparam_map[point_id] = meterparam_map[meter_change["mtid"]]
# 组装pid和meter的对应关系
for point_id, meter_change in point_meter_map.items():
point_meter_map[point_id] = meter_map[meter_change["mid"]] if meter_change["mid"] else {}
point_meter_map[point_id] = meter_map[meter_change["mtid"]] if meter_change["mtid"] else {}
datas = []
for point in points:
......@@ -135,10 +149,6 @@ async def get_user_hardware_info(company_id, page_num, page_size):
data["inline_capacity"] = meter_param["tc"]
if not check_value_is_null(meter_param["vc"]):
data["rated_voltage"] = meter_param["vc"]
if not check_value_is_null(meter_param["bureau_number"]):
data["belong_number"] = meter_param["bureau_number"]
if not check_value_is_null(meter_param["td_type"]):
data["device_type"] = meter_param["td_type"]
datas.append(data)
return {
......
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