Commit ea3c9232 authored by ZZH's avatar ZZH

fix longgang data 2023-7-20

parent e8ab94b6
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) " \
......
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):
......
......@@ -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 (
......
......@@ -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="访问频繁,请10s后访问")
return success_res(code=4011, msg="访问频繁,请60s后访问")
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, 10, 1)
await RedisUtils().setex(access_lim_key, 60, 1)
return StbDataResp(rows=datas, total=results.get("rows", 0))
......
......@@ -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)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment