data["水流量"] = data["水流量"] / 60 # 原单位L/min,现转换为L/sec sj["总用水量"] = 0 # 给总用水量赋一个初始值0 for i in range(len(sj)): Start = sj.loc[i,"事件起始编号"]-1 End = sj.loc[i,"事件终止编号"]-1 if Start != End: for j in range(Start,End): if data.loc[j,"水流量"] != 0: sj.loc[i,"总用水量"] = (data.loc[j + 1,"发生时间"] - data.loc[j,"发生时间"]).seconds* \ data.loc[j,"水流量"] + sj.loc[i,"总用水量"] sj.loc[i,"总用水量"] = sj.loc[i,"总用水量"] + data.loc[End,"水流量"] * 2 else: sj.loc[i,"总用水量"] = data.loc[Start,"水流量"] * 2 sj["平均水流量"] = sj["总用水量"] / sj["用水时长"] # 定义特征 平均水流量 # 构造特征:水流量波动 # 水流量波动=∑(((单次水流的值-平均水流量)^2)*持续时间)/用水时长 sj["水流量波动"] = 0 # 给水流量波动赋一个初始值0 for i in range(len(sj)): Start = sj.loc[i,"事件起始编号"] - 1 End = sj.loc[i,"事件终止编号"] - 1 for j in range(Start,End + 1): if data.loc[j,"水流量"] != 0: slbd = (data.loc[j,"水流量"] - sj.loc[i,"平均水流量"])**2 slsj = (data.loc[j + 1,"发生时间"] - data.loc[j,"发生时间"]).seconds sj.loc[i,"水流量波动"] = slbd * slsj + sj.loc[i,"水流量波动"] sj.loc[i,"水流量波动"] = sj.loc[i,"水流量波动"] / sj.loc[i,"用水时长"] # 构造特征:停顿时长波动 # 停顿时长波动=∑(((单次停顿时长-平均停顿时长)^2)*持续时间)/总停顿时长 sj["停顿时长波动"] = 0 # 给停顿时长波动赋一个初始值0 for i in range(len(sj)): if sj.loc[i,"停顿次数"] > 1: # 当停顿次数为0或1
时间: 2024-04-06 11:32:08 浏览: 98
时,停顿时长波动为0 Start = sj.loc[i,"事件起始编号"] - 1 End = sj.loc[i,"事件终止编号"] - 1 tdsc = sj.loc[i,"停顿时长"] tdc = sj.loc[i,"停顿次数"] for j in range(Start,End): if data.loc[j,"水流量"] == 0: tdsc = (data.loc[j + 1,"发生时间"] - data.loc[j,"发生时间"]).seconds + tdsc sj.loc[i,"总停顿时长"] = tdsc sj.loc[i,"平均停顿时长"] = tdsc / tdc for j in range(Start,End + 1): if data.loc[j,"水流量"] == 0: tdbd = (tdsc / tdc - (data.loc[j + 1,"发生时间"] - data.loc[j,"发生时间"]).seconds)**2 tdsj = (data.loc[j + 1,"发生时间"] - data.loc[j,"发生时间"]).seconds sj.loc[i,"停顿时长波动"] = tdbd * tdsj + sj.loc[i,"停顿时长波动"] sj.loc[i,"停顿时长波动"] = sj.loc[i,"停顿时长波动"] / sj.loc[i,"总停顿时长"] # 构造特征:用水习惯 sj["用水习惯"] = 0 # 给用水习惯赋一个初始值0 for i in range(len(sj)): if sj.loc[i,"用水时长"] > 0: sj.loc[i,"用水习惯"] = sj.loc[i,"总用水量"] / sj.loc[i,"用水时长"]
阅读全文