fix: исправил падение приложения в случае отсутствия меток начала и конца этапа
This commit is contained in:
parent
7683e4395c
commit
34b8b49624
@ -1,3 +1,5 @@
|
|||||||
|
from typing import Optional
|
||||||
|
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
from PyQt5.QtWidgets import QWidget, QVBoxLayout
|
from PyQt5.QtWidgets import QWidget, QVBoxLayout
|
||||||
import pyqtgraph as pg
|
import pyqtgraph as pg
|
||||||
@ -11,15 +13,17 @@ class PlotWidget(BasePlotWidget):
|
|||||||
def _create_stage_region(self,
|
def _create_stage_region(self,
|
||||||
stage: str,
|
stage: str,
|
||||||
times: pd.Series,
|
times: pd.Series,
|
||||||
dataframe: pd.DataFrame) -> pg.LinearRegionItem:
|
dataframe: pd.DataFrame) -> Optional[pg.LinearRegionItem]:
|
||||||
stage_diff = np.diff(dataframe[stage])
|
stage_diff = np.diff(dataframe[stage])
|
||||||
start_index = np.where(stage_diff == 1)[0]
|
start_index = np.where(stage_diff == 1)[0]
|
||||||
finish_index = np.where(stage_diff == -1)[0]
|
finish_index = np.where(stage_diff == -1)[0]
|
||||||
|
if start_index:
|
||||||
start_timestamp = times[start_index[0]]
|
start_timestamp = times[start_index[0]]
|
||||||
finish_timestamp = times[finish_index[0]]
|
finish_timestamp = times[finish_index[0]] if finish_index else times[len(times) - 1]
|
||||||
region = pg.LinearRegionItem([start_timestamp, finish_timestamp], movable=False)
|
region = pg.LinearRegionItem([start_timestamp, finish_timestamp], movable=False)
|
||||||
region.setBrush(pg.mkBrush(self._stage_colors[stage]))
|
region.setBrush(pg.mkBrush(self._stage_colors[stage]))
|
||||||
return region
|
return region
|
||||||
|
return None
|
||||||
|
|
||||||
def _build_widget(self, dataframe: pd.DataFrame) -> QWidget:
|
def _build_widget(self, dataframe: pd.DataFrame) -> QWidget:
|
||||||
widget = QWidget()
|
widget = QWidget()
|
||||||
@ -38,6 +42,7 @@ class PlotWidget(BasePlotWidget):
|
|||||||
if settings["stages"] and all([stage in dataframe_headers for stage in self._stages]):
|
if settings["stages"] and all([stage in dataframe_headers for stage in self._stages]):
|
||||||
for stage in self._stages:
|
for stage in self._stages:
|
||||||
region = self._create_stage_region(stage, time_axis, dataframe)
|
region = self._create_stage_region(stage, time_axis, dataframe)
|
||||||
|
if region:
|
||||||
plot_widget.addItem(region)
|
plot_widget.addItem(region)
|
||||||
|
|
||||||
for signal in description["Signals"]:
|
for signal in description["Signals"]:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user