From d5887363ef5012b1c08dcb6bbf7429024d2c72b7 Mon Sep 17 00:00:00 2001 From: GotthardG <51994228+GotthardG@users.noreply.github.com> Date: Wed, 25 Jun 2025 14:40:38 +0200 Subject: [PATCH] Update WebSocket URL and improve data handling/debugging Updated the WebSocket URL to point to the "tell_runner_router" path. Added detailed debug logging for incoming messages and refined data parsing to handle both "samples" dicts and raw lists. Removed commented-out code and ensured processed data is written to Redis with appropriate logging. --- daq/src/aaredaq/spreadsheetupdater.py | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/daq/src/aaredaq/spreadsheetupdater.py b/daq/src/aaredaq/spreadsheetupdater.py index a8386ca4..4260c61a 100644 --- a/daq/src/aaredaq/spreadsheetupdater.py +++ b/daq/src/aaredaq/spreadsheetupdater.py @@ -10,7 +10,7 @@ from config import BeamlineConfig # Your BeamlineConfig implement from aaredaqlib.beamline import MXBeamline # For beamline id/enum SLOT_IDENTIFIER = "X06DA" # or whatever is relevant -WS_URL = f"wss://mx-db-01.psi.ch/dispatcher/protected_router/ws/samples-spreadsheet/{SLOT_IDENTIFIER}" +WS_URL = f"wss://mx-db-01.psi.ch/dispatcher/protected_router/tell_runner_router/ws/samples-spreadsheet/{SLOT_IDENTIFIER}" WS_HEADERS = [f"X-Shared-Password: {os.getenv('AAREDB_SHARED_PASSWORD')}"] beamline = MXBeamline.X06DA # Use your beamline enum/value @@ -31,12 +31,19 @@ def set_spreadsheet_in_redis(spreadsheet): def on_message(ws, message): try: data = json.loads(message) - pucks = [PuckWithTellPosition(**item) for item in data] + print("[WS][RAW] Message received:", message) + print("[WS][DEBUG] Incoming data:", data) + # Most messages will be dicts with a "samples" list + if isinstance(data, dict) and "samples" in data: + pucks_data = data["samples"] + else: + pucks_data = data # fallback: it might be a list directly + + pucks = [PuckWithTellPosition(**item) for item in pucks_data] sample_short_infos = [] for p in pucks: for s in p.samples or []: - # Build DewarAddress if tell_position is provided and valid dewar_address = None if p.tell_position is not None and len(p.tell_position) == 2: dewar_address = DewarAddress( @@ -58,18 +65,14 @@ def on_message(ws, message): aaredb_params=getattr(s, "data_collection_parameters", None) ) ) - # Wrap in SampleShortInfoList for serialization ret = SampleShortInfoList(s=sample_short_infos) + config.spreadsheet = ret + print("DEBUG: Writing to redis key:", config._BeamlineConfig__bl + ":sample_spreadsheet") + print("[REDIS][INFO] Written spreadsheet to redis via .spreadsheet property") - # TESTING: Print the processed spreadsheet instead of storing to Redis - print("[WS][INFO] Processed spreadsheet for logging:") - print(ret.model_dump_json(indent=2)) - ## Store in Redis via your config property (will use model_dump_json for serialization) - #config.spreadsheet = ret except Exception as exc: print("[WS][ERROR] Failed to parse or convert message:", exc) - def on_error(ws, error): print("[WS][ERROR]", error)