File qt_plot.py changed (mode: 100644) (index a9da129..507ec82) |
... |
... |
def get_estimation_data(estimations, metric): |
861 |
861 |
# pokud nemá - je třeba jej prostě opravit |
# pokud nemá - je třeba jej prostě opravit |
862 |
862 |
nsim = estimation['nsim'] |
nsim = estimation['nsim'] |
863 |
863 |
try: |
try: |
864 |
|
if estimation[metric] > 0: |
|
865 |
|
metric_dict[nsim] = estimation[metric] |
|
|
864 |
|
metric_dict[nsim] = estimation[metric] |
866 |
865 |
except KeyError as e: |
except KeyError as e: |
867 |
866 |
pass #print(self.__class__.__name__ + ":", repr(e)) |
pass #print(self.__class__.__name__ + ":", repr(e)) |
868 |
867 |
|
|
|
... |
... |
class SimpleSimplexEstimationGraph(pg.PlotWidget): |
965 |
964 |
x = y = () # zde jen vytvoříme kostru, nakrmime daty v .redraw() |
x = y = () # zde jen vytvoříme kostru, nakrmime daty v .redraw() |
966 |
965 |
|
|
967 |
966 |
#xkcd_green = (167, 255, 181) # xkcd:light seafoam green #a7ffb5 |
#xkcd_green = (167, 255, 181) # xkcd:light seafoam green #a7ffb5 |
968 |
|
green = (0, 255, 38, 64) |
|
|
967 |
|
green = (0, 255, 38, 96) |
969 |
968 |
#xkcd_red = (253, 193, 197) # xkcd: pale rose (#fdc1c5) |
#xkcd_red = (253, 193, 197) # xkcd: pale rose (#fdc1c5) |
970 |
|
red = (253, 0, 17, 64) |
|
|
969 |
|
red = (253, 0, 17, 96) |
971 |
970 |
#xkcd_cream = (255, 243, 154) # let's try xkcd: dark cream (#fff39a) |
#xkcd_cream = (255, 243, 154) # let's try xkcd: dark cream (#fff39a) |
972 |
|
cream = (255, 221, 0, 64) |
|
973 |
|
grey = (196, 196, 196, 64) |
|
|
971 |
|
cream = (255, 221, 0, 96) |
|
972 |
|
grey = (196, 196, 196, 96) |
974 |
973 |
|
|
975 |
974 |
self.pen_f = self.plot(x, y, brush=red)#, name="failure domain estimation") |
self.pen_f = self.plot(x, y, brush=red)#, name="failure domain estimation") |
976 |
975 |
self.pen_f.setZValue(-100) |
self.pen_f.setZValue(-100) |
|
... |
... |
class SimpleSimplexEstimationGraph(pg.PlotWidget): |
993 |
992 |
self.fill_outside.setZValue(-100) |
self.fill_outside.setZValue(-100) |
994 |
993 |
self.addItem(self.fill_outside) |
self.addItem(self.fill_outside) |
995 |
994 |
|
|
996 |
|
|
|
|
995 |
|
self.one_ruler = self.addLine(y=1, pen='k') |
|
996 |
|
self.zero_ruler = self.addLine(y=0, pen='k') |
997 |
997 |
|
|
998 |
|
pen = pg.mkPen(color='c', width=2) |
|
999 |
|
self.pen_vertex = self.plot(x, y, pen=pen, name="simple pf estimation") |
|
1000 |
|
pen = pg.mkPen(color=(170, 170, 255), width=2) |
|
1001 |
|
self.pen_weighted_vertex = self.plot(x, y, pen=pen, name="weighted pf estimation") |
|
|
998 |
|
|
1002 |
999 |
try: |
try: |
1003 |
1000 |
exact_name = self.dice_box.pf_exact_method |
exact_name = self.dice_box.pf_exact_method |
1004 |
|
pen = pg.mkPen(color='b', width=2) # blue |
|
|
1001 |
|
pen = pg.mkPen(color='b', width=1.5) # blue |
1005 |
1002 |
self.pen_exact = self.addLine(y=self.dice_box.pf_exact, pen=pen, name=exact_name) |
self.pen_exact = self.addLine(y=self.dice_box.pf_exact, pen=pen, name=exact_name) |
1006 |
1003 |
except: |
except: |
1007 |
1004 |
pass |
pass |
1008 |
1005 |
|
|
1009 |
|
self.one_ruler = self.addLine(y=1, pen='k') |
|
1010 |
|
self.zero_ruler = self.addLine(y=0, pen='k') |
|
|
1006 |
|
pen = pg.mkPen(color='m', width=2) |
|
1007 |
|
self.pen_vertex = self.plot(x, y, pen=pen, name="simple pf estimation") |
|
1008 |
|
pen = pg.mkPen(color='r', width=2) #(118, 187, 255) |
|
1009 |
|
self.pen_weighted_vertex = self.plot(x, y, pen=pen, name="weighted pf estimation") |
1011 |
1010 |
|
|
1012 |
1011 |
|
|
1013 |
1012 |
|
|
|
... |
... |
class SimpleSimplexEstimationGraph(pg.PlotWidget): |
1021 |
1020 |
except: |
except: |
1022 |
1021 |
pass |
pass |
1023 |
1022 |
self.setLogMode(y=True) |
self.setLogMode(y=True) |
1024 |
|
self.pen_f.setPen(pg.mkPen(color=(255, 0, 0), width=3)) #, style=QtCore.Qt.DashLine) |
|
|
1023 |
|
#self.pen_f.setPen(pg.mkPen(color=(255, 0, 0), width=3)) #, style=QtCore.Qt.DashLine) |
|
1024 |
|
self.pen_f.setPen(None) |
1025 |
1025 |
self.pen_f.setFillLevel(None) |
self.pen_f.setFillLevel(None) |
1026 |
1026 |
self.pen_success.setFillLevel(0) |
self.pen_success.setFillLevel(0) |
1027 |
1027 |
|
|
|
... |
... |
class SimpleSimplexEstimationGraph(pg.PlotWidget): |
1049 |
1049 |
else: |
else: |
1050 |
1050 |
return data |
return data |
1051 |
1051 |
|
|
|
1052 |
|
def proxy(self, nsim): |
|
1053 |
|
if self.proxy_chk.isChecked(): |
|
1054 |
|
proxy = self.dice_box.proxy |
|
1055 |
|
index = np.array(nsim)-1 |
|
1056 |
|
#č indexy musíme o jedničku změnšit |
|
1057 |
|
#č výsledek nikoliv. Takže v cajku. |
|
1058 |
|
return np.cumsum(~proxy)[index] |
|
1059 |
|
else: |
|
1060 |
|
return nsim |
|
1061 |
|
|
|
1062 |
|
|
1052 |
1063 |
|
|
1053 |
1064 |
def redraw(self): |
def redraw(self): |
1054 |
1065 |
xmin = np.inf |
xmin = np.inf |
|
... |
... |
class SimpleSimplexEstimationGraph(pg.PlotWidget): |
1075 |
1086 |
except KeyError as e: |
except KeyError as e: |
1076 |
1087 |
pass #print(self.__class__.__name__ + ":", repr(e)) |
pass #print(self.__class__.__name__ + ":", repr(e)) |
1077 |
1088 |
|
|
|
1089 |
|
#č neotravuj uživatele chybovejma hlaškama |
|
1090 |
|
if tri_estimation: |
|
1091 |
|
# it can be effectively done with pandas |
|
1092 |
|
self.df = df = pd.DataFrame(tuple(tri_estimation.values())) |
|
1093 |
|
# -1 = 'out', 0=success, 1=failure, 2=mix |
|
1094 |
|
df.rename(columns={-1:'out', 0:'success', 1:'failure', 2:'mix'}, inplace=True) |
|
1095 |
|
df.insert(loc=0, column='nsim', value=tuple(tri_estimation.keys()), allow_duplicates=False) |
|
1096 |
|
df.sort_values('nsim', inplace=True) |
|
1097 |
|
nsim = df.nsim.to_numpy() |
1078 |
1098 |
|
|
1079 |
|
# it can be effectively done with pandas |
|
1080 |
|
self.df = df = pd.DataFrame(tuple(tri_estimation.values())) |
|
1081 |
|
# -1 = 'out', 0=success, 1=failure, 2=mix |
|
1082 |
|
df.rename(columns={-1:'out', 0:'success', 1:'failure', 2:'mix'}, inplace=True) |
|
1083 |
|
df.insert(loc=0, column='x', value=tuple(tri_estimation.keys()), allow_duplicates=False) |
|
1084 |
|
df.sort_values('x', inplace=True) |
|
1085 |
|
x = df.x.to_numpy() |
|
|
1099 |
|
if self.proxy_chk.isChecked(): |
|
1100 |
|
x = self.proxy(nsim) |
|
1101 |
|
df.insert(loc=0, column='nsim (proxy)', value=x) |
|
1102 |
|
else: |
|
1103 |
|
x = nsim |
|
1104 |
|
|
|
1105 |
|
self.pen_f.setData(x, self.zerosafe(df.failure)) |
|
1106 |
|
self.pen_outmix.setData(x, self.zerosafe(df.failure+df.mix)) |
|
1107 |
|
self.pen_success.setData(x, self.zerosafe(df.failure+df.mix+df.out)) |
1086 |
1108 |
|
|
1087 |
|
if self.log_y_chk.isChecked(): |
|
1088 |
|
# Update the data |
|
1089 |
|
# když se někde objeví nula se zapnutým LogModem - qtpygraph hned spadne a není možne ten pad zachytit |
|
1090 |
|
def nonzero(data): return np.where(data > 0, data, 1) |
|
1091 |
|
self.pen_f.setData(x, nonzero(df.failure)) |
|
1092 |
|
self.pen_outmix.setData(x, nonzero(df.failure+df.mix)) |
|
1093 |
|
self.pen_success.setData(x, nonzero(df.failure+df.mix+df.out)) |
|
1094 |
|
else: |
|
1095 |
|
# Update the data |
|
1096 |
|
self.pen_f.setData(x, df.failure) |
|
1097 |
|
self.pen_outmix.setData(x, df.failure+df.mix) |
|
1098 |
|
self.pen_success.setData(x, df.failure+df.mix+df.out) |
|
|
1109 |
|
nsim, y = get_estimation_data(self.dice_box.estimations, 'vertex_estimation') |
|
1110 |
|
df['vertex_estimation'] = y #č spolehám na konzistenci odhadů (ne úplně) |
|
1111 |
|
self.pen_vertex.setData(self.proxy(nsim), self.zerosafe(y)) |
1099 |
1112 |
|
|
1100 |
|
self.pen_vertex.setData(*get_estimation_data(self.dice_box.estimations, 'vertex_estimation')) |
|
1101 |
|
self.pen_weighted_vertex.setData(*get_estimation_data(self.dice_box.estimations, 'weighted_vertex_estimation')) |
|
1102 |
|
|
|
|
1113 |
|
nsim, y = get_estimation_data(self.dice_box.estimations, 'weighted_vertex_estimation') |
|
1114 |
|
df['weighted_vertex_estimation'] = y #č spolehám na konzistenci odhadů (ne úplně) |
|
1115 |
|
self.pen_weighted_vertex.setData(self.proxy(nsim), self.zerosafe(y)) |
1103 |
1116 |
|
|
|
1117 |
|
|
1104 |
1118 |
except BaseException as e: |
except BaseException as e: |
1105 |
1119 |
print(self.__class__.__name__ + ":", repr(e)) |
print(self.__class__.__name__ + ":", repr(e)) |
1106 |
1120 |
|
|
|
... |
... |
class TriEstimationGraph(SimpleSimplexEstimationGraph): |
1116 |
1130 |
def redraw(self): |
def redraw(self): |
1117 |
1131 |
try: # тут всё что угодно может пойти не так |
try: # тут всё что угодно может пойти не так |
1118 |
1132 |
data = self.dice_box.guessbox.estimations[self.tri_estimation_name] |
data = self.dice_box.guessbox.estimations[self.tri_estimation_name] |
1119 |
|
x = data[0] |
|
|
1133 |
|
nsim, tri_data = data |
1120 |
1134 |
# it can be effectively done with pandas |
# it can be effectively done with pandas |
1121 |
|
self.df = df = pd.DataFrame(data[1]) |
|
|
1135 |
|
self.df = df = pd.DataFrame(tri_data) |
1122 |
1136 |
# -1 = 'out', 0=success, 1=failure, 2=mix |
# -1 = 'out', 0=success, 1=failure, 2=mix |
1123 |
1137 |
df.rename(columns={-1:'out', 0:'success', 1:'failure', 2:'mix'}, inplace=True) |
df.rename(columns={-1:'out', 0:'success', 1:'failure', 2:'mix'}, inplace=True) |
1124 |
|
|
|
1125 |
|
# Update the data |
|
1126 |
1138 |
|
|
|
1139 |
|
df.insert(loc=0, column='nsim', value=nsim) |
|
1140 |
|
if self.proxy_chk.isChecked(): |
|
1141 |
|
x = self.proxy(nsim) |
|
1142 |
|
df.insert(loc=0, column='nsim (proxy)', value=x) |
|
1143 |
|
else: |
|
1144 |
|
x = nsim |
|
1145 |
|
|
|
1146 |
|
|
|
1147 |
|
# Update the data |
1127 |
1148 |
self.pen_f.setData(x, self.zerosafe(df.failure)) |
self.pen_f.setData(x, self.zerosafe(df.failure)) |
1128 |
1149 |
self.pen_outmix.setData(x, self.zerosafe(df.failure+df.mix)) |
self.pen_outmix.setData(x, self.zerosafe(df.failure+df.mix)) |
1129 |
1150 |
self.pen_success.setData(x, self.zerosafe(df.failure+df.mix+df.out)) |
self.pen_success.setData(x, self.zerosafe(df.failure+df.mix+df.out)) |
1130 |
1151 |
|
|
1131 |
1152 |
if 'vertex_estimation' in self.dice_box.guessbox.estimations: |
if 'vertex_estimation' in self.dice_box.guessbox.estimations: |
1132 |
1153 |
data = self.dice_box.guessbox.estimations['vertex_estimation'] |
data = self.dice_box.guessbox.estimations['vertex_estimation'] |
1133 |
|
x, y = (*data,) |
|
|
1154 |
|
nsim, y = data |
1134 |
1155 |
# Update the data |
# Update the data |
1135 |
|
self.pen_vertex.setData(x, self.zerosafe(np.array(y))) |
|
|
1156 |
|
#č spolehám na konzistenci blackboxu, ne však úplně |
|
1157 |
|
self.pen_vertex.setData(self.proxy(nsim), self.zerosafe(np.array(y))) |
|
1158 |
|
df['vertex_estimation'] = y |
1136 |
1159 |
|
|
1137 |
1160 |
if 'weighted_vertex_estimation' in self.dice_box.guessbox.estimations: |
if 'weighted_vertex_estimation' in self.dice_box.guessbox.estimations: |
1138 |
1161 |
data = self.dice_box.guessbox.estimations['weighted_vertex_estimation'] |
data = self.dice_box.guessbox.estimations['weighted_vertex_estimation'] |
1139 |
|
x, y = (*data,) |
|
|
1162 |
|
nsim, y = data |
1140 |
1163 |
# Update the data |
# Update the data |
1141 |
|
self.pen_weighted_vertex.setData(x, self.zerosafe(np.array(y))) |
|
|
1164 |
|
#č spolehám na konzistenci blackboxu, ne však úplně |
|
1165 |
|
self.pen_weighted_vertex.setData(self.proxy(nsim), self.zerosafe(np.array(y))) |
|
1166 |
|
df['weighted_vertex_estimation'] = y |
1142 |
1167 |
|
|
1143 |
1168 |
|
|
1144 |
1169 |
|
|