mirror of
https://github.com/bec-project/bec_widgets.git
synced 2025-07-14 03:31:50 +02:00
feat: pydantic validation module for monitor.py
This commit is contained in:
0
bec_widgets/validation/__init__.py
Normal file
0
bec_widgets/validation/__init__.py
Normal file
42
bec_widgets/validation/monitor_config.py
Normal file
42
bec_widgets/validation/monitor_config.py
Normal file
@ -0,0 +1,42 @@
|
||||
from pydantic import BaseModel, Field, ValidationError
|
||||
from typing import List, Dict, Union, Optional
|
||||
|
||||
|
||||
class Signal(BaseModel):
|
||||
name: str
|
||||
entry: Optional[str]
|
||||
|
||||
|
||||
class PlotAxis(BaseModel):
|
||||
label: Optional[str]
|
||||
signals: List[Signal]
|
||||
|
||||
|
||||
class PlotConfig(BaseModel):
|
||||
plot_name: Optional[str]
|
||||
x: PlotAxis
|
||||
y: PlotAxis
|
||||
|
||||
|
||||
class PlotSettings(BaseModel):
|
||||
background_color: str
|
||||
num_columns: int
|
||||
colormap: str
|
||||
scan_types: bool
|
||||
|
||||
|
||||
class DeviceMonitorConfig(BaseModel):
|
||||
plot_settings: PlotSettings
|
||||
plot_data: List[PlotConfig]
|
||||
|
||||
|
||||
class ScanModeConfig(BaseModel):
|
||||
plot_settings: PlotSettings
|
||||
plot_data: Dict[str, List[PlotConfig]]
|
||||
|
||||
|
||||
def validate_config(config_data: dict) -> Union[DeviceMonitorConfig, ScanModeConfig]:
|
||||
if config_data["plot_settings"]["scan_types"]:
|
||||
return ScanModeConfig(**config_data)
|
||||
else:
|
||||
return DeviceMonitorConfig(**config_data)
|
2
setup.py
2
setup.py
@ -4,7 +4,7 @@ __version__ = "0.30.0"
|
||||
|
||||
if __name__ == "__main__":
|
||||
setup(
|
||||
install_requires=["pyqt5", "pyqtgraph", "bec_lib", "zmq", "h5py"],
|
||||
install_requires=["pydantic", "pyqt5", "pyqtgraph", "bec_lib", "zmq", "h5py"],
|
||||
extras_require={"dev": ["pytest", "pytest-random-order", "coverage", "pytest-qt", "black"]},
|
||||
version=__version__,
|
||||
)
|
||||
|
Reference in New Issue
Block a user