pyobs-gui 2.0.0.dev6__py3-none-any.whl → 2.0.0.dev7__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,14 @@
1
- from typing import Any, Dict, TYPE_CHECKING
1
+ import os
2
+ from collections import deque
3
+ from typing import Any, Deque, Dict, Tuple, TYPE_CHECKING
2
4
  from PySide6 import QtWidgets, QtGui, QtCore # type: ignore
3
5
  import logging
4
6
 
7
+ os.environ["QT_API"] = "PySide6"
8
+ from matplotlib import pyplot as plt
9
+ from matplotlib.backends.backend_qtagg import FigureCanvasQTAgg as FigureCanvas
10
+ from matplotlib.dates import DateFormatter
11
+
5
12
  from pyobs.interfaces import IWeather, WeatherState, WeatherSensorReading
6
13
  from pyobs.utils.enums import WeatherSensors
7
14
  from .qt.weatherwidget_ui import Ui_WeatherWidget
@@ -13,6 +20,9 @@ if TYPE_CHECKING:
13
20
 
14
21
  log = logging.getLogger(__name__)
15
22
 
23
+ # how many samples to keep per sensor for the history plot
24
+ _HISTORY_LENGTH = 200
25
+
16
26
 
17
27
  # label and display order for known sensors; anything else reported by the module is ignored
