Skip to content
Snippets Groups Projects
Commit dd1acda8 authored by JOSSOUD Olivier's avatar JOSSOUD Olivier
Browse files

Explo. Visibility, string variables, vline when moving => OK

parent 638508ca
No related branches found
No related tags found
No related merge requests found
...@@ -36,7 +36,7 @@ ...@@ -36,7 +36,7 @@
<x>20</x> <x>20</x>
<y>260</y> <y>260</y>
<width>1021</width> <width>1021</width>
<height>441</height> <height>651</height>
</rect> </rect>
</property> </property>
</widget> </widget>
......
...@@ -127,6 +127,11 @@ class InstrumentInstantLog(InstrumentLog): ...@@ -127,6 +127,11 @@ class InstrumentInstantLog(InstrumentLog):
def get_timeseries(self, variable: str) -> pd.DataFrame: def get_timeseries(self, variable: str) -> pd.DataFrame:
timeseries_df = self.df[self.df["name"] == variable] timeseries_df = self.df[self.df["name"] == variable]
timeseries_df = timeseries_df.drop(columns=['name']) timeseries_df = timeseries_df.drop(columns=['name'])
try:
timeseries_df["value"] = timeseries_df["value"].astype(float)
except ValueError:
timeseries_df["value_int"] = timeseries_df["value"].astype("category").cat.codes
return timeseries_df return timeseries_df
......
...@@ -20,7 +20,7 @@ class Ui_MainWindow(object): ...@@ -20,7 +20,7 @@ class Ui_MainWindow(object):
self.tab_explo = QtWidgets.QWidget() self.tab_explo = QtWidgets.QWidget()
self.tab_explo.setObjectName("tab_explo") self.tab_explo.setObjectName("tab_explo")
self.explo_graphicsview_top = PlotWidget(self.tab_explo) self.explo_graphicsview_top = PlotWidget(self.tab_explo)
self.explo_graphicsview_top.setGeometry(QtCore.QRect(20, 260, 1021, 441)) self.explo_graphicsview_top.setGeometry(QtCore.QRect(20, 260, 1021, 651))
self.explo_graphicsview_top.setObjectName("explo_graphicsview_top") self.explo_graphicsview_top.setObjectName("explo_graphicsview_top")
self.explo_tablewidget_variables = QtWidgets.QTableWidget(self.tab_explo) self.explo_tablewidget_variables = QtWidgets.QTableWidget(self.tab_explo)
self.explo_tablewidget_variables.setGeometry(QtCore.QRect(20, 50, 1021, 201)) self.explo_tablewidget_variables.setGeometry(QtCore.QRect(20, 50, 1021, 201))
......
...@@ -4,6 +4,7 @@ from PyQt5.QtWidgets import * ...@@ -4,6 +4,7 @@ from PyQt5.QtWidgets import *
from PyQt5.QtGui import QColor from PyQt5.QtGui import QColor
from PyQt5.QtCore import * from PyQt5.QtCore import *
import pandas as pd import pandas as pd
from pandas.api.types import is_numeric_dtype
import numpy as np import numpy as np
from pyqtgraph.GraphicsScene.mouseEvents import MouseClickEvent from pyqtgraph.GraphicsScene.mouseEvents import MouseClickEvent
...@@ -155,13 +156,17 @@ class ExploUim: ...@@ -155,13 +156,17 @@ class ExploUim:
visible_item = QCheckBox() visible_item = QCheckBox()
visible_item.setChecked(True) visible_item.setChecked(True)
table.setCellWidget(row_id, self.VISIBLE_COL, visible_item) table.setCellWidget(row_id, self.VISIBLE_COL, visible_item)
table.cellWidget(row_id, self.VISIBLE_COL).stateChanged.connect(
lambda state, row_id=row_id: self.__apply_variable_change__(row_id=row_id))
# X original # X original
xorig_item = QTableWidgetItem() xorig_item = QTableWidgetItem()
xorig_item.setFlags(Qt.ItemIsEnabled) # Read only
table.setItem(row_id, self.XORIG_COL, xorig_item) table.setItem(row_id, self.XORIG_COL, xorig_item)
# Y original # Y original
yorig_item = QTableWidgetItem() yorig_item = QTableWidgetItem()
yorig_item.setFlags(Qt.ItemIsEnabled) # Read only
table.setItem(row_id, self.YORIG_COL, yorig_item) table.setItem(row_id, self.YORIG_COL, yorig_item)
self.__update_instruments_combobox__(row_id) self.__update_instruments_combobox__(row_id)
...@@ -237,11 +242,13 @@ class ExploUim: ...@@ -237,11 +242,13 @@ class ExploUim:
mult = table.cellWidget(row_id, self.MULT_COL).value() mult = table.cellWidget(row_id, self.MULT_COL).value()
timeshift = table.cellWidget(row_id, self.TIMESHIFT_COL).value() timeshift = table.cellWidget(row_id, self.TIMESHIFT_COL).value()
# Get variable visibility
visible = table.cellWidget(row_id, self.VISIBLE_COL).isChecked()
try: try:
self.__update_plot__(timeseries, row_id, color, offset, mult, timeshift) self.__update_plot__(timeseries, row_id, color, offset, mult, timeshift, visible)
except TypeError: except TypeError:
print("Cannot plot that.") self.main_ui.statusbar.showMessage("Failed to plot [" + variable_name + "]", msecs=3000)
def __update_xy_original__(self, instant: datetime.datetime): def __update_xy_original__(self, instant: datetime.datetime):
table = self.main_ui.explo_tablewidget_variables table = self.main_ui.explo_tablewidget_variables
...@@ -253,7 +260,11 @@ class ExploUim: ...@@ -253,7 +260,11 @@ class ExploUim:
# Get Y orig (original non-shifted variable value) # Get Y orig (original non-shifted variable value)
df = self.__get_row_dataframe__(row_id).copy() df = self.__get_row_dataframe__(row_id).copy()
y_orig = df[df["datetime"] <= instant].iloc[-1]["value"] df = df[df["datetime"] <= instant]
if len(df.index) == 0:
y_orig = "Out of range"
else:
y_orig = df.iloc[-1]["value"]
if isinstance(y_orig, float): if isinstance(y_orig, float):
y_orig = "{:.4f}".format(y_orig) y_orig = "{:.4f}".format(y_orig)
table.item(row_id, self.YORIG_COL).setText(y_orig) table.item(row_id, self.YORIG_COL).setText(y_orig)
...@@ -272,26 +283,33 @@ class ExploUim: ...@@ -272,26 +283,33 @@ class ExploUim:
self.lines_items = [] self.lines_items = []
# Vertical line following the cursor # Vertical line following the cursor
self.cursor_vline = pg.InfiniteLine(angle=90, movable=False) self.cursor_vline = pg.InfiniteLine(angle=90, movable=False, pen=pg.mkPen(style=Qt.DotLine))
self.plot_item.addItem(self.cursor_vline, ignoreBounds=True) self.plot_item.addItem(self.cursor_vline, ignoreBounds=True)
self.measure_vline = pg.InfiniteLine(angle=90, movable=False)
self.plot_item.addItem(self.measure_vline, ignoreBounds=True)
def __update_plot__(self, timeseries: pd.DataFrame, row_id: int, color: QColor, def __update_plot__(self, timeseries: pd.DataFrame, row_id: int, color: QColor,
offset: float, mult: float, timeshift_sec: float) -> None: offset: float, mult: float, timeshift_sec: float,
try: visible: bool) -> None:
timeseries["value"] = timeseries["value"].astype(float)
except ValueError:
print("Value is not convertible to float")
return
# Get the to-be-modified curve # Get the to-be-modified curve
if row_id in self.step_curves: if row_id in self.step_curves:
step_curve = self.step_curves[row_id] step_curve = self.step_curves[row_id]
else: else:
step_curve = pg.PlotCurveItem() step_curve = pg.PlotCurveItem()
self.step_curves[row_id] = step_curve
self.plot_item.addItem(step_curve) self.plot_item.addItem(step_curve)
step_curve.scene().sigMouseClicked.connect(lambda event: self.__mouse_clicked__(event)) step_curve.scene().sigMouseClicked.connect(lambda event: self.__mouse_clicked__(event))
self.step_curves[row_id] = step_curve step_curve.scene().sigMouseMoved.connect(lambda event: self.__mouse_moved__(event))
# Set curve visibility
if not visible:
step_curve.hide()
else:
step_curve.show()
# --- X values ---
# As it is a _step_ curve, add a last datetime point to determine the end of the last step. This is the datatime # As it is a _step_ curve, add a last datetime point to determine the end of the last step. This is the datatime
# of the last available data of the dataset, plus one second. # of the last available data of the dataset, plus one second.
last_datetime = self.current_dataset.last_data_datetime + datetime.timedelta(seconds=1) last_datetime = self.current_dataset.last_data_datetime + datetime.timedelta(seconds=1)
...@@ -301,7 +319,12 @@ class ExploUim: ...@@ -301,7 +319,12 @@ class ExploUim:
# Apply time shift # Apply time shift
x_values = x_values + datetime.timedelta(seconds=timeshift_sec) x_values = x_values + datetime.timedelta(seconds=timeshift_sec)
y_values = list(timeseries["value"]) # --- Y values ---
# Get original value if it is a numeric, otherwise get its coded integer version.
if is_numeric_dtype(timeseries["value"]):
y_values = list(timeseries["value"])
else:
y_values = list(timeseries["value_int"])
# Apply multiplicative factor # Apply multiplicative factor
y_values = [y * mult for y in y_values] y_values = [y * mult for y in y_values]
...@@ -315,11 +338,28 @@ class ExploUim: ...@@ -315,11 +338,28 @@ class ExploUim:
pen=color, pen=color,
stepMode=True) stepMode=True)
def __mouse_clicked__(self, event: MouseClickEvent): def __mouse_clicked__(self, event: MouseClickEvent) -> None:
"""Function triggered when the user clicks on the plot. Display a vertical line under the mouse click and call
function ``__update_xy_original__``
Parameters
----------
event: pyqtgraph.MouseClickEvent
"""
pos = event.scenePos() pos = event.scenePos()
mousePoint = self.step_curves[0].getViewBox().mapSceneToView(pos) mouse_point = self.step_curves[0].getViewBox().mapSceneToView(pos)
instant = datetime.datetime.fromtimestamp(mousePoint.x(), tz=datetime.timezone.utc) instant = datetime.datetime.fromtimestamp(mouse_point.x(), tz=datetime.timezone.utc)
# instant = datetime.datetime.fromtimestamp(mousePoint.x()) self.measure_vline.setPos(mouse_point.x())
self.__update_xy_original__(instant) self.__update_xy_original__(instant)
self.cursor_vline.setPos(mousePoint.x())
# print("x="+instant.strftime("%H:%M:%S")) def __mouse_moved__(self, pos: QPointF) -> None:
"""Function triggered when the user's mouse cursor hovers over the plot. Display a vertical line where the
cursor is.
Parameters
----------
pos: PyQt5.QtCore.QPointF
"""
# if self.step_curves[0].sceneBoundingRect().contains(pos):
mouse_point = self.step_curves[0].getViewBox().mapSceneToView(pos)
self.cursor_vline.setPos(mouse_point.x())
\ No newline at end of file
...@@ -36,7 +36,11 @@ class TimeAxisItem(pg.AxisItem): ...@@ -36,7 +36,11 @@ class TimeAxisItem(pg.AxisItem):
self.enableAutoSIPrefix(False) self.enableAutoSIPrefix(False)
def tickStrings(self, values, scale, spacing): def tickStrings(self, values, scale, spacing):
return [datetime.datetime.fromtimestamp(value, tz=datetime.timezone.utc).strftime("%H:%M:%S") for value in values] try:
tick_strings = [datetime.datetime.fromtimestamp(value, tz=datetime.timezone.utc).strftime("%H:%M:%S") for value in values]
except ValueError:
tick_strings = ["ERROR" for value in values]
return tick_strings
def highlight_row(table: QTableWidget, highlighted_row_id: int, def highlight_row(table: QTableWidget, highlighted_row_id: int,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment