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
# /usr/bin/env python
# -*- coding: UTF-8 -*-l
import numpy as np
def voltDipReg(data, ctnum):
if ctnum == 3:
datalen = len(data["ua"])
cycleNum = int(np.floor(datalen / 80))
ampua = [max(data["ua"][i * 80:(i + 1) * 80]) for i in range(cycleNum)]
ampub = [max(data["ub"][i * 80:(i + 1) * 80]) for i in range(cycleNum)]
ampuc = [max(data["uc"][i * 80:(i + 1) * 80]) for i in range(cycleNum)]
maxua = max(ampua)
minua = min(ampua)
interua = (maxua - minua) / 4
splitDict = {"0": [], "1": [], "2": []}
for each in ampua:
for i in range(3):
if each > minua + i * interua and each < minua + (i + 1) * interua:
splitDict[str(i)].append(each)
splitLen = {}
for eachkey in splitDict.keys():
splitLen[eachkey] = len(splitDict[eachkey])
maxlenkey = max(splitLen, key=splitLen.get)
if splitLen[maxlenkey] < 0.1:
return 0
virtual = np.sum(splitDict[maxlenkey]) / splitLen[maxlenkey]
flag = 0
if min(ampua)<0.9*virtual or min(ampub)<0.9*virtual or min(ampuc)<0.9*virtual:
flag=1
else:
datalen = len(data["uab"])
cycleNum = int(np.floor(datalen / 80))
ampuab = [max(data["uab"][i * 80:(i + 1) * 80]) for i in range(cycleNum)]
ampubc = [max(data["ubc"][i * 80:(i + 1) * 80]) for i in range(cycleNum)]
maxua = max(ampuab)
minua = min(ampuab)
interua = (maxua - minua) / 4
splitDict = {"0": [], "1": [], "2": []}
for each in ampuab:
for i in range(3):
if each > minua + i * interua and each < minua + (i + 1) * interua:
splitDict[str(i)].append(each)
splitLen = {}
for eachkey in splitDict.keys():
splitLen[eachkey] = len(splitDict[eachkey])
maxlenkey = max(splitLen, key=splitLen.get)
if splitLen[maxlenkey] < 0.1:
return 0
virtual = np.sum(splitDict[maxlenkey]) / splitLen[maxlenkey]
flag = 0
if min(ampuab)<0.9*virtual or min(ampubc)<0.9*virtual:
flag=1
return flag