Compare commits

..

No commits in common. "327e32b8e1f742d52e3babfc7d54eb2057591d6b" and "c74e55f98c9f248feed502b1ab007028bd7c2f17" have entirely different histories.

View File

@ -1,20 +1,13 @@
from typing import Optional, Any, NamedTuple
from typing import Optional
import pandas as pd
from PyQt5.QtWidgets import QWidget, QVBoxLayout
import pyqtgraph as pg
import numpy as np
from numpy import floating
from base.base import BasePlotWidget
class ProcessStage(NamedTuple):
mean_value: floating[Any]
start_index: int
finish_index: int
class PlotWidget(BasePlotWidget):
def _create_stage_region(self,
@ -33,18 +26,10 @@ class PlotWidget(BasePlotWidget):
return region
return None
@staticmethod
def _init_plot_widget(title: str) -> (pg.PlotWidget, pg.LegendItem):
plot_widget = pg.PlotWidget(title=title)
plot_widget.showGrid(x=True, y=True)
legend = pg.LegendItem((80, 60), offset=(70, 20))
legend.setParentItem(plot_widget.graphicsItem())
return plot_widget, legend
def get_stage_info(self,
stage: str,
dataframe: pd.DataFrame,
signal_name: str) -> Optional[ProcessStage]:
def _find_mid_in_stage(self,
stage: str,
dataframe: pd.DataFrame,
signal_name: str) -> float:
if stage in self._stages:
stage_diff = np.diff(dataframe[stage])
start_index = np.where(stage_diff == 1)[0]
@ -57,8 +42,8 @@ class PlotWidget(BasePlotWidget):
finish = finish_index[0] if finish_index.size else (len(data) - 1)
data_slice = data[start:finish]
mean = np.mean(data_slice)
return ProcessStage(mean_value=mean, start_index=int(start), finish_index=int(finish))
return None
return mean
return 0.0
def _build_widget(self, dataframe: pd.DataFrame) -> QWidget:
widget = QWidget()
@ -68,54 +53,37 @@ class PlotWidget(BasePlotWidget):
dataframe_headers = dataframe.columns.tolist()
for channel, description in self._plt_channels.items():
plot_widget, legend = self._init_plot_widget(title=channel)
plot_widget = pg.PlotWidget(title=channel)
plot_widget.showGrid(x=True, y=True)
legend = pg.LegendItem((80, 60), offset=(70, 20))
legend.setParentItem(plot_widget.graphicsItem())
settings = description["Settings"]
if settings["stages"] and all([stage in dataframe_headers for stage in self._stages]):
for stage in self._stages:
region = self._create_stage_region(stage, time_axis, dataframe)
if region:
plot_widget.addItem(region)
if settings["zoom"]:
if max(time_axis) < 5.0:
stages = [self.get_stage_info("Welding",
dataframe,
signal["name"]) for signal in description["Signals"]]
if stages:
means_raw = [stage.mean_value for stage in stages]
mean = max(means_raw)
start = time_axis[stages[0].start_index]
finish = time_axis[stages[0].finish_index]
if settings["zoom"] and max(time_axis) < 5.0:
means_raw = [self._find_mid_in_stage("Welding",
dataframe,
signal["name"]) for signal in description["Signals"]]
mean = max(means_raw)
region_stable = pg.LinearRegionItem([mean - mean * 0.015,
mean + mean * 0.015],
orientation='horizontal')
region_stable.setBrush(pg.mkBrush([250, 250, 0, 25]))
plot_widget.addItem(region_stable)
overshoot = pg.BarGraphItem(x0=0,
y0=mean - mean * 0.05,
height=mean * 0.05 * 2,
width=start,
brush=pg.mkBrush([0, 250, 0, 100]))
plot_widget.addItem(overshoot)
region_overshoot = pg.LinearRegionItem([mean - mean * 0.05,
mean + mean * 0.05],
orientation='horizontal')
region_overshoot.setBrush(pg.mkBrush([0, 250, 0, 30]))
plot_widget.addItem(region_overshoot)
stable = pg.BarGraphItem(x0=start,
y0=mean - mean * 0.015,
height=mean * 0.015 * 2,
width=finish - start,
brush=pg.mkBrush([0, 250, 0, 100]))
plot_widget.addItem(stable)
plot_widget.setYRange(mean - 260, mean + 260)
plot_widget.setInteractive(False)
else:
max_value = min([max(dataframe[signal["name"]]) for signal in description["Signals"]])
region = pg.LinearRegionItem([max_value - max_value * 0.015,
max_value + max_value * 0.015],
movable=False,
orientation="horizontal")
region.setBrush(pg.mkBrush([0, 250, 0, 100]))
plot_widget.setYRange(max_value - 200, max_value + 200)
plot_widget.setXRange(3.5, 4.5)
plot_widget.addItem(region)
plot_widget.setInteractive(False)
plot_widget.setYRange(mean - 260, mean + 260)
plot_widget.setInteractive(False)
for signal in description["Signals"]:
if signal["name"] in dataframe_headers: