-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfilter_parameter.py
84 lines (63 loc) · 2.65 KB
/
filter_parameter.py
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
#!/usr/bin/env python3
class filterParameter:
def __init__(self):
self.newData = {}
self.arrayParameter = []
def filterKeyValueParameter(self, data):
for key, value in data.items():
if "." not in key and value != '':
self.newData[key] = value
return self.newData
def filterArrayParameter(self, data):
for key, value in data.items():
if "." in key and "#" not in key and "tags" not in key and int(len(key.split("."))) == 2:
self.arrayParameter.append(key.split(".")[0])
arrayParameterSet = set(self.arrayParameter)
for parameter in arrayParameterSet:
newList = []
for key, value in data.items():
if "#" not in key and parameter in key and value != '':
newList.append(value)
self.newData[parameter.split('.')[0]] = newList
return self.newData
## Special thanks to hung_pt for this function
def filterMappingParameter(self, data):
def isValid(key):
if '.' in key and 'tags' not in key and '#' not in key:
return True
else:
return False
def processAllLevel(keys, value, data, repeat=0, isLastArr=False):
if repeat == len(keys) - 1:
if isLastArr != True:
return data.update({keys[repeat]: value})
else:
return data.append(value)
else:
if repeat + 1 == len(keys) - 1:
try:
int(keys[repeat+1])
data.setdefault(keys[repeat], [])
isLastArr = True
except:
data.setdefault(keys[repeat], {})
else:
data.setdefault(keys[repeat], {})
data = processAllLevel(
keys, value, data[keys[repeat]], repeat + 1, isLastArr)
def powerVersion(data):
result = {}
for key, value in data.items():
if isValid(key) == True:
if len(key.split('.')) >= 3:
processAllLevel(key.split('.'), value, result)
return result
self.newData = powerVersion(data)
return self.newData
def filterTagsParameter(self, data):
for key, value in data.items():
newDict = {}
if 'tags' in key and '%' not in key and '.' in key:
newDict[key.split('tags.')[1]] = value
self.newData.setdefault(key.split('.')[0], {}).update(newDict)
return self.newData