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
21b257c1
Commit
21b257c1
authored
Jul 03, 2023
by
lcn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bug修复
parent
d2c161bf
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
76 additions
and
72 deletions
+76
-72
list_point.py
unify_api/modules/common/views/list_point.py
+19
-17
electric_dao.py
unify_api/modules/electric/dao/electric_dao.py
+2
-3
count_info_pds.py
unify_api/modules/home_page/procedures/count_info_pds.py
+55
-52
No files found.
unify_api/modules/common/views/list_point.py
View file @
21b257c1
...
...
@@ -23,39 +23,41 @@ async def post_list_point(req, body: ListPointRequest) -> ListPointResponse:
list_point
=
[]
points
=
{}
groups
=
{}
sql
=
"SELECT p.pid,p.mtid, p.name, p.add_to_company FROM point p "
\
"left join monitor m on p.mtid = m.mtid "
\
"left join monitor_reuse mr on p.mtid = mr.mtid "
\
"WHERE m.demolished = 0 and (p.cid=
%
s or mr.cid =
%
s) "
# 查询属于当前工厂下的监测点 + 其他工厂但是被复用到当前工厂的监测点
if
not
is_power_equipment
:
sql
=
"SELECT p.pid,p.mtid, p.name, p.add_to_company FROM point p "
\
"left join monitor_reuse m on p.mtid = m.mtid "
\
"WHERE p.cid=
%
s or m.cid =
%
s"
else
:
if
is_power_equipment
:
# 动力设备
sql
=
"SELECT p.pid,p.mtid, p.name, p.add_to_company FROM point p "
\
"left join monitor m on p.mtid = m.mtid "
\
"left join monitor_reuse mr on p.mtid = mr.mtid "
\
"WHERE m.demolished = 0 and m.is_power_equipment = 1 and ("
\
"p.cid=
%
s or mr.cid =
%
s)"
sql
+=
" and m.is_power_equipment = 1 "
async
with
MysqlUtil
()
as
conn
:
result
=
await
conn
.
fetchall
(
sql
,
args
=
(
cid
,
cid
))
if
not
result
:
return
ListPointResponse
(
points
=
list_point
,
inlines
=
[],
power_show_all
=
0
)
# 去调拆表的POINT
point_ids
=
[
point
[
"pid"
]
for
point
in
result
]
point_mid_map
,
point_count
=
await
point_to_mid
(
point_ids
)
result
=
[
point
for
point
in
result
if
point
[
"pid"
]
in
point_mid_map
]
for
res
in
result
:
pid
=
res
.
get
(
"pid"
)
points
[
pid
]
=
res
# 获取相应的mtid
point_map_mtids
=
[
point
[
"mtid"
]
for
point
in
result
if
point
[
'pid'
]
in
point_mid_map
]
# 根据pid获取mtd
sql
=
"SELECT ln.lid, mr.`name` `group`, ln.item FROM location ln LEFT JOIN"
\
" monitor mr on ln.mtid = mr.mtid WHERE ( ln.cid=
%
s or ln.mtid in "
\
"
%
s ) and ln.`ad_type` in
%
s"
try
:
async
with
MysqlUtil
()
as
conn
:
result
=
await
conn
.
fetchall
(
sql
,
args
=
(
...
...
@@ -68,7 +70,7 @@ async def post_list_point(req, body: ListPointRequest) -> ListPointResponse:
except
Exception
as
e
:
log
.
exception
(
e
)
return
ListPointResponse
()
.
db_error
()
for
pid
,
point_info
in
points
.
items
():
name
=
point_info
.
get
(
"name"
)
add_to_company
=
point_info
[
"add_to_company"
]
...
...
@@ -80,7 +82,7 @@ async def post_list_point(req, body: ListPointRequest) -> ListPointResponse:
comm_point
=
CommonPoint
(
name
=
name
,
point_id
=
pid
,
locations
=
locations
,
add_to_company
=
add_to_company
)
list_point
.
append
(
comm_point
)
async
with
MysqlUtil
()
as
conn
:
sql
=
"SELECT inlid, `name` FROM inline WHERE cid=
%
s"
inlines
=
await
conn
.
fetchall
(
sql
,
args
=
(
cid
,))
...
...
unify_api/modules/electric/dao/electric_dao.py
View file @
21b257c1
...
...
@@ -75,12 +75,11 @@ async def get_elec_mtid_sid_by_cid(cid):
async
def
load_add_to_compy_ids
(
cid
):
if
not
isinstance
(
cid
,
(
list
,
tuple
)):
cid
=
[
cid
]
symbol
=
"in"
if
isinstance
(
cid
,
(
list
,
tuple
))
else
"="
db
=
SETTING
.
mysql_db
sql
=
f
"SELECT monitor.mtid, monitor.sid FROM {db}.monitor "
\
f
"INNER JOIN {db}.point ON point.mtid=monitor.mtid "
\
f
"WHERE monitor.cid
in
%
s AND point.add_to_company=1 "
\
f
"WHERE monitor.cid
{symbol}
%
s AND point.add_to_company=1 "
\
f
"AND monitor.demolished=0;"
async
with
MysqlUtil
()
as
conn
:
ids
=
await
conn
.
fetchall
(
sql
,
(
cid
,))
...
...
unify_api/modules/home_page/procedures/count_info_pds.py
View file @
21b257c1
...
...
@@ -141,40 +141,40 @@ async def normal_rate_of_location(cid):
lids
=
list
(
loc_infos
.
keys
())
if
not
lids
:
return
"100
%
"
,
"100
%
"
prefix
=
f
"real_time:adio:{SETTING.mysql_db}"
keys
=
[
f
"{prefix}:{lid}"
for
lid
in
lids
]
rt_rlts
=
await
RedisUtils
()
.
mget
(
keys
)
rt_adios
=
[
json
.
loads
(
r
)
for
r
in
rt_rlts
if
r
]
d_rt_adio
=
{
adio
[
"lid"
]:
adio
for
adio
in
rt_adios
}
now_ts
=
pendulum
.
now
(
tz
=
CST
)
.
int_timestamp
for
lid
,
d_loc
in
loc_infos
.
items
():
d_stats
[
d_loc
[
"type"
]][
"total"
]
+=
1
if
lid
not
in
d_rt_adio
:
continue
if
not
isinstance
(
d_loc
[
"threshold"
],
(
float
,
int
)):
continue
try
:
d_adio
=
d_rt_adio
[
lid
]
if
(
now_ts
-
d_adio
[
"ts"
])
>
constants
.
REAL_EXP_TIME
:
log
.
warn
(
f
"adio_current location_id={lid} has expire!"
)
continue
if
d_adio
[
"v"
]
<
d_loc
[
"threshold"
]:
d_stats
[
d_loc
[
"type"
]][
"normal"
]
+=
1
except
Exception
as
e
:
log
.
exception
(
f
"parse real time adio:{d_adio} exc, e:{e}"
)
if
d_stats
[
"temperature"
][
"total"
]
==
0
:
temp_qr
=
"100
%
"
else
:
norm
=
d_stats
[
"temperature"
][
"normal"
]
total
=
d_stats
[
"temperature"
][
"total"
]
temp_qr
=
str
(
round
((
norm
/
total
)
*
100
,
))
+
"
%
"
if
d_stats
[
"residual_current"
][
"total"
]
==
0
:
rc_qr
=
"100
%
"
else
:
...
...
@@ -187,12 +187,15 @@ async def normal_rate_of_location(cid):
async
def
real_time_load
(
cid
,
end_dt
=
None
):
"""实时负荷"""
td_tbls
=
[]
for
item
in
await
load_add_to_compy_ids
(
cid
):
add_to_compy_ids
=
await
load_add_to_compy_ids
(
cid
)
if
not
add_to_compy_ids
:
return
0
for
item
in
add_to_compy_ids
:
mtid
,
sid
=
item
[
"mtid"
],
item
[
"sid"
]
tbl
=
get_td_table_name
(
"electric"
,
mtid
)
td_tbls
.
append
(
tbl
)
td_tbls
.
append
(
f
"s_{sid.lower()}_e"
)
td_mt_tables
=
td3_tbl_compate
(
td_tbls
)
if
not
end_dt
:
end_dt
=
pendulum
.
now
(
tz
=
CST
)
...
...
@@ -204,7 +207,7 @@ async def real_time_load(cid, end_dt=None):
is_succ
,
results
=
await
get_td_engine_data
(
url
,
sql
)
if
not
is_succ
:
return
""
head
=
parse_td_columns
(
results
)
datas
=
[]
for
res
in
results
[
"data"
]:
...
...
@@ -222,7 +225,7 @@ async def power_count_info(cid):
now
=
datetime
.
now
()
start_time
=
(
now
-
timedelta
(
30
))
.
strftime
(
"
%
Y-
%
m-
%
d 00:00:00"
)
end_time
=
now
.
strftime
(
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
)
max_30d_load
,
_time
=
await
load_pttl_max
(
cid
,
start_time
,
end_time
,
-
1
)
cur_load
=
await
real_time_load
(
cid
)
return
round_2
(
cur_load
),
round_2
(
max_30d_load
)
...
...
@@ -314,17 +317,17 @@ async def optimization_count_info(company_id: int):
:param company_id:
:return:
"""
async
with
MysqlUtil
()
as
conn
:
sql
=
"SELECT inlid, `name` FROM inline WHERE cid=
%
s"
inlines
=
await
conn
.
fetchall
(
sql
,
args
=
(
company_id
,))
inline_ids
=
[
inline
[
"inlid"
]
for
inline
in
inlines
]
now
=
datetime
.
now
()
start_time
=
(
pendulum
.
datetime
(
now
.
year
,
now
.
month
,
1
)
.
subtract
(
months
=
1
)
.
strftime
(
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
)
.
subtract
(
months
=
1
)
.
strftime
(
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
)
)
end_time
=
pendulum
.
datetime
(
now
.
year
,
now
.
month
,
1
)
.
strftime
(
"
%
Y-
%
m-
%
d
%
H:
%
M:
%
S"
)
...
...
@@ -348,7 +351,7 @@ async def optimization_count_info(company_id: int):
}
)
return
count_info_map
now
=
datetime
.
now
()
if
now
.
month
==
1
:
last_month_dt
=
datetime
(
year
=
now
.
year
-
1
,
month
=
12
,
day
=
1
)
...
...
@@ -368,7 +371,7 @@ async def optimization_count_info(company_id: int):
2
,
)
total_pf_save
=
0
if
total_pf_save
<=
0
else
total_pf_save
pf_kpi_x_list
=
[
i
[
"kpi_x"
]
for
i
in
power_factor_results
if
type
(
i
[
"kpi_x"
])
in
[
int
,
float
]
...
...
@@ -384,19 +387,19 @@ async def optimization_count_info(company_id: int):
pf_desc
=
"空间适中"
else
:
pf_desc
=
"空间较大"
count_info_map
[
"power_factor"
]
=
{
"save_charge"
:
total_pf_save
if
pf_kpi_x
!=
""
else
""
,
"kpi_x"
:
pf_kpi_x
,
"desc"
:
pf_desc
,
}
# 移峰填谷指数
async
with
MysqlUtil
()
as
conn
:
sql
=
"select `score`, `cost_save` from `algo_plsi_result` "
\
"where `inlid` in
%
s and `month` =
%
s"
pcvfs
=
await
conn
.
fetchall
(
sql
,
args
=
(
inline_ids
,
last_month_str
))
pcvf_kpi_x_list
=
[
i
[
"score"
]
for
i
in
pcvfs
if
type
(
i
[
"score"
])
in
[
int
,
float
]]
pcvf_kpi_x
=
min
(
pcvf_kpi_x_list
)
if
len
(
pcvf_kpi_x_list
)
else
""
...
...
@@ -404,7 +407,7 @@ async def optimization_count_info(company_id: int):
sum
([
i
[
"cost_save"
]
for
i
in
pcvfs
if
i
[
"cost_save"
]
and
i
[
"cost_save"
]
>=
0
]),
2
)
if
pcvf_kpi_x
==
""
:
pcvf_desc
=
""
elif
pcvf_kpi_x
>=
90
:
...
...
@@ -415,14 +418,14 @@ async def optimization_count_info(company_id: int):
pcvf_desc
=
"空间适中"
else
:
pcvf_desc
=
"空间较大"
total_pcvf_save
=
0
if
total_pcvf_save
<=
0
else
total_pcvf_save
count_info_map
[
"pcvf"
]
=
{
"save_charge"
:
total_pcvf_save
if
pcvf_kpi_x
!=
""
else
""
,
"kpi_x"
:
pcvf_kpi_x
,
"desc"
:
pcvf_desc
,
}
# 经济运行
async
with
MysqlUtil
()
as
conn
:
sql
=
"select `kpi_x`, `save_charge`, `mean_load_factor` "
\
...
...
@@ -458,13 +461,13 @@ async def optimization_count_info(company_id: int):
economic_desc
=
"空间适中"
else
:
economic_desc
=
"空间较大"
count_info_map
[
"power_save"
]
=
{
"save_charge"
:
total_economic_save
if
economic_kpi_x
!=
""
else
""
,
"kpi_x"
:
economic_kpi_x
,
"desc"
:
economic_desc
,
}
# 最大需量
async
with
MysqlUtil
()
as
conn
:
sql
=
(
...
...
@@ -475,7 +478,7 @@ async def optimization_count_info(company_id: int):
"where b.inlid in
%
s and a.month =
%
s and b.valid=1;"
)
md_spaces
=
await
conn
.
fetchall
(
sql
,
args
=
(
inline_ids
,
last_month_str
))
md_space_kpi_x_list
=
[
i
[
"kpi_x"
]
for
i
in
md_spaces
if
type
(
i
[
"kpi_x"
])
in
[
int
,
float
]]
md_space_kpi_x
=
max
(
md_space_kpi_x_list
)
if
len
(
...
...
@@ -504,7 +507,7 @@ async def optimization_count_info(company_id: int):
"kpi_x"
:
md_space_kpi_x
,
"desc"
:
md_space_desc
,
}
total_save_cost
=
0
for
_
,
item
in
count_info_map
.
items
():
total_save_cost
+=
(
...
...
@@ -513,12 +516,12 @@ async def optimization_count_info(company_id: int):
)
save_percent
=
total_save_cost
/
month_charge
if
month_charge
else
""
count_info_map
[
"save_percent"
]
=
save_percent
# 计算最大需量
async
with
MysqlUtil
()
as
conn
:
sql
=
"select `price_md`,`price_tc` from `price_policy` where `cid`=
%
s"
price_policy
=
await
conn
.
fetchone
(
sql
,
args
=
(
company_id
,))
total_md_space_charge
=
sum
(
[
i
[
"inline_md_charge"
]
for
i
in
md_spaces
if
i
[
"inline_md_charge"
]])
total_md_space_p
=
(
...
...
@@ -527,7 +530,7 @@ async def optimization_count_info(company_id: int):
else
""
)
count_info_map
[
"md_space_p"
]
=
total_md_space_p
# 经济运行最低负载率
mean_load_factors
=
[
i
[
"mean_load_factor"
]
for
i
in
economic_operations
if
...
...
@@ -583,7 +586,7 @@ async def electric_use_info_points_sdu(start, end, points):
async
with
MysqlUtil
()
as
conn
:
results
=
await
conn
.
fetchall
(
sql
,
args
=
(
points
,
start
,
end
,
SDU_ALARM_LIST
))
first_alarm_cnt
=
0
second_alarm_cnt
=
0
third_alarm_cnt
=
0
...
...
@@ -594,15 +597,15 @@ async def electric_use_info_points_sdu(start, end, points):
second_alarm_cnt
+=
result
[
"doc_count"
]
elif
result
[
"importance"
]
==
Importance
.
Third
.
value
:
third_alarm_cnt
+=
result
[
"doc_count"
]
alarm_score
=
(
first_alarm_cnt
*
2
+
second_alarm_cnt
*
1
+
third_alarm_cnt
*
0.5
)
/
len
(
points
)
if
alarm_score
>=
15
:
alarm_score
=
15
electric_use_score
=
get_electric_index
(
alarm_score
)
log
.
info
(
"point_len={} alarm_score={} electric_use_score={}"
.
format
(
len
(
points
),
alarm_score
,
electric_use_score
...
...
@@ -623,16 +626,16 @@ async def optimization_count_info_new(company_id: int):
:param company_id:
:return:
"""
inlines
=
await
get_inline_by_cid
(
company_id
)
inline_ids
=
[
inline
[
"inlid"
]
for
inline
in
inlines
]
# 获取公司上月用电
now
=
datetime
.
now
()
es_start_time
=
(
pendulum
.
datetime
(
now
.
year
,
now
.
month
,
1
)
.
subtract
(
months
=
1
)
.
strftime
(
"
%
Y-
%
m-
%
dT
%
H:
%
M:
%
S+08:00"
)
.
subtract
(
months
=
1
)
.
strftime
(
"
%
Y-
%
m-
%
dT
%
H:
%
M:
%
S+08:00"
)
)
es_end_time
=
pendulum
.
datetime
(
now
.
year
,
now
.
month
,
1
)
.
strftime
(
"
%
Y-
%
m-
%
dT
%
H:
%
M:
%
S+08:00"
)
...
...
@@ -664,7 +667,7 @@ async def optimization_count_info_new(company_id: int):
last_month_dt
=
datetime
(
year
=
now
.
year
,
month
=
now
.
month
-
1
,
day
=
1
)
last_month_str
=
datetime
.
strftime
(
last_month_dt
,
"
%
Y-
%
m"
)
# 功率因数
power_factor_results
=
await
get_power_factor_kpi
(
inline_ids
,
last_month_dt
)
total_pf_save
=
round
(
...
...
@@ -677,7 +680,7 @@ async def optimization_count_info_new(company_id: int):
(
i
[
"name"
],
i
[
"kpi_x"
])
for
i
in
power_factor_results
if
type
(
i
[
"kpi_x"
])
in
[
int
,
float
]
]
if
len
(
pf_kpi_x_list
):
pf_kpi_x_num
=
[
pf_kpi
[
1
]
for
pf_kpi
in
pf_kpi_x_list
]
pf_kpi_x
=
min
(
pf_kpi_x_num
)
...
...
@@ -712,12 +715,12 @@ async def optimization_count_info_new(company_id: int):
pcvfs
=
await
get_pcvf_kpi
(
inline_ids
,
last_month_str
)
pcvf_kpi_x_list
=
[(
i
[
"name"
],
i
[
"score"
])
for
i
in
pcvfs
if
type
(
i
[
"score"
])
in
[
int
,
float
]]
if
len
(
pcvf_kpi_x_list
):
pcvf_kpi_x_num
=
[
pcvf_kpi
[
1
]
for
pcvf_kpi
in
pcvf_kpi_x_list
]
pcvf_kpi_x
=
min
(
pcvf_kpi_x_num
)
pcvf_kpi_x_name
=
[]
if
pcvf_kpi_x
<
70
:
for
index
,
kpi_num
in
enumerate
(
pcvf_kpi_x_num
):
if
kpi_num
<
70
:
...
...
@@ -731,7 +734,7 @@ async def optimization_count_info_new(company_id: int):
f
"引入新能源,转移高峰电量至低谷"
else
:
pcvf_desc
=
"平均电价处于较低水平,请继续保持"
else
:
pcvf_kpi_x
=
""
pcvf_desc
=
""
...
...
@@ -749,7 +752,7 @@ async def optimization_count_info_new(company_id: int):
sum
([
i
[
"cost_save"
]
for
i
in
pcvfs
if
i
[
"cost_save"
]
and
i
[
"cost_save"
]
>=
0
]),
2
)
total_pcvf_save
=
0
if
total_pcvf_save
<=
0
else
total_pcvf_save
count_info_map
[
"pcvf"
]
=
{
"save_charge"
:
total_pcvf_save
if
pcvf_kpi_x
!=
""
else
""
,
...
...
@@ -757,7 +760,7 @@ async def optimization_count_info_new(company_id: int):
"desc"
:
pcvf_desc
,
"space"
:
pcvf_space
}
# 经济运行
economic_operations
=
await
get_economic_kpi
(
inline_ids
,
last_month_str
)
economic_kpi_x_list
=
[
...
...
@@ -818,14 +821,14 @@ async def optimization_count_info_new(company_id: int):
"desc"
:
economic_desc
,
"space"
:
econ_space
}
# 容量、需量价格
price_policy
=
await
price_policy_by_cid
(
company_id
)
price_md
=
price_policy
[
"price_md"
]
if
price_policy
[
"price_md"
]
else
0
price_tc
=
price_policy
[
"price_tc"
]
if
price_policy
[
"price_tc"
]
else
0
# 最大需量
md_spaces
=
await
get_md_space
(
inline_ids
,
last_month_dt
)
md_space_kpi_x_list
=
[
i
[
"kpi_x"
]
for
i
in
md_spaces
if
type
(
i
[
"kpi_x"
])
in
[
int
,
float
]]
md_space_kpi_x
=
max
(
md_space_kpi_x_list
)
if
len
(
...
...
@@ -855,13 +858,13 @@ async def optimization_count_info_new(company_id: int):
md_space_tc_runtimes
[
index
][
"tc_runtime"
]
*
price_tc
>=
\
price_md
*
item
[
"inline_md_predict"
]:
md_space_name
.
append
(
md_space_tc_runtimes
[
index
][
"name"
])
if
len
(
md_space_name
):
md_space_desc
=
f
"若次月负荷无较大变动,建议{'、'.join(md_space_name)}"
\
f
"选择按最大需量计费"
else
:
md_space_desc
=
"不存在容改需空间"
count_info_map
[
"md_space"
]
=
{
"save_charge"
:
total_md_space_save
if
md_space_kpi_x
!=
""
else
""
,
"kpi_x"
:
md_space_kpi_x
,
...
...
@@ -903,7 +906,7 @@ async def cid_alarm_importance_count(cid, start, end):
point_list
=
[
i
[
"pid"
]
for
i
in
monitor_point_list
]
es_res
=
await
sdu_alarm_importance_dao
(
start
,
end
,
point_list
)
es_res_key
=
{
i
[
"key"
]:
i
for
i
in
es_res
}
res_list
=
[]
for
info
in
monitor_point_list
:
name
=
info
.
get
(
"name"
)
...
...
@@ -919,7 +922,7 @@ async def cid_alarm_importance_count(cid, start, end):
tmp_dic
[
"second"
]
+=
b
[
"doc_count"
]
elif
b
[
"key"
]
==
Importance
.
Third
.
value
:
tmp_dic
[
"third"
]
+=
b
[
"doc_count"
]
tmp_dic
[
"alarm_count"
]
=
tmp_dic
[
"first"
]
+
tmp_dic
[
"second"
]
+
\
tmp_dic
[
"third"
]
res_list
.
append
(
tmp_dic
)
...
...
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