File qt_plot.py changed (mode: 100644) (index 7fe1406..ee2008a) |
... |
... |
class QtGuiPlot2D(QtGui.QMainWindow): |
175 |
175 |
|
|
176 |
176 |
#č graphy už nemusí jít po stm widgetech |
#č graphy už nemusí jít po stm widgetech |
177 |
177 |
dock = QtGui.QDockWidget("TRI_overall estimation graph", self) |
dock = QtGui.QDockWidget("TRI_overall estimation graph", self) |
178 |
|
dock.setWidget(TriEstimationGraph(self, tri_estimation_name='TRI_overall_estimations')) |
|
|
178 |
|
dock.setWidget(TriEstimationGraph(self.sample_box, 'TRI_overall_estimations', self, dock)) |
179 |
179 |
self.dockables.append(dock) |
self.dockables.append(dock) |
180 |
180 |
self.tabifyDockWidget(self.dockables[0], dock) |
self.tabifyDockWidget(self.dockables[0], dock) |
181 |
181 |
|
|
|
... |
... |
def get_estimation_data(estimations, metric): |
870 |
870 |
|
|
871 |
871 |
|
|
872 |
872 |
|
|
873 |
|
class TriEstimationGraph(pg.PlotWidget): |
|
874 |
|
def __init__(self, samplebox_item, tri_estimation_name='TRI_current_estimations', parent=None, *args, **kwargs): |
|
875 |
|
super().__init__(parent) |
|
876 |
|
self.sb_item = samplebox_item |
|
877 |
|
self.sb_item.box_runned.connect(self.redraw) |
|
878 |
|
self.sb_item.estimation_added.connect(self.redraw) |
|
879 |
|
|
|
880 |
|
self.black_box = samplebox_item.sample_box |
|
881 |
|
self.tri_estimation_name = tri_estimation_name |
|
882 |
|
self.setBackground('w') |
|
883 |
|
|
|
884 |
|
# creates instance of LegendItem |
|
885 |
|
# and saves it into plotItem.legend |
|
886 |
|
self.legend = self.addLegend() |
|
887 |
|
|
|
888 |
|
x = y = () # zde jen vytvoříme kostru, nakrmime daty v .redraw() |
|
889 |
|
|
|
890 |
|
#self.pen_f = self.plot(x, y, fillLevel=0, brush='r') # red |
|
891 |
|
pen = pg.mkPen(color=(255, 0, 0), width=3)#, style=QtCore.Qt.DashLine) |
|
892 |
|
self.pen_f = self.plot(x, y, pen=pen) # red |
|
893 |
|
self.pen_mix = self.plot(x, y, fillLevel=0, brush=(255, 165, 0)) # orange |
|
894 |
|
self.pen_outside = self.plot(x, y, fillLevel=0, brush=0.8) # grey |
|
895 |
|
self.pen_success = self.plot(x, y, fillLevel=0, brush='g') # green |
|
896 |
|
self.legend.addItem(self.pen_success, "success domain estimation") |
|
897 |
|
self.legend.addItem(self.pen_outside, "out of sampling domain estimation") |
|
898 |
|
self.legend.addItem(self.pen_mix, "mixed simplices measure") |
|
899 |
|
self.legend.addItem(self.pen_f, "failure domain estimation") |
|
900 |
|
|
|
901 |
|
self.pen_vertex = self.plot(x, y, pen='c', name='simple') |
|
902 |
|
self.pen_weighted_vertex = self.plot(x, y, pen=(170, 170, 255), name='weighted') |
|
903 |
|
self.legend.addItem(self.pen_vertex, "simple pf estimation") |
|
904 |
|
self.legend.addItem(self.pen_weighted_vertex, "weighted pf estimation") |
|
905 |
|
|
|
906 |
|
self.pen_exact = self.plot(x, y, pen='b') # blue |
|
907 |
|
#self.legend.addItem(self.pen_exact) |
|
908 |
|
|
|
909 |
|
self.setLogMode(False, True) |
|
910 |
|
|
|
911 |
|
self.redraw() |
|
912 |
|
|
|
913 |
|
|
|
914 |
|
def redraw(self): |
|
915 |
|
try: # тут всё что угодно может пойти не так |
|
916 |
|
data = self.black_box.guessbox.estimations[self.tri_estimation_name] |
|
917 |
|
x = data[0] |
|
918 |
|
# it can be effectively done with pandas |
|
919 |
|
df = pd.DataFrame(data[1]) |
|
920 |
|
# -1 = 'out', 0=success, 1=failure, 2=mix |
|
921 |
|
df.rename(columns={-1:'out', 0:'success', 1:'failure', 2:'mix'}, inplace=True) |
|
922 |
|
|
|
923 |
|
# Update the data |
|
924 |
|
# když se někde objeví nula se zapnutým LogModem - qtpygraph hned spadne a není možne ten pad zachytit |
|
925 |
|
def nonzero(data): return np.where(data > 0, data, 1) |
|
926 |
|
self.pen_f.setData(np.array(x)[df.failure.to_numpy() > 0], df.failure.to_numpy()[df.failure.to_numpy() > 0]) |
|
927 |
|
self.pen_mix.setData(x, nonzero(df.failure)) |
|
928 |
|
self.pen_outside.setData(x, nonzero(df.failure+df.mix)) |
|
929 |
|
self.pen_success.setData(x, nonzero(df.failure+df.mix+df.out)) # kontrolu, zda je to 1, nechame uživateli |
|
930 |
|
|
|
931 |
|
self.pen_exact.setData((min(x),max(x)), (self.black_box.pf_exact, self.black_box.pf_exact)) |
|
932 |
|
|
|
933 |
|
|
|
934 |
|
if 'vertex_estimation' in self.black_box.guessbox.estimations: |
|
935 |
|
data = self.black_box.guessbox.estimations['vertex_estimation'] |
|
936 |
|
x, y = (*data,) |
|
937 |
|
# Update the data |
|
938 |
|
|
|
939 |
|
self.pen_vertex.setData(x, nonzero(np.array(y))) |
|
940 |
|
|
|
941 |
|
if 'weighted_vertex_estimation' in self.black_box.guessbox.estimations: |
|
942 |
|
data = self.black_box.guessbox.estimations['weighted_vertex_estimation'] |
|
943 |
|
x, y = (*data,) |
|
944 |
|
# Update the data |
|
945 |
|
|
|
946 |
|
self.pen_weighted_vertex.setData(x, nonzero(np.array(y))) |
|
947 |
|
|
|
948 |
|
|
|
949 |
|
|
|
950 |
|
except BaseException as e: |
|
951 |
|
print(self.__class__.__name__ + ":", repr(e)) |
|
952 |
|
|
|
953 |
|
|
|
954 |
|
|
|
955 |
|
|
|
956 |
|
# pen_f.opts['logMode'] |
|
957 |
|
# pen_outside.setLogMode(False, False) |
|
958 |
|
#setLogMode(False, False) |
|
959 |
|
|
|
960 |
|
|
|
961 |
|
|
|
962 |
|
|
|
963 |
873 |
|
|
964 |
874 |
class SimpleSimplexEstimationGraph(pg.PlotWidget): |
class SimpleSimplexEstimationGraph(pg.PlotWidget): |
965 |
|
def __init__(self, black_box, samplebox_item, parent=None, *args, **kwargs): |
|
966 |
|
super().__init__(parent) |
|
967 |
|
self.sb_item = samplebox_item |
|
968 |
|
self.sb_item.box_runned.connect(self.redraw) |
|
969 |
|
self.sb_item.estimation_added.connect(self.redraw) |
|
|
875 |
|
def __init__(self, dice_box, stream=None, parent=None, *args, **kwargs): |
|
876 |
|
super().__init__(parent, *args, **kwargs) |
|
877 |
|
self.stream = stream |
|
878 |
|
if stream is not None: |
|
879 |
|
self.stream.box_runned.connect(self.redraw) |
|
880 |
|
self.stream.estimation_added.connect(self.redraw) |
970 |
881 |
|
|
971 |
|
self.black_box = black_box |
|
|
882 |
|
self.dice_box = dice_box |
972 |
883 |
|
|
|
884 |
|
self.setup_context_menu() |
|
885 |
|
self.setup() |
|
886 |
|
|
|
887 |
|
def setup_context_menu(self): |
973 |
888 |
# creates instance of LegendItem |
# creates instance of LegendItem |
974 |
889 |
# and saves it into plotItem.legend |
# and saves it into plotItem.legend |
975 |
890 |
self.legend = self.addLegend() |
self.legend = self.addLegend() |
|
... |
... |
class SimpleSimplexEstimationGraph(pg.PlotWidget): |
977 |
892 |
self.plotItem.ctrl.xGridCheck.setChecked(True) |
self.plotItem.ctrl.xGridCheck.setChecked(True) |
978 |
893 |
self.plotItem.ctrl.yGridCheck.setChecked(True) |
self.plotItem.ctrl.yGridCheck.setChecked(True) |
979 |
894 |
|
|
980 |
|
self.setup_context_menu() |
|
981 |
|
|
|
982 |
|
self.setup() |
|
983 |
|
|
|
984 |
|
def setup_context_menu(self): |
|
985 |
895 |
# delete build-in Transforms (with Log_x and Log_y) options, |
# delete build-in Transforms (with Log_x and Log_y) options, |
986 |
896 |
# they can cause uncachable exception (on any zero in data) and crash |
# they can cause uncachable exception (on any zero in data) and crash |
987 |
897 |
self.plotItem.ctrlMenu.removeAction(self.plotItem.ctrlMenu.actions()[0]) |
self.plotItem.ctrlMenu.removeAction(self.plotItem.ctrlMenu.actions()[0]) |
|
... |
... |
class SimpleSimplexEstimationGraph(pg.PlotWidget): |
993 |
903 |
self.legend_chk.setCheckable(True) |
self.legend_chk.setCheckable(True) |
994 |
904 |
self.legend_chk.triggered.connect(lambda: self.legend.setVisible(self.legend_chk.isChecked())) |
self.legend_chk.triggered.connect(lambda: self.legend.setVisible(self.legend_chk.isChecked())) |
995 |
905 |
self.custom_menu.addAction(self.legend_chk) |
self.custom_menu.addAction(self.legend_chk) |
|
906 |
|
# apply custom menu option |
|
907 |
|
self.legend.setVisible(self.legend_chk.isChecked()) |
996 |
908 |
|
|
997 |
909 |
self.proxy_chk = QtGui.QAction("Proxy", self.custom_menu) |
self.proxy_chk = QtGui.QAction("Proxy", self.custom_menu) |
998 |
910 |
self.proxy_chk.setCheckable(True) |
self.proxy_chk.setCheckable(True) |
|
... |
... |
class SimpleSimplexEstimationGraph(pg.PlotWidget): |
1022 |
934 |
def export_to_excel(self): |
def export_to_excel(self): |
1023 |
935 |
pass |
pass |
1024 |
936 |
|
|
|
937 |
|
|
|
938 |
|
|
|
939 |
|
# self.legend.addItem(self.pen_success, "success domain estimation") |
|
940 |
|
# self.legend.addItem(self.pen_outside, "out of sampling domain estimation") |
|
941 |
|
# self.legend.addItem(self.pen_mix, "mixed simplices measure") |
|
942 |
|
# self.legend.addItem(self.pen_f, "failure domain estimation") |
|
943 |
|
|
1025 |
944 |
def setup(self, *args, **kwargs): |
def setup(self, *args, **kwargs): |
1026 |
945 |
self.clear() |
self.clear() |
1027 |
946 |
self.setBackground('w') |
self.setBackground('w') |
1028 |
947 |
x = y = () # zde jen vytvoříme kostru, nakrmime daty v .redraw() |
x = y = () # zde jen vytvoříme kostru, nakrmime daty v .redraw() |
1029 |
948 |
|
|
1030 |
|
#self.plotItem.ctrlMenu.actions()[3]. |
|
1031 |
|
|
|
1032 |
|
# apply custom menu option |
|
1033 |
|
self.legend.setVisible(self.legend_chk.isChecked()) |
|
1034 |
|
|
|
1035 |
949 |
if self.log_y_chk.isChecked(): |
if self.log_y_chk.isChecked(): |
1036 |
950 |
self.setLogMode(y=True) |
self.setLogMode(y=True) |
1037 |
951 |
#self.pen_f = self.plot(x, y, fillLevel=0, brush='r') # red |
#self.pen_f = self.plot(x, y, fillLevel=0, brush='r') # red |
|
... |
... |
class SimpleSimplexEstimationGraph(pg.PlotWidget): |
1049 |
963 |
self.pen_mix = self.plot(x, y, fillLevel=0, brush=(255, 165, 0)) # orange |
self.pen_mix = self.plot(x, y, fillLevel=0, brush=(255, 165, 0)) # orange |
1050 |
964 |
self.pen_f = self.plot(x, y, fillLevel=0, brush='r') # red |
self.pen_f = self.plot(x, y, fillLevel=0, brush='r') # red |
1051 |
965 |
|
|
1052 |
|
self.pen_vertex = self.plot(x, y, pen='c', name='simple') |
|
1053 |
|
self.pen_weighted_vertex = self.plot(x, y, pen=(170, 170, 255), name='weighted') |
|
|
966 |
|
self.pen_vertex = self.plot(x, y, pen='c', name="simple pf estimation") |
|
967 |
|
self.pen_weighted_vertex = self.plot(x, y, pen=(170, 170, 255), name="weighted pf estimation") |
1054 |
968 |
try: |
try: |
1055 |
|
exact_name = self.black_box.pf_exact_method |
|
|
969 |
|
exact_name = self.dice_box.pf_exact_method |
1056 |
970 |
except: |
except: |
1057 |
971 |
exact_name = "" |
exact_name = "" |
1058 |
972 |
self.pen_exact = self.plot(x, y, pen='b', name=exact_name) # blue |
self.pen_exact = self.plot(x, y, pen='b', name=exact_name) # blue |
|
... |
... |
class SimpleSimplexEstimationGraph(pg.PlotWidget): |
1072 |
986 |
# bere co chce a jak chce |
# bere co chce a jak chce |
1073 |
987 |
# ne že by to bylo nějak šetrný |
# ne že by to bylo nějak šetrný |
1074 |
988 |
# estimation je slovníkem |
# estimation je slovníkem |
1075 |
|
for estimation in self.black_box.estimations: |
|
|
989 |
|
for estimation in self.dice_box.estimations: |
1076 |
990 |
# nsim musí mäť každej odhad |
# nsim musí mäť každej odhad |
1077 |
991 |
# pokud nemá - je třeba jej prostě opravit |
# pokud nemá - je třeba jej prostě opravit |
1078 |
992 |
nsim = estimation['nsim'] |
nsim = estimation['nsim'] |
|
... |
... |
class SimpleSimplexEstimationGraph(pg.PlotWidget): |
1110 |
1024 |
self.pen_outside.setData(x, df.failure+df.mix+df.out) |
self.pen_outside.setData(x, df.failure+df.mix+df.out) |
1111 |
1025 |
self.pen_success.setData(x, df.failure+df.mix+df.out+df.success) # kontrolu, zda je to 1, nechame uivateli |
self.pen_success.setData(x, df.failure+df.mix+df.out+df.success) # kontrolu, zda je to 1, nechame uivateli |
1112 |
1026 |
|
|
1113 |
|
self.pen_vertex.setData(*get_estimation_data(self.black_box.estimations, 'vertex_estimation')) |
|
1114 |
|
self.pen_weighted_vertex.setData(*get_estimation_data(self.black_box.estimations, 'weighted_vertex_estimation')) |
|
|
1027 |
|
self.pen_vertex.setData(*get_estimation_data(self.dice_box.estimations, 'vertex_estimation')) |
|
1028 |
|
self.pen_weighted_vertex.setData(*get_estimation_data(self.dice_box.estimations, 'weighted_vertex_estimation')) |
1115 |
1029 |
|
|
1116 |
1030 |
if (xmax - xmin) > 0: |
if (xmax - xmin) > 0: |
1117 |
1031 |
if hasattr(self.black_box, 'pf_exact'): |
if hasattr(self.black_box, 'pf_exact'): |
1118 |
1032 |
# poslední. I když spadne, tak už nikomu moc nevadí |
# poslední. I když spadne, tak už nikomu moc nevadí |
1119 |
|
self.pen_exact.setData((xmin,xmax), (self.black_box.pf_exact, self.black_box.pf_exact)) |
|
|
1033 |
|
self.pen_exact.setData((xmin,xmax), (self.black_box.pf_exact, self.dice_box.pf_exact)) |
1120 |
1034 |
|
|
1121 |
1035 |
except BaseException as e: |
except BaseException as e: |
1122 |
1036 |
print(self.__class__.__name__ + ":", repr(e)) |
print(self.__class__.__name__ + ":", repr(e)) |
|
... |
... |
class SimpleSimplexEstimationGraph(pg.PlotWidget): |
1131 |
1045 |
|
|
1132 |
1046 |
|
|
1133 |
1047 |
|
|
1134 |
|
|
|
1135 |
|
|
|
|
1048 |
|
class TriEstimationGraph(SimpleSimplexEstimationGraph): |
|
1049 |
|
def __init__(self, dice_box, tri_estimation_name='TRI_overall_estimations', stream=None, parent=None, *args, **kwargs): |
|
1050 |
|
self.tri_estimation_name = tri_estimation_name |
|
1051 |
|
super().__init__(dice_box, stream, parent, *args, **kwargs) |
|
1052 |
|
|
|
1053 |
|
|
|
1054 |
|
|
|
1055 |
|
def redraw(self): |
|
1056 |
|
try: # тут всё что угодно может пойти не так |
|
1057 |
|
data = self.dice_box.guessbox.estimations[self.tri_estimation_name] |
|
1058 |
|
x = data[0] |
|
1059 |
|
# it can be effectively done with pandas |
|
1060 |
|
df = pd.DataFrame(data[1]) |
|
1061 |
|
# -1 = 'out', 0=success, 1=failure, 2=mix |
|
1062 |
|
df.rename(columns={-1:'out', 0:'success', 1:'failure', 2:'mix'}, inplace=True) |
|
1063 |
|
|
|
1064 |
|
# Update the data |
|
1065 |
|
# když se někde objeví nula se zapnutým LogModem - qtpygraph hned spadne a není možne ten pad zachytit |
|
1066 |
|
def nonzero(data): return np.where(data > 0, data, 1) |
|
1067 |
|
self.pen_f.setData(np.array(x)[df.failure.to_numpy() > 0], df.failure.to_numpy()[df.failure.to_numpy() > 0]) |
|
1068 |
|
self.pen_mix.setData(x, nonzero(df.failure)) |
|
1069 |
|
self.pen_outside.setData(x, nonzero(df.failure+df.mix)) |
|
1070 |
|
self.pen_success.setData(x, nonzero(df.failure+df.mix+df.out)) # kontrolu, zda je to 1, nechame uživateli |
|
1071 |
|
|
|
1072 |
|
self.pen_exact.setData((min(x),max(x)), (self.dice_box.pf_exact, self.dice_box.pf_exact)) |
|
1073 |
|
|
|
1074 |
|
|
|
1075 |
|
if 'vertex_estimation' in self.dice_box.guessbox.estimations: |
|
1076 |
|
data = self.dice_box.guessbox.estimations['vertex_estimation'] |
|
1077 |
|
x, y = (*data,) |
|
1078 |
|
# Update the data |
|
1079 |
|
|
|
1080 |
|
self.pen_vertex.setData(x, nonzero(np.array(y))) |
|
1081 |
|
|
|
1082 |
|
if 'weighted_vertex_estimation' in self.dice_box.guessbox.estimations: |
|
1083 |
|
data = self.dice_box.guessbox.estimations['weighted_vertex_estimation'] |
|
1084 |
|
x, y = (*data,) |
|
1085 |
|
# Update the data |
|
1086 |
|
|
|
1087 |
|
self.pen_weighted_vertex.setData(x, nonzero(np.array(y))) |
|
1088 |
|
|
|
1089 |
|
|
|
1090 |
|
|
|
1091 |
|
except BaseException as e: |
|
1092 |
|
print(self.__class__.__name__ + ":", repr(e)) |
|
1093 |
|
|
|
1094 |
|
|
1136 |
1095 |
|
|
1137 |
1096 |
|
|
1138 |
1097 |
|
|