Commit 354b291f authored by lcn's avatar lcn

bug修复

parent a2e7dd6a
...@@ -27,17 +27,12 @@ async def load_pttl_max(cid, start, end, point_id=None, inline_id=None): ...@@ -27,17 +27,12 @@ async def load_pttl_max(cid, start, end, point_id=None, inline_id=None):
# index = INDEX[date_type] # index = INDEX[date_type]
if date_type == "day": if date_type == "day":
table_name = "point_15min_electric" table_name = "point_15min_electric"
time_format = "%%Y-%%m-%%d %%H:00:00"
elif date_type == "month":
table_name = "point_15min_electric"
time_format = "%%Y-%%m-%%d"
else: else:
table_name = "point_1day_electric" table_name = "point_1day_electric"
time_format = "%%Y-%%m" sum_sql = f"SELECT create_time, sum(pttl_max) pttl_max_sum " \
sum_sql = f"SELECT DATE_FORMAT(create_time, '{time_format}') time_date, " \ f"FROM {table_name} WHERE " \
f"sum(pttl_max) pttl_max_sum FROM {table_name} WHERE " \
f"pid in %s and create_time BETWEEN '{start}' and '{end}' " \ f"pid in %s and create_time BETWEEN '{start}' and '{end}' " \
f"GROUP BY time_date ORDER BY time_date" f"GROUP BY create_time ORDER BY create_time"
async with MysqlUtil() as conn: async with MysqlUtil() as conn:
datas = await conn.fetchall(sql=sum_sql, args=(point_list,)) datas = await conn.fetchall(sql=sum_sql, args=(point_list,))
# 最大需量 # 最大需量
...@@ -48,15 +43,15 @@ async def load_pttl_max(cid, start, end, point_id=None, inline_id=None): ...@@ -48,15 +43,15 @@ async def load_pttl_max(cid, start, end, point_id=None, inline_id=None):
mdp_max_value = data["pttl_max_sum"] mdp_max_value = data["pttl_max_sum"]
if mdp_max_value and mdp_max_value > max_val: if mdp_max_value and mdp_max_value > max_val:
max_val = mdp_max_value max_val = mdp_max_value
max_val_time = data["time_date"] max_val_time = data["create_time"]
# 根据时间范围, 返回不同时间格式 # 根据时间范围, 返回不同时间格式
if max_val_time: if max_val_time:
if date_type == "day": if date_type == "day":
max_val_time = str(max_val_time)[11:16] max_val_time = max_val_time.strftime("%H:00")
elif date_type == "month": elif date_type == "month":
max_val_time = str(max_val_time)[5:10] max_val_time = max_val_time.strftime("%m-%d")
else: else:
max_val_time = str(max_val_time)[:7] max_val_time = max_val_time.strftime("%Y-%m")
return max_val, max_val_time return max_val, max_val_time
......
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