-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwalkthrough.py
157 lines (145 loc) · 5.17 KB
/
walkthrough.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
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
#!/usr/bin/python3
import json
import argparse
import sys
import numpy as np
import const
import walkthrough_base
parser = argparse.ArgumentParser()
parser.add_argument('-o', '--output-file', type=str)
args = parser.parse_args()
"""
Define your services in this array, using this format:
{
'service': 0, # index of service
'name': 'service0', # name of the service
'sd0': (1, True), # value and certificate of the service data 0
'req0': ([0, 2], 1, True), # range of accepted value, cardinality and certification request for service data 0
... add any sd and req you want
'policy': [0.3, 0.6], # low threshold and high threshold for actions
}
"""
services = [
{
'service': 0,
'name': 's_brazil',
'sd0': ('three_biggest_cities', False), # sample type
'sd1': (25, False), # cardinality
'sd2': ('WEU', False), # location
'req0': ({'national', 'three_biggest_cities', 'urban'}, const.REQ_CARDINALITY_FORALL, True), # requirement on type
'req1': ([20, np.inf], const.REQ_CARDINALITY_FORALL, False), # requirement on cardinality
'req2': ({'WEU', 'LATAM'}, const.REQ_CARDINALITY_EXISTS, False), # requirement on location
'policy': [0.4, 0.6]
},
{
'service': 1,
'name': 's_chile',
'sd0': ('national', False), # sample type
'sd1': (25, False), # cardinality
'sd2': ('LATAM', False), # location
'req0': ({'national', 'three_biggest_cities', 'urban'},
const.REQ_CARDINALITY_FORALL, True), # requirement on type
'req1': ([1, np.inf], const.REQ_CARDINALITY_FORALL, False), # requirement on cardinality
'req2': ({'EEU', 'WEU', 'LATAM'}, const.REQ_CARDINALITY_FORALL, False), # requirement on location
'policy': [0.4, 0.7],
'change': []
},
{
'service': 2,
'name': 's_france',
'sd0': ('national', True), # sample type
'sd1': (30, True), # cardinality
'sd2': ('WEU', True), # location
'req0': ({'national'}, const.REQ_CARDINALITY_EXISTS, True), # requirement on type
'req1': ([1, np.inf], const.REQ_CARDINALITY_FORALL, False), # requirement on cardinality
'req2': ({'WEU', 'EEU'}, const.REQ_CARDINALITY_FORALL, True), # requirement on location
'policy': [0.4, 0.7],
'change': []
},
{
'service': 3,
'name': 's_italy',
'sd0': ('national', True), # sample type
'sd1': (30, True), # cardinality
'sd2': ('WEU', True), # location
'req0': ({'national', 'three_biggest_cities', 'urban'},
const.REQ_CARDINALITY_FORALL, True), # requirement on type
'req1': ([30, np.inf], const.REQ_CARDINALITY_FORALL, False), # requirement on cardinality
'req2': ({'EEU', 'WEU'}, const.REQ_CARDINALITY_EXISTS, True), # requirement on location
'policy': [1],
'change': []
},
{
'service': 4,
'name': 's_mexico',
'sd0': ('three_biggest_cities', False), # sample type
'sd1': (25, False), # cardinality
'sd2': ('LATAM', False), # location
'req0': ({'national', 'three_biggest_cities', 'urban'},
const.REQ_CARDINALITY_FORALL, True), # requirement on type
'req1': ([25, np.inf], const.REQ_CARDINALITY_FORALL, False), # requirement on cardinality
'req2': ({'LATAM'}, const.REQ_CARDINALITY_EXISTS, False), # requirement on location
'policy': [0.2, 0.5],
'change': []
},
{
'service': 5,
'name': 's_poland',
'sd0': ('national', True), # sample type
'sd1': (28, True), # cardinality
'sd2': ('EEU', True), # location
'req0': ({'national', 'three_biggest_cities', 'urban'},
const.REQ_CARDINALITY_FORALL, True), # requirement on type
'req1': ([1, np.inf], const.REQ_CARDINALITY_FORALL, False), # requirement on cardinality
'req2': ({'WEU', 'EEU', 'LATAM'}, const.REQ_CARDINALITY_FORALL, False), # requirement on location
'policy': [0.2, 0.5],
'change': []
},
{
'service': 6,
'name': 's_romania',
'sd0': ('national', True), # sample type
'sd1': (35, True), # cardinality
'sd2': ('EEU', True), # location
'req0': ({'national'}, const.REQ_CARDINALITY_EXISTS, True), # requirement on type
'req1': ([1, np.inf], const.REQ_CARDINALITY_FORALL, False), # requirement on cardinality
'req2': ({'WEU', 'EEU'}, const.REQ_CARDINALITY_EXISTS, True), # requirement on location
'policy': [0.4, 0.7],
'change': []
}
]
"""
Define services' changes using this format:
(
'service name',
[
('sd0', <sd0 new value>),
...
('sdn', <sdn new value>)
]
)
"""
changes = [
(
's_chile',
[
('sd2', 'EEU')
]
),
(
's_romania',
[
('sd1', 15)
]
),
(
's_poland',
[
('sd0', 'urban')
]
)
]
results = walkthrough_base.execute_walkthrough(services=services, changes=changes)
if args.output_file:
sys.stdout = open(args.output_file, 'w')
print(json.dumps(results, indent=4))