-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinput.py
More file actions
82 lines (70 loc) · 3.14 KB
/
Copy pathinput.py
File metadata and controls
82 lines (70 loc) · 3.14 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import logging
import pandas as pd
from node import Node
from relation import Relation
def read_input(input_path):
logging.info("Reading data from input files...")
nodes, global_Ap = read_tree(input_path)
relations = read_relations(input_path, nodes)
subjects, avg_comp_price, avg_transfer_price = read_subjects(input_path)
authorizations = read_authorizations(input_path)
return nodes[0], relations, subjects, authorizations, avg_comp_price, avg_transfer_price, global_Ap
def read_tree(input_path):
logging.debug('Reading tree structure...')
global_Ap = set()
nodes = list()
df = pd.read_csv(input_path + 'tree.csv')
df['parent'] = df['parent'].fillna(value=0)
df = df.fillna(value='')
df = df.astype({'ID': 'int', 'parent': 'int'})
df = df.astype({'Ap': 'str', 'Ae': 'str', 'As': 'str'})
for idx, row in df.iterrows():
global_Ap = global_Ap.union(set(row['Ap']))
multi_attr = False
if row['operation'] == 'selection':
if (len(row['Ap']) + len(row['Ae']) + len(row['As'])) > 1:
multi_attr = True
if not idx:
node = Node(
operation=row['operation'], Ap=row['Ap'], Ae=row['Ae'], As=row['As'],
print_label=row['print_label'], group_attr=row['group_attr'], select_multi_attr=multi_attr)
else:
node = Node(
operation=row['operation'], Ap=row['Ap'], Ae=row['Ae'], As=row['As'],
print_label=row['print_label'], group_attr=row['group_attr'],
select_multi_attr=multi_attr, parent=nodes[row['parent'] - 1])
nodes.append(node)
return nodes, global_Ap
def read_relations(input_path, nodes: list):
logging.debug('Reading relations...')
relations = list()
df = pd.read_csv(input_path + 'relations.csv')
df = df.fillna(value='')
df = df.astype('str')
df = df.astype({'node_id': int})
for idx, row in df.iterrows():
relation = Relation(
name=row['name'], storage_provider=row['provider'], primary_key=row['primary_key'],
plain_attr=row['plain_attr'], enc_attr=row['enc_attr'], attr=row['attr'],
enc_costs=row['enc_costs'], dec_costs=row['dec_costs'], size=row['size'])
relations.append(relation)
nodes[row['node_id'] - 1].relation = relation
return relations
def read_subjects(input_path):
logging.debug('Reading subjects...')
df = pd.read_csv(input_path + 'subjects.csv')
if df.isnull().values.any():
raise ValueError("Input: Subjects dataframe can't contain NaN values")
df = df.set_index('subject')
df['sum'] = df['comp_price'] + df['transfer_price']
df = df.sort_values(by=['sum'])
df = df.drop(columns=['sum'])
subjects = df.T.to_dict('dict')
avg_comp_price = df['comp_price'].median()
avg_transfer_price = df['transfer_price'].median()
return subjects, int(avg_comp_price), int(avg_transfer_price)
def read_authorizations(input_path):
logging.debug('Reading authorizations...')
df = pd.read_csv(input_path + 'authorizations.csv')
df = df.fillna(value='')
return df.set_index('subject').T.to_dict('dict')