forked from paai-lab/AIR-BAGEL-2020
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPageTwo.py
More file actions
189 lines (151 loc) · 8.01 KB
/
Copy pathPageTwo.py
File metadata and controls
189 lines (151 loc) · 8.01 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
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
import warnings
warnings.filterwarnings(action='ignore')
#GUI PACKAGES
import tkinter as tk
from tkinter import *
from tkinter import ttk
from tkinter import messagebox
#Pages
from PageTwo_Resource import Resource_Step1
from PageTwo_Resource import Resource_Step1_sub
from PageTwo_Inject_Anomaly import Inject_Anomaly
from PageTwo_System import System_Step1
from PageThree import PageThree
from PageTwo_System_self import System_step1_self
from PageTwo_Resource_self import Resource_step1_self
class PageTwo(tk.Frame):
def new_window1(self, parent, extracted_data):
if self.type1.get() == 'Random':
Win_class = Resource_Step1
if self.type1.get() == 'Self-configuration':
Win_class = Resource_step1_self
global win2
Resource_Step1.extracted_data = extracted_data
Resource_Step1_sub.extracted_data = extracted_data
win2 = tk.Toplevel(self)
Win_class(win2, parent)
Win_class(win2, parent)
def new_window2(self, Win_class):
Inject_Anomaly.a = self.cVar1.get()
Inject_Anomaly.b = self.cVar2.get()
PageThree.a = self.cVar1.get()
PageThree.b = self.cVar2.get()
global win2
win2 = tk.Toplevel(self)
Win_class(win2)
def new_window3(self, parent):
if self.type2.get() == 'Random':
Win_class = System_Step1
if self.type2.get() == 'Self-configuration' :
Win_class = System_step1_self
global win2
win2 = tk.Toplevel(self)
Win_class(win2, parent)
def __init__(self, parent):
tk.Frame.__init__(self, parent, bg='dark slate gray')
# Create main containers
top_frame = Frame(self, bg='dark slate gray', padx=7, pady=3)
center = Frame(self, bg='dark slate gray', padx=7, pady=3)
self.grid_rowconfigure(1, weight=1)
self.grid_columnconfigure(0, weight=1)
top_frame.grid(row=0, sticky="nsew")
center.grid(row=1, sticky="nsew")
top_frame.grid_rowconfigure(0, weight=1)
top_frame.grid_columnconfigure(0, weight=1)
center.grid_rowconfigure(0, weight=1)
center.grid_columnconfigure(0, weight=1)
# Title widget (top frame)
top_mid_label1 = Label(top_frame, text='(2) Root parameter setting', font=("Consolas", 13, 'bold'),
fg="white", bg='gray25', relief = "raised")
top_mid_label1.grid(row=0, column=0, sticky="nsew")
top_mid_label1.grid_rowconfigure(1, weight=1)
top_mid_label1.grid_columnconfigure(0, weight=1)
# Create sub frame (center frame)
ctr_mid = Frame(center, bg='gray1', highlightthickness=1, highlightbackground="gray15")
ctr_mid.grid(row=0, column=0, pady=(0, 3), sticky="nsew")
# ctr_mid.grid_rowconfigure(1, weight=1)
ctr_mid.grid_columnconfigure(0, weight=1)
ctr_mid_label1 = Label(ctr_mid, text='Root design (Resource/System)', font=("Consolas", 10, 'bold'),
fg="white", bg='gray25', relief="raised")
ctr_mid_label1.grid(row=0, column=0, sticky="nsew")
# Page explanation (center-top)
ctr_mid_label2b = LabelFrame(ctr_mid, text=" Explanation ", font=("Consolas", 10, 'bold'),
fg="white", bg='gray1', bd=1)
ctr_mid_label2b.grid(row=1, column=0, padx= 10,sticky='nw')
Guide_container1 = Frame(ctr_mid_label2b, bg='gray0', highlightbackground="gray1",
highlightthickness=0)
Guide_container1.grid(row=0, column=0)
Guide_Label1 = Text(Guide_container1, width=55, height=6, wrap=tk.WORD, fg="aquamarine", bg='gray1', bd=0)
Guide_Label1.insert(tk.CURRENT,
" Select Resource or System as root cause of injected anomalies (it is possible to select both).\n For each root cause, set whether to draw anomalies from a random distribution (random) or through manually set configuration (self-configuration)")
Guide_Label1.grid(row=0, column=0, padx= 3, pady=5)
# Set failure rate (center-mid)
ctr_mid_label2 = LabelFrame(ctr_mid, text=" Set parameters on root causes ", font=("Consolas", 10, 'bold'),
fg="white", bg='gray1', bd=3, padx=14, pady=7)
ctr_mid_label2.grid(row=2, column=0, padx= 10, pady=7, sticky='nws')
# For failure rate of resource (center-mid)
ctr_mid_subframe1 = Frame(ctr_mid_label2, bg='gray1', padx=3, pady=0,
highlightbackground="gray1",
highlightthickness=1)
ctr_mid_subframe1.grid(row=1, column=0)
self.cVar1 = IntVar() #resource button
Resource_Step1.event_log = self.event_log #orginal data without preprocessing
Resource_step1_self.event_log = self.event_log
Resource_Step1.firstpreprocess = self.firstpreprocess #orginal data without preprocessing
Resource_step1_self.firstpreprocess = self.firstpreprocess
Resource_step1_self.extracted_data = self.extracted_data
System_Step1.firstpreprocess = self.firstpreprocess #orginal data without preprocessing
System_step1_self.firstpreprocess = self.firstpreprocess
self.ok=0
s = ttk.Style()
s.configure('Red.TCheckbutton', foreground="white", background='gray1', font=("Consolas", 10, 'bold'))
s.map('Red.TCheckbutton', background=[('active', 'gray1')])
Resource_Label1 = ttk.Checkbutton(ctr_mid_subframe1, text=" Failure rate of Resource: ", variable=self.cVar1, width=27,
onvalue=1, offvalue=0, style='Red.TCheckbutton')
Resource_Label1.grid(row=0, column=0, sticky='w')
self.cVar1.set(1)
dist_chosen1 = ttk.Combobox(ctr_mid_subframe1, width=17, textvariable=tk.StringVar())
dist_chosen1.grid(row=0, column=1, padx=5)
dist_chosen1['values'] = ['Random', 'Self-configuration']
dist_chosen1.current(0)
def Set1():
self.ok=1
self.new_window1(parent, self.extracted_data)
self.type1 = dist_chosen1
ctr_button1 = tk.Button(ctr_mid_subframe1, text="Set", width=8,
command=lambda: Set1())
ctr_button1.grid(row=0, column=2)
# For failure rate of system (center-mid)
self.cVar2 = IntVar() # system button
System_Step1.event_log = self.event_log #orginal data without preprocessing
System_step1_self.event_log = self.event_log
System_Label1 = ttk.Checkbutton(ctr_mid_subframe1, text=" System malfunctioning : ", variable=self.cVar2, width=25,
onvalue=1, offvalue=0, style='Red.TCheckbutton')
System_Label1.grid(row=1, column=0, sticky='w')
self.cVar2.set(0)
dist_chosen2 = ttk.Combobox(ctr_mid_subframe1, width=17, textvariable=tk.StringVar())
dist_chosen2['values'] = list(['Random', 'Self-configuration'])
dist_chosen2.current(0)
dist_chosen2.grid(row=1, column=1, padx=5)
System_Step1.extracted_data = self.extracted_data #data with key attributes
System_step1_self.extracted_data = self.extracted_data
def Set2():
self.ok=1
self.new_window3(parent)
self.type2 = dist_chosen2
ctr_button3 = tk.Button(ctr_mid_subframe1, text="Set", width =8,
command=lambda: Set2())
ctr_button3.grid(row=1, column=2)
def Next():
if self.ok == 1:
Inject_Anomaly.a = self.cVar1.get()
Inject_Anomaly.b = self.cVar2.get()
PageThree.a = self.cVar1.get()
PageThree.b = self.cVar2.get()
parent.show_frame1_2()
else:
messagebox.showinfo("Error", "Set root parameters firstly")
button2 = tk.Button(ctr_mid, text="Next", width=10,
command=Next)
button2.grid(row=3,column=0, sticky='e', padx=(0,20), pady=(10,10))
parent.update()