Source code for prsctrl_gui.task.tasks.measurement
""":class:`.MeasurementTask`."""
from ...measurement.settings import PrsGuiSettings
from ...app_state import device_manager
from prsctrl.measurement.time_estimate import get_time_estimate_per_wavelength
from devctrl.task import Task, taskclass
from typing import Type
import logging
log = logging.getLogger(__name__)
[docs]
@taskclass
class MeasurementTask(Task, PrsGuiSettings):
[docs]
def __init__(self, *args, **kwargs):
Task.__init__(self)
PrsGuiSettings.__init__(self, *args, **kwargs)
[docs]
def estimate_runtime_s(self) -> int:
"""Get the time estimate for the measurement.
This method uses the global device manager to retrieve the required devices.
Since this method may be called while the task is not yet properly configured, any errors are caught and logged, and -1 is returned in that case.
:return: The time estimate or -1 of an error occured.
"""
measurement_settings = self.general
# TODO: get from settings
auto_add_offset_measurements = True
devmg = device_manager.get()
try:
time_estimates = get_time_estimate_per_wavelength(devmg, measurement_settings=self)
if len(time_estimates) == 0: return 0
time_per_wavelength = max(time_estimates.values())
wavelengths = measurement_settings.get_wavelengths_nm_with_offsets(time_per_wavelength, update_field=False)
time_estimate = int(round(len(wavelengths) * time_per_wavelength, 0))
return time_estimate
except Exception as e:
log.debug(f"Error getting time estimate: {type(e)}: {e}")
return -1
[docs]
def get_icon_name(self) -> str:
return "tape-measure"