Commit 1b9dee42 authored by wang.wenrong's avatar wang.wenrong

Merge branch 'wwr' into 'develop'

精细监测

See merge request !35
parents 444ec2cc 5835292c
......@@ -57,7 +57,7 @@ class FineMonitorChartResp(Model, DbErr, ParamErr):
i: list = List("电流").items(Chart)
v: list = List("电压").items(Chart)
ctnum: int = Int("接线方式:包含两表法、三表法").eg(3)
@classmethod
def example(cls):
return {
......@@ -95,3 +95,39 @@ class FineMonitorInfoResp(Model, DbErr, ParamErr):
精确监测-指标统计返回
'''
info_list: list = List("指标统计列表").items(Statistics)
@dataclass
class ElectricIndexParam(Model):
item: str = Str("指标").eg("有功功率P(kW)")
max: float = Float("最大值").eg(3081.60)
max_time: str = Str("最大时间").eg("2022-12-24 23:59:59")
min: float = Float("最小值").eg(324)
min_time: str = Str("最小时间").eg("2022-12-24 12:12:12")
avg: float = Float("平均值").eg(2311.12)
@dataclass
class ElectricIndexListReq(Model):
cid: Cid
mtid: int = Int("单个mtid").eg(1)
start_time: str = Str("开始时间").eg("2022-12-24 00:00:00")
end_time: str = Str("结束时间").eg("2022-12-24 23:59:59")
@dataclass
class ElectricIndexParam(Model):
type: str = Str("类型").eg("temperature")
item: str = Str("指标").eg("有功功率P(kW)")
max: float = Float("最大值").eg(3081.60)
max_time: str = Str("最大时间").eg("2022-12-24 23:59:59")
min: float = Float("最小值").eg(324)
min_time: str = Str("最小时间").eg("2022-12-24 12:12:12")
avg: float = Float("平均值").eg(2311.12)
@dataclass
class ElectricIndexListResp(Model):
ctnum: int = Int("接线方式 2-两表法 3-三表法").eg(1)
general_param: list = List("常规参数").items(ElectricIndexParam)
electric_quality: list = List("电能质量").items(ElectricIndexParam)
safe_param: list = List("安全参数").items(ElectricIndexParam)
......@@ -174,3 +174,60 @@ async def get_point_1day_chart_dao(mtid, stats_items, date_start, date_end):
async with MysqlUtil() as conn:
data = await conn.fetchall(sql, )
return data
async def get_mtid_by_pid_dao(pid):
sql = f"""
SELECT
mtid
FROM
point
WHERE
pid = {pid}
"""
async with MysqlUtil() as conn:
data = await conn.fetchone(sql, )
return data
async def get_point_monitor_dao(id_value, field="m.mtid"):
sql = f"SELECT p.pid,m.meter_no,m.sid,p.ctr,p.ptr,p.ctnum,p.vc,p.tc," \
f"p.imax FROM `point` p INNER JOIN monitor m on m.mtid=p.mtid " \
f"where m.demolished = 0 and {field}=%s;"
async with MysqlUtil() as conn:
data = await conn.fetchone(sql, args=(id_value,))
return data
async def electric_index_list_dao(table_name, point_id, start, end):
"""
获取用电数据
:param table_name:
:param point_id:
:param start:
:param end:
:return:
"""
sql = f"SELECT * FROM {table_name} where pid=%s and create_time " \
f"BETWEEN %s and %s ORDER BY create_time desc"
async with MysqlUtil() as conn:
result = await conn.fetchall(sql, args=(point_id, start, end))
return result or []
async def electric_index_location_dao(table_name, mtid, start, end):
"""
获取安全数据
:param table_name:
:param mtid:
:param start:
:param end:
:return:
"""
location_sql = "SELECT mtid,lid,item,ad_type FROM location WHERE mtid=%s"
datas_sql = f"SELECT * from {table_name} where mtid = %s and create_time" \
f" BETWEEN '{start}' and '{end}' order by create_time desc"
async with MysqlUtil() as conn:
location_datas = await conn.fetchall(location_sql, args=(mtid,))
result = await conn.fetchall(datas_sql, args=(mtid,))
return location_datas or [], result or []
......@@ -2,6 +2,7 @@ from pot_libs.logger import log
from pot_libs.mysql_util.mysql_util import MysqlUtil
from pot_libs.es_util.es_utils import EsUtil
from unify_api import constants
import pandas as pd
async def get_location_by_ids(location_ids):
......@@ -255,14 +256,22 @@ async def get_point_data_chart_pds(ctnum, slots, data):
ia_dict, ib_dict, ic_dict, pttl_dict, qttl_dict, ua_dict, ub_dict, uc_dict \
= {}, {}, {}, {}, {}, {}, {}, {}
[ia_dict.update({i.get("create_time"): i.get("ia_mean")}) for i in data]
[ib_dict.update({i.get("create_time"): i.get("ib_mean")}) for i in data]
[ic_dict.update({i.get("create_time"): i.get("ic_mean")}) for i in data]
[pttl_dict.update({i.get("create_time"): i.get("pttl_mean")}) for i in data]
[qttl_dict.update({i.get("create_time"): i.get("qttl_mean")}) for i in data]
[ua_dict.update({i.get("create_time"): i.get("ua_mean")}) for i in data]
[ub_dict.update({i.get("create_time"): i.get("ub_mean")}) for i in data]
[uc_dict.update({i.get("create_time"): i.get("uc_mean")}) for i in data]
[ia_dict.update({i.get("create_time"): i.get("ia_mean")}) for i in
data]
[ib_dict.update({i.get("create_time"): i.get("ib_mean")}) for i in
data]
[ic_dict.update({i.get("create_time"): i.get("ic_mean")}) for i in
data]
[pttl_dict.update({i.get("create_time"): i.get("pttl_mean")}) for i in
data]
[qttl_dict.update({i.get("create_time"): i.get("qttl_mean")}) for i in
data]
[ua_dict.update({i.get("create_time"): i.get("ua_mean")}) for i in
data]
[ub_dict.update({i.get("create_time"): i.get("ub_mean")}) for i in
data]
[uc_dict.update({i.get("create_time"): i.get("uc_mean")}) for i in
data]
ia_list, ib_list, ic_list, pttl_list, qttl_list, ua_list, ub_list, uc_list \
= [], [], [], [], [], [], [], []
......@@ -298,12 +307,18 @@ async def get_point_data_chart_pds(ctnum, slots, data):
ia_dict, ic_dict, pttl_dict, qttl_dict, uab_dict, ucb_dict, \
= {}, {}, {}, {}, {}, {}
[ia_dict.update({i.get("create_time"): i.get("ia_mean")}) for i in data]
[ic_dict.update({i.get("create_time"): i.get("ic_mean")}) for i in data]
[pttl_dict.update({i.get("create_time"): i.get("pttl_mean")}) for i in data]
[qttl_dict.update({i.get("create_time"): i.get("qttl_mean")}) for i in data]
[uab_dict.update({i.get("create_time"): i.get("ua_mean")}) for i in data]
[ucb_dict.update({i.get("create_time"): i.get("ub_mean")}) for i in data]
[ia_dict.update({i.get("create_time"): i.get("ia_mean")}) for i in
data]
[ic_dict.update({i.get("create_time"): i.get("ic_mean")}) for i in
data]
[pttl_dict.update({i.get("create_time"): i.get("pttl_mean")}) for i in
data]
[qttl_dict.update({i.get("create_time"): i.get("qttl_mean")}) for i in
data]
[uab_dict.update({i.get("create_time"): i.get("ua_mean")}) for i in
data]
[ucb_dict.update({i.get("create_time"): i.get("ub_mean")}) for i in
data]
ia_list, ic_list, pttl_list, qttl_list, uab_list, ucb_list \
= [], [], [], [], [], []
......@@ -327,3 +342,243 @@ async def get_point_data_chart_pds(ctnum, slots, data):
power.append(pttl_value)
power.append(qttl_value)
return i, v, power
GENERAL_PARAM_FIELD_2 = [
"lf_mean", "lf_min", "lf_max", "pttl_mean", "pttl_min",
"pttl_max", "qttl_mean", "qttl_min", "qttl_max",
"costtl_mean", "costtl_min", "costtl_max", "uab_mean",
"uab_min", "uab_max", "ucb_mean", "ucb_min", "ucb_max",
"ia_mean", "ia_min", "ia_max", "ic_mean", "ic_min",
"ic_max", "freq_mean", "freq_min", "freq_max"
]
GENERAL_PARAM_FIELD_3 = [
"lf_mean", "lf_min", "lf_max", "pttl_mean", "pttl_min",
"pttl_max", "qttl_mean", "qttl_min", "qttl_max",
"costtl_mean", "costtl_min", "costtl_max", "ua_mean",
"ua_min", "ua_max", "ub_mean", "ub_min", "ub_max",
"uc_mean", "uc_min", "uc_max", "ia_mean", "ia_min",
"ia_max", "ib_mean", "ib_min", "ib_max", "ic_mean",
"ic_min", "ic_max", "freq_mean", "freq_min",
"freq_max"
]
ELECTRIC_QUALITY_FIELD_2 = [
"ubl_mean", "ubl_min", "ubl_max", "ibl_mean",
"ibl_min", "ibl_max", "thduab_mean", "thduab_min",
"thduab_max", "thducb_mean", "thducb_min",
"thducb_max", "thdia_mean", "thdia_min",
"thdia_max", "thdic_mean", "thdic_min", "thdic_max",
"uab_dev_mean", "uab_dev_min", "uab_dev_max",
"freq_dev_mean", "freq_dev_min", "freq_dev_max",
]
ELECTRIC_QUALITY_FIELD_3 = [
"ubl_mean", "ubl_min", "ubl_max", "ibl_mean",
"ibl_min", "ibl_max", "thdua_mean", "thdua_min",
"thdua_max", "thdub_mean", "thdub_min", "thdub_max",
"thduc_mean", "thduc_min", "thduc_max",
"thdia_mean", "thdia_min", "thdia_max",
"thdib_mean", "thdib_min", "thdib_max",
"thdic_mean", "thdic_min", "thdic_max",
"ua_dev_mean", "ua_dev_min", "ua_dev_max",
"freq_dev_mean", "freq_dev_min", "freq_dev_max"
]
def cal_electic_value(datas, index_fields, mtid=None):
"""
用电指数数据封装
:param datas: 数据
:param index_fields: 字段
:param mtid: 字段是否需要合并mtid
:return:
"""
df = pd.DataFrame(list(datas))
indexes_list = []
_index_fields = {field.rsplit("_", 1)[0] for field in index_fields}
for item in _index_fields:
if datas:
# item = item.rsplit("_", 1)[0]
max_item_name = f"{item}_max"
max_value = df[max_item_name].max()
if not pd.isna(max_value):
max_datas = df.loc[df[max_item_name].idxmax()].to_dict()
max_time = max_datas.get(f"{max_item_name}_time")
max_time = "" if pd.isnull(max_time) else str(max_time)
else:
max_value, max_time = "", ""
min_item_name = f"{item}_min"
min_value = df[min_item_name].min()
if not pd.isna(min_value):
min_datas = df.loc[df[min_item_name].idxmin()].to_dict()
min_time = min_datas.get(f"{min_item_name}_time")
min_time = "" if pd.isnull(min_time) else str(min_time)
else:
min_value, min_time = "", ""
mean_item_name = f"{item}_mean"
avg_value = df[mean_item_name].mean()
if not pd.isna(avg_value):
avg_value = round(avg_value, 2)
else:
avg_value = ""
# if not max_value and not min_value and not avg_value:
# continue
if mtid:
mtid = str(mtid)
electric_index = dict(
index=item,
)
electric_index["max_" + mtid] = max_value
electric_index["max_time_" + mtid] = max_time or ""
electric_index["min_" + mtid] = min_value
electric_index["min_time_" + mtid] = min_time or ""
electric_index["avg_" + mtid] = avg_value
else:
electric_index = dict(
item=item,
max=max_value,
max_time=max_time or "",
min=min_value,
min_time=min_time or "",
avg=avg_value,
)
else:
electric_index = dict(item=item, max="", max_time="", min="",
min_time="", avg="")
indexes_list.append(electric_index)
return indexes_list
def cal_aiao_value(location_datas, datas, mtid=None):
"""
安全指数数据封装
:param location_datas: 安全设置
:param datas: 数据
:param mtid: 字段是否需要合并mtid
:return:
"""
location_map = {loca["lid"]: loca for loca in location_datas}
df = pd.DataFrame(list(datas))
indexes_list = []
for lid, item in location_map.items():
if item["ad_type"] == "residual_current":
index = "漏电流"
else:
index = f"{item.get('item')}"
if datas:
current_df = df.loc[df["lid"] == lid]
if current_df.empty:
continue
max_value = current_df.value_max.max()
if not pd.isna(max_value):
max_datas = df.loc[
current_df.value_max.idxmax()].to_dict()
max_value_time = max_datas.get("value_max_time")
max_value_time = "" if pd.isnull(max_value_time) else str(
max_value_time)
max_value = round(max_value, 2)
else:
max_value, max_value_time = "", ""
min_value = current_df.value_min.min()
if not pd.isna(min_value):
min_datas = df.loc[
current_df.value_min.idxmin()].to_dict()
min_value_time = min_datas.get("value_min_time")
min_value_time = "" if pd.isnull(min_value_time) else str(
min_value_time)
min_value = round(min_value, 2)
else:
min_value, min_value_time = "", ""
mean_value = current_df.value_avg.mean()
if not pd.isna(mean_value):
mean_value = round(mean_value, 2)
else:
mean_value = ""
if mtid:
mtid = str(mtid)
electric_index = dict(
item=index,
)
electric_index["max_" + mtid] = max_value
electric_index["max_time_" + mtid] = max_value_time
electric_index["min_" + mtid] = min_value
electric_index["min_time_" + mtid] = min_value_time
electric_index["avg_" + mtid] = mean_value
else:
electric_index = dict(
type=item["ad_type"],
item=index,
max=max_value,
max_time=max_value_time,
min=min_value,
min_time=min_value_time,
avg=mean_value,
)
else:
electric_index = dict(type=item["ad_type"], item=index, max="",
max_time="", min="",
min_time="", avg="")
indexes_list.append(electric_index)
return indexes_list
def cal_pt_value(datas, mtid=None):
"""
用电指数数据封装
:param datas: 数据
:param mtid: 字段是否需要合并mtid
:return:
"""
df = pd.DataFrame(list(datas))
indexes_list = []
if datas:
# item = item.rsplit("_", 1)[0]
max_item_name = f"temp_max"
max_value = df[max_item_name].max()
if not pd.isna(max_value):
max_datas = df.loc[df[max_item_name].idxmax()].to_dict()
max_time = max_datas.get(f"{max_item_name}_time")
max_time = "" if pd.isnull(max_time) else str(max_time)
else:
max_value, max_time = "", ""
min_item_name = f"temp_min"
min_value = df[min_item_name].min()
if not pd.isna(min_value):
min_datas = df.loc[df[min_item_name].idxmin()].to_dict()
min_time = min_datas.get(f"{min_item_name}_time")
min_time = "" if pd.isnull(min_time) else str(min_time)
else:
min_value, min_time = "", ""
mean_item_name = f"temp_mean"
avg_value = df[mean_item_name].mean()
if not pd.isna(avg_value):
avg_value = round(avg_value, 2)
else:
avg_value = ""
# if not max_value and not min_value and not avg_value:
# continue
if mtid:
mtid = str(mtid)
electric_index = dict(
index="温度(℃)",
)
electric_index["max_" + mtid] = max_value
electric_index["max_time_" + mtid] = max_time or ""
electric_index["min_" + mtid] = min_value
electric_index["min_time_" + mtid] = min_time or ""
electric_index["avg_" + mtid] = avg_value
else:
electric_index = dict(
index="温度(℃)",
max=max_value,
max_time=max_time or "",
min=min_value,
min_time=min_time or "",
avg=avg_value,
)
else:
electric_index = dict(index="温度(℃)", max="", max_time="", min="",
min_time="", avg="")
indexes_list.append(electric_index)
return indexes_list
......@@ -2,6 +2,7 @@ from operator import itemgetter
from itertools import groupby
from pot_libs.common.components.query import Range, Equal, Filter, InGroup, \
Sort
from pot_libs.common.dao.common_dao import get_fields_by_mtid
from pot_libs.es_util import es_helper
from pot_libs.es_util.es_query import EsQuery
from pot_libs.logger import log
......@@ -9,21 +10,25 @@ from pot_libs.common.components.query import PageRequest
from pot_libs.utils.pendulum_wrapper import my_pendulum
from unify_api.modules.anshiu.dao.fine_monitor_dao import get_aiao_1min_dao, \
get_aiao_1day_dao, get_aiao_15min_dao, get_point_15min_chart_dao, \
get_point_1day_chart_dao, get_point_1min_chart_dao
get_point_1day_chart_dao, get_point_1min_chart_dao, get_point_monitor_dao, \
electric_index_list_dao, electric_index_location_dao
from unify_api.utils import time_format
from unify_api.modules.electric.procedures.electric_util import (
get_wiring_type
)
from unify_api.modules.anshiu.components.fine_monitor_cps import (
Statistics, Chart
Statistics, Chart, ElectricIndexParam
)
from unify_api.modules.anshiu.procedures.fine_monitor_pds import (
get_es_point_1min_data, get_es_point_15min_data,
get_es_point_15min_data,
get_es_aiao_15min_data, get_threshold_by_location, get_aiao_1min_pds,
get_aiao_data_pds, get_point_1min_chart_pds, get_point_data_chart_pds
get_aiao_data_pds, get_point_1min_chart_pds, get_point_data_chart_pds,
GENERAL_PARAM_FIELD_2, ELECTRIC_QUALITY_FIELD_2,
GENERAL_PARAM_FIELD_3, ELECTRIC_QUALITY_FIELD_3, cal_electic_value,
cal_aiao_value, cal_pt_value
)
from unify_api.utils.time_format import convert_timestamp_to_str
from unify_api.utils.time_format import convert_timestamp_to_str, get_time_diff
async def get_adio_chart_data(location_group, location_info, date_start,
......@@ -89,12 +94,14 @@ async def get_point_chart_data(point_id, date_start, date_end, intervel,
]
if 15 * 60 >= intervel > 60:
elec_data = await get_point_15min_chart_dao(mtid, stats_items, date_start,
elec_data = await get_point_15min_chart_dao(mtid, stats_items,
date_start,
date_end)
power, i, u = await get_point_data_chart_pds(ctnum, slots, elec_data)
elif intervel == 86400:
elec_data = await get_point_1day_chart_dao(mtid, stats_items, date_start,
elec_data = await get_point_1day_chart_dao(mtid, stats_items,
date_start,
date_end)
power, i, u = await get_point_data_chart_pds(ctnum, slots, elec_data)
else:
......@@ -299,3 +306,164 @@ async def get_point_info_data(point_id, start_time,
common_indexes.append(elec_index)
return common_indexes
async def electric_index_list_service(mtid, start_time, end_time,
param_types=None):
"""
用电指标数据列表
:param mtid:
:param start_time:
:param end_time:
:param param_types:
:return:
"""
general_param, electric_quality, safe_param = [], [], []
# 1,获取信息
monitor = await get_fields_by_mtid(mtid)
if not monitor:
return -1, general_param, electric_quality, safe_param
time_diff = get_time_diff(start_time, end_time)
if time_diff <= 24 * 3600:
table_name = "point_15min_electric"
aiao_table_name = "location_15min_aiao"
else:
table_name = "point_1day_electric"
aiao_table_name = "location_1day_aiao"
# 字段是否需要组装mtid(前端下载要求的)
is_merge_mtid = mtid if param_types else None
if monitor.get("m_type") == 126:
pt_info = await get_fields_by_mtid(mtid, "pt_info", "pt_id")
if not pt_info:
return -1, general_param, electric_quality, safe_param
pt_id = pt_info.get("pt_id")
# 电容
ctnum, pt_datas = 0, []
# 安全参数
if not param_types or 'safe_param' in param_types:
safe_param = cal_pt_value(pt_datas, is_merge_mtid)
if not param_types:
safe_param = electric_index_list_return_data(safe_param)
else:
monitor_info = await get_point_monitor_dao(mtid)
if not monitor_info:
return -1, general_param, electric_quality, safe_param
ctnum = monitor_info.get("ctnum") or 3
datas, locations_datas, aiao_datas = [], [], []
if (not param_types or 'general_param' in param_types or
'electric_quality' in param_types):
datas = await electric_index_list_dao(table_name,
monitor_info.get("pid"),
start_time,
end_time)
if not param_types or 'safe_param' in param_types:
locations_datas, aiao_datas = await electric_index_location_dao(
aiao_table_name, mtid, start_time, end_time)
# 2,封装信息
if ctnum == 2:
general_param_field = GENERAL_PARAM_FIELD_2
electric_quality_field = ELECTRIC_QUALITY_FIELD_2
else:
general_param_field = GENERAL_PARAM_FIELD_3
electric_quality_field = ELECTRIC_QUALITY_FIELD_3
# 常规参数统计
if not param_types or 'general_param' in param_types:
general_param = cal_electic_value(datas, general_param_field,
is_merge_mtid)
if not param_types:
general_param = electric_index_list_return_data(general_param)
# 电能质量统计
if not param_types or 'electric_quality' in param_types:
electric_quality = cal_electic_value(datas, electric_quality_field,
is_merge_mtid)
if not param_types:
electric_quality = electric_index_list_return_data(
electric_quality)
# 安全参数
if not param_types or 'safe_param' in param_types:
safe_param = cal_aiao_value(locations_datas, aiao_datas,
is_merge_mtid)
if not param_types:
safe_param = electric_index_list_return_data(safe_param)
# 3,返回信息
return ctnum, general_param, electric_quality, safe_param
async def electric_index_export_service(cid, mtids, start_time, end_time,
param_types=None):
"""
用电指标数据导出
:param cid:
:param mtids:
:param start_time:
:param end_time:
:param param_types:
:return:
"""
general_param_list = []
electric_quality_list = []
safe_param_list = []
ctnums = []
for mtid in mtids:
ctnum, general_one, electric_one, safe_one = await \
electric_index_list_service(mtid, start_time, end_time,
param_types)
if ctnum == 0:
return 0, [], [], []
general_param_list.extend(general_one)
electric_quality_list.extend(electric_one)
safe_param_list.extend(safe_one)
ctnums.append(ctnum)
if len(set(ctnums)) > 1:
return -1, [], [], []
general_param, electric_quality, safe_param = [], [], []
# 常规参数
if 'general_param' in param_types:
general_param = electric_index_export_return_data(general_param_list)
# 用电质量
if 'electric_quality' in param_types:
electric_quality = electric_index_export_return_data(
electric_quality_list)
# 安全参数
if 'safe_param' in param_types:
safe_param = electric_index_export_return_data(safe_param_list)
# 2,返回信息
return 1, general_param, electric_quality, safe_param
def electric_index_list_return_data(datas):
"""
用电指标列表数据打包
:param datas:
:return:
"""
index_list = []
for data in datas:
electric_index = ElectricIndexParam(**data)
index_list.append(electric_index)
return index_list
def electric_index_export_return_data(datas):
"""
用电指标导出数据打包
:param datas:
:return:
"""
export_dict = dict()
for data in datas:
if data["index"] not in export_dict:
export_dict[data["index"]] = data
else:
export_dict[data["index"]].update(data)
return list(export_dict.values())
......@@ -2,18 +2,19 @@ from pot_libs.sanic_api import summary, examples
from pot_libs.common.components.query import PageRequest
from pot_libs.logger import log
from pot_libs.utils.pendulum_wrapper import my_pendulum
from unify_api.modules.anshiu.dao.fine_monitor_dao import get_mtid_by_pid_dao
from unify_api.utils.request_util import filed_value_from_list
from unify_api.utils import time_format
from unify_api.modules.anshiu.components.fine_monitor_cps import (
FineMonitorChartReq, FineMonitorInfoReq, FineMonitorChartResp,
FineMonitorInfoResp
FineMonitorInfoResp, ElectricIndexListResp
)
from unify_api.modules.anshiu.procedures.fine_monitor_pds import (
get_location_by_ids, get_threshold_by_location, get_mtid_by_location_ids
)
from unify_api.modules.anshiu.service.fine_monitor_serv import (
get_adio_chart_data, get_point_chart_data, get_adio_info_data,
get_point_info_data
get_point_info_data, electric_index_list_service
)
......@@ -69,19 +70,12 @@ async def post_fine_monitor_chart(request,
ctnum=ctnum)
@summary("精细监测-指标统计")
async def post_fine_monitor_info(request,
body: FineMonitorInfoReq) -> FineMonitorInfoResp:
@summary("精细监测-指标统计1")
async def post_fine_monitor_info1(request,
body: FineMonitorInfoReq) -> FineMonitorInfoResp:
try:
date_start = body.start
date_end = body.end
# 起始时间转化为时间戳
start_timestamp = time_format.get_date_timestamp(date_start)
end_timestamp = time_format.get_date_timestamp(date_end)
# 起始时间转化为es时间格式
es_start_dt = my_pendulum.from_format(date_start,
"YYYY-MM-DD HH:mm:ss")
es_end_dt = my_pendulum.from_format(date_end, "YYYY-MM-DD HH:mm:ss")
# 获取监测点
point_id = body.pid
......@@ -105,11 +99,31 @@ async def post_fine_monitor_info(request,
info_list = []
# 环境相关数据
adio_list = await get_adio_info_data(location_group,
location_info, start_timestamp,
end_timestamp)
location_info, date_start,
date_end)
# 用电相关数据
point_list = await get_point_info_data(point_id, es_start_dt,
es_end_dt)
point_list = await get_point_info_data(point_id, date_start,
date_end)
info_list.extend(adio_list)
info_list.extend(point_list)
return FineMonitorInfoResp(info_list=info_list)
@summary("精细监测-指标统计")
async def post_fine_monitor_info(request,
body: FineMonitorInfoReq) -> FineMonitorInfoResp:
mtid = await get_mtid_by_pid_dao(body.pid)
mtid = mtid["mtid"]
# 1,获取参数
start_time = body.start
end_time = body.end
# 2,获取信息
ctnum, general_param, electric_quality, safe_param = await \
electric_index_list_service(mtid, start_time, end_time)
if ctnum == -1:
raise Exception("监测点出错")
# 3,返回信息
info_list = []
info_list.extend(general_param)
info_list.extend(safe_param)
return FineMonitorInfoResp(info_list=info_list)
......@@ -1532,4 +1532,16 @@ def time_pick_transf_new(start, end):
dt = start_f.add(months=1 * i).format("YYYY-MM")
dt_str = str(dt)
slots.append(dt_str)
return intervel, slots
\ No newline at end of file
return intervel, slots
def get_time_diff(start, end):
"""
获取时间段内的间隔
:param start:
:param end:
:return:
"""
start_f = my_pendulum.from_format(start, 'YYYY-MM-DD HH:mm:ss')
end_f = my_pendulum.from_format(end, 'YYYY-MM-DD HH:mm:ss')
diff = end_f.int_timestamp - start_f.int_timestamp
return diff
\ No newline at end of file
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