Skip to content
Snippets Groups Projects
Commit 9e192a9a authored by David Hammer's avatar David Hammer
Browse files

Add preview scene for SimpleAssembler

parent 3dcad0a5
No related branches found
No related tags found
1 merge request!12Snapshot: field test deployed version as of end of run 202201
...@@ -53,7 +53,7 @@ class SimpleAssembler(TrainMatcher.TrainMatcher): ...@@ -53,7 +53,7 @@ class SimpleAssembler(TrainMatcher.TrainMatcher):
( (
OVERWRITE_ELEMENT(expected) OVERWRITE_ELEMENT(expected)
.key("availableScenes") .key("availableScenes")
.setNewDefaultValue(["scene", "assemblerOverview"]) .setNewDefaultValue(["overview", "trainMatcherScene"])
.commit(), .commit(),
FLOAT_ELEMENT(expected) FLOAT_ELEMENT(expected)
...@@ -135,7 +135,7 @@ class SimpleAssembler(TrainMatcher.TrainMatcher): ...@@ -135,7 +135,7 @@ class SimpleAssembler(TrainMatcher.TrainMatcher):
def requestScene(self, params): def requestScene(self, params):
# TODO: unify with TrainMatcher overview # TODO: unify with TrainMatcher overview
scene_name = params.get("name", default="") scene_name = params.get("name", default="")
if scene_name == "assemblerOverview": if scene_name == "overview":
payload = Hash("name", scene_name, "success", True) payload = Hash("name", scene_name, "success", True)
payload["data"] = scenes.simple_assembler_overview( payload["data"] = scenes.simple_assembler_overview(
device_id=self.getInstanceId(), device_id=self.getInstanceId(),
...@@ -153,7 +153,8 @@ class SimpleAssembler(TrainMatcher.TrainMatcher): ...@@ -153,7 +153,8 @@ class SimpleAssembler(TrainMatcher.TrainMatcher):
payload, payload,
) )
) )
else: elif scene_name == "trainMatcherScene":
params["name"] = "scene"
return super().requestScene(params) return super().requestScene(params)
def receive_geometry(self, data, metadata): def receive_geometry(self, data, metadata):
...@@ -238,14 +239,6 @@ class SimpleAssembler(TrainMatcher.TrainMatcher): ...@@ -238,14 +239,6 @@ class SimpleAssembler(TrainMatcher.TrainMatcher):
channel.update() channel.update()
self.rate_out.update() self.rate_out.update()
def _update_rate(self):
self._buffered_status_update.set(
"processingTime", self._processing_time_ema.get()
)
self._buffered_status_update.set("timeOfFlight", self._time_of_flight_ema.get())
self._buffered_status_update.set("rate", self._rate_tracker.get())
self.set(self._buffered_status_update)
@functools.lru_cache() @functools.lru_cache()
def _source_to_index(self, source): def _source_to_index(self, source):
# note: cache means warning only shows up once (also not performance-critical) # note: cache means warning only shows up once (also not performance-critical)
......
...@@ -5,6 +5,7 @@ from karabo.common.scenemodel.api import ( ...@@ -5,6 +5,7 @@ from karabo.common.scenemodel.api import (
CheckBoxModel, CheckBoxModel,
ColorBoolModel, ColorBoolModel,
DeviceSceneLinkModel, DeviceSceneLinkModel,
DetectorGraphModel,
DisplayCommandModel, DisplayCommandModel,
DisplayLabelModel, DisplayLabelModel,
DisplayStateColorModel, DisplayStateColorModel,
...@@ -20,8 +21,10 @@ from karabo.common.scenemodel.api import ( ...@@ -20,8 +21,10 @@ from karabo.common.scenemodel.api import (
write_scene, write_scene,
) )
# section: common setup # section: common setup
BASE_INC = 25 BASE_INC = 25
NARROW_INC = 20 NARROW_INC = 20
PADDING = 5 PADDING = 5
...@@ -115,6 +118,11 @@ def boxed(component_class): ...@@ -115,6 +118,11 @@ def boxed(component_class):
# section: useful layout and utility classes # section: useful layout and utility classes
def DisplayRoundedFloat(*args, decimals=2, **kwargs):
# note: naive subclass breaks as registry looks for writer based on exact class
return EvaluatorModel(*args, expression=f"f'{{x:{decimals}}}'", **kwargs)
class Space: class Space:
def __init__(self, width, height): def __init__(self, width, height):
self.width = width self.width = width
...@@ -124,6 +132,27 @@ class Space: ...@@ -124,6 +132,27 @@ class Space:
return [] return []
def dummy_wrap(model_class):
class Wrapper:
def __init__(self, *args, **kwargs):
self.thing = model_class(*args, **kwargs)
def render(self, x, y):
self.thing.x = x
self.thing.y = y
return [self.thing]
@property
def width(self):
return self.thing.width
@property
def height(self):
return self.thing.height
return Wrapper
class HorizontalLayout: class HorizontalLayout:
def __init__(self, *arg_children, children=None, padding=PADDING): def __init__(self, *arg_children, children=None, padding=PADDING):
self.children = list(arg_children) self.children = list(arg_children)
...@@ -374,14 +403,12 @@ class CorrectionDeviceStatus(VerticalLayout): ...@@ -374,14 +403,12 @@ class CorrectionDeviceStatus(VerticalLayout):
width=7 * BASE_INC, width=7 * BASE_INC,
height=BASE_INC, height=BASE_INC,
) )
rate = EvaluatorModel( rate = DisplayRoundedFloat(
expression="f'{x:.02f}'",
keys=[f"{device_id}.performance.rate"], keys=[f"{device_id}.performance.rate"],
width=7 * BASE_INC, width=7 * BASE_INC,
height=BASE_INC, height=BASE_INC,
) )
processing_time = EvaluatorModel( processing_time = DisplayRoundedFloat(
expression="f'{x:.02f}'",
keys=[f"{device_id}.performance.processingTime"], keys=[f"{device_id}.performance.processingTime"],
width=7 * BASE_INC, width=7 * BASE_INC,
height=BASE_INC, height=BASE_INC,
...@@ -433,8 +460,7 @@ class CompactCorrectionDeviceOverview(HorizontalLayout): ...@@ -433,8 +460,7 @@ class CompactCorrectionDeviceOverview(HorizontalLayout):
width=6 * BASE_INC, width=6 * BASE_INC,
height=BASE_INC, height=BASE_INC,
), ),
EvaluatorModel( DisplayRoundedFloat(
expression="f'{x:.02f}'",
keys=[f"{device_id}.performance.rate"], keys=[f"{device_id}.performance.rate"],
width=4 * BASE_INC, width=4 * BASE_INC,
height=BASE_INC, height=BASE_INC,
...@@ -476,6 +502,47 @@ class CompactDeviceLinkList(VerticalLayout): ...@@ -476,6 +502,47 @@ class CompactDeviceLinkList(VerticalLayout):
) )
@titled("Assembler status", width=8 * NARROW_INC)
@boxed
class AssemblerDeviceStatus(VerticalLayout):
def __init__(self, device_id):
super().__init__(padding=0)
name = DisplayLabelModel(
keys=[f"{device_id}.deviceId"],
width=14 * BASE_INC,
height=BASE_INC,
)
state = DisplayStateColorModel(
show_string=True,
keys=[f"{device_id}.state"],
width=7 * BASE_INC,
height=BASE_INC,
)
train_id = DisplayLabelModel(
keys=[f"{device_id}.trainId"],
width=7 * BASE_INC,
height=BASE_INC,
)
self.children.extend(
[
name,
HorizontalLayout(
state,
train_id,
padding=0,
),
DeviceSceneLinkModel(
text="I'm actually a TrainMatcher",
keys=[f"{device_id}.availableScenes"],
target="trainMatcherScene",
target_window=SceneTargetWindow.Dialog,
width=14 * BASE_INC,
height=BASE_INC,
),
]
)
# section: generating actual scenes # section: generating actual scenes
...@@ -583,6 +650,39 @@ def manager_device_overview_scene( ...@@ -583,6 +650,39 @@ def manager_device_overview_scene(
), ),
) )
@scene_generator
def simple_assembler_overview(device_id, geometry_device_id):
return VerticalLayout(
HorizontalLayout(
AssemblerDeviceStatus(device_id),
titled("My geometry device")(boxed(VerticalLayout))(
DeviceSceneLinkModel(
text=f"Geometry device: {geometry_device_id}",
keys=[f"{geometry_device_id}.availableScenes"],
target="overview",
target_window=SceneTargetWindow.Dialog,
frame_width=1,
width=14 * BASE_INC,
height=BASE_INC,
),
DisplayCommandModel(
keys=[f"{geometry_device_id}.pleaseSendYourGeometry"],
width=14 * BASE_INC,
height=BASE_INC,
),
padding=0,
),
),
titled("Preview image")(boxed(dummy_wrap(DetectorGraphModel)))(
keys=[f"{device_id}.preview.output.schema.image"],
colormap="viridis",
width=30 * BASE_INC,
height=30 * BASE_INC,
x=PADDING,
y=PADDING,
),
)
# section: here be monsters # section: here be monsters
......
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