1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
import pandas as pd
def likesEquip(time):
res = []
for each in time:
eachtime = str(each).split(" ")[1].split(":")[0]
if int(eachtime) > 19 or int(eachtime) < 5:
res.append("大功率设备疑似热水器")
elif int(eachtime) > 18 and int(eachtime) < 19:
res.append("大功率设备疑似洗衣机")
elif int(eachtime) > 5 and int(eachtime) < 8:
res.append("大功率设备疑似电吹风")
else:
res.append("大功率设备疑似电磁炉")
return res
def bigPowerReg(eachdata="powerdata", key="a"):
overload = 3500
bigpower = 2500
bigpowerone = [1000, 90]
bigpowertwo = [1500, 120]
# quanter = quancalcu(sid, key=key)
# print(quanter)
powerdata = eachdata["p"].values
day_time = eachdata["time"].values.tolist()
day_time_all = [pd.to_datetime(day_time[i], format='%Y-%m-%d %H:%M:%S') for
i in
range(len(day_time))]
power_Series = pd.Series(powerdata, index=day_time_all)
power_Series_diff = power_Series.diff(1)
power_Series_diff_list = list(power_Series_diff[1:])
flag1 = 0
timeone = 0
flag2 = 0
timetwo = 0
flag3 = 0
timethr = 0
res = []
for i in range(len(power_Series_diff) - 10):
if flag1 == 1 and power_Series_diff[i] * 1000 > -400:
timeone = timeone + 1
continue
if flag1 == 1 and power_Series_diff[i] * 1000 < -1000 and powerdata[
i] * 1000 < 2000 and max(powerdata[i + 1:i + 10]) * 1000 < 2000:
res.append(day_time_all[i])
timeone = 0
flag1 = 0
if flag2 == 1 and power_Series_diff[i] * 1000 < -500:
if timetwo > 120 and max(powerdata[i + 1:i + 10]) * 1000 < 500:
res.append(day_time_all[i])
timetwo = 0
flag2 = 0
if flag2 == 1 and power_Series_diff[i] * 1000 > -400:
timetwo = timetwo + 1
continue
if flag3 == 1 and power_Series_diff[i] * 1000 < -1500:
if max(powerdata[i + 1:i + 10]) * 1000 < 500:
res.append(day_time_all[i])
print(4)
timethr = 0
flag3 = 0
if flag3 == 1 and power_Series_diff[i] * 1000 > -400:
timethr = timethr + 1
continue
# if powerdata[i] * 1000 > bigpowerone[0] and powerdata[
# i] * 1000 > quanter * 0.6 and flag1 == 0:
# timeone = timeone + 1
# flag1 = 1
# res.append(day_time_all[i])
elif power_Series_diff[i] * 1000 > bigpowertwo[0] and \
power_Series_diff[i] * 1000 < bigpower:
res.append(day_time_all[i])
timetwo = timetwo + 1
flag2 = 1
if powerdata[i] > overload:
res.append(day_time_all[i])
timethr = timethr + 1
flag3 = 1
equips = likesEquip(time=res[0::2])
timer = [str(each) for each in res[0::2]]
return timer, equips
def vioPowerReg(eachdata="powerdata", key="a"):
viopowerone = [240, 150]
viopowertwo = [120, 1000]
viopowerthr = [3, 15, 700]
powerdata = eachdata["p"].values
day_time = eachdata["time"].values.tolist()
flag1 = 0
timeone = 0
startimeone = ""
flag2 = 0
timetwo = 0
startimetwo = ""
flag3 = 0
timethr = 0
startimethr = ""
totalthr = 0
res = []
equips = []
for i in range(1, len(powerdata) - 1):
if flag2 == 0 and powerdata[i] * 1000 > viopowertwo[1]:
timetwo = timetwo + 1
startimetwo = day_time[i]
flag2 = 1
continue
if flag2 == 1 and powerdata[i] * 1000 < viopowertwo[1] and timetwo >= \
viopowertwo[0]:
if int(str(day_time[i]).split(" ")[1].split(":")[0]) > 5 and int(
str(day_time[i]).split(" ")[1].split(":")[0]) < 22:
res.append(startimetwo)
equips.append("违规电器疑似电磁炉")
else:
res.append(startimetwo)
equips.append("违规电器疑似大功率充电器")
flag2 = 0
startimetwo = ""
timetwo = 0
continue
if flag2 == 1 and powerdata[i] * 1000 < viopowertwo[1]:
flag2 = 0
startimetwo = ""
timetwo = 0
if flag2 == 1 and powerdata[i] * 1000 > viopowertwo[1]:
timetwo = timetwo + 1
continue
if flag2 == 1 and powerdata[i] * 1000 < viopowertwo[1] and timeone < \
viopowertwo[0]:
flag2 = 0
startimetwo = ""
timetwo = 0
continue
if flag3 == 0 and abs(powerdata[i] - powerdata[i - 1]) * 1000 > \
viopowerthr[2]:
timethr = timethr + 1
startimethr = day_time[i]
totalthr = 1
flag3 = 1
continue
if flag3 == 1 and timethr > viopowerthr[1] and totalthr < viopowerthr[
0]:
startimethr = ""
totalthr = 0
flag3 = 0
timethr = 0
if flag3 == 1 and abs(powerdata[i] - powerdata[i - 1]) * 1000 < \
viopowerthr[2] and timethr < viopowerthr[1]:
timethr = timethr + 1
if flag3 == 1 and abs(powerdata[i] - powerdata[i - 1]) * 1000 > \
viopowerthr[2] and timethr < viopowerthr[1]:
totalthr = totalthr + 1
timethr = timethr + 1
if flag3 == 1 and timethr <= viopowerthr[1] and totalthr >= \
viopowerthr[0] and powerdata[i] > 1.5:
res.append(startimethr)
equips.append("违规电器疑似电磁炉")
startimethr = ""
totalthr = 0
flag3 = 0
timethr = 0
continue
if flag1 == 0 and powerdata[i] * 1000 > viopowerone[1]:
timeone = timeone + 1
startimeone = day_time[i]
flag1 = 1
continue
if flag1 == 1 and powerdata[i] * 1000 < viopowerone[1] and timeone >= \
viopowerone[0]:
res.append(startimeone)
equips.append("违规电器疑似电动自行车")
flag1 = 0
startimeone = ""
timeone = 0
continue
if flag1 == 1 and powerdata[i] * 1000 < viopowerone[1]:
flag1 = 0
startimeone = ""
timeone = 0
if flag1 == 1 and powerdata[i] * 1000 > viopowerone[1]:
timeone = timeone + 1
continue
timer = [str(each) for each in res]
return timer, equips
# plt.rcParams['font.sans-serif'] = ['SimHei']
# plt.rcParams['axes.unicode_minus'] = False
#
# sidpath = "D:\gas\data\elect\struct\sort"
# keys = ["pa", "pb", "pc"]
# sids = os.listdir(sidpath)
# for sid in sids:
# print(sid)
# files = os.listdir(os.path.join(sidpath, sid))
# for file in files:
# print(file)
# eachpath = os.path.join(sidpath, sid, file)
# eachdata = pd.read_csv(eachpath, index_col=0)
# for key in keys:
# res, equips = bigPowerReg(eachdata=eachdata, key=key)
# fig, ax = plt.subplots()
# ax.plot(eachdata[key].values)
# if len(res) % 2 != 0:
# res.pop(-1)
# for each in range(len(res)):
# index = eachdata["time"].values.tolist().index(str(res[each]))
# # if each % 2==0:
# plt.annotate(equips[each],
# xy=(index, eachdata[key].values.tolist()[index]),
# xytext=(index, 0.5 + eachdata[key][index]),
# arrowprops=dict(arrowstyle='->'), fontsize=6)
# # else:
# # plt.annotate("关闭大功率设备", xy=(index, eachdata[key].values.tolist()[index]),
# # xytext=(index , 1+eachdata[key][index]), arrowprops=dict(arrowstyle='->'), fontsize=6)
# res, equips = vioPowerReg(eachdata=eachdata, key=key)
# for each in range(len(res)):
# index = eachdata["time"].values.tolist().index(str(res[each]))
# plt.annotate(equips[each],
# xy=(index, eachdata[key].values.tolist()[index]),
# xytext=(index, eachdata[key][index]),
# arrowprops=dict(arrowstyle='->'), fontsize=6)
#
# plt.show()
# print(res)