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
3eca62e3
Commit
3eca62e3
authored
Sep 08, 2022
by
peng.xiaozhe
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
zd-info-factory接口修复
parent
6d640792
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
56 additions
and
2 deletions
+56
-2
count_info_pds.py
unify_api/modules/home_page/procedures/count_info_pds.py
+54
-0
count_info_service.py
unify_api/modules/home_page/service/count_info_service.py
+2
-2
No files found.
unify_api/modules/home_page/procedures/count_info_pds.py
View file @
3eca62e3
...
...
@@ -38,6 +38,60 @@ from unify_api.modules.electric_optimization.dao.power_index import (
async
def
other_info
(
company_id
):
"""
今日报警数和累计安全运行天数,报警数
"""
alarm_sql
=
f
"""
SELECT
DATE(pevent.event_datetime) event_date,
COUNT(*) event_count
FROM
point_1min_event pevent
WHERE
cid =
%
s
GROUP BY
DATE(pevent.event_datetime)
"""
now_time
=
datetime
.
now
()
# 获取到工厂安装时间create_time
async
with
MysqlUtil
()
as
conn
:
company_sql
=
"select create_time from company where cid =
%
s"
alarm_data
=
await
conn
.
fetchone
(
alarm_sql
,
(
company_id
,))
company
=
await
conn
.
fetchone
(
company_sql
,
(
company_id
,))
create_time_timestamp
=
company
[
"create_time"
]
create_time
=
datetime
.
fromtimestamp
(
create_time_timestamp
)
today_alarm_count
=
0
alarm_count
=
0
if
not
alarm_data
:
log
.
warn
(
"No alarm data
%
s"
%
(
company_id
)
)
# 1. 增加逻辑,新增工厂如果还没有事件产生
# 系统安全运行天数: 当前时间 - 工厂安装时间 + 1
safe_run_days
=
(
now_time
-
create_time
)
.
days
+
1
return
today_alarm_count
,
safe_run_days
,
alarm_count
# 5. 构造返回
# 如果每天都有报警, 防止安全运行天数-1天, 所以total_days +2
total_days
=
(
now_time
-
create_time
)
.
days
+
2
has_alarm_days
=
0
for
data
in
alarm_data
:
create_time
.
strftime
(
"
%
Y-
%
m-
%
d"
)
if
data
[
"event_date"
]
.
strftime
(
"
%
Y-
%
m-
%
d"
)
==
str
(
now_time
)[:
10
]:
today_alarm_count
+=
data
[
"event_count"
]
if
data
[
"event_count"
]
!=
0
:
# 没有报警,看做是安全运行了,统计累计安全运行的天数
has_alarm_days
+=
1
alarm_count
+=
data
[
"event_count"
]
safe_run_days
=
total_days
-
has_alarm_days
log
.
info
(
f
"today_alarm_count={today_alarm_count} safe_run_days={safe_run_days}"
)
return
today_alarm_count
,
safe_run_days
,
alarm_count
async
def
other_info_old
(
company_id
):
"""
今日报警数和累计安全运行天数,报警数
:param company_id:
...
...
unify_api/modules/home_page/service/count_info_service.py
View file @
3eca62e3
...
...
@@ -13,7 +13,7 @@ from unify_api.modules.common.procedures.points import proxy_points, list_point
from
unify_api.modules.elec_charge.dao.elec_charge_dao
import
\
query_charge_aggs_points
,
point_aggs_kwh
from
unify_api.modules.elec_charge.procedures.elec_charge_pds
import
\
proxy_power
proxy_power
,
proxy_power15
from
unify_api.modules.home_page.components.count_info_proxy_cps
import
\
IycResp
,
IycmResp
,
RtrResp
,
AlarmLevelCnt
,
AlarmContentCnt
,
CmResp
,
\
ApcResp
,
AsiResp
,
HsiResp
,
AiiResp
...
...
@@ -51,7 +51,7 @@ async def post_zd_info_factory_service(cid_list):
safe_operation_days
+=
safe_run_days
total_alarm
+=
alarm_count
# 4. 累计监测用电
total_power
=
await
proxy_power
(
cid_list
)
total_power
=
await
proxy_power
15
(
cid_list
)
# 5. 日均碳排放 = 累计用电 * 0.754 / 总运行天数
# 运行天数
sql
=
"select create_time from company where cid =
%
s"
...
...
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