Commit 747aba6e authored by lcn's avatar lcn

bug修复

parent 2d16cd9d
......@@ -20,9 +20,10 @@ async def get_location_dao(lids):
return location_info
async def get_location_15min_dao(lid, start, end):
async def get_location_15min_dao(lid, start, end,
table_name="location_15min_aiao"):
sql = f"SELECT lid,value_max,value_max_time,value_avg,value_min," \
f"value_min_time FROM `location_15min_aiao`WHERE lid = %s " \
f"value_min_time FROM {table_name} WHERE lid = %s " \
f"and create_time BETWEEN '{start}' and '{end}'"
async with MysqlUtil() as conn:
result = await conn.fetchall(sql, args=(lid,))
......
......@@ -6,6 +6,7 @@ import aioredis
from pot_libs.aredis_util.aredis_utils import RedisClient, RedisUtils
from pot_libs.settings import SETTING
from pot_libs.utils import time_format
from unify_api import constants
from unify_api.constants import POINT_LEVEL_MAP
from unify_api.modules.adio.components.adio import AdioIndex
......@@ -116,21 +117,14 @@ async def post_adio_card_service(location_list, cid):
async def adio_index_service(location_group, start, end):
redis_data, redis_key = await get_location_15min_redis(location_group,
start, end)
if redis_data:
datas = redis_data.get("data")
else:
# # load location表信息
location_info = await get_location_dao(location_group)
tasks = [get_location_15min_service(location_info, lid, start, end) for
lid
in location_group]
adio_index_result = await asyncio.gather(*tasks)
datas = list(adio_index_result)
# set to redis
await RedisUtils().setex(redis_key, 60 * 7,
json.dumps({"data": datas}))
# # load location表信息
location_info = await get_location_dao(location_group)
intervel, _ = time_format.time_pick_transf(start, end)
tasks = [get_location_15min_service(
location_info, lid, start, end, intervel) for lid in
location_group]
adio_index_result = await asyncio.gather(*tasks)
datas = list(adio_index_result)
adio_indexes = []
for data in datas:
adio_index = AdioIndex(**data)
......@@ -138,18 +132,14 @@ async def adio_index_service(location_group, start, end):
return adio_indexes
async def get_location_15min_redis(location_group, start, end):
redis_key_data = json.dumps(
{"group": location_group, "start": start, "end": end})
redis_key = hashlib.md5(redis_key_data.encode()).hexdigest()
redis_data = await RedisUtils().get(redis_key)
return json.loads(redis_data) if redis_data else {}, redis_key
async def get_location_15min_service(location_info, lid, start, end):
async def get_location_15min_service(location_info, lid, start, end, intervel):
value_max, value_min, value_avg = [], [], []
value_max_time, value_min_time = [], []
datas = await get_location_15min_dao(lid, start, end)
if intervel == 24 * 3600:
table_name = "location_1day_aiao"
else:
table_name = "location_15min_aiao"
datas = await get_location_15min_dao(lid, start, end, table_name)
for data in datas:
value_max.append(data.get("value_max"))
value_min.append(data.get("value_min"))
......
......@@ -90,7 +90,7 @@ async def alarm_behavior_curve_service(point_id, req_date, product):
behavior_illegal_app = []
if behavior_res:
for i in behavior_res:
tmp_dic = {"name": i["key"], "value": i["doc_count"]}
tmp_dic = {"name": i["appliance"], "value": i["doc_count"]}
behavior_illegal_app.append(tmp_dic)
behavior_illegal_app = sorted(behavior_illegal_app,
key=lambda x: x["value"], reverse=True)
......
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