fix: исправлен расчет TWC_time (теперь берется отрезок времени от начала первого closing до конца последнего relief) + исправено отображение ROI при инициализации

This commit is contained in:
Andrew 2025-02-04 12:52:40 +03:00
parent a8a9d6fdb6
commit b15b079221
23 changed files with 23 additions and 14 deletions

View File

@ -27,6 +27,8 @@ class ChannelTimings():
TWC_time: float = 0.0
ideal_time: float = 0.0
client_time: float = 0.0
TWC_start: float = 0.0
TWC_end: float = 0.0
worst_performance: float = 2
worst_timeframe: list = field(default_factory=lambda: [0, 0])
@ -151,7 +153,9 @@ class CustomPlotLayout(pg.GraphicsLayoutWidget):
self.addItem(plot_item, widget_num, 0)
navigator = NavigatorPlot(plot_timings.worst_timeframe, main_plot)
timings = ChannelTimings()
if self.property('performance'):timings:ChannelTimings = self.property('performance')
navigator = NavigatorPlot(timings.worst_timeframe, main_plot)
if navigator is not None:
self.addItem(navigator, widget_num+1, 0)
@ -210,6 +214,7 @@ class PlotItemGenerator:
point_data: PointPassport = data
ideal_data = copy.deepcopy(point_data.ideal_data)
is_last = (cur_point == len(points_pocket) - 1)
is_first = (cur_point == 0)
if self._ideal_mode:
timings, point_data.events, point_data.timeframe = self._generate_synthetic_events(timings, ideal_data)
@ -239,14 +244,13 @@ class PlotItemGenerator:
self._add_ideal_signals(plot_item, legend, ideal_data, point_data.events, description["Ideal_signals"], pyqt_container.curves, is_last)
if settings["performance"]:
timings = self._calc_performance(timings, point_data, ideal_data, is_last)
timings = self._calc_performance(timings, point_data, ideal_data, is_first, is_last)
self._parent._update_status(widget_steps, point_steps, widget_num, cur_point)
# Добавляем реальные сигналы
if not self._ideal_mode:
self._add_real_signals(plot_item, dataframe, description["Real_signals"], legend, pyqt_container.curves)
return (plot_item, timings)
@staticmethod
@ -415,24 +419,26 @@ class PlotItemGenerator:
def _calc_performance(self,
timings:ChannelTimings,
point_data: PointPassport,
ideal_data:dict,
ideal_data:dict,
is_first:bool,
is_last:bool) -> ChannelTimings:
if is_last:
if is_first:
if not self._ideal_mode:
TWC_delta = sum([point_data.events[stage][1] - point_data.events[stage][0]
for stage in ["Closing", "Squeeze", "Welding"]])
else: TWC_delta = 0
timings.TWC_start = point_data.events["Closing"][0]
ideal_delta = ideal_data["Ideal cycle"]
elif is_last:
if not self._ideal_mode:
timings.TWC_end = point_data.events["Relief"][1]
timings.TWC_time = timings.TWC_end - timings.TWC_start
timings.worst_timeframe = [timings.TWC_start, timings.TWC_end]
ideal_delta = sum(ideal_data["Ideal timings"][0:3])
else:
if not self._ideal_mode: TWC_delta = point_data.timeframe[1] - point_data.timeframe[0]
else: TWC_delta = 0
ideal_delta = ideal_data["Ideal cycle"]
timings.TWC_time += TWC_delta
timings.ideal_time += ideal_delta
curr_perf = ideal_delta/TWC_delta if TWC_delta != 0 else 1
#curr_perf = ideal_delta/TWC_delta if TWC_delta != 0 else 1
if curr_perf < timings.worst_performance:
if False: #curr_perf < timings.worst_performance:
timings.worst_performance = curr_perf
timings.worst_timeframe = point_data.timeframe
return timings
@ -509,6 +515,7 @@ class NavigatorPlot(pg.PlotItem):
"""
Связывает изменения навигатора и других графиков друг с другом
"""
self._sync_main_plot_with_navigator(main_plot, self.ROI_region)
self.ROI_region.sigRegionChanged.connect(
lambda: self._sync_main_plot_with_navigator(main_plot, self.ROI_region)
)
@ -533,8 +540,10 @@ class NavigatorPlot(pg.PlotItem):
x_downsampled, y_downsampled = self._downsample_data(x, y, max_points=1000)
self.plot(x_downsampled, y_downsampled, pen=signal_pen, name=curve_name)
self.ROI_region = pg.LinearRegionItem(values=time_region, movable=True, brush=pg.mkBrush(0, 0, 255, 100), pen=pg.mkPen(width=4))
self.ROI_region = pg.LinearRegionItem(movable=True, brush=pg.mkBrush(0, 0, 255, 100), pen=pg.mkPen(width=4))
self.ROI_region.setBounds([0, x[-1]])
self.ROI_region.setRegion(time_region)
self.addItem(self.ROI_region)
self.getViewBox().setLimits(xMin=0, xMax=x[-1])