Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
U
unify_api2
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
chaonan
unify_api2
Commits
edbbe5c2
Commit
edbbe5c2
authored
Apr 21, 2023
by
lcn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修复Bug
parent
fb18f2f4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
213 additions
and
147 deletions
+213
-147
load_forecast_dao.py
unify_api/modules/load_analysis/dao/load_forecast_dao.py
+39
-10
load_forecast_service.py
...pi/modules/load_analysis/service/load_forecast_service.py
+133
-136
load_forecast.py
unify_api/modules/load_analysis/views/load_forecast.py
+6
-1
time_format.py
unify_api/utils/time_format.py
+35
-0
No files found.
unify_api/modules/load_analysis/dao/load_forecast_dao.py
View file @
edbbe5c2
from
pot_libs.mysql_util.mysql_util
import
MysqlUtil
async
def
get_kwh_p_dao
(
table_name
,
terms
,
start
,
end
):
sql
=
f
"SELECT create_time,kwh,p FROM {table_name} WHERE cid in
%
s "
\
f
"and create_time BETWEEN '{start}' and '{end}'"
async
def
get_kwh_p_dao
(
terms
,
start_time
,
end_time
,
table_name
=
"company_15min_power"
,
time_fmt
=
"
%%
Y-
%%
m-
%%
d"
):
"""
负荷实际数据
:param terms:
:param start_time:
:param end_time:
:param table_name:
:param time_fmt:
:return:
"""
sql
=
f
"""
select p,kwh,DATE_FORMAT(create_time,"{time_fmt}") as cal_time
from {table_name} where cid in
%
s and create_time >=
%
s
and create_time <=
%
s
"""
async
with
MysqlUtil
()
as
conn
:
datas
=
await
conn
.
fetchall
(
sql
,
args
=
(
terms
,
))
return
datas
result
=
await
conn
.
fetchall
(
sql
,
args
=
(
terms
,
start_time
,
end_time
))
return
result
or
[]
async
def
get_pred_p_dao
(
terms
,
start
,
end
):
sql
=
f
"SELECT create_time,p FROM company_day_ahead_predict "
\
f
"WHERE cid in
%
s and create_time BETWEEN '{start}' and '{end}'"
async
def
get_pred_p_dao
(
terms
,
start_time
,
end_time
,
time_fmt
=
"
%%
Y-
%%
m-
%%
d"
):
"""
负荷预测数据
:param terms:
:param start_time:
:param end_time:
:param time_fmt:
:return:
"""
sql
=
f
"""
select avg(p) p ,count(*) p_count,DATE_FORMAT(create_time,
"{time_fmt}") as cal_time
from company_day_ahead_predict
where cid in
%
s and create_time >=
%
s and create_time <=
%
s
group by cal_time
"""
async
with
MysqlUtil
()
as
conn
:
datas
=
await
conn
.
fetchall
(
sql
,
args
=
(
terms
,))
return
datas
\ No newline at end of file
result
=
await
conn
.
fetchall
(
sql
,
args
=
(
terms
,
start_time
,
end_time
))
return
result
or
[]
unify_api/modules/load_analysis/service/load_forecast_service.py
View file @
edbbe5c2
This diff is collapsed.
Click to expand it.
unify_api/modules/load_analysis/views/load_forecast.py
View file @
edbbe5c2
...
...
@@ -5,6 +5,7 @@ from unify_api.modules.load_analysis.components.load_forecast_cps import (
)
from
unify_api.modules.load_analysis.service.load_forecast_service
import
\
load_forecast_service
,
load_forecast_service_new15
from
unify_api.utils.time_format
import
time_pick_transf_new
@
summary
(
"负荷预测"
)
...
...
@@ -17,4 +18,8 @@ async def post_load_forecast(req, body: ForecastReq) -> ForecastResp:
# 管理版本多个工厂的情况, 兼容能力最强的参数cids, 保留旧有的cid:
cids
=
body
.
cids
# return await load_forecast_service(cid, cids, start, end)
return
await
load_forecast_service_new15
(
cid
,
cids
,
start
,
end
)
terms
=
cids
if
cids
else
[
cid
]
# 获取时间差
interval
,
slots
=
time_pick_transf_new
(
start
,
end
)
return
await
load_forecast_service_new15
(
terms
,
start
,
end
,
interval
,
slots
)
unify_api/utils/time_format.py
View file @
edbbe5c2
...
...
@@ -60,6 +60,41 @@ def time_pick_transf(start, end, is_range=0):
return
intervel
,
slots
def
time_pick_transf_new
(
start
,
end
):
"""获取intervel和slots, 详细显示时间轴信息,新接口都使用这个来获取时间"""
start_f
=
my_pendulum
.
from_format
(
start
,
'YYYY-MM-DD HH:mm:ss'
)
end_f
=
my_pendulum
.
from_format
(
end
,
'YYYY-MM-DD HH:mm:ss'
)
diff
=
end_f
.
int_timestamp
-
start_f
.
int_timestamp
# 1. 计算intervel
# 1.1 区间48小时之内, 返回15min
if
diff
<=
48
*
3600
:
intervel
=
15
*
60
# 1.2 区间在60天以内, 返回1day
elif
48
*
3600
<
diff
<=
60
*
86400
:
intervel
=
86400
# 1.3 选择年, 返回1个月
else
:
intervel
=
30
*
86400
# 2. 计算slots
# 2.1 取到点的个数, 比如15min的96个点
slots
=
[]
slot_num
=
round
((
end_f
.
int_timestamp
-
start_f
.
int_timestamp
)
/
intervel
)
for
i
in
range
(
slot_num
):
# 区间48小时之内
if
diff
<=
48
*
3600
:
dt
=
start_f
.
add
(
minutes
=
15
*
i
)
.
format
(
"YYYY-MM-DD HH:mm"
)
dt_str
=
str
(
dt
)
# 区间在60天以内
elif
48
*
3600
<
diff
<=
60
*
86400
:
dt
=
start_f
.
add
(
days
=
1
*
i
)
.
format
(
"YYYY-MM-DD"
)
dt_str
=
str
(
dt
)
else
:
dt
=
start_f
.
add
(
months
=
1
*
i
)
.
format
(
"YYYY-MM"
)
dt_str
=
str
(
dt
)
slots
.
append
(
dt_str
)
return
intervel
,
slots
def
power_slots
(
start
,
end
):
"""电量电费,用电统计,time=range slots计算"""
start_f
=
my_pendulum
.
from_format
(
start
,
'YYYY-MM-DD HH:mm:ss'
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment