Commit e57796df authored by lcn's avatar lcn

bug修复

parent 1602e4f3
......@@ -23,15 +23,15 @@ async def load_forecast_srv(cids, s_time, e_time, interval, slots):
time_fmt = "%%Y-%%m"
now_time_fmt = "YYYY-MM"
tbl_name = "company_1day_power"
now_time = pendulum.now().format(now_time_fmt)
now_month = pendulum.now().format("YYYY-MM")
# 1,获取实际数据
real_result = await get_kwh_p_dao(cids, s_time, e_time, tbl_name, time_fmt)
# if not real_result:
# return [], [], [], [], [], [], [], 0, "", 0, "", 0, 0
real_data = {i["cal_time"]: i for i in real_result}
real_list, real_power_list = [], []
for slot in slots:
......@@ -51,7 +51,7 @@ async def load_forecast_srv(cids, s_time, e_time, interval, slots):
value, kwh = "", ""
real_list.append(value)
real_power_list.append(kwh)
# 2,获取预测数据
forecast_result = await get_pred_p_dao(cids, s_time, e_time, time_fmt)
# if not forecast_result:
......@@ -76,7 +76,7 @@ async def load_forecast_srv(cids, s_time, e_time, interval, slots):
else:
power_value = ""
forecast_power_list.append(power_value)
# 3.求偏差数据
deviation_list, deviation_power_list = [], [] # 偏差取绝对值, 最大/最小/平均偏差都是绝对值后数据
for num, value in enumerate(real_list):
......@@ -86,7 +86,7 @@ async def load_forecast_srv(cids, s_time, e_time, interval, slots):
# (预测-实际)/实际 * 100%
deviation = (forecast_list[num] - value) / value
deviation_list.append(abs(round(deviation, 4)))
for num, value in enumerate(real_power_list):
if not value or not forecast_power_list[num]:
deviation_power = ""
......@@ -99,10 +99,10 @@ async def load_forecast_srv(cids, s_time, e_time, interval, slots):
num == slots.index(now_time):
deviation_power = ""
deviation_power_list.append(deviation_power)
# 4,求偏差统计值
deviation_list_tmp = [i for i in deviation_list if i != ""]
if deviation_list_tmp:
count, max_deviation, min_deviation, average, max_index, min_index = \
choose_list(deviation_list_tmp, 4)
......@@ -120,19 +120,23 @@ async def load_forecast_srv(cids, s_time, e_time, interval, slots):
else:
max_deviation, max_time, min_deviation, min_time = 0, "", 0, ""
avg_deviation, total_deviation = 0, 0
# 重置 slots
if interval == 15 * 60:
for num, slot in enumerate(slots):
slot = pendulum.parse(slot).format("HH:mm")
slots[num] = slot
elif interval == 86400:
for num, slot in enumerate(slots):
slot = pendulum.parse(slot).format("MM-DD")
slots[num] = slot
return ForecastResp(
pred_data=LoadValue(slots=slots, value=forecast_list),
real_data=LoadValue(slots=slots, value=real_list),
deviation_list=deviation_list,
max_deviation=[max_deviation,max_time],
min_deviation=[min_deviation,min_time],
max_deviation=[max_deviation, max_time],
min_deviation=[min_deviation, min_time],
avg_deviation=avg_deviation,
total_deviation=total_deviation,
real_power_list=LoadValue(slots=slots, value=real_power_list),
......
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