Commit 21b257c1 authored by lcn's avatar lcn

bug修复

parent d2c161bf
...@@ -23,39 +23,41 @@ async def post_list_point(req, body: ListPointRequest) -> ListPointResponse: ...@@ -23,39 +23,41 @@ async def post_list_point(req, body: ListPointRequest) -> ListPointResponse:
list_point = [] list_point = []
points = {} points = {}
groups = {} groups = {}
sql = "SELECT p.pid,p.mtid, p.name, p.add_to_company FROM point p " \
"left join monitor m on p.mtid = m.mtid " \
"left join monitor_reuse mr on p.mtid = mr.mtid " \
"WHERE m.demolished = 0 and (p.cid=%s or mr.cid = %s) "
# 查询属于当前工厂下的监测点 + 其他工厂但是被复用到当前工厂的监测点 # 查询属于当前工厂下的监测点 + 其他工厂但是被复用到当前工厂的监测点
if not is_power_equipment: if is_power_equipment:
sql = "SELECT p.pid,p.mtid, p.name, p.add_to_company FROM point p " \
"left join monitor_reuse m on p.mtid = m.mtid " \
"WHERE p.cid=%s or m.cid = %s"
else:
# 动力设备 # 动力设备
sql = "SELECT p.pid,p.mtid, p.name, p.add_to_company FROM point p " \ sql += " and m.is_power_equipment = 1 "
"left join monitor m on p.mtid = m.mtid " \
"left join monitor_reuse mr on p.mtid = mr.mtid " \
"WHERE m.demolished = 0 and m.is_power_equipment = 1 and (" \
"p.cid=%s or mr.cid = %s)"
async with MysqlUtil() as conn: async with MysqlUtil() as conn:
result = await conn.fetchall(sql, args=(cid, cid)) result = await conn.fetchall(sql, args=(cid, cid))
if not result:
return ListPointResponse(
points=list_point,
inlines=[],
power_show_all=0
)
# 去调拆表的POINT # 去调拆表的POINT
point_ids = [point["pid"] for point in result] point_ids = [point["pid"] for point in result]
point_mid_map, point_count = await point_to_mid(point_ids) point_mid_map, point_count = await point_to_mid(point_ids)
result = [point for point in result if point["pid"] in point_mid_map] result = [point for point in result if point["pid"] in point_mid_map]
for res in result: for res in result:
pid = res.get("pid") pid = res.get("pid")
points[pid] = res points[pid] = res
# 获取相应的mtid # 获取相应的mtid
point_map_mtids = [point["mtid"] for point in result if point_map_mtids = [point["mtid"] for point in result if
point['pid'] in point_mid_map] point['pid'] in point_mid_map]
# 根据pid获取mtd # 根据pid获取mtd
sql = "SELECT ln.lid, mr.`name` `group`, ln.item FROM location ln LEFT JOIN" \ sql = "SELECT ln.lid, mr.`name` `group`, ln.item FROM location ln LEFT JOIN" \
" monitor mr on ln.mtid = mr.mtid WHERE ( ln.cid=%s or ln.mtid in " \ " monitor mr on ln.mtid = mr.mtid WHERE ( ln.cid=%s or ln.mtid in " \
"%s ) and ln.`ad_type` in %s" "%s ) and ln.`ad_type` in %s"
try: try:
async with MysqlUtil() as conn: async with MysqlUtil() as conn:
result = await conn.fetchall(sql, args=( result = await conn.fetchall(sql, args=(
...@@ -68,7 +70,7 @@ async def post_list_point(req, body: ListPointRequest) -> ListPointResponse: ...@@ -68,7 +70,7 @@ async def post_list_point(req, body: ListPointRequest) -> ListPointResponse:
except Exception as e: except Exception as e:
log.exception(e) log.exception(e)
return ListPointResponse().db_error() return ListPointResponse().db_error()
for pid, point_info in points.items(): for pid, point_info in points.items():
name = point_info.get("name") name = point_info.get("name")
add_to_company = point_info["add_to_company"] add_to_company = point_info["add_to_company"]
...@@ -80,7 +82,7 @@ async def post_list_point(req, body: ListPointRequest) -> ListPointResponse: ...@@ -80,7 +82,7 @@ async def post_list_point(req, body: ListPointRequest) -> ListPointResponse:
comm_point = CommonPoint(name=name, point_id=pid, locations=locations, comm_point = CommonPoint(name=name, point_id=pid, locations=locations,
add_to_company=add_to_company) add_to_company=add_to_company)
list_point.append(comm_point) list_point.append(comm_point)
async with MysqlUtil() as conn: async with MysqlUtil() as conn:
sql = "SELECT inlid, `name` FROM inline WHERE cid=%s" sql = "SELECT inlid, `name` FROM inline WHERE cid=%s"
inlines = await conn.fetchall(sql, args=(cid,)) inlines = await conn.fetchall(sql, args=(cid,))
......
...@@ -75,12 +75,11 @@ async def get_elec_mtid_sid_by_cid(cid): ...@@ -75,12 +75,11 @@ async def get_elec_mtid_sid_by_cid(cid):
async def load_add_to_compy_ids(cid): async def load_add_to_compy_ids(cid):
if not isinstance(cid, (list, tuple)): symbol = "in" if isinstance(cid, (list, tuple)) else "="
cid = [cid]
db = SETTING.mysql_db db = SETTING.mysql_db
sql = f"SELECT monitor.mtid, monitor.sid FROM {db}.monitor " \ sql = f"SELECT monitor.mtid, monitor.sid FROM {db}.monitor " \
f"INNER JOIN {db}.point ON point.mtid=monitor.mtid " \ f"INNER JOIN {db}.point ON point.mtid=monitor.mtid " \
f"WHERE monitor.cid in %s AND point.add_to_company=1 " \ f"WHERE monitor.cid {symbol} %s AND point.add_to_company=1 " \
f"AND monitor.demolished=0;" f"AND monitor.demolished=0;"
async with MysqlUtil() as conn: async with MysqlUtil() as conn:
ids = await conn.fetchall(sql, (cid,)) ids = await conn.fetchall(sql, (cid,))
......
...@@ -141,40 +141,40 @@ async def normal_rate_of_location(cid): ...@@ -141,40 +141,40 @@ async def normal_rate_of_location(cid):
lids = list(loc_infos.keys()) lids = list(loc_infos.keys())
if not lids: if not lids:
return "100%", "100%" return "100%", "100%"
prefix = f"real_time:adio:{SETTING.mysql_db}" prefix = f"real_time:adio:{SETTING.mysql_db}"
keys = [f"{prefix}:{lid}" for lid in lids] keys = [f"{prefix}:{lid}" for lid in lids]
rt_rlts = await RedisUtils().mget(keys) rt_rlts = await RedisUtils().mget(keys)
rt_adios = [json.loads(r) for r in rt_rlts if r] rt_adios = [json.loads(r) for r in rt_rlts if r]
d_rt_adio = {adio["lid"]: adio for adio in rt_adios} d_rt_adio = {adio["lid"]: adio for adio in rt_adios}
now_ts = pendulum.now(tz=CST).int_timestamp now_ts = pendulum.now(tz=CST).int_timestamp
for lid, d_loc in loc_infos.items(): for lid, d_loc in loc_infos.items():
d_stats[d_loc["type"]]["total"] += 1 d_stats[d_loc["type"]]["total"] += 1
if lid not in d_rt_adio: if lid not in d_rt_adio:
continue continue
if not isinstance(d_loc["threshold"], (float, int)): if not isinstance(d_loc["threshold"], (float, int)):
continue continue
try: try:
d_adio = d_rt_adio[lid] d_adio = d_rt_adio[lid]
if (now_ts - d_adio["ts"]) > constants.REAL_EXP_TIME: if (now_ts - d_adio["ts"]) > constants.REAL_EXP_TIME:
log.warn(f"adio_current location_id={lid} has expire!") log.warn(f"adio_current location_id={lid} has expire!")
continue continue
if d_adio["v"] < d_loc["threshold"]: if d_adio["v"] < d_loc["threshold"]:
d_stats[d_loc["type"]]["normal"] += 1 d_stats[d_loc["type"]]["normal"] += 1
except Exception as e: except Exception as e:
log.exception(f"parse real time adio:{d_adio} exc, e:{e}") log.exception(f"parse real time adio:{d_adio} exc, e:{e}")
if d_stats["temperature"]["total"] == 0: if d_stats["temperature"]["total"] == 0:
temp_qr = "100%" temp_qr = "100%"
else: else:
norm = d_stats["temperature"]["normal"] norm = d_stats["temperature"]["normal"]
total = d_stats["temperature"]["total"] total = d_stats["temperature"]["total"]
temp_qr = str(round((norm / total) * 100, )) + "%" temp_qr = str(round((norm / total) * 100, )) + "%"
if d_stats["residual_current"]["total"] == 0: if d_stats["residual_current"]["total"] == 0:
rc_qr = "100%" rc_qr = "100%"
else: else:
...@@ -187,12 +187,15 @@ async def normal_rate_of_location(cid): ...@@ -187,12 +187,15 @@ async def normal_rate_of_location(cid):
async def real_time_load(cid, end_dt=None): async def real_time_load(cid, end_dt=None):
"""实时负荷""" """实时负荷"""
td_tbls = [] td_tbls = []
for item in await load_add_to_compy_ids(cid): add_to_compy_ids = await load_add_to_compy_ids(cid)
if not add_to_compy_ids:
return 0
for item in add_to_compy_ids:
mtid, sid = item["mtid"], item["sid"] mtid, sid = item["mtid"], item["sid"]
tbl = get_td_table_name("electric", mtid) tbl = get_td_table_name("electric", mtid)
td_tbls.append(tbl) td_tbls.append(tbl)
td_tbls.append(f"s_{sid.lower()}_e") td_tbls.append(f"s_{sid.lower()}_e")
td_mt_tables = td3_tbl_compate(td_tbls) td_mt_tables = td3_tbl_compate(td_tbls)
if not end_dt: if not end_dt:
end_dt = pendulum.now(tz=CST) end_dt = pendulum.now(tz=CST)
...@@ -204,7 +207,7 @@ async def real_time_load(cid, end_dt=None): ...@@ -204,7 +207,7 @@ async def real_time_load(cid, end_dt=None):
is_succ, results = await get_td_engine_data(url, sql) is_succ, results = await get_td_engine_data(url, sql)
if not is_succ: if not is_succ:
return "" return ""
head = parse_td_columns(results) head = parse_td_columns(results)
datas = [] datas = []
for res in results["data"]: for res in results["data"]:
...@@ -222,7 +225,7 @@ async def power_count_info(cid): ...@@ -222,7 +225,7 @@ async def power_count_info(cid):
now = datetime.now() now = datetime.now()
start_time = (now - timedelta(30)).strftime("%Y-%m-%d 00:00:00") start_time = (now - timedelta(30)).strftime("%Y-%m-%d 00:00:00")
end_time = now.strftime("%Y-%m-%d %H:%M:%S") end_time = now.strftime("%Y-%m-%d %H:%M:%S")
max_30d_load, _time = await load_pttl_max(cid, start_time, end_time, -1) max_30d_load, _time = await load_pttl_max(cid, start_time, end_time, -1)
cur_load = await real_time_load(cid) cur_load = await real_time_load(cid)
return round_2(cur_load), round_2(max_30d_load) return round_2(cur_load), round_2(max_30d_load)
...@@ -314,17 +317,17 @@ async def optimization_count_info(company_id: int): ...@@ -314,17 +317,17 @@ async def optimization_count_info(company_id: int):
:param company_id: :param company_id:
:return: :return:
""" """
async with MysqlUtil() as conn: async with MysqlUtil() as conn:
sql = "SELECT inlid, `name` FROM inline WHERE cid=%s" sql = "SELECT inlid, `name` FROM inline WHERE cid=%s"
inlines = await conn.fetchall(sql, args=(company_id,)) inlines = await conn.fetchall(sql, args=(company_id,))
inline_ids = [inline["inlid"] for inline in inlines] inline_ids = [inline["inlid"] for inline in inlines]
now = datetime.now() now = datetime.now()
start_time = ( start_time = (
pendulum.datetime(now.year, now.month, 1) pendulum.datetime(now.year, now.month, 1)
.subtract(months=1) .subtract(months=1)
.strftime("%Y-%m-%d %H:%M:%S") .strftime("%Y-%m-%d %H:%M:%S")
) )
end_time = pendulum.datetime(now.year, now.month, 1).strftime( end_time = pendulum.datetime(now.year, now.month, 1).strftime(
"%Y-%m-%d %H:%M:%S") "%Y-%m-%d %H:%M:%S")
...@@ -348,7 +351,7 @@ async def optimization_count_info(company_id: int): ...@@ -348,7 +351,7 @@ async def optimization_count_info(company_id: int):
} }
) )
return count_info_map return count_info_map
now = datetime.now() now = datetime.now()
if now.month == 1: if now.month == 1:
last_month_dt = datetime(year=now.year - 1, month=12, day=1) last_month_dt = datetime(year=now.year - 1, month=12, day=1)
...@@ -368,7 +371,7 @@ async def optimization_count_info(company_id: int): ...@@ -368,7 +371,7 @@ async def optimization_count_info(company_id: int):
2, 2,
) )
total_pf_save = 0 if total_pf_save <= 0 else total_pf_save total_pf_save = 0 if total_pf_save <= 0 else total_pf_save
pf_kpi_x_list = [ pf_kpi_x_list = [
i["kpi_x"] for i in power_factor_results if i["kpi_x"] for i in power_factor_results if
type(i["kpi_x"]) in [int, float] type(i["kpi_x"]) in [int, float]
...@@ -384,19 +387,19 @@ async def optimization_count_info(company_id: int): ...@@ -384,19 +387,19 @@ async def optimization_count_info(company_id: int):
pf_desc = "空间适中" pf_desc = "空间适中"
else: else:
pf_desc = "空间较大" pf_desc = "空间较大"
count_info_map["power_factor"] = { count_info_map["power_factor"] = {
"save_charge": total_pf_save if pf_kpi_x != "" else "", "save_charge": total_pf_save if pf_kpi_x != "" else "",
"kpi_x": pf_kpi_x, "kpi_x": pf_kpi_x,
"desc": pf_desc, "desc": pf_desc,
} }
# 移峰填谷指数 # 移峰填谷指数
async with MysqlUtil() as conn: async with MysqlUtil() as conn:
sql = "select `score`, `cost_save` from `algo_plsi_result` " \ sql = "select `score`, `cost_save` from `algo_plsi_result` " \
"where `inlid` in %s and `month` = %s" "where `inlid` in %s and `month` = %s"
pcvfs = await conn.fetchall(sql, args=(inline_ids, last_month_str)) pcvfs = await conn.fetchall(sql, args=(inline_ids, last_month_str))
pcvf_kpi_x_list = [i["score"] for i in pcvfs if pcvf_kpi_x_list = [i["score"] for i in pcvfs if
type(i["score"]) in [int, float]] type(i["score"]) in [int, float]]
pcvf_kpi_x = min(pcvf_kpi_x_list) if len(pcvf_kpi_x_list) else "" pcvf_kpi_x = min(pcvf_kpi_x_list) if len(pcvf_kpi_x_list) else ""
...@@ -404,7 +407,7 @@ async def optimization_count_info(company_id: int): ...@@ -404,7 +407,7 @@ async def optimization_count_info(company_id: int):
sum([i["cost_save"] for i in pcvfs if sum([i["cost_save"] for i in pcvfs if
i["cost_save"] and i["cost_save"] >= 0]), 2 i["cost_save"] and i["cost_save"] >= 0]), 2
) )
if pcvf_kpi_x == "": if pcvf_kpi_x == "":
pcvf_desc = "" pcvf_desc = ""
elif pcvf_kpi_x >= 90: elif pcvf_kpi_x >= 90:
...@@ -415,14 +418,14 @@ async def optimization_count_info(company_id: int): ...@@ -415,14 +418,14 @@ async def optimization_count_info(company_id: int):
pcvf_desc = "空间适中" pcvf_desc = "空间适中"
else: else:
pcvf_desc = "空间较大" pcvf_desc = "空间较大"
total_pcvf_save = 0 if total_pcvf_save <= 0 else total_pcvf_save total_pcvf_save = 0 if total_pcvf_save <= 0 else total_pcvf_save
count_info_map["pcvf"] = { count_info_map["pcvf"] = {
"save_charge": total_pcvf_save if pcvf_kpi_x != "" else "", "save_charge": total_pcvf_save if pcvf_kpi_x != "" else "",
"kpi_x": pcvf_kpi_x, "kpi_x": pcvf_kpi_x,
"desc": pcvf_desc, "desc": pcvf_desc,
} }
# 经济运行 # 经济运行
async with MysqlUtil() as conn: async with MysqlUtil() as conn:
sql = "select `kpi_x`, `save_charge`, `mean_load_factor` " \ sql = "select `kpi_x`, `save_charge`, `mean_load_factor` " \
...@@ -458,13 +461,13 @@ async def optimization_count_info(company_id: int): ...@@ -458,13 +461,13 @@ async def optimization_count_info(company_id: int):
economic_desc = "空间适中" economic_desc = "空间适中"
else: else:
economic_desc = "空间较大" economic_desc = "空间较大"
count_info_map["power_save"] = { count_info_map["power_save"] = {
"save_charge": total_economic_save if economic_kpi_x != "" else "", "save_charge": total_economic_save if economic_kpi_x != "" else "",
"kpi_x": economic_kpi_x, "kpi_x": economic_kpi_x,
"desc": economic_desc, "desc": economic_desc,
} }
# 最大需量 # 最大需量
async with MysqlUtil() as conn: async with MysqlUtil() as conn:
sql = ( sql = (
...@@ -475,7 +478,7 @@ async def optimization_count_info(company_id: int): ...@@ -475,7 +478,7 @@ async def optimization_count_info(company_id: int):
"where b.inlid in %s and a.month = %s and b.valid=1;" "where b.inlid in %s and a.month = %s and b.valid=1;"
) )
md_spaces = await conn.fetchall(sql, args=(inline_ids, last_month_str)) md_spaces = await conn.fetchall(sql, args=(inline_ids, last_month_str))
md_space_kpi_x_list = [i["kpi_x"] for i in md_spaces if md_space_kpi_x_list = [i["kpi_x"] for i in md_spaces if
type(i["kpi_x"]) in [int, float]] type(i["kpi_x"]) in [int, float]]
md_space_kpi_x = max(md_space_kpi_x_list) if len( md_space_kpi_x = max(md_space_kpi_x_list) if len(
...@@ -504,7 +507,7 @@ async def optimization_count_info(company_id: int): ...@@ -504,7 +507,7 @@ async def optimization_count_info(company_id: int):
"kpi_x": md_space_kpi_x, "kpi_x": md_space_kpi_x,
"desc": md_space_desc, "desc": md_space_desc,
} }
total_save_cost = 0 total_save_cost = 0
for _, item in count_info_map.items(): for _, item in count_info_map.items():
total_save_cost += ( total_save_cost += (
...@@ -513,12 +516,12 @@ async def optimization_count_info(company_id: int): ...@@ -513,12 +516,12 @@ async def optimization_count_info(company_id: int):
) )
save_percent = total_save_cost / month_charge if month_charge else "" save_percent = total_save_cost / month_charge if month_charge else ""
count_info_map["save_percent"] = save_percent count_info_map["save_percent"] = save_percent
# 计算最大需量 # 计算最大需量
async with MysqlUtil() as conn: async with MysqlUtil() as conn:
sql = "select `price_md`,`price_tc` from `price_policy` where `cid`=%s" sql = "select `price_md`,`price_tc` from `price_policy` where `cid`=%s"
price_policy = await conn.fetchone(sql, args=(company_id,)) price_policy = await conn.fetchone(sql, args=(company_id,))
total_md_space_charge = sum( total_md_space_charge = sum(
[i["inline_md_charge"] for i in md_spaces if i["inline_md_charge"]]) [i["inline_md_charge"] for i in md_spaces if i["inline_md_charge"]])
total_md_space_p = ( total_md_space_p = (
...@@ -527,7 +530,7 @@ async def optimization_count_info(company_id: int): ...@@ -527,7 +530,7 @@ async def optimization_count_info(company_id: int):
else "" else ""
) )
count_info_map["md_space_p"] = total_md_space_p count_info_map["md_space_p"] = total_md_space_p
# 经济运行最低负载率 # 经济运行最低负载率
mean_load_factors = [ mean_load_factors = [
i["mean_load_factor"] for i in economic_operations if i["mean_load_factor"] for i in economic_operations if
...@@ -583,7 +586,7 @@ async def electric_use_info_points_sdu(start, end, points): ...@@ -583,7 +586,7 @@ async def electric_use_info_points_sdu(start, end, points):
async with MysqlUtil() as conn: async with MysqlUtil() as conn:
results = await conn.fetchall(sql, args=(points, start, end, results = await conn.fetchall(sql, args=(points, start, end,
SDU_ALARM_LIST)) SDU_ALARM_LIST))
first_alarm_cnt = 0 first_alarm_cnt = 0
second_alarm_cnt = 0 second_alarm_cnt = 0
third_alarm_cnt = 0 third_alarm_cnt = 0
...@@ -594,15 +597,15 @@ async def electric_use_info_points_sdu(start, end, points): ...@@ -594,15 +597,15 @@ async def electric_use_info_points_sdu(start, end, points):
second_alarm_cnt += result["doc_count"] second_alarm_cnt += result["doc_count"]
elif result["importance"] == Importance.Third.value: elif result["importance"] == Importance.Third.value:
third_alarm_cnt += result["doc_count"] third_alarm_cnt += result["doc_count"]
alarm_score = (first_alarm_cnt * 2 + second_alarm_cnt * 1 + alarm_score = (first_alarm_cnt * 2 + second_alarm_cnt * 1 +
third_alarm_cnt * 0.5) / len(points) third_alarm_cnt * 0.5) / len(points)
if alarm_score >= 15: if alarm_score >= 15:
alarm_score = 15 alarm_score = 15
electric_use_score = get_electric_index(alarm_score) electric_use_score = get_electric_index(alarm_score)
log.info( log.info(
"point_len={} alarm_score={} electric_use_score={}".format( "point_len={} alarm_score={} electric_use_score={}".format(
len(points), alarm_score, electric_use_score len(points), alarm_score, electric_use_score
...@@ -623,16 +626,16 @@ async def optimization_count_info_new(company_id: int): ...@@ -623,16 +626,16 @@ async def optimization_count_info_new(company_id: int):
:param company_id: :param company_id:
:return: :return:
""" """
inlines = await get_inline_by_cid(company_id) inlines = await get_inline_by_cid(company_id)
inline_ids = [inline["inlid"] for inline in inlines] inline_ids = [inline["inlid"] for inline in inlines]
# 获取公司上月用电 # 获取公司上月用电
now = datetime.now() now = datetime.now()
es_start_time = ( es_start_time = (
pendulum.datetime(now.year, now.month, 1) pendulum.datetime(now.year, now.month, 1)
.subtract(months=1) .subtract(months=1)
.strftime("%Y-%m-%dT%H:%M:%S+08:00") .strftime("%Y-%m-%dT%H:%M:%S+08:00")
) )
es_end_time = pendulum.datetime(now.year, now.month, 1).strftime( es_end_time = pendulum.datetime(now.year, now.month, 1).strftime(
"%Y-%m-%dT%H:%M:%S+08:00") "%Y-%m-%dT%H:%M:%S+08:00")
...@@ -664,7 +667,7 @@ async def optimization_count_info_new(company_id: int): ...@@ -664,7 +667,7 @@ async def optimization_count_info_new(company_id: int):
last_month_dt = datetime(year=now.year, month=now.month - 1, day=1) last_month_dt = datetime(year=now.year, month=now.month - 1, day=1)
last_month_str = datetime.strftime(last_month_dt, "%Y-%m") last_month_str = datetime.strftime(last_month_dt, "%Y-%m")
# 功率因数 # 功率因数
power_factor_results = await get_power_factor_kpi(inline_ids, power_factor_results = await get_power_factor_kpi(inline_ids,
last_month_dt) last_month_dt)
total_pf_save = round( total_pf_save = round(
...@@ -677,7 +680,7 @@ async def optimization_count_info_new(company_id: int): ...@@ -677,7 +680,7 @@ async def optimization_count_info_new(company_id: int):
(i["name"], i["kpi_x"]) for i in power_factor_results if (i["name"], i["kpi_x"]) for i in power_factor_results if
type(i["kpi_x"]) in [int, float] type(i["kpi_x"]) in [int, float]
] ]
if len(pf_kpi_x_list): if len(pf_kpi_x_list):
pf_kpi_x_num = [pf_kpi[1] for pf_kpi in pf_kpi_x_list] pf_kpi_x_num = [pf_kpi[1] for pf_kpi in pf_kpi_x_list]
pf_kpi_x = min(pf_kpi_x_num) pf_kpi_x = min(pf_kpi_x_num)
...@@ -712,12 +715,12 @@ async def optimization_count_info_new(company_id: int): ...@@ -712,12 +715,12 @@ async def optimization_count_info_new(company_id: int):
pcvfs = await get_pcvf_kpi(inline_ids, last_month_str) pcvfs = await get_pcvf_kpi(inline_ids, last_month_str)
pcvf_kpi_x_list = [(i["name"], i["score"]) for i in pcvfs if pcvf_kpi_x_list = [(i["name"], i["score"]) for i in pcvfs if
type(i["score"]) in [int, float]] type(i["score"]) in [int, float]]
if len(pcvf_kpi_x_list): if len(pcvf_kpi_x_list):
pcvf_kpi_x_num = [pcvf_kpi[1] for pcvf_kpi in pcvf_kpi_x_list] pcvf_kpi_x_num = [pcvf_kpi[1] for pcvf_kpi in pcvf_kpi_x_list]
pcvf_kpi_x = min(pcvf_kpi_x_num) pcvf_kpi_x = min(pcvf_kpi_x_num)
pcvf_kpi_x_name = [] pcvf_kpi_x_name = []
if pcvf_kpi_x < 70: if pcvf_kpi_x < 70:
for index, kpi_num in enumerate(pcvf_kpi_x_num): for index, kpi_num in enumerate(pcvf_kpi_x_num):
if kpi_num < 70: if kpi_num < 70:
...@@ -731,7 +734,7 @@ async def optimization_count_info_new(company_id: int): ...@@ -731,7 +734,7 @@ async def optimization_count_info_new(company_id: int):
f"引入新能源,转移高峰电量至低谷" f"引入新能源,转移高峰电量至低谷"
else: else:
pcvf_desc = "平均电价处于较低水平,请继续保持" pcvf_desc = "平均电价处于较低水平,请继续保持"
else: else:
pcvf_kpi_x = "" pcvf_kpi_x = ""
pcvf_desc = "" pcvf_desc = ""
...@@ -749,7 +752,7 @@ async def optimization_count_info_new(company_id: int): ...@@ -749,7 +752,7 @@ async def optimization_count_info_new(company_id: int):
sum([i["cost_save"] for i in pcvfs if sum([i["cost_save"] for i in pcvfs if
i["cost_save"] and i["cost_save"] >= 0]), 2 i["cost_save"] and i["cost_save"] >= 0]), 2
) )
total_pcvf_save = 0 if total_pcvf_save <= 0 else total_pcvf_save total_pcvf_save = 0 if total_pcvf_save <= 0 else total_pcvf_save
count_info_map["pcvf"] = { count_info_map["pcvf"] = {
"save_charge": total_pcvf_save if pcvf_kpi_x != "" else "", "save_charge": total_pcvf_save if pcvf_kpi_x != "" else "",
...@@ -757,7 +760,7 @@ async def optimization_count_info_new(company_id: int): ...@@ -757,7 +760,7 @@ async def optimization_count_info_new(company_id: int):
"desc": pcvf_desc, "desc": pcvf_desc,
"space": pcvf_space "space": pcvf_space
} }
# 经济运行 # 经济运行
economic_operations = await get_economic_kpi(inline_ids, last_month_str) economic_operations = await get_economic_kpi(inline_ids, last_month_str)
economic_kpi_x_list = [ economic_kpi_x_list = [
...@@ -818,14 +821,14 @@ async def optimization_count_info_new(company_id: int): ...@@ -818,14 +821,14 @@ async def optimization_count_info_new(company_id: int):
"desc": economic_desc, "desc": economic_desc,
"space": econ_space "space": econ_space
} }
# 容量、需量价格 # 容量、需量价格
price_policy = await price_policy_by_cid(company_id) price_policy = await price_policy_by_cid(company_id)
price_md = price_policy["price_md"] if price_policy["price_md"] else 0 price_md = price_policy["price_md"] if price_policy["price_md"] else 0
price_tc = price_policy["price_tc"] if price_policy["price_tc"] else 0 price_tc = price_policy["price_tc"] if price_policy["price_tc"] else 0
# 最大需量 # 最大需量
md_spaces = await get_md_space(inline_ids, last_month_dt) md_spaces = await get_md_space(inline_ids, last_month_dt)
md_space_kpi_x_list = [i["kpi_x"] for i in md_spaces if md_space_kpi_x_list = [i["kpi_x"] for i in md_spaces if
type(i["kpi_x"]) in [int, float]] type(i["kpi_x"]) in [int, float]]
md_space_kpi_x = max(md_space_kpi_x_list) if len( md_space_kpi_x = max(md_space_kpi_x_list) if len(
...@@ -855,13 +858,13 @@ async def optimization_count_info_new(company_id: int): ...@@ -855,13 +858,13 @@ async def optimization_count_info_new(company_id: int):
md_space_tc_runtimes[index]["tc_runtime"] * price_tc >= \ md_space_tc_runtimes[index]["tc_runtime"] * price_tc >= \
price_md * item["inline_md_predict"]: price_md * item["inline_md_predict"]:
md_space_name.append(md_space_tc_runtimes[index]["name"]) md_space_name.append(md_space_tc_runtimes[index]["name"])
if len(md_space_name): if len(md_space_name):
md_space_desc = f"若次月负荷无较大变动,建议{'、'.join(md_space_name)}" \ md_space_desc = f"若次月负荷无较大变动,建议{'、'.join(md_space_name)}" \
f"选择按最大需量计费" f"选择按最大需量计费"
else: else:
md_space_desc = "不存在容改需空间" md_space_desc = "不存在容改需空间"
count_info_map["md_space"] = { count_info_map["md_space"] = {
"save_charge": total_md_space_save if md_space_kpi_x != "" else "", "save_charge": total_md_space_save if md_space_kpi_x != "" else "",
"kpi_x": md_space_kpi_x, "kpi_x": md_space_kpi_x,
...@@ -903,7 +906,7 @@ async def cid_alarm_importance_count(cid, start, end): ...@@ -903,7 +906,7 @@ async def cid_alarm_importance_count(cid, start, end):
point_list = [i["pid"] for i in monitor_point_list] point_list = [i["pid"] for i in monitor_point_list]
es_res = await sdu_alarm_importance_dao(start, end, point_list) es_res = await sdu_alarm_importance_dao(start, end, point_list)
es_res_key = {i["key"]: i for i in es_res} es_res_key = {i["key"]: i for i in es_res}
res_list = [] res_list = []
for info in monitor_point_list: for info in monitor_point_list:
name = info.get("name") name = info.get("name")
...@@ -919,7 +922,7 @@ async def cid_alarm_importance_count(cid, start, end): ...@@ -919,7 +922,7 @@ async def cid_alarm_importance_count(cid, start, end):
tmp_dic["second"] += b["doc_count"] tmp_dic["second"] += b["doc_count"]
elif b["key"] == Importance.Third.value: elif b["key"] == Importance.Third.value:
tmp_dic["third"] += b["doc_count"] tmp_dic["third"] += b["doc_count"]
tmp_dic["alarm_count"] = tmp_dic["first"] + tmp_dic["second"] + \ tmp_dic["alarm_count"] = tmp_dic["first"] + tmp_dic["second"] + \
tmp_dic["third"] tmp_dic["third"]
res_list.append(tmp_dic) res_list.append(tmp_dic)
......
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