-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.py
2408 lines (2053 loc) · 77.3 KB
/
test.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
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import matplotlib
import matplotlib.pyplot as plt
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.backends.backend_qt4agg import NavigationToolbar2QT as NavigationToolbar
import sys
import csv
import PyQt4
import plot
import ply.lex as lex
import ply.yacc as yacc
from sys import stdout
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4 import QtGui, QtCore
import os
if(os.path.isfile("objs.pkl") == True):
os.remove("objs.pkl")
if(os.path.isfile("objs_sd.pkl") == True):
os.remove("objs_sd.pkl")
if(os.path.isfile("out_cfg.csv") == True):
os.remove("out_cfg.csv")
if(os.path.isfile("out_cfg1.csv") == True):
os.remove("out_cfg1.csv")
if(os.path.isfile("out_cfg0.csv") == True):
os.remove("out_cfg0.csv")
#matplotlib.use("QT4Agg")
fields = [] #stores the column(field) names
col_with_strings = [] #stores names of those columns which can have strings as values
col_fil_list = {} #stores the upper and lower limits(set by user) of each columns(used in column filtering)
cfg_file_name = "cfg.csv" #the default "configure file"
lower_limit = {} #stores the lower limit of each columns(from the file)
upper_limit = {} #stores the upper limit of each columns(from the file)
lll = [] #temporary variable used to calculate lower limit (lll = lower limit list)
ull = [] #temporary variable used to calculate upper limit (ull = upper limit list)
out_list = [] #stores the items to be outputted in configure file
curr_filename = "" #stores the current file name
change = 0 #used to sync the sliders and combo boxes
cons={} #dictionary to store values of fields applied in generate constraints box
final_constraints=[] #list of all constraints to generate constraints file
undo_old = "" #stores old configuration string which can be recovered on pressing undo
undo_new = "" #stores configuration string on update press
write = "" #stores the string to be written in constraints.ecl
range_constraints_string ="" #hardcoded string (added for now for the tool)
class col_filtering_window(QWidget): #defines the class for column filtering window
def __init__(self):
super(col_filtering_window,self).__init__()
self.setWindowTitle("Column Filtering")
lay_range = QVBoxLayout()
lay_main = QHBoxLayout()
lay_but = QHBoxLayout()
lay_final = QVBoxLayout()
lay_l = QHBoxLayout()
lay_h = QHBoxLayout()
lay_filters_label = QHBoxLayout()
self.field = QLabel("Field")
self.field.setAlignment(Qt.AlignLeft)
self.lowerlim = QLabel("Lower Limit")
self.lowerlim.setAlignment(Qt.AlignLeft)
self.upperlim = QLabel("Upper Limit")
self.upperlim.setAlignment(Qt.AlignLeft)
lay_filters_label.addWidget(self.field)
lay_filters_label.addWidget(self.lowerlim)
lay_filters_label.addWidget(self.upperlim)
lay_filters = QHBoxLayout() #for displaying already applied column filters
self.display = QTextEdit()
self.display.setReadOnly(True)
self.display.setAlignment(Qt.AlignLeft)
self.enable_noresize = QCheckBox("Do not automatically resize axes")
self.enable_noresize.setEnabled(True)
self.enable_noresize.setChecked(False)
self.displ = QTextEdit()
self.displ.setReadOnly(True)
self.displ.setAlignment(Qt.AlignLeft)
self.dispu = QTextEdit()
self.dispu.setReadOnly(True)
self.dispu.setAlignment(Qt.AlignLeft)
lay_filters.addWidget(self.display)
lay_filters.addWidget(self.displ)
lay_filters.addWidget(self.dispu)
self.low = QLabel("Lower Limit")
self.low.setAlignment(Qt.AlignLeft)
self.up = QLabel("Upper Limit")
self.up.setAlignment(Qt.AlignLeft)
self.cb = QComboBox()
self.sl_l = QSlider(Qt.Horizontal)
self.sl_l.setRange(0,100)
self.sl_h = QSlider(Qt.Horizontal)
self.sl_h.setRange(0,100)
self.sp_l = QDoubleSpinBox()
self.sp_l.valueChanged.connect(self.sp_l_valuechange)
self.sp_l.setDecimals(6)
self.sp_h = QDoubleSpinBox()
self.sp_h.valueChanged.connect(self.sp_h_valuechange)
self.sp_h.setDecimals(6)
self.sl_l.valueChanged.connect(self.print_l)
self.sl_h.valueChanged.connect(self.print_h)
self.apply_but = QPushButton('&Apply')
self.apply_but.setDefault(True)
self.apply_but.clicked.connect(self.apply_func)
self.cancel_but = QPushButton('&Reset')
self.cancel_but.setDefault(True)
self.cancel_but.clicked.connect(self.cancel_func)
self.reset_all_but = QPushButton('&Reset All')
self.reset_all_but.setDefault(True)
self.reset_all_but.clicked.connect(self.reset_all_func)
self.ok_but = QPushButton('&OK')
self.ok_but.setDefault(True)
self.ok_but.clicked.connect(self.ok_func)
self.cb.currentIndexChanged.connect(self.selectionchange)
lay_l.addWidget(self.sl_l)
lay_l.addWidget(self.sp_l)
lay_h.addWidget(self.sl_h)
lay_h.addWidget(self.sp_h)
lay_range.addWidget(self.low)
lay_range.addLayout(lay_l)
lay_range.addWidget(self.up)
lay_range.addLayout(lay_h)
lay_main.addWidget(self.cb)
lay_main.addLayout(lay_range)
lay_but.addWidget(self.ok_but,0,Qt.AlignLeft)
lay_but.addWidget(self.apply_but,0,Qt.AlignRight)
lay_but.addWidget(self.cancel_but,0,Qt.AlignRight)
lay_but.addWidget(self.reset_all_but,0,Qt.AlignRight)
lay_final.addLayout(lay_filters_label)
lay_final.addLayout(lay_filters)
lay_final.addLayout(lay_main)
lay_final.addWidget(self.enable_noresize)
lay_final.addLayout(lay_but)
self.setLayout(lay_final)
def for_undo_redo(self): #Restores the values of column filters after undo or redo
global col_fil_list
global col_with_strings
global fields
self.selectionchange()
self.display.clear()
self.displ.clear()
self.dispu.clear()
for xy in fields:
if xy not in col_with_strings:
self.display.append(xy)
self.displ.append(str(col_fil_list[xy][0]))
self.dispu.append(str(col_fil_list[xy][1]))
def sp_l_valuechange(self): #changes value of lower slider based on value of lower spin box
global change
change = 1
b = str(PyQt4.QtCore.QString(self.cb.currentText()))
if b in lower_limit.keys():
if upper_limit[b] == lower_limit[b]:
a = (int)(self.sp_l.value())
else:
a = (int)(((self.sp_l.value() - lower_limit[b])*100)/(upper_limit[b] - lower_limit[b]))
else:
a = (int)(self.sp_l.value())
self.sl_l.setValue(a)
def sp_h_valuechange(self): #changes value of upper slider based on value of upper spin box
global change
change = 1
b = str(PyQt4.QtCore.QString(self.cb.currentText()))
if b in lower_limit.keys():
if upper_limit[b]==lower_limit[b]:
a = (int)(self.sp_h.value())
else:
a = (int)(((self.sp_h.value() - lower_limit[b])*100)/(upper_limit[b] - lower_limit[b]))
else:
a = (int)(self.sp_h.value())
self.sl_h.setValue(a)
def print_l(self): #changes value of lower spin box based on value of lower slider
global change
if change == 1:
change = 0
else :
b = str(PyQt4.QtCore.QString(self.cb.currentText()))
if b in lower_limit.keys():
a = lower_limit[b] + (((float)(self.sl_l.value())/100) * (upper_limit[b] - lower_limit[b]))
else:
a = (float)(self.sl_l.value())
self.sp_l.setValue(a)
def print_h(self): #changes value of upper spin box based on value of upper slider
global change
if change == 1:
change = 0
else :
b = str(PyQt4.QtCore.QString(self.cb.currentText()))
if b in lower_limit.keys():
a = lower_limit[b] + (((float)(self.sl_h.value())/100) * (upper_limit[b] - lower_limit[b]))
else:
a = (float)(self.sl_h.value())
self.sp_h.setValue(a)
def selectionchange(self): #changes values of both spin boxes and sliders based on the field
b = str(PyQt4.QtCore.QString(self.cb.currentText()))
if(lower_limit):
(temp_ll,temp_ul)=col_fil_list[b]
self.sp_l.setRange(lower_limit[b],upper_limit[b])
self.sp_h.setRange(lower_limit[b],upper_limit[b])
self.sp_l.setValue(temp_ll)
self.sp_h.setValue(temp_ul)
if b in lower_limit.keys():
if upper_limit[b] == lower_limit[b]:
a = (int)(self.sp_l.value())
else:
a = (int)(((self.sp_l.value() - lower_limit[b])*100)/(upper_limit[b] - lower_limit[b]))
else:
a = (int)(self.sp_l.value())
self.sl_l.setValue(a)
if b in lower_limit.keys():
if upper_limit[b] == lower_limit[b]:
a = (int)(self.sp_h.value())
else:
a = (int)(((self.sp_h.value() - lower_limit[b])*100)/(upper_limit[b] - lower_limit[b]))
else:
a = (int)(self.sp_h.value())
self.sl_h.setValue(a)
def reset_all_func(self): #Resets the sliders and spin boxes in column filtering window
global col_fil_list
global lower_limit
global upper_limit
global col_with_strings
global fields
for b in col_fil_list.keys():
col_fil_list[b]=(lower_limit[b],upper_limit[b])
b = str(PyQt4.QtCore.QString(self.cb.currentText()))
self.sp_l.setValue(lower_limit[b])
self.sp_h.setValue(upper_limit[b])
self.sl_l.setValue(0)
self.sl_h.setValue(100)
self.display.clear()
self.displ.clear()
self.dispu.clear()
for xy in fields:
if xy not in col_with_strings:
self.display.append(xy)
self.displ.append(str(col_fil_list[xy][0]))
self.dispu.append(str(col_fil_list[xy][1]))
def apply_func(self): #stores the upper and lower limit of the current field(as set by user) in col_fill_list[]
global col_fil_list
global lower_limit
global upper_limit
global col_with_strings
global fields
b = str(PyQt4.QtCore.QString(self.cb.currentText()))
if self.sp_l.value()>self.sp_h.value():
msg = QMessageBox()
msg.setIcon(QMessageBox.Warning)
msg.setText("Lower limit greater than upper limit for x-axis")
msg.setWindowTitle("Error")
msg.setStandardButtons(QMessageBox.Ok)
msg.exec_()
else:
col_fil_list[b]=(self.sp_l.value(),self.sp_h.value())
self.display.clear()
self.displ.clear()
self.dispu.clear()
for xy in fields:
if xy not in col_with_strings:
self.display.append(xy)
self.displ.append(str(col_fil_list[xy][0]))
self.dispu.append(str(col_fil_list[xy][1]))
def cancel_func(self): #resets the value of current field if previously stored(changess it back to the maximum upper limit and minimum lower limit as seen from file)
global col_fil_list
global lower_limit
global upper_limit
global col_with_strings
global fields
b = str(PyQt4.QtCore.QString(self.cb.currentText()))
col_fil_list[b]=(lower_limit[b],upper_limit[b])
self.sp_l.setValue(lower_limit[b])
self.sp_h.setValue(upper_limit[b])
self.sl_l.setValue(0)
self.sl_h.setValue(100)
self.display.clear()
self.displ.clear()
self.dispu.clear()
for xy in fields:
if xy not in col_with_strings:
self.display.append(xy)
self.displ.append(str(col_fil_list[xy][0]))
self.dispu.append(str(col_fil_list[xy][1]))
def ok_func(self): #same as apply, but closes the column filtering window afterwards
global col_fil_list
global lower_limit
global upper_limit
global col_with_strings
global fields
b = str(PyQt4.QtCore.QString(self.cb.currentText()))
if self.sp_l.value()>self.sp_h.value():
msg = QMessageBox()
msg.setIcon(QMessageBox.Warning)
msg.setText("Lower limit greater than upper limit for x-axis")
msg.setWindowTitle("Error")
msg.setStandardButtons(QMessageBox.Ok)
msg.exec_()
else:
col_fil_list[b]=(self.sp_l.value(),self.sp_h.value())
self.display.clear()
self.displ.clear()
self.dispu.clear()
for xy in fields:
if xy not in col_with_strings:
self.display.append(xy)
self.displ.append(str(col_fil_list[xy][0]))
self.dispu.append(str(col_fil_list[xy][1]))
self.close()
class update_constraints_window(QWidget): # WINDOW TO GENERATE CONSTRAINTS FILE
def __init__(self):
super(update_constraints_window,self).__init__()
self.setWindowTitle(" Setting constraints ")
self.cb = QComboBox()
self.cb.clear()
# LOWER
self.lower_limit_label = QLabel("Lower limit: ")
self.lower_limit = QLineEdit()
self.lower_limit_label.setEnabled(False)
self.lower_limit.setEnabled(False)
lay_lower_limit = QHBoxLayout();
lay_lower_limit.addWidget(self.lower_limit_label)
lay_lower_limit.addWidget(self.lower_limit)
self.enable_lower_limit = QCheckBox("Enable lower limit")
self.enable_lower_limit.setChecked(False)
self.enable_lower_limit.stateChanged.connect(self.lower_limit_func)
lower_limitf = QVBoxLayout();
lower_limitf.addWidget(self.enable_lower_limit)
lower_limitf.addLayout(lay_lower_limit)
# UPPER
self.upper_limit_label = QLabel("Upper Limit: ")
self.upper_limit = QLineEdit()
self.upper_limit_label.setEnabled(False)
self.upper_limit.setEnabled(False)
lay_upper_limit = QHBoxLayout();
lay_upper_limit.addWidget(self.upper_limit_label)
lay_upper_limit.addWidget(self.upper_limit)
self.enable_upper_limit = QCheckBox("Enable upper limit")
self.enable_upper_limit.setChecked(False)
self.enable_upper_limit.stateChanged.connect(self.upper_limit_func)
upper_limitf = QVBoxLayout();
upper_limitf.addWidget(self.enable_upper_limit)
upper_limitf.addLayout(lay_upper_limit)
# DISCRETE VALUES
self.allowed_values_label = QLabel("List of allowed values: ")
self.allowed_values = QLineEdit()
self.allowed_values_label.setEnabled(False)
self.allowed_values.setEnabled(False)
lay_allowed_values = QHBoxLayout();
lay_allowed_values.addWidget(self.allowed_values_label)
lay_allowed_values.addWidget(self.allowed_values)
self.enable_allowed_values = QCheckBox("Enable values insertion")
self.enable_allowed_values.setChecked(False)
self.enable_allowed_values.stateChanged.connect(self.discrete_values_func)
allowed_valuesf = QVBoxLayout();
allowed_valuesf.addWidget(self.enable_allowed_values)
allowed_valuesf.addLayout(lay_allowed_values)
choose = QVBoxLayout();
choose.addLayout(lower_limitf)
choose.addLayout(upper_limitf)
choose.addLayout(allowed_valuesf)
lay_constraints = QHBoxLayout()
lay_constraints.addWidget(self.cb)
lay_constraints.addLayout(choose)
self.apply_but = QPushButton('&Apply')
self.apply_but.setDefault(True)
self.apply_but.clicked.connect(self.apply_func)
self.generate_but = QPushButton('&Generate')
self.generate_but.setDefault(True)
self.generate_but.clicked.connect(self.generate_func)
self.cancel_but = QPushButton('&Cancel')
self.cancel_but.setDefault(True)
self.cancel_but.clicked.connect(self.cancel_func)
lay_buttons = QHBoxLayout()
lay_buttons.addWidget(self.apply_but)
lay_buttons.addWidget(self.generate_but)
lay_buttons.addWidget(self.cancel_but)
layout_final = QVBoxLayout() #final layout of window
layout_final.addLayout(lay_constraints)
layout_final.addLayout(lay_buttons)
self.setLayout(layout_final)
def lower_limit_func(self): #to enable/disable lower limit bar
if self.enable_lower_limit.isChecked():
self.lower_limit_label.setEnabled(True)
self.lower_limit.setEnabled(True)
self.enable_allowed_values.setEnabled (False)
else:
self.lower_limit_label.setEnabled(False)
self.lower_limit.setEnabled(False)
self.enable_allowed_values.setEnabled (True)
def upper_limit_func(self): #to enable/disable upper limit bar
if self.enable_upper_limit.isChecked():
self.upper_limit_label.setEnabled(True)
self.upper_limit.setEnabled(True)
self.enable_allowed_values.setEnabled (False)
else:
self.upper_limit_label.setEnabled(False)
self.upper_limit.setEnabled(False)
self.enable_allowed_values.setEnabled (True)
def discrete_values_func(self): #to enable/disable discrete values bar
if self.enable_allowed_values.isChecked():
self.allowed_values_label.setEnabled(True)
self.allowed_values.setEnabled(True)
self.enable_lower_limit.setEnabled (False)
self.enable_upper_limit.setEnabled (False)
else:
self.allowed_values_label.setEnabled(False)
self.allowed_values.setEnabled(False)
self.enable_lower_limit.setEnabled (True)
self.enable_upper_limit.setEnabled (True)
def apply_func(self): #stores the upper and lower limit of the current field(as set by user) in cons{}
global cons
b=str(PyQt4.QtCore.QString(self.cb.currentText()))
if (self.enable_allowed_values.isChecked()):
values = (self.allowed_values.text())
cons[b]=[3,str(values)]
#print cons[b]
elif (self.enable_lower_limit.isChecked() and self.enable_upper_limit.isChecked()):
ll = float(self.lower_limit.text())
ul = float(self.upper_limit.text())
if (ll>ul):
msg = QMessageBox()
msg.setIcon(QMessageBox.Warning)
msg.setText("Lower limit greater than upper limit")
msg.setWindowTitle("Error")
msg.setStandardButtons(QMessageBox.Ok)
msg.exec_()
else:
cons[b]=[2,ll,ul]
elif (self.enable_lower_limit.isChecked()):
ll=float(self.lower_limit.text())
cons[b]=[0,ll]
elif (self.enable_upper_limit.isChecked()):
ul = float(self.upper_limit.text())
cons[b]=[1,ul]
self.lower_limit.setText('')
self.upper_limit.setText('')
self.allowed_values.setText('')
self.lower_limit_label.setEnabled(False)
self.lower_limit.setEnabled(False)
self.upper_limit_label.setEnabled(False)
self.upper_limit.setEnabled(False)
self.enable_lower_limit.setChecked(False)
self.enable_upper_limit.setChecked(False)
self.enable_allowed_values.setChecked(False)
def generate_func(self):
global cons # dictionary to store the final constraints
global final_constraints
global undo_old
global undo_new
global write
global range_constraints_string
b=str(PyQt4.QtCore.QString(self.cb.currentText()))
if (self.enable_allowed_values.isChecked()):
values = (self.allowed_values.text())
cons[b]=[3,str(values)] # 3 denotes insertion of discrete values
#print cons[b]
elif (self.enable_lower_limit.isChecked() and self.enable_upper_limit.isChecked()):
ll = float(self.lower_limit.text())
ul = float(self.upper_limit.text())
if (ll>ul):
msg = QMessageBox()
msg.setIcon(QMessageBox.Warning)
msg.setText("Lower limit greater than upper limit")
msg.setWindowTitle("Error")
msg.setStandardButtons(QMessageBox.Ok)
msg.exec_()
else:
cons[b]=[2,ll,ul] # 2 implies both upper and lower limits have been specified
elif (self.enable_lower_limit.isChecked()):
ll=float(self.lower_limit.text())
cons[b]=[0,ll] # 0 if only the lower limit specified
elif (self.enable_upper_limit.isChecked()):
ul = float(self.upper_limit.text())
cons[b]=[1,ul] # 1 if only the upper limit is specified
#final_constraints list created from the dictionary cons to be written in to the contrainsts file
if (len(cons)==0):
final_constraints.append(-1)
else:
for field in cons:
final_constraints.append(field)
for values in cons[field]:
final_constraints.append(values)
f = open("constraints.ecl","w+")
write = ""
a = final_constraints[:-1]
# The list is parsed and the string to be written into the file is created
i = 0
while i < len(a):
if final_constraints[i+1] == 0:
write += '\n\t'+final_constraints[i].strip()+' $>= '+str(int(final_constraints[i+2]))+','
i += 3
elif final_constraints[i+1] == 1:
write += '\n\t'+final_constraints[i].strip()+' $=< '+str(int(final_constraints[i+2]))+','
i += 3
elif final_constraints[i+1] == 2:
write += '\n\t'+final_constraints[i].strip()+' $>= '+str(int(final_constraints[i+2]))+','
write += '\n\t'+final_constraints[i].strip()+' $=< '+str(int(final_constraints[i+3]))+','
i += 4
else:
write += '\n\t'+final_constraints[i].strip()+' :: '+str(map(int,final_constraints[i+2].split(" ")))+','
i += 3
if len(write)>0:
write = write[:-1] + '.';
range_constraints_string = "range_constraints("
for i in fields[:-1]:
range_constraints_string += i.strip()+", ";
if (len(fields)>0):
range_constraints_string += fields[-1].strip()
range_constraints_string += ") :-"
range_constraints_string = "range_constraints(Ncore, Battery, MinFrames, WS, Atotal, Blife, Weight) :-" #These fields have been hardcoded for now as it was found some of these fields are necessary for tool to run
# Remove the above line to make the constraints file according to the fields of the currently open file
# range_constraints_string += "\t\nNcore :: [1,2,4,8],\n"
# range_constraints_string += "\tBattery :: [1,2,3,4],\n"
# range_constraints_string += "\tMinFrames :: [3],\n"
# range_constraints_string += "\tWS :: [25,50,75,100,125,150],"
# These are the fields that were present in the original test file
undo_old = undo_new
undo_new = write
f.write(range_constraints_string)
f.write(write);
f.close() #constraints file updated
self.close()
os.system("../eclipse/bin/x86_64_linux/eclipse -f ../eclipse/tmp/test.ecl -f constraints.ecl -e main,fail") #tool called
file_change = open("file.txt","r")
newfile = open("generated.csv","w") #generated.csv removes the leading and trailing brackets present in each line of file.txt
x = file_change.readlines()
for i in x:
newfile.write(i[1:-2]+'\n')
file_change.close()
newfile.close()
def cancel_func(self): #resets all the constraints set after opening this window
global final_constraints
del final_constraints[:]
global cons
cons.clear()
def addItemsinCB(self): #adds fields to the combo box with stripped spaces
self.cb.clear()
self.cb.addItems([i.strip() for i in fields])
class sub_window(QWidget): #class defining the sub windows(as they appear in tabs)
subwindow_id = 0
def __init__(self):
super(sub_window, self).__init__()
group_box_x = QGroupBox('&X-Axis')
group_box_y = QGroupBox('&Y-Axis')
group_box_z = QGroupBox('&Z-Axis/Secondary Y-Axis')
group_box_3 = QGroupBox('&Third Parameter(Default:Color)')
group_box_4 = QGroupBox('&Fourth Parameter(shape/Grouping)')
group_box_pareto = QGroupBox('&Pareto Parameters')
group_box_type_of_graph = QGroupBox('&Type of Graph')
group_box_curve_fitting = QGroupBox('&Curve Fitting')
lay_3_4 = QVBoxLayout()
lay_3_4.addWidget(group_box_3)
lay_3_4.addWidget(group_box_4)
self.graph_type = QLabel("Select Type:") #Adding things in graph_type combo box
self.graph_type_cb = QComboBox()
self.graph_type_cb.addItem("scatter")
self.graph_type_cb.addItem("line")
self.graph_type_cb.addItem("histogram")
self.graph_type_cb.addItem("bar-graph")
self.graph_type_cb.addItem("bar-scatter")
#new segment of code to add if min max or avg in bar graph
self.bargraph_cb = QComboBox()
self.bargraph_cb.addItem("Minimum")
self.bargraph_cb.addItem("Average")
self.bargraph_cb.addItem("Maximum")
self.bargraph_cb.addItem("All")
self.bargraph_cb.setEnabled(False)
self.bargraph_cb.currentIndexChanged.connect(self.bargraph_func)
#new segment of code to enable labelling y value on bars
self.enable_yval = QCheckBox("Enable values on bars")
self.enable_yval.setChecked(False)
self.enable_yval.setEnabled(False)
#new segment of code to add if normalization or not
self.norm = QLabel("Normalization:")
self.norm.setAlignment(Qt.AlignRight)
self.norm.setEnabled(False)
self.norm_cb = QComboBox()
self.norm_cb.addItem("Yes")
self.norm_cb.addItem("No")
self.norm_cb.setEnabled(False)
lay_norm = QHBoxLayout()
lay_norm.addWidget(self.norm)
lay_norm.addWidget(self.norm_cb)
lay_graph_type = QVBoxLayout()
lay_graph_type.addWidget(self.graph_type)
lay_graph_type.addWidget(self.graph_type_cb)
lay_graph_type.addWidget(self.bargraph_cb)
lay_graph_type.addLayout(lay_norm)
lay_graph_type.addWidget(self.enable_yval)
group_box_type_of_graph.setLayout(lay_graph_type)
self.degree_label = QLabel("Enter degree:")
self.curve_fitting_sb = QSpinBox()
self.curve_fitting_sb.setMaximum(100)
self.degree_label.setEnabled(False)
self.curve_fitting_sb.setEnabled(False)
self.enable_curve_fitting = QCheckBox("Enable curve fitting")
self.enable_curve_fitting.setChecked(False)
self.enable_curve_fitting.stateChanged.connect(self.curve_fitting_func)
self.graph_type_cb.currentIndexChanged.connect(self.selectionchangetype)
lay_curve_fitting_h = QHBoxLayout()
lay_curve_fitting_v = QVBoxLayout()
lay_curve_fitting_h.addWidget(self.degree_label)
lay_curve_fitting_h.addWidget(self.curve_fitting_sb)
lay_curve_fitting_v.addLayout(lay_curve_fitting_h)
lay_curve_fitting_v.addWidget(self.enable_curve_fitting)
group_box_curve_fitting.setLayout(lay_curve_fitting_v)
lay_curve_fit_graph_type = QVBoxLayout()
lay_curve_fit_graph_type.addWidget(group_box_type_of_graph)
lay_curve_fit_graph_type.addWidget(group_box_curve_fitting)
self.title_label = QLabel("Title:")
self.title_name = QLineEdit()
self.title_label.setEnabled(False)
self.title_name.setEnabled(False)
self.pareto_x = QLabel("X-axis:")
self.pareto_y = QLabel("Y-Axis:")
self.pareto_x.setEnabled(False)
self.pareto_y.setEnabled(False)
self.pareto_cbx = QComboBox()
self.pareto_cby = QComboBox()
self.pareto_cbx.setEnabled(False)
self.pareto_cby.setEnabled(False)
self.pareto_cbx.addItem("Maximize")
self.pareto_cbx.addItem("Minimize")
self.pareto_cby.addItem("Maximize")
self.pareto_cby.addItem("Minimize")
lay_pareto_x = QHBoxLayout()
lay_pareto_y = QHBoxLayout()
lay_pareto_main = QVBoxLayout()
lay_pareto_final = QVBoxLayout()
self.enable_plot_pareto = QCheckBox("Plot Pareto Curve")
self.enable_plot_pareto.setChecked(False)
self.enable_plot_pareto.stateChanged.connect(self.pareto_func)
lay_pareto_x.addWidget(self.pareto_x)
lay_pareto_x.addWidget(self.pareto_cbx)
lay_pareto_y.addWidget(self.pareto_y)
lay_pareto_y.addWidget(self.pareto_cby)
lay_pareto_main.addLayout(lay_pareto_x)
lay_pareto_main.addLayout(lay_pareto_y)
lay_pareto_final.addLayout(lay_pareto_main)
lay_pareto_final.addWidget(self.enable_plot_pareto)
group_box_pareto.setLayout(lay_pareto_final)
final_layout = QHBoxLayout() #final layout including graphic view
layout = QVBoxLayout() #main layout
layout_az = QHBoxLayout() #layout for third and fourth parameters group box
lay_title = QHBoxLayout() #title layout
title_f = QVBoxLayout()
lay_xx = QHBoxLayout() #layout containins lay_x_s and drop down box for x-axis
lay_yy = QHBoxLayout() #layout containing lay_y_s and drop down box for y-axis
lay_33 = QVBoxLayout()
lay_44 = QVBoxLayout()
lay_zz = QVBoxLayout()
lay_y_custom = QVBoxLayout()
lay_custom = QHBoxLayout()
lay_x_s = QVBoxLayout() #layout for slider x (contains slider and label)
lay_y_s = QVBoxLayout() #layout for slider y (contains slider and label)
lay_z_s = QVBoxLayout()
lay_z_field = QHBoxLayout()
lay_xl_sp = QHBoxLayout() #layouts joining sliders and spin boxes
lay_xh_sp = QHBoxLayout()
lay_yl_sp = QHBoxLayout()
lay_yh_sp = QHBoxLayout()
lay_zl_sp = QHBoxLayout()
lay_zh_sp = QHBoxLayout()
lay_gv = QVBoxLayout()
lay_up_cb = QHBoxLayout()
self.figure = plt.figure()
self.canvas = FigureCanvas(self.figure)
#self.canvas.setFixedSize(500,500)
self.toolbar = NavigationToolbar(self.canvas,self)
self.update_but = QPushButton('&Update')
self.update_but.setDefault(True)
self.update_but.clicked.connect(self.update_plot)
self.column_filtering_but = QPushButton('&Column Filtering')
self.column_filtering_but.setDefault(True)
self.column_filtering_but.clicked.connect(self.column_filtering_func)
self.swap_axis_but = QPushButton('&Swap Axis')
self.swap_axis_but.setDefault(True)
self.swap_axis_but.clicked.connect(self.swap_axis_func)
self.update_constraints_but = QPushButton('&Generate constraints file')
self.update_constraints_but.setDefault(True)
self.update_constraints_but.clicked.connect(self.constraints_file_func)
self.undo_but = QPushButton('&Undo')
self.undo_but.setDefault(True)
self.undo_but.clicked.connect(self.undo_func)
self.redo_but = QPushButton('&Redo')
self.redo_but.setDefault(True)
self.redo_but.clicked.connect(self.redo_func)
self.enable_cb_3 = QCheckBox("Enable Third Parameter")
self.enable_cb_3.setChecked(False)
self.enable_cb_3.stateChanged.connect(self.enable_func_3)
self.barstyle_cb = QComboBox()
self.barstyle_cb.addItem("Color")
self.barstyle_cb.addItem("Pattern")
self.barstyle_cb.setEnabled(False)
self.enable_cb_4 = QCheckBox("Enable Fourth Parameter")
self.enable_cb_4.setChecked(False)
self.enable_cb_4.stateChanged.connect(self.enable_func_4)
self.enable_3d = QCheckBox("Enable 3D")
self.enable_3d.setChecked(False)
self.enable_3d.stateChanged.connect(self.enable_3d_func)
self.enable_title = QCheckBox("Enable Title")
self.enable_title.setChecked(False)
self.enable_title.stateChanged.connect(self.title_func)
self.enable_custom_formula = QCheckBox("Use Custom Formula for Y-Axis")
self.enable_custom_formula.setChecked(False)
self.enable_custom_formula.stateChanged.connect(self.enable_custom_formula_func)
self.custom_formula_title = QLabel("Custom Formula:")
self.custom_formula_title.setAlignment(Qt.AlignLeft)
self.custom_formula_box = QLineEdit()
self.custom_formula_title.setEnabled(False)
self.custom_formula_box.setEnabled(False)
self.xl = QLabel("Lower Limit")
self.xl.setAlignment(Qt.AlignLeft)
self.xh = QLabel("Upper Limit")
self.xh.setAlignment(Qt.AlignLeft)
self.yl = QLabel("Lower Limit")
self.yl.setAlignment(Qt.AlignLeft)
self.yh = QLabel("Upper Limit")
self.yh.setAlignment(Qt.AlignLeft)
self.zl = QLabel("Lower Limit")
self.zl.setAlignment(Qt.AlignLeft)
self.zl.setEnabled(False)
self.zh = QLabel("Upper Limit")
self.zh.setAlignment(Qt.AlignLeft)
self.zh.setEnabled(False)
#**************new segment for custom x,y axis label********************
lay_xlabelf = QVBoxLayout()
lay_xlabel = QHBoxLayout()
lay_ylabelf = QVBoxLayout()
lay_ylabel = QHBoxLayout()
self.enable_xlabel = QCheckBox("Enable X-Axis Label")
self.enable_xlabel.setChecked(False)
self.enable_xlabel.stateChanged.connect(self.xlabel_func)
self.enable_ylabel = QCheckBox("Enable Y-Axis Label")
self.enable_ylabel.setChecked(False)
self.enable_ylabel.stateChanged.connect(self.ylabel_func)
self.xlabel_label = QLabel("X-Axis Label:")
self.xlabel_name = QLineEdit()
self.xlabel_label.setEnabled(False)
self.xlabel_name.setEnabled(False)
self.ylabel_label = QLabel("Y-Axis Label:")
self.ylabel_name = QLineEdit()
self.ylabel_label.setEnabled(False)
self.ylabel_name.setEnabled(False)
lay_xlabel.addWidget(self.xlabel_label)
lay_xlabel.addWidget(self.xlabel_name)
lay_ylabel.addWidget(self.ylabel_label)
lay_ylabel.addWidget(self.ylabel_name)
lay_xlabelf.addWidget(self.enable_xlabel)
lay_xlabelf.addLayout(lay_xlabel)
lay_ylabelf.addWidget(self.enable_ylabel)
lay_ylabelf.addLayout(lay_ylabel)
#************new segment******************
self.enable_interval = QCheckBox("Enable interval range")
self.enable_interval.setEnabled(False)
self.enable_interval.setChecked(False)
self.enable_interval.stateChanged.connect(self.interval_func)
self.interval = QLabel("Interval Range:")
self.interval.setAlignment(Qt.AlignRight)
self.interval.setEnabled(False)
self.interval_box = QLineEdit()
self.interval_box.setEnabled(False)
lay_tinterval = QHBoxLayout()
lay_tinterval.addWidget(self.interval)
lay_tinterval.addWidget(self.interval_box)
lay_interval = QVBoxLayout()
lay_interval.addWidget(self.enable_interval)
lay_interval.addLayout(lay_tinterval)
#***********new segment for setting y-axis start value
self.enable_ystart = QCheckBox("Set Y-Axis start value")
self.enable_ystart.setEnabled(True)
self.enable_ystart.setChecked(False)
self.enable_ystart.stateChanged.connect(self.ystart_func)
self.ystart_box = QLineEdit()
self.ystart_box.setEnabled(False)
lay_ystart = QHBoxLayout()
lay_ystart.addWidget(self.enable_ystart)
lay_ystart.addWidget(self.ystart_box)
self.cbx = QComboBox()
self.cby = QComboBox()
self.cb3 = QComboBox()
self.cb4 = QComboBox()
self.cb4.setEnabled(False)
self.cb3.setEnabled(False)
self.cb_axes = QComboBox()
self.cb_axes.setEnabled(False)
self.cbz = QComboBox()
self.cbz.setEnabled(False)
self.cbz.currentIndexChanged.connect(self.selectionchangez)
self.cbx.currentIndexChanged.connect(self.selectionchangex)
self.cby.currentIndexChanged.connect(self.selectionchangey)
self.slzl = QSlider(Qt.Horizontal)
self.slzl.setRange(0,100)
self.slzl.setEnabled(False)
self.slzh = QSlider(Qt.Horizontal)
self.slzh.setRange(0,100)
self.slzh.setEnabled(False)
self.slxl = QSlider(Qt.Horizontal)
self.slxl.setRange(0,100)
self.slxh = QSlider(Qt.Horizontal)
self.slxh.setRange(0,100)
self.slyl = QSlider(Qt.Horizontal)