From a3cc9f29a7e603aa7a2497644df03f75ba5b4229 Mon Sep 17 00:00:00 2001 From: GotthardG <51994228+GotthardG@users.noreply.github.com> Date: Wed, 25 Jun 2025 17:37:17 +0200 Subject: [PATCH] Add method to insert manual samples into the database Introduce `create_manual_sample` method to handle the creation of manual samples using `SampleShortInfo`. This includes optional handling of data collection parameters and integrates with the existing API for database insertion. --- daq/pyproject.toml | 4 ++-- daq/src/aaredaq/aaredb.py | 39 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/daq/pyproject.toml b/daq/pyproject.toml index a5cc5da6..a9d9c8a5 100644 --- a/daq/pyproject.toml +++ b/daq/pyproject.toml @@ -13,12 +13,12 @@ dependencies = [ "fastapi==0.115.12", "uvicorn==0.34.2", "ultralytics==8.3.133", - "aaredb==0.1.1a9", + "aaredb==0.1.1a11", "opencv-python-headless==4.11.0.86", "python_multipart==0.0.20", "websocket-client", "sseclient-py>=1.8.0", - "aaredaqlib==0.2.0" + #"aaredaqlib==0.2.0", ] [lint] diff --git a/daq/src/aaredaq/aaredb.py b/daq/src/aaredaq/aaredb.py index 848cb1eb..91f03a9a 100644 --- a/daq/src/aaredaq/aaredb.py +++ b/daq/src/aaredaq/aaredb.py @@ -25,7 +25,7 @@ from aaredaqlib.models import ( PuckLoadedInfo, DewarAddress, SampleShortInfoList, - DAQStatusModel, + DAQStatusModel, SessionStatus, ) from aaredaqlib.beamline import MXBeamline @@ -67,6 +67,43 @@ class AareWrapper: ) print(ret) + def create_manual_sample( + self, + s: SampleShortInfo, + p: SessionStatus, + cellparameters: Optional[str] = None, + spacegroupnumber: Optional[int] = None, + + ) -> Optional[object]: + """ + Insert a new manual sample into the database using a SampleShortInfo object. + + Args: + s (SampleShortInfo): The sample info object to extract data from. + p (SessionStatus): The session status object to extract data from. + + Returns: + API response object or None if there was an error. + """ + from aareDBclient.models import ManualSampleCreate, DataCollectionParameters + data_collection_parameters = DataCollectionParameters( + cellparameters="76.79, 76.79, 37.8, 90.0, 90.0, 90.0", + spacegroupnumber=96 + ) + manual_sample = ManualSampleCreate( + pgroup=p.current_pgroup, + sample_name=s.sample_name, + data_collection_parameters=data_collection_parameters, + ) + + try: + result = self.__sample_api.insert_sample(manual_sample) + print(f"Sample created: {result}") + return result + except Exception as e: + print(f"Error inserting sample: {e}") + return None + def sample_mounted(self, s: Optional[SampleShortInfo]): if s is not None: try: