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
fb18f2f4
Commit
fb18f2f4
authored
Apr 21, 2023
by
lcn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修复Bug
parent
80208422
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
256 additions
and
181 deletions
+256
-181
elec_charge_pds.py
unify_api/modules/elec_charge/procedures/elec_charge_pds.py
+6
-4
elec_charge_service.py
unify_api/modules/elec_charge/service/elec_charge_service.py
+14
-3
elec_charge.py
unify_api/modules/elec_charge/views/elec_charge.py
+40
-9
electric_dao.py
unify_api/modules/electric/dao/electric_dao.py
+11
-5
count_info_pds.py
unify_api/modules/home_page/procedures/count_info_pds.py
+160
-145
time_format.py
unify_api/utils/time_format.py
+25
-15
No files found.
unify_api/modules/elec_charge/procedures/elec_charge_pds.py
View file @
fb18f2f4
...
@@ -229,7 +229,8 @@ async def power_aggs_cid_proxy(start, end, cid_list, date_type):
...
@@ -229,7 +229,8 @@ async def power_aggs_cid_proxy(start, end, cid_list, date_type):
continue
continue
except
Exception
as
e
:
except
Exception
as
e
:
log
.
error
(
e
)
log
.
error
(
e
)
log
.
info
(
f
"本次有电量数据, 上周期没有电量数据, cid:{cid}, start:{start}, end:{end}"
)
log
.
info
(
f
"本次有电量数据, 上周期没有电量数据, cid:{cid}, start:{start}, end:{end}"
)
continue
continue
charge
=
round_2
(
info
.
get
(
"charge"
)[
"value"
])
charge
=
round_2
(
info
.
get
(
"charge"
)[
"value"
])
...
@@ -241,7 +242,8 @@ async def power_aggs_cid_proxy(start, end, cid_list, date_type):
...
@@ -241,7 +242,8 @@ async def power_aggs_cid_proxy(start, end, cid_list, date_type):
except
Exception
as
e
:
except
Exception
as
e
:
log
.
error
(
e
)
log
.
error
(
e
)
log
.
info
(
"本次有数据, 上周期没有数据"
)
log
.
info
(
"本次有数据, 上周期没有数据"
)
log
.
info
(
f
"本次有电费数据, 上周期没有电费数据, cid:{cid}, start:{start}, end:{end}"
)
log
.
info
(
f
"本次有电费数据, 上周期没有电费数据, cid:{cid}, start:{start}, end:{end}"
)
continue
continue
price
=
round_2
(
charge
/
kwh
)
price
=
round_2
(
charge
/
kwh
)
price_last
=
round_2
(
charge_last
/
kwh_last
)
price_last
=
round_2
(
charge_last
/
kwh_last
)
...
...
unify_api/modules/elec_charge/service/elec_charge_service.py
View file @
fb18f2f4
import
pendulum
from
unify_api.constants
import
POINT_LEVEL_MAP
from
unify_api.constants
import
POINT_LEVEL_MAP
from
unify_api.modules.common.components.common_cps
import
LevelResp
from
unify_api.modules.common.components.common_cps
import
LevelResp
from
unify_api.modules.common.procedures.points
import
points_by_storeys
from
unify_api.modules.common.procedures.points
import
points_by_storeys
...
@@ -6,6 +8,8 @@ from unify_api.modules.elec_charge.dao.elec_charge_dao import \
...
@@ -6,6 +8,8 @@ from unify_api.modules.elec_charge.dao.elec_charge_dao import \
query_charge_aggs_points
,
query_charge_aggs_points_new15
query_charge_aggs_points
,
query_charge_aggs_points_new15
from
unify_api.modules.electric.dao.electric_dao
import
\
from
unify_api.modules.electric.dao.electric_dao
import
\
monitor_point_join_by_points
monitor_point_join_by_points
from
unify_api.modules.home_page.procedures.count_info_pds
import
current_load
,
\
current_load_new15
from
unify_api.utils.common_utils
import
round_2
,
division_two
from
unify_api.utils.common_utils
import
round_2
,
division_two
...
@@ -101,4 +105,11 @@ async def kwh_card_level_service(cid, point_list, start, end):
...
@@ -101,4 +105,11 @@ async def kwh_card_level_service(cid, point_list, start, end):
)
)
async
def
load_info_service
(
cid_list
):
# 实时负荷
cur_load
=
await
current_load_new15
(
cid_list
)
yesterday_dt
=
pendulum
.
now
(
tz
=
"Asia/Shanghai"
)
.
subtract
(
days
=
1
)
yes_load
=
await
current_load_new15
(
cid_list
,
yesterday_dt
)
load_percent
=
round
((
cur_load
-
yes_load
)
/
yes_load
,
2
)
if
cur_load
and
yes_load
else
""
return
cur_load
,
yes_load
,
load_percent
unify_api/modules/elec_charge/views/elec_charge.py
View file @
fb18f2f4
...
@@ -16,14 +16,16 @@ from unify_api.modules.elec_charge.components.elec_charge_cps import \
...
@@ -16,14 +16,16 @@ from unify_api.modules.elec_charge.components.elec_charge_cps import \
power_overview_example
,
PricePolicyReq
,
PricePolicyResp
,
\
power_overview_example
,
PricePolicyReq
,
PricePolicyResp
,
\
PricePolicy
,
AverPriceReq
,
PowerViewRes
,
Spvf
,
AverPriceResp
,
ChargeKwh
,
\
PricePolicy
,
AverPriceReq
,
PowerViewRes
,
Spvf
,
AverPriceResp
,
ChargeKwh
,
\
IndexChargeReq
,
IndexChargeResp
,
PopReq
,
PopResp
,
MtpResp
,
PspResp
,
\
IndexChargeReq
,
IndexChargeResp
,
PopReq
,
PopResp
,
MtpResp
,
PspResp
,
\
IpspResp
,
KpReq
,
KpResp
,
KclReq
,
ProductProxyReq
IpspResp
,
KpReq
,
KpResp
,
KclReq
,
ProductProxyReq
,
LoadInfoReq
,
LoadInfoResp
from
unify_api.modules.elec_charge.dao.elec_charge_dao
import
\
from
unify_api.modules.elec_charge.dao.elec_charge_dao
import
\
query_charge_aggs_points
,
get_kwh_charge
,
query_charge_aggs_points_new15
query_charge_aggs_points
,
get_kwh_charge
,
query_charge_aggs_points_new15
from
unify_api.modules.elec_charge.procedures.elec_charge_pds
import
\
from
unify_api.modules.elec_charge.procedures.elec_charge_pds
import
\
quarters_trans
,
power_overview_proxy
,
total_value
,
power_aggs_cid_proxy_new15
,
\
quarters_trans
,
power_overview_proxy
,
total_value
,
\
power_aggs_cid_proxy_new15
,
\
power_index_cid_proxy_new15
,
power_overview_proxy15
power_index_cid_proxy_new15
,
power_overview_proxy15
from
unify_api.modules.elec_charge.service.elec_charge_service
import
\
from
unify_api.modules.elec_charge.service.elec_charge_service
import
\
kwh_points_service
,
kwh_card_level_service
kwh_points_service
,
kwh_card_level_service
,
load_info_service
from
unify_api.modules.users.procedures.jwt_user
import
jwt_user
from
unify_api.utils.common_utils
import
round_2
,
round_4
,
NumListHelper
from
unify_api.utils.common_utils
import
round_2
,
round_4
,
NumListHelper
from
unify_api.utils.es_query_body
import
agg_statistics
from
unify_api.utils.es_query_body
import
agg_statistics
from
unify_api.utils.request_util
import
filed_value_from_list
from
unify_api.utils.request_util
import
filed_value_from_list
...
@@ -289,7 +291,7 @@ async def post_power_overview_proxy(req, body: PopReq) -> PopResp:
...
@@ -289,7 +291,7 @@ async def post_power_overview_proxy(req, body: PopReq) -> PopResp:
proxy_id
=
body
.
proxy_id
proxy_id
=
body
.
proxy_id
host
=
req
.
host
host
=
req
.
host
product
=
PRODUCT
.
get
(
host
)
product
=
PRODUCT
.
get
(
host
)
user_id
=
req
.
ctx
.
user_id
user_id
=
jwt_user
(
req
)
# 全部工厂
# 全部工厂
if
not
cid_list
:
if
not
cid_list
:
log
.
info
(
f
"power_overview_proxy根据用户userId:{user_id} "
log
.
info
(
f
"power_overview_proxy根据用户userId:{user_id} "
...
@@ -314,7 +316,8 @@ async def post_power_overview_proxy(req, body: PopReq) -> PopResp:
...
@@ -314,7 +316,8 @@ async def post_power_overview_proxy(req, body: PopReq) -> PopResp:
# 获取上一周期开始结束时间
# 获取上一周期开始结束时间
start_last
,
end_last
=
last_time_str
(
start
,
end
,
date_type
)
start_last
,
end_last
=
last_time_str
(
start
,
end
,
date_type
)
power
,
charge
=
await
power_overview_proxy15
(
start
,
end
,
cid_list
)
power
,
charge
=
await
power_overview_proxy15
(
start
,
end
,
cid_list
)
power_last
,
charge_last
=
await
power_overview_proxy15
(
start_last
,
end_last
,
power_last
,
charge_last
=
await
power_overview_proxy15
(
start_last
,
end_last
,
cid_list
)
cid_list
)
if
not
all
([
power
,
charge
,
power_last
,
charge_last
]):
if
not
all
([
power
,
charge
,
power_last
,
charge_last
]):
return
PopResp
(
power
=
Spvf
(),
charge
=
Spvf
())
return
PopResp
(
power
=
Spvf
(),
charge
=
Spvf
())
...
@@ -351,7 +354,7 @@ async def post_month_today_proxy(req, body: ProductProxyReq) -> MtpResp:
...
@@ -351,7 +354,7 @@ async def post_month_today_proxy(req, body: ProductProxyReq) -> MtpResp:
# 1. 获取参数
# 1. 获取参数
host
=
req
.
host
host
=
req
.
host
product
=
PRODUCT
.
get
(
host
)
product
=
PRODUCT
.
get
(
host
)
user_id
=
req
.
ctx
.
user_id
user_id
=
jwt_user
(
req
)
# cid_list = await get_cids(user_id, product)
# cid_list = await get_cids(user_id, product)
proxy_id
=
body
.
proxy_id
proxy_id
=
body
.
proxy_id
cid_list
=
await
get_proxy_cids
(
user_id
,
product
,
proxy_id
)
\
cid_list
=
await
get_proxy_cids
(
user_id
,
product
,
proxy_id
)
\
...
@@ -364,7 +367,7 @@ async def post_month_today_proxy(req, body: ProductProxyReq) -> MtpResp:
...
@@ -364,7 +367,7 @@ async def post_month_today_proxy(req, body: ProductProxyReq) -> MtpResp:
today_start
,
today_end
,
month_start
,
month_end
=
today_month_date
()
today_start
,
today_end
,
month_start
,
month_end
=
today_month_date
()
# 2. 本月/上月数据
# 2. 本月/上月数据
last_month_start
,
last_month_end
=
last_time_str
(
month_start
,
month_end
,
last_month_start
,
last_month_end
=
last_time_str
(
month_start
,
month_end
,
"month"
)
"month"
,
True
)
this_month_p
,
this_month_charge
=
await
power_overview_proxy15
(
this_month_p
,
this_month_charge
=
await
power_overview_proxy15
(
month_start
,
month_end
,
cid_list
)
month_start
,
month_end
,
cid_list
)
last_month_p
,
last_month_charge
=
await
power_overview_proxy15
(
last_month_p
,
last_month_charge
=
await
power_overview_proxy15
(
...
@@ -541,3 +544,31 @@ async def post_kwh_card_level(req, body: KclReq) -> LevelResp:
...
@@ -541,3 +544,31 @@ async def post_kwh_card_level(req, body: KclReq) -> LevelResp:
start
=
body
.
start
start
=
body
.
start
end
=
body
.
end
end
=
body
.
end
return
await
kwh_card_level_service
(
cid
,
point_list
,
start
,
end
)
return
await
kwh_card_level_service
(
cid
,
point_list
,
start
,
end
)
@
summary
(
"获取知电管理版首页负荷信息"
)
async
def
post_load_info
(
request
,
body
:
LoadInfoReq
)
->
LoadInfoResp
:
# 1. 获取company_id
# 1. 获取参数
product
=
PRODUCT
.
get
(
request
.
host
)
user_id
=
jwt_user
(
request
)
proxy_id
=
body
.
proxy_id
cid_list
=
await
get_proxy_cids
(
user_id
,
product
,
proxy_id
)
\
if
proxy_id
else
None
# 全部工厂
if
not
cid_list
:
log
.
info
(
f
"未查询到工厂, userId:{user_id} product:{product}"
)
return
LoadInfoResp
()
try
:
# 实时负荷,昨日同时负荷,对比昨日
current_load
,
yesterday_load
,
load_percent
=
await
load_info_service
(
cid_list
)
except
Exception
as
e
:
log
.
exception
(
e
)
return
LoadInfoResp
()
.
server_error
()
return
LoadInfoResp
(
current_load
=
current_load
,
yesterday_load
=
yesterday_load
,
load_percent
=
load_percent
)
unify_api/modules/electric/dao/electric_dao.py
View file @
fb18f2f4
...
@@ -5,7 +5,7 @@ async def monitor_point_join_by_points(points):
...
@@ -5,7 +5,7 @@ async def monitor_point_join_by_points(points):
"""monitor和point关联"""
"""monitor和point关联"""
sql
=
"SELECT m.mtid,p.ctnum,m.name, m.m_type, p.pid,p.cid "
\
sql
=
"SELECT m.mtid,p.ctnum,m.name, m.m_type, p.pid,p.cid "
\
"FROM monitor m inner join point p on m.mtid = p.mtid "
\
"FROM monitor m inner join point p on m.mtid = p.mtid "
\
"WHERE p.pid in
%
s and m.demolished = 0 order by field(p.pid,{})"
.
\
"WHERE p.pid in
%
s and m.demolished = 0 order by field(p.pid,{})"
.
\
format
(
str
(
points
)
.
replace
(
"["
,
""
)
.
replace
(
"]"
,
""
))
format
(
str
(
points
)
.
replace
(
"["
,
""
)
.
replace
(
"]"
,
""
))
async
with
MysqlUtil
()
as
conn
:
async
with
MysqlUtil
()
as
conn
:
monitor_point_list
=
await
conn
.
fetchall
(
sql
,
args
=
(
tuple
(
points
),))
monitor_point_list
=
await
conn
.
fetchall
(
sql
,
args
=
(
tuple
(
points
),))
...
@@ -26,7 +26,7 @@ async def get_electric_datas_dao(table_name, pid, start, end):
...
@@ -26,7 +26,7 @@ async def get_electric_datas_dao(table_name, pid, start, end):
sql
=
f
"SELECT * FROM {table_name} where pid=
%
s and create_time "
\
sql
=
f
"SELECT * FROM {table_name} where pid=
%
s and create_time "
\
f
"BETWEEN '{start}' and '{end}' ORDER BY create_time desc"
f
"BETWEEN '{start}' and '{end}' ORDER BY create_time desc"
async
with
MysqlUtil
()
as
conn
:
async
with
MysqlUtil
()
as
conn
:
electric_datas
=
await
conn
.
fetchall
(
sql
,
args
=
(
pid
,
))
electric_datas
=
await
conn
.
fetchall
(
sql
,
args
=
(
pid
,))
return
electric_datas
return
electric_datas
...
@@ -35,7 +35,7 @@ async def get_qual_history_dao(table_name, pid, start, end, date_format):
...
@@ -35,7 +35,7 @@ async def get_qual_history_dao(table_name, pid, start, end, date_format):
f
"p.* FROM {table_name} p where p.pid=
%
s and p.create_time "
\
f
"p.* FROM {table_name} p where p.pid=
%
s and p.create_time "
\
f
"BETWEEN '{start}' and '{end}' order by p.create_time"
f
"BETWEEN '{start}' and '{end}' order by p.create_time"
async
with
MysqlUtil
()
as
conn
:
async
with
MysqlUtil
()
as
conn
:
datas
=
await
conn
.
fetchall
(
sql
,
args
=
(
pid
,
))
datas
=
await
conn
.
fetchall
(
sql
,
args
=
(
pid
,))
return
datas
return
datas
...
@@ -51,6 +51,12 @@ async def get_elec_history_dao(table_name, pid, start, end, date_format):
...
@@ -51,6 +51,12 @@ async def get_elec_history_dao(table_name, pid, start, end, date_format):
async
def
get_elec_mtid_sid_by_cid
(
cid
):
async
def
get_elec_mtid_sid_by_cid
(
cid
):
if
isinstance
(
cid
,
tuple
):
cid_tuple
=
cid
elif
isinstance
(
cid
,
list
):
cid_tuple
=
tuple
(
cid
)
else
:
cid_tuple
=
(
cid
,)
sql
=
(
sql
=
(
f
"""
f
"""
SELECT
SELECT
...
@@ -59,9 +65,9 @@ async def get_elec_mtid_sid_by_cid(cid):
...
@@ -59,9 +65,9 @@ async def get_elec_mtid_sid_by_cid(cid):
FROM
FROM
monitor
monitor
WHERE
WHERE
cid
= {cid}
;
cid
in
%
s
;
"""
"""
)
)
async
with
MysqlUtil
()
as
conn
:
async
with
MysqlUtil
()
as
conn
:
datas
=
await
conn
.
fetchall
(
sql
)
datas
=
await
conn
.
fetchall
(
sql
,
args
=
(
cid_tuple
,)
)
return
datas
if
datas
else
[]
return
datas
if
datas
else
[]
unify_api/modules/home_page/procedures/count_info_pds.py
View file @
fb18f2f4
...
@@ -3,6 +3,10 @@ import time
...
@@ -3,6 +3,10 @@ import time
from
datetime
import
datetime
,
timedelta
from
datetime
import
datetime
,
timedelta
from
math
import
sqrt
from
math
import
sqrt
import
pendulum
import
pendulum
from
pot_libs.settings
import
SETTING
from
unify_api.modules.electric.dao.electric_dao
import
\
get_elec_mtid_sid_by_cid
from
unify_api.utils.common_utils
import
round_2
from
unify_api.utils.common_utils
import
round_2
from
pot_libs.aredis_util.aredis_utils
import
RedisUtils
from
pot_libs.aredis_util.aredis_utils
import
RedisUtils
from
pot_libs.common.components.query
import
Range
,
Equal
,
Filter
,
PageRequest
from
pot_libs.common.components.query
import
Range
,
Equal
,
Filter
,
PageRequest
...
@@ -35,7 +39,9 @@ from unify_api.modules.home_page.dao.count_info_dao import (
...
@@ -35,7 +39,9 @@ from unify_api.modules.home_page.dao.count_info_dao import (
from
unify_api.modules.electric_optimization.dao.power_index
import
(
from
unify_api.modules.electric_optimization.dao.power_index
import
(
price_policy_by_cid
price_policy_by_cid
)
)
from
unify_api.utils.taos_new
import
parse_td_columns
from
unify_api.utils.taos_new
import
parse_td_columns
,
get_td_table_name
,
\
td3_tbl_compate
,
get_td_engine_data
async
def
other_info
(
company_id
):
async
def
other_info
(
company_id
):
"""
"""
...
@@ -337,7 +343,7 @@ async def electric_use_info_new15(cid):
...
@@ -337,7 +343,7 @@ async def electric_use_info_new15(cid):
f
"GROUP BY importance"
f
"GROUP BY importance"
first_score
,
second_score
,
third_score
=
0
,
0
,
0
first_score
,
second_score
,
third_score
=
0
,
0
,
0
async
with
MysqlUtil
()
as
conn
:
async
with
MysqlUtil
()
as
conn
:
score_datas
=
await
conn
.
fetchall
(
score_sql
,
args
=
(
cid
,
))
score_datas
=
await
conn
.
fetchall
(
score_sql
,
args
=
(
cid
,))
alarm_datas
=
await
conn
.
fetchall
(
alarm_sql
,
args
=
(
cid
,
score_events
))
alarm_datas
=
await
conn
.
fetchall
(
alarm_sql
,
args
=
(
cid
,
score_events
))
for
data
in
score_datas
:
for
data
in
score_datas
:
if
data
[
"importance"
]
==
Importance
.
First
.
value
:
if
data
[
"importance"
]
==
Importance
.
First
.
value
:
...
@@ -598,39 +604,46 @@ async def current_load(company_id):
...
@@ -598,39 +604,46 @@ async def current_load(company_id):
return
""
return
""
async
def
current_load_new15
(
cid
):
async
def
current_load_new15
(
cid
,
end_dt
=
None
):
"""实时负荷"""
"""实时负荷"""
import
re
datas
=
await
get_elec_mtid_sid_by_cid
(
cid
)
from
pot_libs.settings
import
SETTING
td_mt_tables
=
tuple
(
from
unify_api.modules.common.service.td_engine_service
import
\
(
get_td_table_name
(
"electric"
,
data
[
"mtid"
])
for
data
in
datas
if
get_td_engine_data
data
[
"mtid"
]))
td_mt_tables
=
td3_tbl_compate
(
td_mt_tables
)
if
not
end_dt
:
end_dt
=
pendulum
.
now
(
tz
=
"Asia/Shanghai"
)
start_dt
=
end_dt
.
subtract
(
minutes
=
2
)
sql
=
f
"select last_row(mdptime, pttl) from electric_stb "
\
f
"where TBNAME IN {td_mt_tables} and ts>='{str(start_dt)}' and ts "
\
f
"<='{str(end_dt)}' group by tbname"
url
=
f
"{SETTING.stb_url}db_electric?tz=Asia/Shanghai"
url
=
f
"{SETTING.stb_url}db_electric?tz=Asia/Shanghai"
sql
=
f
"""
select last_row(*) from electric_stb
where cpyid={cid}
group by tbname
"""
is_succ
,
results
=
await
get_td_engine_data
(
url
,
sql
)
is_succ
,
results
=
await
get_td_engine_data
(
url
,
sql
)
now_tt
=
int
(
time
.
time
())
if
not
is_succ
:
if
is_succ
:
return
""
if
not
results
[
"data"
]:
# 兼容:mt表(2.0架构)里面拿不到数据再从sid表(1.0架构)里面拿
td_s_tables
=
tuple
(
(
f
"s{data['sid'].lower()}_e"
for
data
in
datas
if
data
[
"sid"
]))
td_s_tables
=
td3_tbl_compate
(
td_s_tables
)
sql
=
f
"select last_row(mdptime, pttl) from electric_stb "
\
f
"where TBNAME IN {td_s_tables} group by tbname"
is_succ
,
results
=
await
get_td_engine_data
(
url
,
sql
)
if
not
is_succ
:
return
""
head
=
parse_td_columns
(
results
)
head
=
parse_td_columns
(
results
)
datas
=
[]
datas
=
[]
for
res
in
results
[
"data"
]:
for
res
in
results
[
"data"
]:
datas
.
append
(
dict
(
zip
(
head
,
res
)))
datas
.
append
(
dict
(
zip
(
head
,
res
)))
total
=
0
total
=
0
for
item
in
datas
:
for
item
in
datas
:
# 这里是有可能item为None的
if
not
item
:
if
item
:
continue
mdptime_tt
=
None
if
"mdptime"
in
item
:
mdptime_dt
=
pendulum
.
parse
(
item
[
"mdptime"
])
item_tt
=
item
.
get
(
"timestamp"
)
or
mdptime_dt
.
int_timestamp
if
item_tt
:
# 小于2分钟内的数据相加为实时负荷
if
now_tt
-
item_tt
<=
2
*
60
:
total
+=
item
[
"pttl"
]
total
+=
item
[
"pttl"
]
return
total
return
total
return
""
async
def
power_count_info
(
company_id
):
async
def
power_count_info
(
company_id
):
...
@@ -769,7 +782,8 @@ async def company_power_use_info_new15(company_id, start, end):
...
@@ -769,7 +782,8 @@ 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
):
async
def
get_company_charge_price
(
company_id
,
es_time_start
,
es_time_end
):
power_use_info
=
await
company_power_use_info_new15
(
company_id
,
es_time_start
,
power_use_info
=
await
company_power_use_info_new15
(
company_id
,
es_time_start
,
es_time_end
)
es_time_end
)
if
power_use_info
[
"kwh"
]:
if
power_use_info
[
"kwh"
]:
unit_price
=
power_use_info
[
"charge"
]
/
power_use_info
[
"kwh"
]
unit_price
=
power_use_info
[
"charge"
]
/
power_use_info
[
"kwh"
]
...
@@ -835,7 +849,7 @@ async def power_charge_price_new15(cid):
...
@@ -835,7 +849,7 @@ async def power_charge_price_new15(cid):
year
=
now
.
year
-
1
year
=
now
.
year
-
1
last_month_start
=
datetime
(
year
=
year
,
month
=
last_month
,
day
=
1
)
last_month_start
=
datetime
(
year
=
year
,
month
=
last_month
,
day
=
1
)
else
:
else
:
last_month_start
=
datetime
(
year
=
now
.
year
,
month
=
now
.
month
-
1
,
day
=
1
)
last_month_start
=
datetime
(
year
=
now
.
year
,
month
=
now
.
month
-
1
,
day
=
1
)
last_month_end
=
datetime
(
year
=
now
.
year
,
month
=
now
.
month
,
day
=
1
)
last_month_end
=
datetime
(
year
=
now
.
year
,
month
=
now
.
month
,
day
=
1
)
last_month_datas
=
await
company_power_use_info_new15
(
last_month_datas
=
await
company_power_use_info_new15
(
cid
,
str
(
last_month_start
),
str
(
last_month_end
)
cid
,
str
(
last_month_start
),
str
(
last_month_end
)
...
@@ -934,7 +948,7 @@ async def power_factor_new15(cid):
...
@@ -934,7 +948,7 @@ async def power_factor_new15(cid):
"""首页获取实时功率因数, 上月功率因数"""
"""首页获取实时功率因数, 上月功率因数"""
point_sql
=
"select pid,inlid from point where cid=
%
s and add_to_company=1"
point_sql
=
"select pid,inlid from point where cid=
%
s and add_to_company=1"
async
with
MysqlUtil
()
as
conn
:
async
with
MysqlUtil
()
as
conn
:
points
=
await
conn
.
fetchall
(
point_sql
,
args
=
(
cid
,
))
points
=
await
conn
.
fetchall
(
point_sql
,
args
=
(
cid
,))
point_ids
=
[
i
[
"pid"
]
for
i
in
points
]
point_ids
=
[
i
[
"pid"
]
for
i
in
points
]
now
=
datetime
.
now
()
now
=
datetime
.
now
()
if
now
.
month
==
1
:
if
now
.
month
==
1
:
...
@@ -961,7 +975,7 @@ async def power_factor_new15(cid):
...
@@ -961,7 +975,7 @@ async def power_factor_new15(cid):
dt
=
pendulum
.
now
(
tz
=
"Asia/Shanghai"
)
dt
=
pendulum
.
now
(
tz
=
"Asia/Shanghai"
)
tstamp
=
dt
.
int_timestamp
//
(
15
*
60
)
*
(
15
*
60
)
tstamp
=
dt
.
int_timestamp
//
(
15
*
60
)
*
(
15
*
60
)
dt
=
pendulum
.
from_timestamp
(
tstamp
,
tz
=
"Asia/Shanghai"
)
dt
=
pendulum
.
from_timestamp
(
tstamp
,
tz
=
"Asia/Shanghai"
)
end_dt
=
(
dt
-
timedelta
(
minutes
=
15
))
.
strftime
(
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
)
end_dt
=
(
dt
-
timedelta
(
minutes
=
15
))
.
strftime
(
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
)
str_dt
=
dt
.
strftime
(
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
)
str_dt
=
dt
.
strftime
(
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
)
electric_sql
=
f
"SELECT pid,create_time,pttl_mean,qttl_mean FROM "
\
electric_sql
=
f
"SELECT pid,create_time,pttl_mean,qttl_mean FROM "
\
f
"`point_15min_electric` where create_time in "
\
f
"`point_15min_electric` where create_time in "
\
...
@@ -1415,7 +1429,7 @@ async def electric_use_info_points_sdu_new15(start, end, points):
...
@@ -1415,7 +1429,7 @@ async def electric_use_info_points_sdu_new15(start, end, points):
f
"where pid in
%
s and event_datetime BETWEEN
%
s and
%
s "
\
f
"where pid in
%
s and event_datetime BETWEEN
%
s and
%
s "
\
f
"and event_type in
%
s group by importance"
f
"and event_type in
%
s group by importance"
async
with
MysqlUtil
()
as
conn
:
async
with
MysqlUtil
()
as
conn
:
results
=
await
conn
.
fetchall
(
sql
,
args
=
(
points
,
start
,
end
,
results
=
await
conn
.
fetchall
(
sql
,
args
=
(
points
,
start
,
end
,
SDU_ALARM_LIST
))
SDU_ALARM_LIST
))
first_alarm_cnt
=
0
first_alarm_cnt
=
0
...
@@ -1470,7 +1484,8 @@ async def optimization_count_info_new(company_id: int):
...
@@ -1470,7 +1484,8 @@ async def optimization_count_info_new(company_id: int):
)
)
es_end_time
=
pendulum
.
datetime
(
now
.
year
,
now
.
month
,
1
)
.
strftime
(
es_end_time
=
pendulum
.
datetime
(
now
.
year
,
now
.
month
,
1
)
.
strftime
(
"
%
Y-
%
m-
%
dT
%
H:
%
M:
%
S+08:00"
)
"
%
Y-
%
m-
%
dT
%
H:
%
M:
%
S+08:00"
)
power_use_info
=
await
company_power_use_info_new15
(
company_id
,
es_start_time
,
power_use_info
=
await
company_power_use_info_new15
(
company_id
,
es_start_time
,
es_end_time
)
es_end_time
)
month_charge
=
power_use_info
[
"charge"
]
month_charge
=
power_use_info
[
"charge"
]
count_info_map
=
{
count_info_map
=
{
...
...
unify_api/utils/time_format.py
View file @
fb18f2f4
...
@@ -115,6 +115,7 @@ def proxy_power_slots(start, end, date_format="MM-DD", is_duration=False):
...
@@ -115,6 +115,7 @@ def proxy_power_slots(start, end, date_format="MM-DD", is_duration=False):
slots
.
append
(
dt
)
slots
.
append
(
dt
)
return
slots
return
slots
def
day_of_month
(
start
):
def
day_of_month
(
start
):
"""这个月有几天"""
"""这个月有几天"""
start_f
=
my_pendulum
.
from_format
(
start
,
'YYYY-MM-DD HH:mm:ss'
)
start_f
=
my_pendulum
.
from_format
(
start
,
'YYYY-MM-DD HH:mm:ss'
)
...
@@ -311,7 +312,7 @@ def convert_to_es_str(str1, format="YYYY-MM-DD HH:mm:ss"):
...
@@ -311,7 +312,7 @@ def convert_to_es_str(str1, format="YYYY-MM-DD HH:mm:ss"):
return
str
(
es_date
)
return
str
(
es_date
)
def
last_time_str
(
start
,
end
,
date_type
):
def
last_time_str
(
start
,
end
,
date_type
,
date_end
=
False
):
"""年月日, 获取上一周期时间"""
"""年月日, 获取上一周期时间"""
if
date_type
not
in
(
"day"
,
"month"
,
"year"
):
if
date_type
not
in
(
"day"
,
"month"
,
"year"
):
return
None
return
None
...
@@ -319,12 +320,21 @@ def last_time_str(start, end, date_type):
...
@@ -319,12 +320,21 @@ def last_time_str(start, end, date_type):
end_f
=
my_pendulum
.
from_format
(
end
,
'YYYY-MM-DD HH:mm:ss'
)
end_f
=
my_pendulum
.
from_format
(
end
,
'YYYY-MM-DD HH:mm:ss'
)
if
date_type
==
"day"
:
if
date_type
==
"day"
:
start_last
=
start_f
.
subtract
(
days
=
1
)
start_last
=
start_f
.
subtract
(
days
=
1
)
if
date_end
:
end_last
=
start_last
.
end_of
(
unit
=
date_type
)
else
:
end_last
=
end_f
.
subtract
(
days
=
1
)
end_last
=
end_f
.
subtract
(
days
=
1
)
elif
date_type
==
"month"
:
elif
date_type
==
"month"
:
start_last
=
start_f
.
subtract
(
months
=
1
)
start_last
=
start_f
.
subtract
(
months
=
1
)
if
date_end
:
end_last
=
start_last
.
end_of
(
unit
=
date_type
)
else
:
end_last
=
end_f
.
subtract
(
months
=
1
)
end_last
=
end_f
.
subtract
(
months
=
1
)
else
:
else
:
start_last
=
start_f
.
subtract
(
years
=
1
)
start_last
=
start_f
.
subtract
(
years
=
1
)
if
date_end
:
end_last
=
start_last
.
end_of
(
unit
=
date_type
)
else
:
end_last
=
end_f
.
subtract
(
years
=
1
)
end_last
=
end_f
.
subtract
(
years
=
1
)
return
start_last
.
format
(
"YYYY-MM-DD HH:mm:ss"
),
end_last
.
format
(
return
start_last
.
format
(
"YYYY-MM-DD HH:mm:ss"
),
end_last
.
format
(
"YYYY-MM-DD HH:mm:ss"
)
"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