18
28
  SENSOR_LABELS: Dict[WeatherSensors, str] = {
@@ -92,6 +102,14 @@ class WeatherWidget(BaseWidget, Ui_WeatherWidget):
92
102
  self._good: bool | None = None
93
103
  self._readings: Dict[WeatherSensors, WeatherSensorReading] = {}
94
104
  self._current_widgets: Dict[str, WidgetCurrentSensor] = {}
105
+ self._history: Dict[WeatherSensors, "Deque[Tuple[Time, float]]"] = {}
106
+
107
+ # add plot
108
+ self.figure = plt.figure()
109
+ layout = QtWidgets.QVBoxLayout(self.framePlot)
110
+ self.canvas = FigureCanvas(self.figure)
111
+ layout.addWidget(self.canvas)
112
+ self.framePlot.setLayout(layout)
95
113
 
96
114
  # before first update, disable myself
97
115
  self.setEnabled(False)
@@ -106,6 +124,11 @@ class WeatherWidget(BaseWidget, Ui_WeatherWidget):
106
124
  self._time = state.time
107
125
  self._good = state.good
108
126
  self._readings = {r.sensor: r for r in state.readings}
127
+ for reading in state.readings:
128
+ if reading.value is not None:
129
+ self._history.setdefault(reading.sensor, deque(maxlen=_HISTORY_LENGTH)).append(
130
+ (reading.time, reading.value)
131
+ )
109
132
  self.signal_update_gui.emit()
110
133
 
111
134
  def update_gui(self) -> None:
@@ -150,5 +173,32 @@ class WeatherWidget(BaseWidget, Ui_WeatherWidget):
150
173
  widget.set_value(s)
151
174
  widget.set_good(self._good)
152
175
 
176
+ self._plot_history()
177
+
178
+ def _plot_history(self) -> None:
179
+ # one stacked subplot per sensor that has history, in the same order as the current-value
180
+ # tiles; the sensor set (and therefore the subplot count) can change at runtime, so the
181
+ # figure is rebuilt from scratch rather than reusing fixed axes
182
+ sensors = [s for s in SENSOR_LABELS if self._history.get(s)]
183
+
184
+ self.figure.clear()
185
+ if not sensors:
186
+ self.canvas.draw()
187
+ return
188
+
189
+ axes = self.figure.subplots(len(sensors), 1, sharex=True)
190
+ if len(sensors) == 1:
191
+ axes = [axes]
192
+ for ax, sensor in zip(axes, sensors, strict=True):
193
+ times, values = zip(*self._history[sensor], strict=True)
194
+ ax.plot([t.to_datetime() for t in times], values, color="tab:blue")
195
+ ax.set_ylabel(SENSOR_LABELS[sensor], fontsize="small")
196
+ ax.grid(linestyle=":", alpha=0.5)
197
+ ax.set_axisbelow(True)
198
+ axes[-1].xaxis.set_major_formatter(DateFormatter("%H:%M:%S"))
199
+ self.figure.autofmt_xdate()
200
+ self.figure.tight_layout()
201
+ self.canvas.draw()
202
+
153
203
 
154
204
  __all__ = ["WeatherWidget"]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pyobs-gui
3
- Version: 2.0.0.dev6
3
+ Version: 2.0.0.dev7
4
4
  Summary: A remote GUI for pyobs
5
5
  Author-email: Tim-Oliver Husser <thusser@uni-goettingen.de>
6
6
  License-Expression: MIT
@@ -33,7 +33,7 @@ pyobs_gui/temperatureswidget.py,sha256=Hz1pYT9w3lODdgqpxDLX8EByWEIqbhfTwbGm5hzdX
33
33
  pyobs_gui/utils.py,sha256=dzv9vvGlptdvrEl4D19bQweYU0XxYMLtlKpwZ-WXfFI,2940
34
34
  pyobs_gui/videowidget.py,sha256=zy0QAJjveH6C8k2Ud-xmwcHBTpVcBxdy5UAz1Q3nhDo,9785
35
35
  pyobs_gui/watchedlabel.py,sha256=nX8FlOJwxehk6VzorA1uFvU255g1a7vt8HrYxowMaZY,554
36
- pyobs_gui/weatherwidget.py,sha256=O1KBnVuYo-KaOVEUz7KRNFCtmH7rQX0gtW00HC98AY0,5370
36
+ pyobs_gui/weatherwidget.py,sha256=SSXOAGxzutGlpV_IByhI8t5M9wnjyYhWsG5pF3447No,7413
37
37
  pyobs_gui/qt/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
38
38
  pyobs_gui/qt/acquisitionwidget.ui,sha256=tvSfZdYHoUUZWOsOq5xLd8VxOJidLEq0gxa1MBtBnIE,4661
39
39
  pyobs_gui/qt/acquisitionwidget_ui.py,sha256=LZQ3cHRmhorM347pIHrqrFx2VW9D0EDiOPOxZfOpOhc,6512
@@ -96,8 +96,8 @@ pyobs_gui/qt/resources/cloud-sun-solid.svg,sha256=qXGvtPuQYIAHlLc1Cqiy5M6s2-JOPF
96
96
  pyobs_gui/qt/resources/edit-solid.svg,sha256=R2lehJgb5DxyOXMmj5ACJsxOTqi9heXhj6WB9fdLelY,735
97
97
  pyobs_gui/qt/resources/search-solid.svg,sha256=8WR3B4MQyr76HrFvw6f7vQGyCWS7vQXF1WPWCWr3heQ,577
98
98
  pyobs_gui/qt/resources/undo-solid.svg,sha256=6O_Pyjo59fCCynMz5XhWU4wI1egQ3anNpToH9fpmISw,767
99
- pyobs_gui-2.0.0.dev6.dist-info/METADATA,sha256=LlMKkmuJSSqtTTmPF4NO2m_bQzniv7NssJ2uP3rKZRs,649
100
- pyobs_gui-2.0.0.dev6.dist-info/WHEEL,sha256=lCkmxWfQsSc9CfIClYeavTdQeEX2toPqufh9gI35EQA,87
101
- pyobs_gui-2.0.0.dev6.dist-info/entry_points.txt,sha256=KVqjHdiT1nvlYkkDPUb_rzBhC-Cs0MrpA_JA9_ddZ30,54
102
- pyobs_gui-2.0.0.dev6.dist-info/licenses/LICENSE,sha256=gC8djBliCENDmuRvzCoejpWbsn8eqKx61Hc8bmDZ2LI,1099
103
- pyobs_gui-2.0.0.dev6.dist-info/RECORD,,
99
+ pyobs_gui-2.0.0.dev7.dist-info/METADATA,sha256=jbc8sbmXBRFCgnH_thlAqHzxX7Y2P87IbvAJWh99E0Y,649
100
+ pyobs_gui-2.0.0.dev7.dist-info/WHEEL,sha256=lCkmxWfQsSc9CfIClYeavTdQeEX2toPqufh9gI35EQA,87
101
+ pyobs_gui-2.0.0.dev7.dist-info/entry_points.txt,sha256=KVqjHdiT1nvlYkkDPUb_rzBhC-Cs0MrpA_JA9_ddZ30,54
102
+ pyobs_gui-2.0.0.dev7.dist-info/licenses/LICENSE,sha256=gC8djBliCENDmuRvzCoejpWbsn8eqKx61Hc8bmDZ2LI,1099
103
+ pyobs_gui-2.0.0.dev7.dist-info/RECORD,,