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
ea3c9232
Commit
ea3c9232
authored
Jul 20, 2023
by
ZZH
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix longgang data 2023-7-20
parent
e8ab94b6
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
7 additions
and
62 deletions
+7
-62
alarm_cps.py
unify_api/modules/common/procedures/alarm_cps.py
+1
-35
power_cps.py
unify_api/modules/common/procedures/power_cps.py
+0
-18
count_info_proxy.py
unify_api/modules/home_page/views/count_info_proxy.py
+2
-5
open_data_service.py
unify_api/modules/shidianu/service/open_data_service.py
+2
-2
open_data.py
unify_api/modules/shidianu/views/open_data.py
+2
-2
No files found.
unify_api/modules/common/procedures/alarm_cps.py
View file @
ea3c9232
from
pot_libs.es_util.es_utils
import
EsUtil
from
unify_api
import
constants
from
unify_api.constants
import
Importance
,
SDU_ALARM_LIST
from
unify_api.constants
import
SDU_ALARM_LIST
from
pot_libs.mysql_util.mysql_util
import
MysqlUtil
async
def
alarm_count
(
company_ids
):
query_body
=
{
"query"
:
{
"bool"
:
{
"filter"
:
[
{
"terms"
:
{
"cid"
:
company_ids
}},
{
"terms"
:
{
"importance"
:
[
Importance
.
First
.
value
,
Importance
.
Second
.
value
,
Importance
.
Third
.
value
,
]
}
},
]
}
},
"size"
:
0
,
"aggs"
:
{
"cid_alarm_aggs"
:
{
"terms"
:
{
"field"
:
"cid"
,
"size"
:
10000
}}},
}
async
with
EsUtil
()
as
es
:
es_result
=
await
es
.
search_origin
(
body
=
query_body
,
index
=
constants
.
POINT_1MIN_EVENT
)
cid_alarm_buckets
=
(
es_result
.
get
(
"aggregations"
,
{})
.
get
(
"cid_alarm_aggs"
,
{})
.
get
(
"buckets"
,
[])
)
total_alarm_cnt
=
sum
([
i
[
"doc_count"
]
for
i
in
cid_alarm_buckets
])
return
total_alarm_cnt
async
def
load_alarm_cnt_sdu
(
cids
):
sql
=
f
"select count(1) doc_count from point_1min_event "
\
f
"where cid in
%
s and importance in (1, 2, 3) "
\
...
...
unify_api/modules/common/procedures/power_cps.py
View file @
ea3c9232
from
pot_libs.es_util.es_utils
import
EsUtil
from
pot_libs.mysql_util.mysql_util
import
MysqlUtil
from
unify_api
import
constants
async
def
power_use_count
(
company_ids
):
query_body
=
{
"query"
:
{
"bool"
:
{
"filter"
:
[{
"terms"
:
{
"cid"
:
company_ids
}},
]}},
"size"
:
0
,
"aggs"
:
{
"kwh"
:
{
"sum"
:
{
"field"
:
"kwh"
}}},
}
async
with
EsUtil
()
as
es
:
es_result
=
await
es
.
search_origin
(
body
=
query_body
,
index
=
constants
.
COMPANY_15MIN_POWER
)
total_power
=
round
(
es_result
.
get
(
"aggregations"
,
{})
.
get
(
"kwh"
,
{})
.
get
(
"value"
)
or
0
,
2
)
return
total_power
async
def
load_cmpy_power
(
cids
):
...
...
unify_api/modules/home_page/views/count_info_proxy.py
View file @
ea3c9232
...
...
@@ -4,14 +4,11 @@ from pot_libs.mysql_util.mysql_util import MysqlUtil
from
pot_libs.sanic_api
import
summary
from
unify_api.constants
import
Product
,
PRODUCT
from
unify_api.modules.common.dao.common_dao
import
monitor_by_cid
from
unify_api.modules.common.procedures.alarm_cps
import
alarm_count
,
\
load_alarm_cnt_sdu
from
unify_api.modules.common.procedures.alarm_cps
import
load_alarm_cnt_sdu
from
unify_api.modules.common.procedures.cids
import
get_cids
,
get_cid_info
,
\
get_proxy_cids
from
unify_api.modules.common.procedures.common_cps
import
proxy_safe_run_info
from
unify_api.modules.common.procedures.points
import
proxy_points
from
unify_api.modules.common.procedures.power_cps
import
power_use_count
,
\
load_cmpy_power
from
unify_api.modules.common.procedures.power_cps
import
load_cmpy_power
from
unify_api.modules.elec_charge.procedures.elec_charge_pds
import
\
load_proxy_power
from
unify_api.modules.home_page.components.count_info_proxy_cps
import
(
...
...
unify_api/modules/shidianu/service/open_data_service.py
View file @
ea3c9232
...
...
@@ -71,7 +71,7 @@ async def stb_data_longgang_service(user_id, d_type):
access_lim_key
=
f
"access_data_{d_type}:{user_id}"
if
await
RedisUtils
()
.
get
(
access_lim_key
):
return
success_res
(
code
=
4011
,
msg
=
"访问频繁,请
1
0s后访问"
)
return
success_res
(
code
=
4011
,
msg
=
"访问频繁,请
6
0s后访问"
)
cids
=
[
223
]
if
not
await
get_power
(
user_id
,
cids
):
...
...
@@ -94,7 +94,7 @@ async def stb_data_longgang_service(user_id, d_type):
data
[
"ts"
]
=
data
[
"ts_origin"
]
data
.
pop
(
"ts_origin"
)
await
RedisUtils
()
.
setex
(
access_lim_key
,
1
0
,
1
)
await
RedisUtils
()
.
setex
(
access_lim_key
,
6
0
,
1
)
return
StbDataResp
(
rows
=
datas
,
total
=
results
.
get
(
"rows"
,
0
))
...
...
unify_api/modules/shidianu/views/open_data.py
View file @
ea3c9232
...
...
@@ -14,7 +14,7 @@ from pot_libs.settings import SETTING
from
unify_api.utils.time_format
import
last30_day_range
from
unify_api.modules.common.dao.common_dao
import
monitor_by_cid
from
unify_api.modules.home_page.service.count_info_service
import
safe_run_sdu
from
unify_api.modules.common.procedures.power_cps
import
power_use_count
from
unify_api.modules.common.procedures.power_cps
import
load_cmpy_power
from
unify_api.modules.common.procedures.alarm_cps
import
load_alarm_cnt_sdu
from
unify_api.modules.shidianu.service.open_data_service
import
get_power
from
unify_api.modules.common.components.select_company_cps
import
CmReq
...
...
@@ -112,7 +112,7 @@ async def post_home_page_data(req, body: CmReq) -> HomeDataResp:
online_rate
=
88
+
random
.
choice
([
1
,
1.5
,
2
,
2.5
,
3
,
3.5
,
4
])
# 4.累计用电
total_power
=
await
power_use_count
(
cids
)
total_power
=
await
load_cmpy_power
(
cids
)
# 5. 累计报警
total_alarm
=
await
load_alarm_cnt_sdu
(
cids
)
...
...
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