-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFilter.py
More file actions
60 lines (52 loc) · 2.34 KB
/
Filter.py
File metadata and controls
60 lines (52 loc) · 2.34 KB
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
#['Group','AM','Client','Solution Portfolio']
import os
import pandas as pd
import numpy as np
def filter(df):
base_path = os.path.abspath(os.path.dirname(__file__))
file_path = os.path.join(base_path,"Config/ClientWhiteList.txt")
with open(file_path, "r", newline="\n") as cols:
filter = cols.read().splitlines()
cols.close()
cInd = []
out = list(set(df['Client'].values.tolist()) - set(filter))
for x in out:
cInd += df.index[ (df['Client'] == x)].tolist()
cInd = [ 2 + i for i in cInd]
file_path = os.path.join(base_path,"Config/AMWhiteList.txt")
with open(file_path, "r", newline="\n") as cols:
filter = cols.read().splitlines()
cols.close()
AMInd = []
out = list(set(df['AM'].values.tolist()) - set(filter))
for x in out:
AMInd += df.index[ (df['AM'] == x)].tolist()
AMInd = [ 2 + i for i in AMInd]
file_path = os.path.join(base_path,"Config/GroupWhiteList.txt")
with open(file_path, "r", newline="\n") as cols:
filter = cols.read().splitlines()
cols.close()
gInd = []
out = list(set(df['Group'].values.tolist()) - set(filter))
for x in out:
gInd += df.index[ (df['Group'] == x)].tolist()
gInd = [ 2 + i for i in gInd]
file_path = os.path.join(base_path,"Config/SolPortWhiteList.txt")
with open(file_path, "r", newline="\n") as cols:
filter = cols.read().splitlines()
cols.close()
sInd = []
out = list(set(df['Solution Portfolio'].values.tolist()) - set(filter))
for x in out:
sInd += df.index[ (df['Solution Portfolio'] == x)].tolist()
sInd = [ 2 + i for i in sInd]
if (not gInd and not sInd and not AMInd and not cInd):
return True
else:
f = open("Output/WhiteListLog.txt", "w")
f.write("Rows which have values outside the whitelisted values under Client: " + ' '.join(str(x) for x in cInd)+ "\n\n")
f.write("Rows which have values outside the whitelisted values under AM: " + ' '.join(str(x) for x in AMInd)+ "\n\n")
f.write("Rows which have values outside the whitelisted values under Groups: " + ' '.join(str(x) for x in gInd)+ "\n\n")
f.write("Rows which have values outside the whitelisted values under Solution Portfolio: " + ' '.join(str(x) for x in sInd)+ "\n\n")
f.close()
return False