Commit 04eac214 authored by peng.xiaozhe's avatar peng.xiaozhe

alarm-price-costtl 大屏报警相关bug修复

parent 70e2c2d1
......@@ -505,44 +505,19 @@ async def sdu_alarm_aggs_type(cid, start, end):
async def alarm_aggs_importance(cid, start, end):
"""按报警等级聚合"""
start_dt = datetime.strptime(start, "%Y-%m-%d %H:%M:%S")
end_dt = datetime.strptime(end, "%Y-%m-%d %H:%M:%S")
es_start_str = datetime(year=start_dt.year, month=start_dt.month,
day=start_dt.day).strftime(
"%Y-%m-%dT%H:%M:%S+08:00")
es_end_str = end_dt.strftime("%Y-%m-%dT%H:%M:%S+08:00")
query_body = {
"size": 0,
"query": {
"bool": {
"must": [
{
"term": {
"cid": cid
}
},
{
"range": {
"datetime": {
"gte": es_start_str,
"lte": es_end_str
}
}
}
]
}
},
"aggs": {
"importance": {
"terms": {
"field": "importance",
"size": 10
}
}
}
}
log.info("query_body={}".format(query_body))
async with EsUtil() as es:
es_result = await es.search_origin(body=query_body,
index=constants.POINT_1MIN_EVENT)
return es_result["aggregations"]["importance"]["buckets"]
sql = f"""
SELECT
COUNT(*) alarm_count,
importance
FROM
point_1min_event pevent
WHERE
cid = {54}
AND pevent.event_datetime >= '{start}'
AND pevent.event_datetime <= '{end}'
GROUP BY
pevent.importance
"""
async with MysqlUtil() as conn:
datas = await conn.fetchall(sql)
return datas if datas else []
......@@ -717,7 +717,7 @@ async def company_power_use_info_new15(company_id, start, end):
async def get_company_charge_price(company_id, es_time_start, es_time_end):
power_use_info = await company_power_use_info(company_id, es_time_start,
power_use_info = await company_power_use_info_new15(company_id, es_time_start,
es_time_end)
if power_use_info["kwh"]:
unit_price = power_use_info["charge"] / power_use_info["kwh"]
......@@ -1715,12 +1715,12 @@ async def alarm_importance_count_total(cid, start, end):
es_res = await alarm_aggs_importance(cid, start, end)
first_cnt, second_cnt, third_cnt = 0, 0, 0
for buckets in es_res:
if buckets["key"] == Importance.First.value:
first_cnt += buckets["doc_count"]
elif buckets["key"] == Importance.Second.value:
second_cnt += buckets["doc_count"]
elif buckets["key"] == Importance.Third.value:
third_cnt += buckets["doc_count"]
if buckets["importance"] == Importance.First.value:
first_cnt += buckets["alarm_count"]
elif buckets["importance"] == Importance.Second.value:
second_cnt += buckets["alarm_count"]
elif buckets["importance"] == Importance.Third.value:
third_cnt += buckets["alarm_count"]
return {
"first_cnt": first_cnt,
"second_cnt": second_cnt,
......
......@@ -23,7 +23,8 @@ from unify_api.modules.home_page.procedures.count_info_pds import other_info, \
electric_use_info, cid_alarm_importance_count, \
alarm_importance_count_total, power_factor, current_load, \
get_company_charge_price, health_status_res, carbon_status_res_web, \
optimization_count_info, economic_index_desc, electric_use_info_new15
optimization_count_info, economic_index_desc, electric_use_info_new15, \
power_factor_new15, current_load_new15
from unify_api.modules.home_page.procedures.count_info_proxy_pds import \
alarm_percentage_count, alarm_safe_power
from unify_api.modules.tsp_water.dao.drop_dust_dao import \
......@@ -290,9 +291,9 @@ async def alarm_price_costtl_service(cid):
# 1. 今日报警
imp_dic = await alarm_importance_count_total(cid, today_start, today_end)
# 2. 实时功率因数, 上月功率因数
cos_ttl, last_month_cos = await power_factor(cid)
cos_ttl, last_month_cos = await power_factor_new15(cid)
# 3. 实时负荷
cur_load = await current_load(cid)
cur_load = await current_load_new15(cid)
# 4. 平均电价
# 昨天
yesterday_start, yesterday_end = yesterday_range()
......
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