33from pathlib import Path
44from typing import Dict , List , Optional
55
6+ import requests
67from fastapi import APIRouter , Depends
78from fastapi .responses import FileResponse
89from ispyb .sqlalchemy import AutoProcProgram as ISPyBAutoProcProgram
@@ -417,24 +418,31 @@ def register_atlas(
417418
418419class SquareRegistration (BaseModel ):
419420 tag : str
421+ image_path : str | None = None
420422 count : int | None = None
423+ serialem : bool = False
421424
422425
423426@spa_router .post ("/sessions/{session_id}/register_square/{gsid}" )
424427def register_square (
425428 session_id : MurfeySessionID ,
426- gsid : int ,
429+ gsid : int | str ,
427430 square_registration_data : SquareRegistration ,
428431 db = murfey_db ,
429432):
430433 if SMARTEM_ACTIVE :
431- gs = db .exec (
432- select (GridSquare )
433- .where (GridSquare .name == gsid )
434- .where (GridSquare .tag == square_registration_data .tag )
435- .where (GridSquare .session_id == session_id )
436- ).one_or_none ()
437- if gs and gs .smartem_uuid :
434+ logger .info (f"smartem active for square { sanitise (str (gsid ))} " )
435+ if square_registration_data .serialem :
436+ smartem_uuid : int | str | None = gsid
437+ else :
438+ gs = db .exec (
439+ select (GridSquare )
440+ .where (GridSquare .name == gsid )
441+ .where (GridSquare .tag == square_registration_data .tag )
442+ .where (GridSquare .session_id == session_id )
443+ ).one_or_none ()
444+ smartem_uuid = gs .smartem_uuid if gs else None
445+ if smartem_uuid is not None :
438446 session = db .exec (select (Session ).where (Session .id == session_id )).one ()
439447 machine_config = get_machine_config (session .instrument_name )[
440448 session .instrument_name
@@ -444,8 +452,16 @@ def register_square(
444452 base_url = machine_config .smartem_api_url , logger = logger
445453 )
446454 smartem_client .gridsquare_registered (
447- gs .smartem_uuid , count = square_registration_data .count
455+ smartem_uuid , count = square_registration_data .count
456+ )
457+ result = requests .put (
458+ f"{ machine_config .smartem_api_url } /gridsquares/{ smartem_uuid } " ,
459+ json = {"image_path" : square_registration_data .image_path },
448460 )
461+ if not result .status_code == 200 :
462+ logger .warning (
463+ f"Post to smartem gridsquares returned { result .status_code } "
464+ )
449465 else :
450466 logger .info ("smartem deactivated so did not register square" )
451467
0 commit comments