Commit 13285235 authored by wang.wenrong's avatar wang.wenrong

Merge branch 'wwr' into 'develop'

fix_shiduanu

See merge request !30
parents 7ef9a0de 9d4a6d83
......@@ -63,8 +63,8 @@ async def points_monitor_by_cid(cids):
async def mid_by_pid(pid):
"""根据pid查询mid"""
sql = "select mid from change_meter_record where pid=%s " \
"order by start_time desc limit 1 "
sql = "select mtid from point where pid=%s " \
"order by create_time desc limit 1 "
async with MysqlUtil() as conn:
mid_dic = await conn.fetchone(sql, args=(pid,))
return mid_dic
......
......@@ -30,78 +30,26 @@ async def get_mean_datas_dao(pids, words, start, end):
async def health_score_points_aggs(start, end, point_list):
"""根据points分组, 再求平均值"""
# start_es = convert_es_str(start)
# end_es = convert_es_str(end)
# 所有报警类型
query_body = {
"query": {
"bool": {
"filter": [
{
"terms": {
"pid": point_list
}
},
{
"range": {
"quarter_time": {
"gte": start,
"lte": end
}
}
}
]
}
},
"size": 0,
"aggs": {
"points": {
"terms": {
"field": "pid",
"size": 1000
},
"aggs": {
"ua_mean_avg": {
"avg": {
"field": "ua_mean"
}
},
"freq_mean_avg": {
"avg": {
"field": "freq_mean"
}
},
"ubl_mean_avg": {
"avg": {
"field": "ubl_mean"
}
},
"costtl_mean_avg": {
"avg": {
"field": "costtl_mean"
}
},
"thdua_mean_avg": {
"avg": {
"field": "thdua_mean"
}
},
"lf_mean_avg": {
"avg": {
"field": "lf_mean"
}
},
"uab_mean_avg": {
"avg": {
"field": "ua_mean"
}
}
}
}
}
}
log.info("query_body={}".format(query_body))
async with EsUtil() as es:
es_result = await es.search_origin(body=query_body,
index=constants.POINT_15MIN_INDEX)
return es_result["aggregations"]["points"]["buckets"]
sql = f"""
SELECT
pid,
avg( uab_mean ) uab_mean_avg,
avg( costtl_mean ) costtl_mean_avg,
avg( lf_mean ) lf_mean_avg,
avg( thduab_mean ) thduab_mean_avg,
avg( ubl_mean ) ubl_mean_avg,
avg( freq_mean ) freq_mean_avg,
avg( ua_mean ) ua_mean_avg
FROM
point_15min_electric
WHERE
create_time > "{start}"
AND create_time < "{end}"
AND pid in %s
GROUP BY
pid
"""
async with MysqlUtil() as conn:
datas = await conn.fetchall(sql, args=(tuple(point_list),)) if point_list else []
return datas
......@@ -55,7 +55,7 @@ async def load_health_radar(cid, param_point_id=None):
es_health = await health_score_points_aggs(
start_time, end_time, inline_point_ids + point_ids
)
es_dic = {i["key"]: i for i in es_health}
es_dic = {i["pid"]: i for i in es_health if es_health}
# 统计所有点所有平均值
for point_id in inline_point_ids + point_ids:
ctnum = point_info_map[point_id]["ctnum"]
......@@ -71,7 +71,7 @@ async def load_health_radar(cid, param_point_id=None):
if not point_v:
stats[point_id][item] = None
else:
stats[point_id][item] = point_v[item + '_avg'].get("value")
stats[point_id][item] = point_v[item + '_avg']
'''
range = Range(field="quarter_time", start=start_time, end=end_time)
stats = {point_id: {} for point_id in inline_point_ids + point_ids}
......@@ -109,17 +109,17 @@ async def load_health_radar(cid, param_point_id=None):
avg = aggregations.get("%s_avg" % item, {}).get("value")
stats[point_id][item] = avg
'''
# 获取所有poin_id和mid对应关系
# 获取所有poin_id和mtid对应关系
all_point_ids = inline_point_ids + point_ids
point_mid_map = {}
if all_point_ids:
sql = (
"SELECT pid, mid FROM change_meter_record WHERE pid IN %s order by pid, start_time asc"
"SELECT pid, mtid FROM point WHERE pid IN %s order by pid, create_time asc"
)
async with MysqlUtil() as conn:
change_meter_records = await conn.fetchall(sql, args=(tuple(all_point_ids),))
point_mid_map = {
i["pid"]: i["mid"] for i in change_meter_records if i["mid"] is not None
i["pid"]: i["mtid"] for i in change_meter_records if i["mtid"] is not None
}
# 获取meter_param_record中的标准电压
......@@ -127,9 +127,9 @@ async def load_health_radar(cid, param_point_id=None):
meter_param_map = {}
if all_mids:
async with MysqlUtil() as conn:
sql = "SELECT mid, vc, voltage_side, ctnum FROM meter_param_record WHERE mid IN %s order by mid, start_time asc"
sql = "SELECT mtid, vc, voltage_side, ctnum FROM point WHERE mtid IN %s order by mtid, create_time asc"
meter_param_records = await conn.fetchall(sql, args=(tuple(all_mids),))
meter_param_map = {i["mid"]: i for i in meter_param_records}
meter_param_map = {i["mtid"]: i for i in meter_param_records}
log.info(f"all_mids={all_mids}")
# 电压偏差评分
......@@ -139,14 +139,14 @@ async def load_health_radar(cid, param_point_id=None):
if ua_mean is None:
continue
mid = point_mid_map.get(point_id)
if not mid:
mtid = point_mid_map.get(point_id)
if not mtid:
# pid没有mid,拆了
log.warning(f"pid={point_id} mid={mid} mid无效")
log.warning(f"pid={point_id} mtid={mtid} mid无效")
continue
meter_param = meter_param_map.get(mid)
meter_param = meter_param_map.get(mtid)
if not meter_param:
log.warning(f"pid={point_id} mid={mid} 没有表参数")
log.warning(f"pid={point_id} mtid={mtid} 没有表参数")
continue
meter_vc, ctnum = meter_param.get("vc"), meter_param.get("ctnum") or 3
if meter_vc:
......
......@@ -45,25 +45,16 @@ async def batch_get_wiring_type(point_ids):
:return: ctnum, mid
"""
# 根据point_id去change_meter_record查询最新的mid
sql = "SELECT pid, mid FROM change_meter_record WHERE " \
"pid in %s ORDER BY pid, start_time"
sql = "SELECT pid, mtid, ctnum FROM point WHERE " \
"pid in %s ORDER BY pid, create_time"
async with MysqlUtil() as conn:
change_meter_records = await conn.fetchall(sql, args=(point_ids,)) if point_ids else []
new_meter_id_map = {i["pid"]: i["mid"] for i in change_meter_records}
change_meter_records = await conn.fetchall(sql, args=(
point_ids,)) if point_ids else []
newest_mids = [i for i in new_meter_id_map.values() if i]
# 2. 根据mid去meter_param_record查最新ctnum
sql = "SELECT mid, ctnum FROM meter_param_record " \
"WHERE mid in %s ORDER BY mid, start_time"
point_info_map = {
i["pid"]: i for i in change_meter_records if i.get("pid")}
async with MysqlUtil() as conn:
meter_param_records = await conn.fetchall(sql, args=(newest_mids,)) if newest_mids else []
meter_param_map = {i["mid"]: i["ctnum"] for i in meter_param_records}
point_info_map = defaultdict(dict)
for pid, mid in new_meter_id_map.items():
point_info_map[pid] = {"mid": mid, "ctnum": meter_param_map.get(mid)}
return point_info_map
......
......@@ -7,7 +7,6 @@ import os
import pandas as pd
import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['axes.unicode_minus'] = False
illegalConfig_hold = 2500
......@@ -100,4 +99,3 @@ def addLabels(sid="sid", aircondRunStages="", electroRunStages="",
x = [each.split(" ")[1][:-3] for each in timeAll]
plt.show()
return 0
......@@ -2,42 +2,56 @@ import time
def findStart(timeaircond="timeaircond", timeaircond_last="", ahead=0):
timeaircond_last_stemp = int(time.mktime(time.strptime(timeaircond_last, "%Y-%m-%d %H:%M:%S")))
timeaircond_stemp = [int(time.mktime(time.strptime(each_time, "%Y-%m-%d %H:%M:%S"))) for each_time in timeaircond]
timeaircond_last_stemp = int(
time.mktime(time.strptime(timeaircond_last, "%Y-%m-%d %H:%M:%S")))
timeaircond_stemp = [
int(time.mktime(time.strptime(each_time, "%Y-%m-%d %H:%M:%S"))) for
each_time in timeaircond]
if ahead < len(timeaircond) - 1:
time_substruct = [1000000 if timeaircond_stemp[
each_timeaircond_stemp] - timeaircond_last_stemp <= 0 or each_timeaircond_stemp < ahead else
timeaircond_stemp[each_timeaircond_stemp] - timeaircond_last_stemp for each_timeaircond_stemp
timeaircond_stemp[
each_timeaircond_stemp] - timeaircond_last_stemp
for each_timeaircond_stemp
in range(len(timeaircond_stemp))]
else:
time_substruct = [1000000 if timeaircond_last_stemp - timeaircond_stemp[
each_timeaircond_stemp] <= 0 or each_timeaircond_stemp < ahead else timeaircond_last_stemp -
timeaircond_stemp[
each_timeaircond_stemp] for
each_timeaircond_stemp in range(len(timeaircond_stemp))]
time_substruct = [
1000000 if timeaircond_last_stemp - timeaircond_stemp[
each_timeaircond_stemp] <= 0 or each_timeaircond_stemp < ahead else timeaircond_last_stemp -
timeaircond_stemp[
each_timeaircond_stemp]
for
each_timeaircond_stemp in range(len(timeaircond_stemp))]
index = time_substruct.index(min(time_substruct))
return index
def aircondAnalysis(statesaircond="",statesaircond_off="",timeaircond="",timeaircond_off="",eachdata_pow="",eachdata_cur="",timer=""):
timeaircond_off_chang=[each.split(" ")[1][:-3].split(":") for each in timeaircond_off]
timeaircond_off_hour=[each[0] for each in timeaircond_off_chang]
def aircondAnalysis(statesaircond="", statesaircond_off="", timeaircond="",
timeaircond_off="", eachdata_pow="", eachdata_cur="",
timer=""):
timeaircond_off_chang = [each.split(" ")[1][:-3].split(":") for each in
timeaircond_off]
timeaircond_off_hour = [each[0] for each in timeaircond_off_chang]
aircondRunStages=[]
aircondRunStages = []
aircondRunStages.append(timeaircond[0])
for each_off in range(1,len(timeaircond_off)):
if int(timeaircond_off_hour[-1])-int(timeaircond_off_hour[-2])<=2 and each_off==len(timeaircond_off_hour)-1:
for each_off in range(1, len(timeaircond_off)):
if int(timeaircond_off_hour[-1]) - int(
timeaircond_off_hour[-2]) <= 2 and each_off == len(
timeaircond_off_hour) - 1:
aircondRunStages.append(timeaircond_off[each_off])
if int(timeaircond_off_hour[each_off])-int(timeaircond_off_hour[each_off-1])<=2:
if int(timeaircond_off_hour[each_off]) - int(
timeaircond_off_hour[each_off - 1]) <= 2:
continue
else:
if each_off<len(timeaircond)-1:
aircondRunStages.append(timeaircond_off[each_off-1])
findStart1=findStart(timeaircond=timeaircond,timeaircond_last=timeaircond_off[each_off-1],ahead=each_off)
if each_off < len(timeaircond) - 1:
aircondRunStages.append(timeaircond_off[each_off - 1])
findStart1 = findStart(timeaircond=timeaircond,
timeaircond_last=timeaircond_off[
each_off - 1], ahead=each_off)
aircondRunStages.append(timeaircond[findStart1])
else:
aircondRunStages.append(timeaircond_off[each_off])
return aircondRunStages
\ No newline at end of file
return aircondRunStages
import time
def componentStage(aircondRunStages="", electroRunStages="", heaterRunStages="", refrigRunStages=""):
def componentStage(aircondRunStages="", electroRunStages="",
heaterRunStages="", refrigRunStages=""):
stageComponent = []
stampDict = {}
if len(aircondRunStages) > 1:
aircondRunStages_stemp = [int(time.mktime(time.strptime(each, "%Y-%m-%d %H:%M:%S"))) for each in
aircondRunStages]
aircondRunStages_stemp = [
int(time.mktime(time.strptime(each, "%Y-%m-%d %H:%M:%S"))) for each
in
aircondRunStages]
for each_i in range(len(aircondRunStages_stemp)):
if each_i % 2==0:
stampDict[aircondRunStages_stemp[each_i]]="开启空调"
if each_i % 2 == 0:
stampDict[aircondRunStages_stemp[each_i]] = "开启空调"
else:
stampDict[aircondRunStages_stemp[each_i]]="关闭空调"
stampDict[aircondRunStages_stemp[each_i]] = "关闭空调"
if len(electroRunStages) > 1:
electroRunStages_stemp = [int(time.mktime(time.strptime(each, "%Y-%m-%d %H:%M:%S"))) for each in
electroRunStages]
electroRunStages_stemp = [
int(time.mktime(time.strptime(each, "%Y-%m-%d %H:%M:%S"))) for each
in
electroRunStages]
for each_i in range(len(electroRunStages_stemp)):
if each_i % 2==0:
stampDict[electroRunStages_stemp[each_i]]= "开启电磁炉"
if each_i % 2 == 0:
stampDict[electroRunStages_stemp[each_i]] = "开启电磁炉"
else:
stampDict[electroRunStages_stemp[each_i]]= "关闭电磁炉"
stampDict[electroRunStages_stemp[each_i]] = "关闭电磁炉"
if len(heaterRunStages) > 1:
heaterRunStages_stemp = [int(time.mktime(time.strptime(each, "%Y-%m-%d %H:%M:%S"))) for each in heaterRunStages]
heaterRunStages_stemp = [
int(time.mktime(time.strptime(each, "%Y-%m-%d %H:%M:%S"))) for each
in heaterRunStages]
for each_i in range(len(heaterRunStages_stemp)):
if each_i % 2==0:
stampDict[heaterRunStages_stemp[each_i]]= "开启热水器"
if each_i % 2 == 0:
stampDict[heaterRunStages_stemp[each_i]] = "开启热水器"
else:
stampDict[heaterRunStages_stemp[each_i]]= "关闭热水器"
stampDict[heaterRunStages_stemp[each_i]] = "关闭热水器"
if len(refrigRunStages) > 1:
refrigRunStages_stemp = [int(time.mktime(time.strptime(each, "%Y-%m-%d %H:%M:%S"))) for each in refrigRunStages]
refrigRunStages_stemp = [
int(time.mktime(time.strptime(each, "%Y-%m-%d %H:%M:%S"))) for each
in refrigRunStages]
for each_i in range(len(refrigRunStages_stemp)):
if each_i % 2==0:
stampDict[refrigRunStages_stemp[each_i]]= "开启电冰箱"
if each_i % 2 == 0:
stampDict[refrigRunStages_stemp[each_i]] = "开启电冰箱"
else:
stampDict[refrigRunStages_stemp[each_i]]= "关闭电冰箱"
stampDict=sorted(stampDict.items(),key=lambda d:d[0])
timeOrder=[each[0] for each in stampDict]
actionOrder=[each[1] for each in stampDict]
timeOrder=[time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(each)) for each in timeOrder]
timestage=[]
stampDict[refrigRunStages_stemp[each_i]] = "关闭电冰箱"
stampDict = sorted(stampDict.items(), key=lambda d: d[0])
timeOrder = [each[0] for each in stampDict]
actionOrder = [each[1] for each in stampDict]
timeOrder = [time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(each)) for
each in timeOrder]
timestage = []
for each_i in range(len(actionOrder)):
stageComponent.append([])
if each_i==0 and actionOrder[0][:2]=="开启":
if each_i == 0 and actionOrder[0][:2] == "开启":
if stageComponent[-1] == []:
stageComponent.pop(-1)
continue
else:
if actionOrder[each_i-1][:2]=="开启":
stageComponent[-1].append(actionOrder[each_i-1][2:]+"运行")
timestage.append([timeOrder[each_i-1],timeOrder[each_i]])
if len(timestage)>1 and timestage[-2]==timestage[-1]:
if actionOrder[each_i - 1][:2] == "开启":
stageComponent[-1].append(actionOrder[each_i - 1][2:] + "运行")
timestage.append([timeOrder[each_i - 1], timeOrder[each_i]])
if len(timestage) > 1 and timestage[-2] == timestage[-1]:
timestage.pop(-1)
if actionOrder[:each_i].count("开启电冰箱")>actionOrder[:each_i].count("关闭电冰箱") and actionOrder[each_i-1] != "开启电冰箱" and "电冰箱运行" not in stageComponent:
if actionOrder[:each_i].count("开启电冰箱") > actionOrder[
:each_i].count(
"关闭电冰箱") and actionOrder[
each_i - 1] != "开启电冰箱" and "电冰箱运行" not in stageComponent:
stageComponent[-1].append("电冰箱运行")
timestage.append([timeOrder[each_i-1],timeOrder[each_i]])
if len(timestage)>1 and timestage[-2]==timestage[-1]:
timestage.append([timeOrder[each_i - 1], timeOrder[each_i]])
if len(timestage) > 1 and timestage[-2] == timestage[-1]:
timestage.pop(-1)
if actionOrder[:each_i].count("开启电磁炉")>actionOrder[:each_i].count("关闭电磁炉") and actionOrder[each_i-1] != "开启电磁炉" and "电磁炉运行" not in stageComponent:
if actionOrder[:each_i].count("开启电磁炉") > actionOrder[
:each_i].count(
"关闭电磁炉") and actionOrder[
each_i - 1] != "开启电磁炉" and "电磁炉运行" not in stageComponent:
stageComponent[-1].append("电磁炉运行")
timestage.append([timeOrder[each_i-1],timeOrder[each_i]])
if len(timestage)>1 and timestage[-2]==timestage[-1]:
timestage.append([timeOrder[each_i - 1], timeOrder[each_i]])
if len(timestage) > 1 and timestage[-2] == timestage[-1]:
timestage.pop(-1)
if actionOrder[:each_i].count("开启热水器")>actionOrder[:each_i].count("关闭热水器") and actionOrder[each_i-1] != "开启热水器" and "热水器运行" not in stageComponent:
if actionOrder[:each_i].count("开启热水器") > actionOrder[
:each_i].count(
"关闭热水器") and actionOrder[
each_i - 1] != "开启热水器" and "热水器运行" not in stageComponent:
stageComponent[-1].append("热水器运行")
timestage.append([timeOrder[each_i-1],timeOrder[each_i]])
if len(timestage)>1 and timestage[-2]==timestage[-1]:
timestage.append([timeOrder[each_i - 1], timeOrder[each_i]])
if len(timestage) > 1 and timestage[-2] == timestage[-1]:
timestage.pop(-1)
if actionOrder[:each_i].count("开启空调")>actionOrder[:each_i].count("关闭空调") and actionOrder[each_i-1] != "开启空调" and "空调运行" not in stageComponent:
if actionOrder[:each_i].count("开启空调") > actionOrder[:each_i].count(
"关闭空调") and actionOrder[
each_i - 1] != "开启空调" and "空调运行" not in stageComponent:
stageComponent[-1].append("空调运行")
timestage.append([timeOrder[each_i-1],timeOrder[each_i]])
if len(timestage)>1 and timestage[-2]==timestage[-1]:
timestage.append([timeOrder[each_i - 1], timeOrder[each_i]])
if len(timestage) > 1 and timestage[-2] == timestage[-1]:
timestage.pop(-1)
if stageComponent[-1]==[]:
if stageComponent[-1] == []:
stageComponent.pop(-1)
return stageComponent,timestage,timeOrder,actionOrder
return stageComponent, timestage, timeOrder, actionOrder
......@@ -23,16 +23,40 @@ def pieceWise(eachdata, params="params"):
heaterRunStages = []
statesaircond, statesrefrig, stateselectro, statesricecook, statesheater, timeaircond, timerefrig, timericecook, timeelectro, timeheater, statesaircond_off, statesrefrig_off, stateselectro_off, statesricecook_off, statesheater_off, timeaircond_off, timerefrig_off, timericecook_off, timeelectro_off, timeheater_off = piececlassfy(
current=eachdata_cur, power=eachdata_pow, timer=timer, params=params)
if len(statesaircond_off)>0:
aircondRunStages=aircondAnalysis(statesaircond=statesaircond,statesaircond_off=statesaircond_off,timeaircond=timeaircond,timeaircond_off=timeaircond_off,eachdata_pow=eachdata_pow,eachdata_cur=eachdata_cur,timer=timer)
if len(statesaircond_off) > 0:
aircondRunStages = aircondAnalysis(statesaircond=statesaircond,
statesaircond_off=statesaircond_off,
timeaircond=timeaircond,
timeaircond_off=timeaircond_off,
eachdata_pow=eachdata_pow,
eachdata_cur=eachdata_cur,
timer=timer)
#
if len(stateselectro)>0:
electroRunStages=electroAnalysis(stateselectro=stateselectro,stateselectro_off=stateselectro_off,timeelectro=timeelectro,timeelectro_off=timeelectro_off,eachdata_pow=eachdata_pow,eachdata_cur=eachdata_cur,timer=timer)
if len(stateselectro) > 0:
electroRunStages = electroAnalysis(stateselectro=stateselectro,
stateselectro_off=stateselectro_off,
timeelectro=timeelectro,
timeelectro_off=timeelectro_off,
eachdata_pow=eachdata_pow,
eachdata_cur=eachdata_cur,
timer=timer)
if len(statesheater)>0:
heaterRunStages=heaterAnalysis(statesheater=statesheater,statesheater_off=statesheater_off,timeheater=timeheater,timeheater_off=timeheater_off,eachdata_pow=eachdata_pow,eachdata_cur=eachdata_cur,timer=timer)
if len(statesheater) > 0:
heaterRunStages = heaterAnalysis(statesheater=statesheater,
statesheater_off=statesheater_off,
timeheater=timeheater,
timeheater_off=timeheater_off,
eachdata_pow=eachdata_pow,
eachdata_cur=eachdata_cur,
timer=timer)
if len(statesrefrig)>0:
refrigRunStages=refrigAnalysis(statesrefrig=statesrefrig,statesrefrig_off=statesrefrig_off,timerefrig=timerefrig,timerefrig_off=timerefrig_off,eachdata_pow=eachdata_pow,eachdata_cur=eachdata_cur,timer=timer)
if len(statesrefrig) > 0:
refrigRunStages = refrigAnalysis(statesrefrig=statesrefrig,
statesrefrig_off=statesrefrig_off,
timerefrig=timerefrig,
timerefrig_off=timerefrig_off,
eachdata_pow=eachdata_pow,
eachdata_cur=eachdata_cur,
timer=timer)
return aircondRunStages, electroRunStages, heaterRunStages, refrigRunStages
......@@ -2,36 +2,46 @@ import time
def findStart(timeelectro="timeelectro", timeelectro_last="", ahead=0):
timeelectro_last_stemp = int(time.mktime(time.strptime(timeelectro_last, "%Y-%m-%d %H:%M:%S")))
timeelectro_stemp = [int(time.mktime(time.strptime(each_time, "%Y-%m-%d %H:%M:%S"))) for each_time in timeelectro]
timeelectro_last_stemp = int(
time.mktime(time.strptime(timeelectro_last, "%Y-%m-%d %H:%M:%S")))
timeelectro_stemp = [
int(time.mktime(time.strptime(each_time, "%Y-%m-%d %H:%M:%S"))) for
each_time in timeelectro]
if ahead < len(timeelectro) - 1:
time_substruct = [1000000 if timeelectro_stemp[
each_timeelectro_stemp] - timeelectro_last_stemp <= 0 or each_timeelectro_stemp < ahead else
timeelectro_stemp[each_timeelectro_stemp] - timeelectro_last_stemp for each_timeelectro_stemp
timeelectro_stemp[
each_timeelectro_stemp] - timeelectro_last_stemp
for each_timeelectro_stemp
in range(len(timeelectro_stemp))]
else:
time_substruct = [1000000 if timeelectro_last_stemp - timeelectro_stemp[
each_timeelectro_stemp] <= 0 or each_timeelectro_stemp < ahead else timeelectro_last_stemp -
timeelectro_stemp[
each_timeelectro_stemp] for
each_timeelectro_stemp in range(len(timeelectro_stemp))]
time_substruct = [
1000000 if timeelectro_last_stemp - timeelectro_stemp[
each_timeelectro_stemp] <= 0 or each_timeelectro_stemp < ahead else timeelectro_last_stemp -
timeelectro_stemp[
each_timeelectro_stemp]
for
each_timeelectro_stemp in range(len(timeelectro_stemp))]
index = time_substruct.index(min(time_substruct))
return index
def electroAnalysis(stateselectro="stateselectro", stateselectro_off="stateselectro_off"
, timeelectro="timeelectro", timeelectro_off="timeelectro_off", eachdata_pow="eachdata_pow"
def electroAnalysis(stateselectro="stateselectro",
stateselectro_off="stateselectro_off"
, timeelectro="timeelectro",
timeelectro_off="timeelectro_off",
eachdata_pow="eachdata_pow"
, eachdata_cur="eachdata_cur", timer="timer"):
electroRunStages = []
timeelectro_chang = [each.split(" ")[1][:-3].split(":") for each in timeelectro]
timeelectro_chang = [each.split(" ")[1][:-3].split(":") for each in
timeelectro]
timeelectro_hour = [each[0] for each in timeelectro_chang]
timeelectro_minute = [each[1] for each in timeelectro_chang]
timeelectro_off_chang = [each.split(" ")[1][:-3].split(":") for each in timeelectro_off]
timeelectro_off_chang = [each.split(" ")[1][:-3].split(":") for each in
timeelectro_off]
timeelectro_off_hour = [each[0] for each in timeelectro_off_chang]
timeelectro_off_minute = [each[1] for each in timeelectro_off_chang]
......@@ -40,22 +50,30 @@ def electroAnalysis(stateselectro="stateselectro", stateselectro_off="stateselec
electroRunStages.append(timeelectro[0])
for each_off in range(1, len(timeelectro_off)):
# if each_off==len(timeaircond_off)-1:
if int(timeelectro_off_hour[-1]) - int(timeelectro_off_hour[-2]) > 2 and each_off == len(
if int(timeelectro_off_hour[-1]) - int(
timeelectro_off_hour[-2]) > 2 and each_off == len(
timeelectro_off_hour) - 1:
if flag == 1:
index = findStart(timeelectro=timeelectro, timeelectro_last=timeelectro_off[each_off], ahead=each_off)
index = findStart(timeelectro=timeelectro,
timeelectro_last=timeelectro_off[each_off],
ahead=each_off)
electroRunStages.append(timeelectro[index])
electroRunStages.append(timeelectro_off[each_off])
elif int(timeelectro_off_hour[each_off]) - int(timeelectro_off_hour[each_off - 1]) <= 1:
elif int(timeelectro_off_hour[each_off]) - int(
timeelectro_off_hour[each_off - 1]) <= 1:
continue
else:
if each_off < len(timeelectro_off_hour) - 1:
electroRunStages.append(timeelectro_off[each_off - 1])
index = findStart(timeelectro=timeelectro, timeelectro_last=timeelectro_off[each_off - 1],
index = findStart(timeelectro=timeelectro,
timeelectro_last=timeelectro_off[
each_off - 1],
ahead=each_off)
electroRunStages.append(timeelectro[index])
if int(timeelectro_off_hour[each_off]) - int(timeelectro_hour[index]) <= 1 and int(
timeelectro_off_hour[each_off]) - int(timeelectro_off_hour[each_off + 1]) < -1:
if int(timeelectro_off_hour[each_off]) - int(
timeelectro_hour[index]) <= 1 and int(
timeelectro_off_hour[each_off]) - int(
timeelectro_off_hour[each_off + 1]) < -1:
electroRunStages.append(timeelectro_off[each_off])
flag = 1
......
import time
def findStart(timeheater="timeheater", timeheater_last="", ahead=0):
timeelectro_last_stemp = int(time.mktime(time.strptime(timeheater_last, "%Y-%m-%d %H:%M:%S")))
timeelectro_stemp = [int(time.mktime(time.strptime(each_time, "%Y-%m-%d %H:%M:%S"))) for each_time in timeheater]
def findStart(timeheater="timeheater", timeheater_last="", ahead=0):
timeelectro_last_stemp = int(
time.mktime(time.strptime(timeheater_last, "%Y-%m-%d %H:%M:%S")))
timeelectro_stemp = [
int(time.mktime(time.strptime(each_time, "%Y-%m-%d %H:%M:%S"))) for
each_time in timeheater]
if ahead < len(timeheater) - 1:
time_substruct = [1000000 if timeelectro_stemp[
each_timeelectro_stemp] - timeelectro_last_stemp <= 0 or each_timeelectro_stemp < ahead else
timeelectro_stemp[each_timeelectro_stemp] - timeelectro_last_stemp for each_timeelectro_stemp
timeelectro_stemp[
each_timeelectro_stemp] - timeelectro_last_stemp
for each_timeelectro_stemp
in range(len(timeelectro_stemp))]
else:
time_substruct = [1000000 if timeelectro_last_stemp - timeelectro_stemp[
each_timeelectro_stemp] <= 0 or each_timeelectro_stemp < ahead else timeelectro_last_stemp -
timeelectro_stemp[
each_timeelectro_stemp] for
each_timeelectro_stemp in range(len(timeelectro_stemp))]
time_substruct = [
1000000 if timeelectro_last_stemp - timeelectro_stemp[
each_timeelectro_stemp] <= 0 or each_timeelectro_stemp < ahead else timeelectro_last_stemp -
timeelectro_stemp[
each_timeelectro_stemp]
for
each_timeelectro_stemp in range(len(timeelectro_stemp))]
index = time_substruct.index(min(time_substruct))
return index
def heaterAnalysis(statesheater="statesheater", statesheater_off="", timeheater="timeheater",
timeheater_off="timeheater_off", eachdata_pow="eachdata_pow", eachdata_cur="eachdata_cur",
def heaterAnalysis(statesheater="statesheater", statesheater_off="",
timeheater="timeheater",
timeheater_off="timeheater_off",
eachdata_pow="eachdata_pow", eachdata_cur="eachdata_cur",
timer="timer"):
heaterRunStages = []
timeheater_chang = [each.split(" ")[1][:-3].split(":") for each in timeheater]
timeheater_chang = [each.split(" ")[1][:-3].split(":") for each in
timeheater]
timeheater_hour = [each[0] for each in timeheater_chang]
timeheater_minute = [each[1] for each in timeheater_chang]
timeheater_off_chang = [each.split(" ")[1][:-3].split(":") for each in timeheater_off]
timeheater_off_chang = [each.split(" ")[1][:-3].split(":") for each in
timeheater_off]
timeheater_off_hour = [each[0] for each in timeheater_off_chang]
timeheater_off_minute = [each[1] for each in timeheater_off_chang]
......@@ -39,22 +50,30 @@ def heaterAnalysis(statesheater="statesheater", statesheater_off="", timeheater=
for each_off in range(1, len(timeheater_off)):
# if each_off==len(timeaircond_off)-1:
if int(timeheater_off_hour[-1]) - int(timeheater_off_hour[-2]) > 2 and each_off == len(
if int(timeheater_off_hour[-1]) - int(
timeheater_off_hour[-2]) > 2 and each_off == len(
timeheater_off_hour) - 1:
if flag == 1:
index = findStart(timeheater=timeheater, timeheater_last=timeheater_off[each_off], ahead=each_off)
index = findStart(timeheater=timeheater,
timeheater_last=timeheater_off[each_off],
ahead=each_off)
heaterRunStages.append(timeheater[index])
heaterRunStages.append(timeheater_off[each_off])
elif int(timeheater_off_hour[each_off]) - int(timeheater_off_hour[each_off - 1]) <= 1:
elif int(timeheater_off_hour[each_off]) - int(
timeheater_off_hour[each_off - 1]) <= 1:
continue
else:
if each_off < len(timeheater) - 1:
heaterRunStages.append(timeheater_off[each_off - 1])
index = findStart(timeheater=timeheater, timeheater_last=timeheater_off[each_off - 1],
index = findStart(timeheater=timeheater,
timeheater_last=timeheater_off[
each_off - 1],
ahead=each_off)
heaterRunStages.append(timeheater[index])
if int(timeheater_off_hour[each_off]) - int(timeheater_hour[index]) <= 1 and int(
timeheater_off_hour[each_off]) - int(timeheater_off_hour[each_off + 1]) < -1:
if int(timeheater_off_hour[each_off]) - int(
timeheater_hour[index]) <= 1 and int(
timeheater_off_hour[each_off]) - int(
timeheater_off_hour[each_off + 1]) < -1:
heaterRunStages.append(timeheater_off[each_off])
flag = 1
......
......@@ -94,7 +94,7 @@ def bigPowerReg(eachdata="powerdata", key="a"):
timethr = timethr + 1
flag3 = 1
equips = likesEquip(time=res[0::2])
timer=[str(each) for each in res[0::2]]
timer = [str(each) for each in res[0::2]]
return timer, equips
......@@ -199,10 +199,9 @@ def vioPowerReg(eachdata="powerdata", key="a"):
if flag1 == 1 and powerdata[i] * 1000 > viopowerone[1]:
timeone = timeone + 1
continue
timer=[str(each) for each in res]
timer = [str(each) for each in res]
return timer, equips
# plt.rcParams['font.sans-serif'] = ['SimHei']
# plt.rcParams['axes.unicode_minus'] = False
#
......
......@@ -21,7 +21,7 @@ from pot_libs.aredis_util.aredis_utils import RedisUtils
from unify_api.utils import time_format
async def basic_info_longgang_service(user_id, page_size, page_num):
async def basic_info_longgang_service(user_id, page_size, page_num):
# 1.验证权限
cids = [223]
is_auth = await get_power(user_id, cids)
......@@ -236,7 +236,8 @@ async def result_longgang_service(user_id, importance, page_size, page_num):
is_auth = await get_power(user_id, cids)
if not is_auth:
return success_res(code=4001, msg="您没有权限访问")
es_res = await result_longgang_by_cid(cids, page_num, page_size, importance)
es_res = await result_longgang_by_cid(cids, page_num, page_size,
importance)
if not es_res["hits"]["hits"]:
return ListAlarmResponse(total=0, rows=[])
# 2. 构建返回数据
......@@ -247,7 +248,7 @@ async def result_longgang_service(user_id, importance, page_size, page_num):
mp_map[mp_list["pid"]] = {
"sid": mp_list["sid"], "mtid": mp_list["mtid"],
"storey_name": mp_list["storey_name"],
"room_name": mp_list["room_name"],
"room_name": mp_list["room_name"],
"fullname": mp_list["fullname"],
}
......
......@@ -198,7 +198,7 @@ async def params_mining(date_time_list, sid, sn):
pd.to_datetime(day_time_all[i], format='%Y-%m-%d %H:%M:%S') for
i in range(len(day_time_all))]
power_pa_Series = pd.Series(power_pa, index=day_time_all)
power_pa_Series=power_pa_Series.interpolate(method='nearest')
power_pa_Series = power_pa_Series.interpolate(method='nearest')
# power_pb_Series = pd.Series(power_pb, index=day_time_all)
# power_pc_Series = pd.Series(power_pc, index=day_time_all)
......
......@@ -2,7 +2,8 @@ import numpy as np
import re
def piececlassfy(current="eachnode_cur", power="eachnode_pow", timer="timer", params="params"):
def piececlassfy(current="eachnode_cur", power="eachnode_pow", timer="timer",
params="params"):
month = timer[0].split(" ")[0].split("-")[1]
day = timer[0].split(" ")[0].split("-")[2]
hours = [each.split(" ")[1].split(":")[0] for each in timer]
......@@ -35,7 +36,8 @@ def piececlassfy(current="eachnode_cur", power="eachnode_pow", timer="timer", pa
timeelectro_off = []
timeheater_off = []
quannums = [.01, .03, .05, .1, .2, .3, .4, .5, .6, .7, .8, .9, .95, .98, .99]
quannums = [.01, .03, .05, .1, .2, .3, .4, .5, .6, .7, .8, .9, .95, .98,
.99]
opernumstate = []
for i in range(dataLen):
if i == 0:
......@@ -55,48 +57,60 @@ def piececlassfy(current="eachnode_cur", power="eachnode_pow", timer="timer", pa
his_p.append(now_p[0])
now_p = now_p[-5:]
now_i = now_i[-5:]
if 1000 * (now_p[0] - his_p[-1]) > params[0] - 50 and 1000 * (now_p[0] - his_p[-1]) < min(params[1:]) + 50:
if 1000 * (now_p[0] - his_p[-1]) > params[0] - 50 and 1000 * (
now_p[0] - his_p[-1]) < min(params[1:]) + 50:
statesrefrig.append("电冰箱运行")
timerefrig.append(timer[i])
if 1000 * (now_p[0] - his_p[-1]) > params[1] - 50 and 1000 * (now_p[0] - his_p[-1]) < min(params[2:]) + 50:
if 1000 * (now_p[0] - his_p[-1]) > params[1] - 50 and 1000 * (
now_p[0] - his_p[-1]) < min(params[2:]) + 50:
statesaircond.append("空调运行")
timeaircond.append(timer[i])
if 1000 * (now_p[0] - his_p[-1]) > min(params[2:]) - 50 and (
int(hours[i]) >= 22 or int(hours[i]) < 5 or int(hours[i]) >= 19):
int(hours[i]) >= 22 or int(hours[i]) < 5 or int(
hours[i]) >= 19):
statesheater.append("热水器启动")
timeheater.append(timer[i])
if 1000 * (now_p[0] - his_p[-1]) > min(params[3:]) - 50 and 1000 * (now_p[0] - his_p[-1]) < max(
if 1000 * (now_p[0] - his_p[-1]) > min(
params[3:]) - 50 and 1000 * (now_p[0] - his_p[-1]) < max(
params[3:]) + 50 and (
int(hours[i]) >= 10 and int(hours[i]) < 14 or int(hours[i]) >= 17 and int(hours[i]) < 20 or int(
int(hours[i]) >= 10 and int(hours[i]) < 14 or int(
hours[i]) >= 17 and int(hours[i]) < 20 or int(
hours[i]) >= 5 and int(hours[i]) < 10):
statesricecook.append("电饭煲启动")
timericecook.append(timer[i])
if 1000 * (now_p[0] - his_p[-1]) > max(params[3:]) - 50 and (
int(hours[i]) >= 10 and int(hours[i]) < 14 or int(hours[i]) >= 17 and int(hours[i]) < 20 or int(
int(hours[i]) >= 10 and int(hours[i]) < 14 or int(
hours[i]) >= 17 and int(hours[i]) < 20 or int(
hours[i]) >= 5 and int(hours[i]) < 10):
stateselectro.append("电磁炉运行")
timeelectro.append(timer[i])
# return 0
if 1000 * (his_p[-1] - now_p[0]) > params[0] - 50 and 1000 * (his_p[-1] - now_p[0]) < min(params[1:]) + 50:
if 1000 * (his_p[-1] - now_p[0]) > params[0] - 50 and 1000 * (
his_p[-1] - now_p[0]) < min(params[1:]) + 50:
statesrefrig_off.append("电冰箱关闭")
timerefrig_off.append(timer[i])
if 1000 * (his_p[-1] - now_p[0]) > params[1] - 50 and 1000 * (his_p[-1] - now_p[0]) < min(params[2:]) + 50:
if 1000 * (his_p[-1] - now_p[0]) > params[1] - 50 and 1000 * (
his_p[-1] - now_p[0]) < min(params[2:]) + 50:
statesaircond_off.append("空调关闭")
timeaircond_off.append(timer[i])
if 1000 * (his_p[-1] - now_p[0]) > min(params[2:]) - 50 and (
int(hours[i]) >= 22 or int(hours[i]) < 5 or int(hours[i]) >= 19):
int(hours[i]) >= 22 or int(hours[i]) < 5 or int(
hours[i]) >= 19):
statesheater_off.append("热水器关闭")
timeheater_off.append(timer[i])
if 1000 * (his_p[-1] - now_p[0]) > min(params[3:]) - 50 and 1000 * (his_p[-1] - now_p[0]) < max(
if 1000 * (his_p[-1] - now_p[0]) > min(
params[3:]) - 50 and 1000 * (his_p[-1] - now_p[0]) < max(
params[3:]) + 50 and (
int(hours[i]) >= 10 and int(hours[i]) < 14 or int(hours[i]) >= 17 and int(hours[i]) < 20 or int(
int(hours[i]) >= 10 and int(hours[i]) < 14 or int(
hours[i]) >= 17 and int(hours[i]) < 20 or int(
hours[i]) >= 5 and int(hours[i]) < 10):
statesricecook_off.append("电饭煲关闭")
timericecook_off.append(timer[i])
if 1000 * (his_p[-1] - now_p[0]) > max(params[3:]) - 50 and (
int(hours[i]) >= 10 and int(hours[i]) < 14 or int(hours[i]) >= 17 and int(hours[i]) < 20 or int(
int(hours[i]) >= 10 and int(hours[i]) < 14 or int(
hours[i]) >= 17 and int(hours[i]) < 20 or int(
hours[i]) >= 5 and int(hours[i]) < 10):
stateselectro_off.append("电磁炉关闭")
timeelectro_off.append(timer[i])
......
......@@ -2,53 +2,78 @@ import time
def findStart(timerefrig="timerefrig", timerefrig_last="", ahead=0):
timerefrig_last_stemp = int(time.mktime(time.strptime(timerefrig_last, "%Y-%m-%d %H:%M:%S")))
timerefrig_stemp = [int(time.mktime(time.strptime(each_time, "%Y-%m-%d %H:%M:%S"))) for each_time in timerefrig]
timerefrig_last_stemp = int(
time.mktime(time.strptime(timerefrig_last, "%Y-%m-%d %H:%M:%S")))
timerefrig_stemp = [
int(time.mktime(time.strptime(each_time, "%Y-%m-%d %H:%M:%S"))) for
each_time in timerefrig]
if ahead < len(timerefrig) - 1:
time_substruct = [1000000 if timerefrig_stemp[
each_timerefrig_stemp] - timerefrig_last_stemp <= 0 or each_timerefrig_stemp < ahead else
timerefrig_stemp[each_timerefrig_stemp] - timerefrig_last_stemp for each_timerefrig_stemp
timerefrig_stemp[
each_timerefrig_stemp] - timerefrig_last_stemp
for each_timerefrig_stemp
in range(len(timerefrig_stemp))]
else:
time_substruct = [1000000 if timerefrig_last_stemp - timerefrig_stemp[
each_timerefrig_stemp] <= 0 or each_timerefrig_stemp < ahead else timerefrig_last_stemp -
timerefrig_stemp[
each_timerefrig_stemp] for
each_timerefrig_stemp in range(len(timerefrig_stemp))]
timerefrig_stemp[
each_timerefrig_stemp]
for
each_timerefrig_stemp in
range(len(timerefrig_stemp))]
index = time_substruct.index(min(time_substruct))
return index
def refrigAnalysis(statesrefrig="",statesrefrig_off="",timerefrig="",timerefrig_off="",eachdata_pow="",eachdata_cur="",timer=""):
timerefrig_chang=[each.split(" ")[1][:-3].split(":") for each in timerefrig]
timerefrig_hour=[each[0] for each in timerefrig_chang]
timerefrig_minute=[each[1] for each in timerefrig_chang]
timerefrig_off_chang=[each.split(" ")[1][:-3].split(":") for each in timerefrig_off]
timerefrig_off_hour=[each[0] for each in timerefrig_off_chang]
timerefrig_off_minute=[each[1] for each in timerefrig_off_chang]
refrigRunStages=[]
if int(timerefrig_off_hour[-1])>=22 and int(timerefrig_off_hour[0])<=2:
def refrigAnalysis(statesrefrig="", statesrefrig_off="", timerefrig="",
timerefrig_off="", eachdata_pow="", eachdata_cur="",
timer=""):
timerefrig_chang = [each.split(" ")[1][:-3].split(":") for each in
timerefrig]
timerefrig_hour = [each[0] for each in timerefrig_chang]
timerefrig_minute = [each[1] for each in timerefrig_chang]
timerefrig_off_chang = [each.split(" ")[1][:-3].split(":") for each in
timerefrig_off]
timerefrig_off_hour = [each[0] for each in timerefrig_off_chang]
timerefrig_off_minute = [each[1] for each in timerefrig_off_chang]
refrigRunStages = []
if int(timerefrig_off_hour[-1]) >= 22 and int(timerefrig_off_hour[0]) <= 2:
refrigRunStages.append(timerefrig[0])
refrigRunStages.append(timerefrig_off[-1])
else:
refrigRunStages.append(timerefrig[0])
for each_off in range(1,len(timerefrig_off)):
for each_off in range(1, len(timerefrig_off)):
# if each_off==len(timerefrig_off)-1:
print("timerefrig_off_hour",timerefrig_off_hour)
print("timerefrig_off_hour", timerefrig_off_hour)
if len(timerefrig_off_hour)>=3 and int(timerefrig_off_hour[-1])-int(timerefrig_off_hour[-2])<=2 and int(timerefrig_off_hour[-2])-int(timerefrig_off_hour[-3])<=2 and each_off==len(timerefrig_off_hour)-1:
if len(timerefrig_off_hour) >= 3 and int(
timerefrig_off_hour[-1]) - int(
timerefrig_off_hour[-2]) <= 2 and int(
timerefrig_off_hour[-2]) - int(
timerefrig_off_hour[-3]) <= 2 and each_off == len(
timerefrig_off_hour) - 1:
refrigRunStages.append(timerefrig_off[each_off])
if len(timerefrig_off_hour)>=2 and int(timerefrig_off_hour[-1])-int(timerefrig_off_hour[-2])<=2 and each_off==len(timerefrig_off_hour)-1:
if len(timerefrig_off_hour) >= 2 and int(
timerefrig_off_hour[-1]) - int(
timerefrig_off_hour[-2]) <= 2 and each_off == len(
timerefrig_off_hour) - 1:
refrigRunStages.append(timerefrig_off[each_off])
if int(timerefrig_off_hour[each_off])-int(timerefrig_off_hour[each_off-1])<=2 or int(timerefrig_off_hour[each_off])<6 or int(timerefrig_off_hour[each_off])>21:
if int(timerefrig_off_hour[each_off]) - int(
timerefrig_off_hour[each_off - 1]) <= 2 or int(
timerefrig_off_hour[each_off]) < 6 or int(
timerefrig_off_hour[each_off]) > 21:
continue
else:
if each_off<len(timerefrig)-1:
refrigRunStages.append(timerefrig_off[each_off-1])
findStart1=findStart(timerefrig=timerefrig,timerefrig_last=timerefrig_off[each_off-1],ahead=each_off)
if each_off < len(timerefrig) - 1:
refrigRunStages.append(timerefrig_off[each_off - 1])
findStart1 = findStart(timerefrig=timerefrig,
timerefrig_last=timerefrig_off[
each_off - 1], ahead=each_off)
refrigRunStages.append(timerefrig[findStart1])
else:
refrigRunStages.append(timerefrig_off[each_off])
return refrigRunStages
\ No newline at end of file
return refrigRunStages
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