1111import sqlalchemy
1212from fastapi import APIRouter , Depends , Request
1313from fastapi .responses import FileResponse , HTMLResponse
14+ from ispyb .sqlalchemy import Atlas
1415from ispyb .sqlalchemy import AutoProcProgram as ISPyBAutoProcProgram
1516from ispyb .sqlalchemy import (
1617 BLSample ,
@@ -611,7 +612,7 @@ def register_foil_hole(
611612 except Exception :
612613 if _transport_object :
613614 fh_ispyb_response = _transport_object .do_insert_foil_hole (
614- gsid .id , gs .thumbnail_size_x / gs .readout_area_x , foil_hole_params
615+ gs .id , gs .thumbnail_size_x / gs .readout_area_x , foil_hole_params
615616 )
616617 else :
617618 fh_ispyb_response = {"success" : False , "return_value" : None }
@@ -1339,7 +1340,7 @@ def suggest_path(
13391340 check_path = machine_config .rsync_basepath / base_path
13401341
13411342 # Check previous year to account for the year rolling over during data collection
1342- if not check_path .exists ():
1343+ if not check_path .parent . exists ():
13431344 base_path_parts = base_path .split ("/" )
13441345 for part in base_path_parts :
13451346 # Find the path part corresponding to the year
@@ -1351,10 +1352,10 @@ def suggest_path(
13511352 check_path = machine_config .rsync_basepath / base_path
13521353
13531354 # If it's not in the previous year either, it's a genuine error
1354- if not check_path .exists ():
1355+ if not check_path .parent . exists ():
13551356 log_message = (
13561357 "Unable to find current visit folder under "
1357- f"{ str (check_path_prev )!r} or { str (check_path )!r} "
1358+ f"{ str (check_path_prev . parent )!r} or { str (check_path . parent )!r} "
13581359 )
13591360 log .error (log_message )
13601361 raise FileNotFoundError (log_message )
@@ -1370,9 +1371,13 @@ def suggest_path(
13701371 return {"suggested_path" : check_path .relative_to (machine_config .rsync_basepath )}
13711372
13721373
1373- @router .post ("/{session_id}/make_rsyncer_destination" )
1374- def make_rsyncer_destination (session_id : int , destination : Path , db = murfey_db ):
1375- secure_path_parts = [secure_filename (p ) for p in destination .parts ]
1374+ class Dest (BaseModel ):
1375+ destination : Path
1376+
1377+
1378+ @router .post ("/sessions/{session_id}/make_rsyncer_destination" )
1379+ def make_rsyncer_destination (session_id : int , destination : Dest , db = murfey_db ):
1380+ secure_path_parts = [secure_filename (p ) for p in destination .destintion .parts ]
13761381 destination_path = "/" .join (secure_path_parts )
13771382 instrument_name = (
13781383 db .exec (select (Session ).where (Session .id == session_id )).one ().instrument_name
@@ -1427,19 +1432,31 @@ def register_dc_group(
14271432 dcg_murfey [0 ].atlas = dcg_params .atlas
14281433 dcg_murfey [0 ].sample = dcg_params .sample
14291434 dcg_murfey [0 ].atlas_pixel_size = dcg_params .atlas_pixel_size
1435+
1436+ if _transport_object :
1437+ if dcg_murfey [0 ].atlas_id is not None :
1438+ _transport_object .send (
1439+ _transport_object .feedback_queue ,
1440+ {
1441+ "register" : "atlas_update" ,
1442+ "atlas_id" : dcg_murfey [0 ].atlas_id ,
1443+ "atlas" : dcg_params .atlas ,
1444+ "sample" : dcg_params .sample ,
1445+ "atlas_pixel_size" : dcg_params .atlas_pixel_size ,
1446+ },
1447+ )
1448+ else :
1449+ atlas_id_response = _transport_object .do_insert_atlas (
1450+ Atlas (
1451+ dataCollectionGroupId = dcg_murfey [0 ].id ,
1452+ atlasImage = dcg_params .atlas ,
1453+ pixelSize = dcg_params .atlas_pixel_size ,
1454+ cassetteSlot = dcg_params .sample ,
1455+ )
1456+ )
1457+ dcg_murfey [0 ].atlas_id = atlas_id_response ["return_value" ]
14301458 db .add (dcg_murfey [0 ])
14311459 db .commit ()
1432- if _transport_object :
1433- _transport_object .send (
1434- _transport_object .feedback_queue ,
1435- {
1436- "register" : "atlas_update" ,
1437- "atlas_id" : dcg_murfey .atlas_id ,
1438- "atlas" : dcg_params .atlas ,
1439- "sample" : dcg_params .sample ,
1440- "atlas_pixel_size" : dcg_params .atlas_pixel_size ,
1441- },
1442- )
14431460 else :
14441461 dcg_parameters = {
14451462 "start_time" : str (datetime .datetime .now ()),
@@ -1528,6 +1545,7 @@ def register_proc(
15281545 "session_id" : session_id ,
15291546 "experiment_type" : proc_params .experiment_type ,
15301547 "recipe" : proc_params .recipe ,
1548+ "source" : proc_params .source ,
15311549 "tag" : proc_params .tag ,
15321550 "job_parameters" : {
15331551 k : v for k , v in proc_params .parameters .items () if v not in (None , "None" )
0 commit comments