diff --git a/backend/app/data/data.py b/backend/app/data/data.py index 9ead521..616e261 100644 --- a/backend/app/data/data.py +++ b/backend/app/data/data.py @@ -395,10 +395,11 @@ beamtimes = [ Beamtime( id=1, pgroups="p20001", + shift="morning", beamtime_name="p20001-test", beamline="X06DA", - start_date=datetime.strptime("06.02.2025", "%d.%m.%Y").date(), - end_date=datetime.strptime("07.02.2025", "%d.%m.%Y").date(), + start_date=datetime.strptime("06.05.2025", "%d.%m.%Y").date(), + end_date=datetime.strptime("06.05.2025", "%d.%m.%Y").date(), status="confirmed", comments="this is a test beamtime", proposal_id=1, @@ -407,10 +408,11 @@ beamtimes = [ Beamtime( id=2, pgroups="p20002", + shift="afternoon", beamtime_name="p20001-test", beamline="X06DA", - start_date=datetime.strptime("07.02.2025", "%d.%m.%Y").date(), - end_date=datetime.strptime("08.02.2025", "%d.%m.%Y").date(), + start_date=datetime.strptime("07.05.2025", "%d.%m.%Y").date(), + end_date=datetime.strptime("08.05.2025", "%d.%m.%Y").date(), status="confirmed", comments="this is a test beamtime", proposal_id=2, diff --git a/backend/app/models.py b/backend/app/models.py index 657a5ff..7ebca2e 100644 --- a/backend/app/models.py +++ b/backend/app/models.py @@ -8,6 +8,7 @@ from sqlalchemy import ( DateTime, Boolean, func, + Enum, ) from sqlalchemy.orm import relationship from .database import Base @@ -235,11 +236,15 @@ class PuckEvent(Base): puck = relationship("Puck", back_populates="events") +SHIFT_CHOICES = ("morning", "afternoon", "night") + + class Beamtime(Base): __tablename__ = "beamtimes" id = Column(Integer, primary_key=True, index=True, autoincrement=True) pgroups = Column(String(255), nullable=False) + shift = Column(Enum(*SHIFT_CHOICES, name="shift_enum"), nullable=False, index=True) beamtime_name = Column(String(255), index=True) beamline = Column(String(255), nullable=True) start_date = Column(Date, nullable=True) @@ -282,6 +287,7 @@ class Results(Base): __tablename__ = "results" id = Column(Integer, primary_key=True, index=True, autoincrement=True) + status = Column(String(255), nullable=False) result = Column(JSON, nullable=False) # store the full result object as JSON sample_id = Column(Integer, ForeignKey("samples.id"), nullable=False) run_id = Column(Integer, ForeignKey("experiment_parameters.id"), nullable=False) @@ -310,7 +316,7 @@ class Results(Base): class JobStatus(str, enum.Enum): - TODO = "todo" + TO_DO = "to_do" SUBMITTED = "submitted" DONE = "done" TO_CANCEL = "to_cancel" diff --git a/backend/app/routers/beamtime.py b/backend/app/routers/beamtime.py new file mode 100644 index 0000000..c077ea5 --- /dev/null +++ b/backend/app/routers/beamtime.py @@ -0,0 +1,72 @@ +from fastapi import APIRouter, HTTPException, status, Depends +from sqlalchemy.orm import Session +from sqlalchemy import or_ + +from app.models import Beamtime as BeamtimeModel +from app.schemas import Beamtime as BeamtimeSchema, BeamtimeCreate, loginData +from app.dependencies import get_db +from app.routers.auth import get_current_user + +beamtime_router = APIRouter() + + +@beamtime_router.post("/", response_model=BeamtimeSchema) +async def create_beamtime( + beamtime: BeamtimeCreate, + db: Session = Depends(get_db), + current_user: loginData = Depends(get_current_user), +): + # Validate the pgroup belongs to the current user + if beamtime.pgroups not in current_user.pgroups: + raise HTTPException( + status_code=status.HTTP_400_BAD_REQUEST, + detail="You do not have permission to create a beamtime for this pgroup.", + ) + + # Check for existing beamtime for this pgroup, date, and shift + existing = ( + db.query(BeamtimeModel) + .filter( + BeamtimeModel.pgroups == beamtime.pgroups, + BeamtimeModel.start_date == beamtime.start_date, + BeamtimeModel.shift == beamtime.shift, + ) + .first() + ) + if existing: + raise HTTPException( + status_code=status.HTTP_400_BAD_REQUEST, + detail="A beamtime for this pgroup/shift/date already exists.", + ) + + db_beamtime = BeamtimeModel( + pgroups=beamtime.pgroups, + shift=beamtime.shift, + beamtime_name=beamtime.beamtime_name, + beamline=beamtime.beamline, + start_date=beamtime.start_date, + end_date=beamtime.end_date, + status=beamtime.status, + comments=beamtime.comments, + proposal_id=beamtime.proposal_id, + local_contact_id=beamtime.local_contact_id, + ) + + db.add(db_beamtime) + db.commit() + db.refresh(db_beamtime) + return db_beamtime + + +@beamtime_router.get( + "/my-beamtimes", + response_model=list[BeamtimeSchema], +) +async def get_my_beamtimes( + db: Session = Depends(get_db), + current_user: loginData = Depends(get_current_user), +): + user_pgroups = current_user.pgroups + filters = [BeamtimeModel.pgroups.like(f"%{pgroup}%") for pgroup in user_pgroups] + beamtimes = db.query(BeamtimeModel).filter(or_(*filters)).all() + return beamtimes diff --git a/backend/app/routers/protected_router.py b/backend/app/routers/protected_router.py index 52f04d7..75cb265 100644 --- a/backend/app/routers/protected_router.py +++ b/backend/app/routers/protected_router.py @@ -2,6 +2,7 @@ from fastapi import APIRouter, Depends from app.routers.auth import get_current_user from app.routers.address import address_router +from app.routers.beamtime import beamtime_router from app.routers.contact import contact_router from app.routers.shipment import shipment_router from app.routers.dewar import dewar_router @@ -20,3 +21,6 @@ protected_router.include_router( shipment_router, prefix="/shipments", tags=["shipments"] ) protected_router.include_router(dewar_router, prefix="/dewars", tags=["dewars"]) +protected_router.include_router( + beamtime_router, prefix="/beamtimes", tags=["beamtimes"] +) diff --git a/backend/app/routers/sample.py b/backend/app/routers/sample.py index 4327f7d..f2c31b6 100644 --- a/backend/app/routers/sample.py +++ b/backend/app/routers/sample.py @@ -399,7 +399,7 @@ def update_experiment_run_dataset( sample_id=sample_id, run_id=run_id, experiment_parameters=exp, # adjust this line as appropriate - status=JobStatus.TODO, + status=JobStatus.TO_DO, ) db.add(new_job) db.commit() diff --git a/backend/app/schemas.py b/backend/app/schemas.py index 16ebc8a..cc5ec72 100644 --- a/backend/app/schemas.py +++ b/backend/app/schemas.py @@ -772,6 +772,7 @@ class PuckWithTellPosition(BaseModel): class Beamtime(BaseModel): id: int pgroups: str + shift: str beamtime_name: str beamline: str start_date: date @@ -779,7 +780,6 @@ class Beamtime(BaseModel): status: str comments: Optional[constr(max_length=200)] = None proposal_id: Optional[int] - proposal: Optional[Proposal] local_contact_id: Optional[int] local_contact: Optional[LocalContact] @@ -787,6 +787,19 @@ class Beamtime(BaseModel): from_attributes = True +class BeamtimeCreate(BaseModel): + pgroups: str # this should be changed to pgroup + shift: str + beamtime_name: str + beamline: str + start_date: date + end_date: date + status: str + comments: Optional[constr(max_length=200)] = None + proposal_id: Optional[int] + local_contact_id: Optional[int] + + class ImageCreate(BaseModel): pgroup: str sample_id: int @@ -940,6 +953,7 @@ class SampleResult(BaseModel): class ResultCreate(BaseModel): sample_id: int + status: str run_id: int result: Results @@ -949,6 +963,7 @@ class ResultCreate(BaseModel): class ResultResponse(BaseModel): id: int + status: str sample_id: int run_id: int result: Results diff --git a/docker-compose.yml b/docker-compose.yml index 197a8ce..de0324c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -13,14 +13,17 @@ services: - ./app:/app/app # Map app directory to /app/app - ./config_${ENVIRONMENT}.json:/app/backend/config_${ENVIRONMENT}.json # Explicitly map config_dev.json - ./backend/ssl:/app/backend/ssl # clearly mount SSL files explicitly into Docker + - ./uploads:/app/backend/uploads + - ./uploads:/app/backend/images + working_dir: /app/backend # Set working directory to backend/ command: python main.py # Command to run main.py depends_on: # ⬅️ New addition: wait until postgres is started - postgres healthcheck: test: [ "CMD-SHELL", "curl -k -f https://localhost:${PORT}/openapi.json || exit 1" ] - interval: 1m - timeout: 10s + interval: 30s + timeout: 5s retries: 5 environment: # ⬅️ Provide DB info to your backend ENVIRONMENT: ${ENVIRONMENT} @@ -39,7 +42,7 @@ services: ports: - "5432:5432" volumes: - - pgdata:/var/lib/postgresql/data + - ./db_data:/var/lib/postgresql/data frontend: diff --git a/frontend/src/components/ResultGrid.tsx b/frontend/src/components/ResultGrid.tsx index f159328..3a0ebf9 100644 --- a/frontend/src/components/ResultGrid.tsx +++ b/frontend/src/components/ResultGrid.tsx @@ -5,7 +5,7 @@ import './SampleImage.css'; import './ResultGrid.css'; import { OpenAPI, SamplesService } from '../../openapi'; import ScheduleIcon from '@mui/icons-material/Schedule'; -import AutorenewIcon from '@mui/icons-material/Autorenew'; +import DoDisturbIcon from '@mui/icons-material/DoDisturb'; import TaskAltIcon from '@mui/icons-material/TaskAlt'; import ErrorOutlineIcon from '@mui/icons-material/ErrorOutline'; import InfoOutlinedIcon from '@mui/icons-material/InfoOutlined'; @@ -152,6 +152,8 @@ const ResultGrid: React.FC = ({ activePgroup }) => { ); case 'failed': return ; + case 'cancelled': + return ; case 'no job': default: return ; diff --git a/testfunctions.ipynb b/testfunctions.ipynb index 2a37a84..8595a84 100644 --- a/testfunctions.ipynb +++ b/testfunctions.ipynb @@ -3,21 +3,21 @@ { "metadata": { "ExecuteTime": { - "end_time": "2025-04-29T21:16:17.176129Z", - "start_time": "2025-04-29T21:16:17.104720Z" + "end_time": "2025-05-05T13:24:28.514707Z", + "start_time": "2025-05-05T13:24:27.932416Z" } }, "cell_type": "code", "source": [ "import json\n", - "\n", + "import requests\n", "#from nbclient.client import timestamp\n", "\n", "import backend.aareDBclient as aareDBclient\n", "from aareDBclient.rest import ApiException\n", "from pprint import pprint\n", "\n", - "from app.schemas import characterizationParameters, ResultCreate\n", + "from app.schemas import characterizationParameters, ResultCreate, BeamtimeCreate\n", "\n", "#from app.data.data import sample\n", "\n", @@ -32,6 +32,15 @@ " host = \"https://localhost:8000\"\n", ")\n", "\n", + "# 1. Get the token\n", + "login_resp = requests.post(\n", + " \"https://localhost:8000/auth/token/login\",\n", + " data={\"username\": \"testuser\", \"password\": \"testpass\"},\n", + " verify=False # Only for self-signed/dev certs!\n", + ")\n", + "\n", + "token = login_resp.json()[\"access_token\"]\n", + "\n", "print(configuration.host)\n", "\n", "configuration.verify_ssl = False # Disable SSL verification\n", @@ -39,6 +48,16 @@ ], "id": "3b7c27697a4d5c83", "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): localhost:8000\n", + "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/urllib3/connectionpool.py:1103: InsecureRequestWarning: Unverified HTTPS request is being made to host 'localhost'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#tls-warnings\n", + " warnings.warn(\n", + "DEBUG:urllib3.connectionpool:https://localhost:8000 \"POST /auth/token/login HTTP/1.1\" 200 233\n" + ] + }, { "name": "stdout", "output_type": "stream", @@ -48,7 +67,7 @@ ] } ], - "execution_count": 3 + "execution_count": 1 }, { "metadata": {}, @@ -427,21 +446,21 @@ { "metadata": { "ExecuteTime": { - "end_time": "2025-04-29T21:15:51.203912Z", - "start_time": "2025-04-29T21:15:51.200888Z" + "end_time": "2025-05-05T13:31:12.902282Z", + "start_time": "2025-05-05T13:31:12.900432Z" } }, "cell_type": "code", - "source": "sample_id = 204", + "source": "sample_id = 277", "id": "54d4d46ca558e7b9", "outputs": [], - "execution_count": 1 + "execution_count": 7 }, { "metadata": { "ExecuteTime": { - "end_time": "2025-04-29T20:57:41.460728Z", - "start_time": "2025-04-29T20:57:41.399620Z" + "end_time": "2025-05-05T13:31:16.752616Z", + "start_time": "2025-05-05T13:31:16.720296Z" } }, "cell_type": "code", @@ -493,7 +512,7 @@ "DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): localhost:8000\n", "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/urllib3/connectionpool.py:1103: InsecureRequestWarning: Unverified HTTPS request is being made to host 'localhost'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#tls-warnings\n", " warnings.warn(\n", - "DEBUG:urllib3.connectionpool:https://localhost:8000 \"POST /samples/samples/204/events HTTP/1.1\" 200 413\n" + "DEBUG:urllib3.connectionpool:https://localhost:8000 \"POST /samples/samples/277/events HTTP/1.1\" 200 413\n" ] }, { @@ -503,9 +522,9 @@ "Payload being sent to API:\n", "{\"event_type\":\"Collecting\"}\n", "API response:\n", - "('id', 204)\n", - "('sample_name', 'Sample204')\n", - "('position', 16)\n", + "('id', 277)\n", + "('sample_name', 'Sample277')\n", + "('position', 15)\n", "('puck_id', 30)\n", "('crystalname', None)\n", "('proteinname', None)\n", @@ -513,13 +532,13 @@ "('priority', None)\n", "('comments', None)\n", "('data_collection_parameters', None)\n", - "('events', [SampleEventResponse(event_type='Mounting', id=396, sample_id=204, timestamp=datetime.datetime(2025, 4, 28, 12, 56)), SampleEventResponse(event_type='Collecting', id=397, sample_id=204, timestamp=datetime.datetime(2025, 4, 29, 20, 57, 41, 453326))])\n", + "('events', [SampleEventResponse(event_type='Mounting', id=533, sample_id=277, timestamp=datetime.datetime(2025, 5, 4, 14, 9)), SampleEventResponse(event_type='Collecting', id=534, sample_id=277, timestamp=datetime.datetime(2025, 5, 5, 13, 31, 16, 741949))])\n", "('mount_count', 0)\n", "('unmount_count', 0)\n" ] } ], - "execution_count": 15 + "execution_count": 8 }, { "metadata": { @@ -563,8 +582,8 @@ { "metadata": { "ExecuteTime": { - "end_time": "2025-04-29T20:57:47.969390Z", - "start_time": "2025-04-29T20:57:47.936166Z" + "end_time": "2025-05-05T13:31:21.833174Z", + "start_time": "2025-05-05T13:31:21.791711Z" } }, "cell_type": "code", @@ -635,7 +654,7 @@ "DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): 127.0.0.1:8000\n", "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/urllib3/connectionpool.py:1103: InsecureRequestWarning: Unverified HTTPS request is being made to host '127.0.0.1'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#tls-warnings\n", " warnings.warn(\n", - "DEBUG:urllib3.connectionpool:https://127.0.0.1:8000 \"POST /samples/204/upload-images HTTP/1.1\" 200 205\n" + "DEBUG:urllib3.connectionpool:https://127.0.0.1:8000 \"POST /samples/277/upload-images HTTP/1.1\" 200 205\n" ] }, { @@ -645,11 +664,11 @@ "Uploading after_dc.jpeg.jpg...\n", "API Response for after_dc.jpeg.jpg:\n", "200\n", - "{'pgroup': 'p20003', 'sample_id': 204, 'sample_event_id': 397, 'filepath': 'images/p20003/2025-04-29/Dewar Five/PKK007/16/Collecting_2025-04-29_20-57-41/after_dc.jpeg.jpg', 'status': 'active', 'comment': None, 'id': 1}\n" + "{'pgroup': 'p20003', 'sample_id': 277, 'sample_event_id': 534, 'filepath': 'images/p20003/2025-05-05/Dewar Five/PKK007/15/Collecting_2025-05-05_13-31-16/after_dc.jpeg.jpg', 'status': 'active', 'comment': None, 'id': 1}\n" ] } ], - "execution_count": 16 + "execution_count": 9 }, { "metadata": {}, @@ -662,8 +681,8 @@ { "metadata": { "ExecuteTime": { - "end_time": "2025-04-30T14:32:12.061767Z", - "start_time": "2025-04-30T14:32:12.043500Z" + "end_time": "2025-05-05T13:34:32.164108Z", + "start_time": "2025-05-05T13:34:32.130230Z" } }, "cell_type": "code", @@ -780,7 +799,7 @@ "DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): localhost:8000\n", "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/urllib3/connectionpool.py:1103: InsecureRequestWarning: Unverified HTTPS request is being made to host 'localhost'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#tls-warnings\n", " warnings.warn(\n", - "DEBUG:urllib3.connectionpool:https://localhost:8000 \"POST /samples/samples/204/experiment_parameters HTTP/1.1\" 200 905\n" + "DEBUG:urllib3.connectionpool:https://localhost:8000 \"POST /samples/samples/277/experiment_parameters HTTP/1.1\" 200 904\n" ] }, { @@ -788,17 +807,17 @@ "output_type": "stream", "text": [ "API Response:\n", - "run_number=8 type='standard' beamline_parameters=BeamlineParameters(synchrotron='Swiss Light Source', beamline='PXIII', detector=Detector(manufacturer='DECTRIS', model='PILATUS4 2M', type='photon-counting', serial_number='16684dscsd668468', detector_distance_mm=232.0, beam_center_x_px=768.0, beam_center_y_px=857.0, pixel_size_x_um=150.0, pixel_size_y_um=150.0), wavelength=1.033, ring_current_a=0.4, ring_mode='Machine Development', undulator=None, undulatorgap_mm=None, monochromator='Si111', transmission=10.0, focusing_optic='Kirkpatrick-Baez', beamline_flux_at_sample_ph_s=0.0, beam_size_width=30.0, beam_size_height=30.0, characterization=None, rotation=RotationParameters(omega_start_deg=0.0, omega_step=0.2, chi=0.0, phi=10.0, number_of_images=1800, exposure_time_s=0.01), grid_scan=None, jet=None, cryojet_temperature_k=None, humidifier_temperature_k=None, humidifier_humidity=None) dataset=None sample_id=204 id=10\n" + "run_number=2 type='standard' beamline_parameters=BeamlineParameters(synchrotron='Swiss Light Source', beamline='PXIII', detector=Detector(manufacturer='DECTRIS', model='PILATUS4 2M', type='photon-counting', serial_number='16684dscsd668468', detector_distance_mm=232.0, beam_center_x_px=768.0, beam_center_y_px=857.0, pixel_size_x_um=150.0, pixel_size_y_um=150.0), wavelength=1.033, ring_current_a=0.4, ring_mode='Machine Development', undulator=None, undulatorgap_mm=None, monochromator='Si111', transmission=10.0, focusing_optic='Kirkpatrick-Baez', beamline_flux_at_sample_ph_s=0.0, beam_size_width=30.0, beam_size_height=30.0, characterization=None, rotation=RotationParameters(omega_start_deg=0.0, omega_step=0.2, chi=0.0, phi=10.0, number_of_images=1800, exposure_time_s=0.01), grid_scan=None, jet=None, cryojet_temperature_k=None, humidifier_temperature_k=None, humidifier_humidity=None) dataset=None sample_id=277 id=2\n" ] } ], - "execution_count": 26 + "execution_count": 13 }, { "metadata": { "ExecuteTime": { - "end_time": "2025-04-30T14:32:24.370041Z", - "start_time": "2025-04-30T14:32:24.347435Z" + "end_time": "2025-05-05T13:34:49.891432Z", + "start_time": "2025-05-05T13:34:49.872697Z" } }, "cell_type": "code", @@ -806,7 +825,7 @@ "from datetime import datetime\n", "\n", "sample_id = sample_id\n", - "run_id = 10\n", + "run_id = 2\n", "\n", "def test_mark_run_written(sample_id, run_id, configuration):\n", " # Prepare your dataset dict as required by your API (.dict() results if using Pydantic model)\n", @@ -840,7 +859,7 @@ "DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): localhost:8000\n", "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/urllib3/connectionpool.py:1103: InsecureRequestWarning: Unverified HTTPS request is being made to host 'localhost'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#tls-warnings\n", " warnings.warn(\n", - "DEBUG:urllib3.connectionpool:https://localhost:8000 \"PATCH /samples/update-dataset/204/10 HTTP/1.1\" 200 1086\n" + "DEBUG:urllib3.connectionpool:https://localhost:8000 \"PATCH /samples/update-dataset/277/2 HTTP/1.1\" 200 1085\n" ] }, { @@ -848,17 +867,17 @@ "output_type": "stream", "text": [ "Dataset updated successfully:\n", - "run_number=8 type='standard' beamline_parameters=BeamlineParameters(synchrotron='Swiss Light Source', beamline='PXIII', detector=Detector(manufacturer='DECTRIS', model='PILATUS4 2M', type='photon-counting', serial_number='16684dscsd668468', detector_distance_mm=232.0, beam_center_x_px=768.0, beam_center_y_px=857.0, pixel_size_x_um=150.0, pixel_size_y_um=150.0), wavelength=1.033, ring_current_a=0.4, ring_mode='Machine Development', undulator=None, undulatorgap_mm=None, monochromator='Si111', transmission=10.0, focusing_optic='Kirkpatrick-Baez', beamline_flux_at_sample_ph_s=0.0, beam_size_width=30.0, beam_size_height=30.0, characterization=None, rotation=RotationParameters(omega_start_deg=0.0, omega_step=0.2, chi=0.0, phi=10.0, number_of_images=1800, exposure_time_s=0.01), grid_scan=None, jet=None, cryojet_temperature_k=None, humidifier_temperature_k=None, humidifier_humidity=None) dataset=Datasets(filepath='/das/work/p11/p11206/raw_data/vincent/20250415_6D_SLS2_1st_data/20250415_fullbeam_dtz220_Lyso102_again_360deg', status='written', written_at=datetime.datetime(2025, 4, 30, 16, 32, 24, 348891)) sample_id=204 id=10\n" + "run_number=2 type='standard' beamline_parameters=BeamlineParameters(synchrotron='Swiss Light Source', beamline='PXIII', detector=Detector(manufacturer='DECTRIS', model='PILATUS4 2M', type='photon-counting', serial_number='16684dscsd668468', detector_distance_mm=232.0, beam_center_x_px=768.0, beam_center_y_px=857.0, pixel_size_x_um=150.0, pixel_size_y_um=150.0), wavelength=1.033, ring_current_a=0.4, ring_mode='Machine Development', undulator=None, undulatorgap_mm=None, monochromator='Si111', transmission=10.0, focusing_optic='Kirkpatrick-Baez', beamline_flux_at_sample_ph_s=0.0, beam_size_width=30.0, beam_size_height=30.0, characterization=None, rotation=RotationParameters(omega_start_deg=0.0, omega_step=0.2, chi=0.0, phi=10.0, number_of_images=1800, exposure_time_s=0.01), grid_scan=None, jet=None, cryojet_temperature_k=None, humidifier_temperature_k=None, humidifier_humidity=None) dataset=Datasets(filepath='/das/work/p11/p11206/raw_data/vincent/20250415_6D_SLS2_1st_data/20250415_fullbeam_dtz220_Lyso102_again_360deg', status='written', written_at=datetime.datetime(2025, 5, 5, 15, 34, 49, 874526)) sample_id=277 id=2\n" ] } ], - "execution_count": 27 + "execution_count": 15 }, { "metadata": { "ExecuteTime": { - "end_time": "2025-04-29T08:37:38.265277Z", - "start_time": "2025-04-29T08:37:38.237143Z" + "end_time": "2025-05-02T13:49:50.890862Z", + "start_time": "2025-05-02T13:49:50.841161Z" } }, "cell_type": "code", @@ -874,7 +893,8 @@ "\n", "# Your actual sample and experiment IDs\n", "sample_id = sample_id # Replace with valid IDs\n", - "run_id = 3 # Replace with valid run_id\n", + "status = \"successful\"\n", + "run_id = 1 # Replace with valid run_id\n", "\n", "# Function to generate list of CurvePoint (resolution, value pairs)\n", "def logarithmic_decay_curve(length, min_res=4.0, max_res=1.0, max_value=1.0, min_value=0.0, noise=0.005, decimals=3):\n", @@ -920,6 +940,7 @@ "# correct serialization, passing exact required dict structure\n", "payload_dict = {\n", " \"sample_id\": sample_id,\n", + " \"status\": status,\n", " \"run_id\": run_id,\n", " \"result\": results_data.model_dump(),\n", "}\n", @@ -947,7 +968,7 @@ "DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): localhost:8000\n", "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/urllib3/connectionpool.py:1103: InsecureRequestWarning: Unverified HTTPS request is being made to host 'localhost'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#tls-warnings\n", " warnings.warn(\n", - "DEBUG:urllib3.connectionpool:https://localhost:8000 \"POST /samples/processing-results HTTP/1.1\" 200 7199\n" + "DEBUG:urllib3.connectionpool:https://localhost:8000 \"POST /samples/processing-results HTTP/1.1\" 200 7192\n" ] }, { @@ -955,17 +976,17 @@ "output_type": "stream", "text": [ "API call successful:\n", - "ResultResponse(id=1, sample_id=243, run_id=3, result=Results(pipeline='autoproc', resolution=1.47, unit_cell='93.58, 89.37, 32.51, 60.74, 112.89, 91.46', spacegroup='C2', rmerge=0.097, rmeas=0.093, isig=6.21, cc=[CurvePoint(resolution=3.983, value=1.0), CurvePoint(resolution=3.965, value=1.0), CurvePoint(resolution=3.939, value=0.995), CurvePoint(resolution=3.907, value=0.998), CurvePoint(resolution=3.813, value=0.996), CurvePoint(resolution=3.756, value=0.997), CurvePoint(resolution=3.737, value=1.0), CurvePoint(resolution=3.708, value=1.0), CurvePoint(resolution=3.706, value=1.0), CurvePoint(resolution=3.701, value=0.996), CurvePoint(resolution=3.674, value=0.999), CurvePoint(resolution=3.65, value=0.997), CurvePoint(resolution=3.6, value=0.998), CurvePoint(resolution=3.563, value=0.997), CurvePoint(resolution=3.519, value=0.997), CurvePoint(resolution=3.386, value=0.999), CurvePoint(resolution=3.377, value=0.997), CurvePoint(resolution=3.375, value=1.0), CurvePoint(resolution=3.253, value=0.995), CurvePoint(resolution=3.221, value=0.996), CurvePoint(resolution=3.194, value=0.999), CurvePoint(resolution=3.182, value=0.999), CurvePoint(resolution=3.149, value=0.998), CurvePoint(resolution=3.128, value=0.998), CurvePoint(resolution=3.115, value=0.998), CurvePoint(resolution=3.101, value=0.999), CurvePoint(resolution=3.072, value=0.997), CurvePoint(resolution=3.018, value=0.999), CurvePoint(resolution=3.013, value=1.0), CurvePoint(resolution=2.96, value=1.0), CurvePoint(resolution=2.935, value=1.0), CurvePoint(resolution=2.882, value=1.0), CurvePoint(resolution=2.866, value=1.0), CurvePoint(resolution=2.855, value=1.0), CurvePoint(resolution=2.695, value=1.0), CurvePoint(resolution=2.689, value=1.0), CurvePoint(resolution=2.628, value=1.0), CurvePoint(resolution=2.62, value=0.997), CurvePoint(resolution=2.595, value=0.997), CurvePoint(resolution=2.563, value=0.996), CurvePoint(resolution=2.562, value=1.0), CurvePoint(resolution=2.559, value=1.0), CurvePoint(resolution=2.542, value=1.0), CurvePoint(resolution=2.518, value=0.998), CurvePoint(resolution=2.477, value=1.0), CurvePoint(resolution=2.395, value=1.0), CurvePoint(resolution=2.388, value=0.997), CurvePoint(resolution=2.388, value=0.996), CurvePoint(resolution=2.37, value=0.999), CurvePoint(resolution=2.361, value=0.995), CurvePoint(resolution=2.359, value=0.995), CurvePoint(resolution=2.356, value=0.998), CurvePoint(resolution=2.33, value=1.0), CurvePoint(resolution=2.25, value=0.996), CurvePoint(resolution=2.246, value=0.998), CurvePoint(resolution=2.242, value=1.0), CurvePoint(resolution=2.2, value=0.995), CurvePoint(resolution=2.18, value=1.0), CurvePoint(resolution=2.165, value=1.0), CurvePoint(resolution=2.154, value=1.0), CurvePoint(resolution=2.146, value=1.0), CurvePoint(resolution=2.036, value=1.0), CurvePoint(resolution=1.995, value=1.0), CurvePoint(resolution=1.958, value=0.996), CurvePoint(resolution=1.915, value=1.0), CurvePoint(resolution=1.912, value=0.996), CurvePoint(resolution=1.866, value=0.996), CurvePoint(resolution=1.779, value=0.99), CurvePoint(resolution=1.751, value=0.994), CurvePoint(resolution=1.75, value=0.989), CurvePoint(resolution=1.739, value=0.994), CurvePoint(resolution=1.69, value=0.993), CurvePoint(resolution=1.665, value=0.985), CurvePoint(resolution=1.662, value=0.987), CurvePoint(resolution=1.613, value=0.979), CurvePoint(resolution=1.609, value=0.981), CurvePoint(resolution=1.545, value=0.97), CurvePoint(resolution=1.49, value=0.963), CurvePoint(resolution=1.476, value=0.956), CurvePoint(resolution=1.468, value=0.956), CurvePoint(resolution=1.447, value=0.947), CurvePoint(resolution=1.422, value=0.944), CurvePoint(resolution=1.413, value=0.94), CurvePoint(resolution=1.403, value=0.927), CurvePoint(resolution=1.403, value=0.934), CurvePoint(resolution=1.368, value=0.915), CurvePoint(resolution=1.35, value=0.906), CurvePoint(resolution=1.229, value=0.784), CurvePoint(resolution=1.212, value=0.757), CurvePoint(resolution=1.206, value=0.749), CurvePoint(resolution=1.192, value=0.719), CurvePoint(resolution=1.144, value=0.613), CurvePoint(resolution=1.144, value=0.616), CurvePoint(resolution=1.138, value=0.605), CurvePoint(resolution=1.124, value=0.56), CurvePoint(resolution=1.104, value=0.504), CurvePoint(resolution=1.082, value=0.424), CurvePoint(resolution=1.079, value=0.407), CurvePoint(resolution=1.026, value=0.162), CurvePoint(resolution=1.0, value=0.005)], cchalf=[CurvePoint(resolution=3.988, value=0.997), CurvePoint(resolution=3.959, value=1.0), CurvePoint(resolution=3.886, value=1.0), CurvePoint(resolution=3.828, value=1.0), CurvePoint(resolution=3.814, value=0.996), CurvePoint(resolution=3.756, value=0.997), CurvePoint(resolution=3.721, value=1.0), CurvePoint(resolution=3.696, value=0.996), CurvePoint(resolution=3.67, value=0.996), CurvePoint(resolution=3.631, value=0.997), CurvePoint(resolution=3.607, value=0.998), CurvePoint(resolution=3.556, value=1.0), CurvePoint(resolution=3.549, value=0.995), CurvePoint(resolution=3.539, value=1.0), CurvePoint(resolution=3.538, value=1.0), CurvePoint(resolution=3.517, value=1.0), CurvePoint(resolution=3.514, value=1.0), CurvePoint(resolution=3.463, value=1.0), CurvePoint(resolution=3.434, value=0.999), CurvePoint(resolution=3.433, value=1.0), CurvePoint(resolution=3.419, value=1.0), CurvePoint(resolution=3.409, value=0.999), CurvePoint(resolution=3.389, value=0.997), CurvePoint(resolution=3.384, value=0.995), CurvePoint(resolution=3.355, value=0.996), CurvePoint(resolution=3.273, value=0.998), CurvePoint(resolution=3.239, value=1.0), CurvePoint(resolution=3.235, value=1.0), CurvePoint(resolution=3.23, value=0.996), CurvePoint(resolution=3.229, value=0.998), CurvePoint(resolution=3.222, value=1.0), CurvePoint(resolution=3.208, value=1.0), CurvePoint(resolution=3.133, value=0.998), CurvePoint(resolution=3.107, value=1.0), CurvePoint(resolution=3.106, value=0.996), CurvePoint(resolution=3.072, value=1.0), CurvePoint(resolution=3.005, value=0.997), CurvePoint(resolution=2.974, value=0.999), CurvePoint(resolution=2.947, value=1.0), CurvePoint(resolution=2.901, value=0.996), CurvePoint(resolution=2.874, value=0.998), CurvePoint(resolution=2.849, value=0.997), CurvePoint(resolution=2.842, value=0.996), CurvePoint(resolution=2.812, value=1.0), CurvePoint(resolution=2.79, value=1.0), CurvePoint(resolution=2.741, value=0.995), CurvePoint(resolution=2.719, value=1.0), CurvePoint(resolution=2.704, value=1.0), CurvePoint(resolution=2.695, value=0.997), CurvePoint(resolution=2.625, value=1.0), CurvePoint(resolution=2.624, value=1.0), CurvePoint(resolution=2.519, value=1.0), CurvePoint(resolution=2.518, value=1.0), CurvePoint(resolution=2.493, value=0.996), CurvePoint(resolution=2.457, value=0.997), CurvePoint(resolution=2.436, value=0.997), CurvePoint(resolution=2.427, value=1.0), CurvePoint(resolution=2.419, value=0.995), CurvePoint(resolution=2.348, value=0.996), CurvePoint(resolution=2.293, value=1.0), CurvePoint(resolution=2.29, value=0.999), CurvePoint(resolution=2.226, value=1.0), CurvePoint(resolution=2.137, value=0.995), CurvePoint(resolution=2.114, value=0.998), CurvePoint(resolution=2.064, value=1.0), CurvePoint(resolution=2.052, value=1.0), CurvePoint(resolution=2.05, value=1.0), CurvePoint(resolution=2.04, value=1.0), CurvePoint(resolution=2.031, value=1.0), CurvePoint(resolution=1.995, value=0.996), CurvePoint(resolution=1.986, value=1.0), CurvePoint(resolution=1.97, value=0.998), CurvePoint(resolution=1.966, value=1.0), CurvePoint(resolution=1.929, value=0.996), CurvePoint(resolution=1.854, value=0.995), CurvePoint(resolution=1.845, value=0.996), CurvePoint(resolution=1.823, value=0.995), CurvePoint(resolution=1.744, value=0.995), CurvePoint(resolution=1.732, value=0.989), CurvePoint(resolution=1.722, value=0.989), CurvePoint(resolution=1.711, value=0.994), CurvePoint(resolution=1.707, value=0.992), CurvePoint(resolution=1.555, value=0.98), CurvePoint(resolution=1.505, value=0.963), CurvePoint(resolution=1.459, value=0.958), CurvePoint(resolution=1.426, value=0.938), CurvePoint(resolution=1.419, value=0.943), CurvePoint(resolution=1.406, value=0.935), CurvePoint(resolution=1.396, value=0.929), CurvePoint(resolution=1.378, value=0.918), CurvePoint(resolution=1.308, value=0.874), CurvePoint(resolution=1.252, value=0.815), CurvePoint(resolution=1.212, value=0.756), CurvePoint(resolution=1.192, value=0.719), CurvePoint(resolution=1.189, value=0.719), CurvePoint(resolution=1.144, value=0.616), CurvePoint(resolution=1.143, value=0.617), CurvePoint(resolution=1.111, value=0.521), CurvePoint(resolution=1.095, value=0.471), CurvePoint(resolution=1.023, value=0.139)], completeness=94.67, multiplicity=8.01, nobs=263890, total_refl=142999, unique_refl=47873, comments='Random auto-generated test entry'))\n" + "ResultResponse(id=2, sample_id=204, run_id=6, result=Results(pipeline='autoproc', resolution=3.73, unit_cell='86.44, 99.53, 23.45, 111.04, 110.10, 115.31', spacegroup='P21212', rmerge=0.029, rmeas=0.052, isig=16.74, cc=[CurvePoint(resolution=3.991, value=1.0), CurvePoint(resolution=3.93, value=1.0), CurvePoint(resolution=3.926, value=0.995), CurvePoint(resolution=3.894, value=0.997), CurvePoint(resolution=3.774, value=1.0), CurvePoint(resolution=3.658, value=0.996), CurvePoint(resolution=3.656, value=1.0), CurvePoint(resolution=3.612, value=1.0), CurvePoint(resolution=3.612, value=1.0), CurvePoint(resolution=3.594, value=1.0), CurvePoint(resolution=3.59, value=1.0), CurvePoint(resolution=3.571, value=1.0), CurvePoint(resolution=3.57, value=0.995), CurvePoint(resolution=3.562, value=0.999), CurvePoint(resolution=3.495, value=0.999), CurvePoint(resolution=3.436, value=0.999), CurvePoint(resolution=3.389, value=1.0), CurvePoint(resolution=3.365, value=0.997), CurvePoint(resolution=3.291, value=0.999), CurvePoint(resolution=3.224, value=0.999), CurvePoint(resolution=3.215, value=0.999), CurvePoint(resolution=3.201, value=1.0), CurvePoint(resolution=3.188, value=0.999), CurvePoint(resolution=3.161, value=1.0), CurvePoint(resolution=3.121, value=0.996), CurvePoint(resolution=3.111, value=0.997), CurvePoint(resolution=3.016, value=1.0), CurvePoint(resolution=2.973, value=0.996), CurvePoint(resolution=2.969, value=0.998), CurvePoint(resolution=2.925, value=0.998), CurvePoint(resolution=2.925, value=0.998), CurvePoint(resolution=2.908, value=1.0), CurvePoint(resolution=2.896, value=0.998), CurvePoint(resolution=2.854, value=1.0), CurvePoint(resolution=2.843, value=1.0), CurvePoint(resolution=2.841, value=0.997), CurvePoint(resolution=2.84, value=0.999), CurvePoint(resolution=2.831, value=1.0), CurvePoint(resolution=2.777, value=1.0), CurvePoint(resolution=2.759, value=0.999), CurvePoint(resolution=2.757, value=1.0), CurvePoint(resolution=2.74, value=1.0), CurvePoint(resolution=2.723, value=1.0), CurvePoint(resolution=2.698, value=1.0), CurvePoint(resolution=2.689, value=0.998), CurvePoint(resolution=2.614, value=1.0), CurvePoint(resolution=2.569, value=0.997), CurvePoint(resolution=2.561, value=1.0), CurvePoint(resolution=2.547, value=1.0), CurvePoint(resolution=2.518, value=1.0), CurvePoint(resolution=2.506, value=0.996), CurvePoint(resolution=2.455, value=1.0), CurvePoint(resolution=2.446, value=0.996), CurvePoint(resolution=2.374, value=1.0), CurvePoint(resolution=2.365, value=0.999), CurvePoint(resolution=2.298, value=0.996), CurvePoint(resolution=2.287, value=1.0), CurvePoint(resolution=2.278, value=0.996), CurvePoint(resolution=2.278, value=1.0), CurvePoint(resolution=2.272, value=0.995), CurvePoint(resolution=2.211, value=1.0), CurvePoint(resolution=2.195, value=1.0), CurvePoint(resolution=2.165, value=1.0), CurvePoint(resolution=2.14, value=1.0), CurvePoint(resolution=2.108, value=1.0), CurvePoint(resolution=2.067, value=0.999), CurvePoint(resolution=2.021, value=0.996), CurvePoint(resolution=1.992, value=0.995), CurvePoint(resolution=1.947, value=0.995), CurvePoint(resolution=1.937, value=1.0), CurvePoint(resolution=1.904, value=0.995), CurvePoint(resolution=1.865, value=0.992), CurvePoint(resolution=1.8, value=0.992), CurvePoint(resolution=1.752, value=0.995), CurvePoint(resolution=1.751, value=0.989), CurvePoint(resolution=1.739, value=0.995), CurvePoint(resolution=1.716, value=0.993), CurvePoint(resolution=1.7, value=0.992), CurvePoint(resolution=1.659, value=0.988), CurvePoint(resolution=1.594, value=0.982), CurvePoint(resolution=1.586, value=0.984), CurvePoint(resolution=1.555, value=0.973), CurvePoint(resolution=1.555, value=0.979), CurvePoint(resolution=1.463, value=0.953), CurvePoint(resolution=1.442, value=0.943), CurvePoint(resolution=1.412, value=0.94), CurvePoint(resolution=1.407, value=0.935), CurvePoint(resolution=1.394, value=0.924), CurvePoint(resolution=1.377, value=0.923), CurvePoint(resolution=1.374, value=0.922), CurvePoint(resolution=1.358, value=0.905), CurvePoint(resolution=1.34, value=0.894), CurvePoint(resolution=1.319, value=0.879), CurvePoint(resolution=1.306, value=0.875), CurvePoint(resolution=1.257, value=0.817), CurvePoint(resolution=1.225, value=0.773), CurvePoint(resolution=1.141, value=0.608), CurvePoint(resolution=1.139, value=0.606), CurvePoint(resolution=1.059, value=0.322), CurvePoint(resolution=1.013, value=0.082)], cchalf=[CurvePoint(resolution=3.98, value=0.995), CurvePoint(resolution=3.98, value=1.0), CurvePoint(resolution=3.947, value=1.0), CurvePoint(resolution=3.837, value=1.0), CurvePoint(resolution=3.769, value=0.999), CurvePoint(resolution=3.757, value=1.0), CurvePoint(resolution=3.731, value=0.999), CurvePoint(resolution=3.723, value=1.0), CurvePoint(resolution=3.694, value=1.0), CurvePoint(resolution=3.685, value=0.995), CurvePoint(resolution=3.658, value=1.0), CurvePoint(resolution=3.643, value=1.0), CurvePoint(resolution=3.615, value=1.0), CurvePoint(resolution=3.522, value=0.999), CurvePoint(resolution=3.502, value=1.0), CurvePoint(resolution=3.491, value=0.998), CurvePoint(resolution=3.486, value=1.0), CurvePoint(resolution=3.474, value=1.0), CurvePoint(resolution=3.468, value=0.997), CurvePoint(resolution=3.464, value=1.0), CurvePoint(resolution=3.463, value=1.0), CurvePoint(resolution=3.43, value=1.0), CurvePoint(resolution=3.378, value=0.999), CurvePoint(resolution=3.297, value=0.998), CurvePoint(resolution=3.25, value=1.0), CurvePoint(resolution=3.244, value=1.0), CurvePoint(resolution=3.191, value=0.998), CurvePoint(resolution=3.188, value=0.998), CurvePoint(resolution=3.17, value=0.996), CurvePoint(resolution=3.158, value=0.995), CurvePoint(resolution=3.158, value=1.0), CurvePoint(resolution=3.145, value=0.996), CurvePoint(resolution=3.142, value=1.0), CurvePoint(resolution=3.122, value=0.996), CurvePoint(resolution=3.093, value=1.0), CurvePoint(resolution=3.089, value=0.995), CurvePoint(resolution=3.013, value=1.0), CurvePoint(resolution=2.975, value=1.0), CurvePoint(resolution=2.955, value=1.0), CurvePoint(resolution=2.813, value=0.999), CurvePoint(resolution=2.74, value=1.0), CurvePoint(resolution=2.723, value=0.997), CurvePoint(resolution=2.695, value=0.997), CurvePoint(resolution=2.692, value=0.995), CurvePoint(resolution=2.673, value=1.0), CurvePoint(resolution=2.645, value=0.997), CurvePoint(resolution=2.608, value=1.0), CurvePoint(resolution=2.582, value=1.0), CurvePoint(resolution=2.556, value=1.0), CurvePoint(resolution=2.457, value=1.0), CurvePoint(resolution=2.422, value=1.0), CurvePoint(resolution=2.408, value=0.998), CurvePoint(resolution=2.388, value=0.996), CurvePoint(resolution=2.377, value=0.996), CurvePoint(resolution=2.347, value=1.0), CurvePoint(resolution=2.325, value=0.998), CurvePoint(resolution=2.299, value=0.998), CurvePoint(resolution=2.275, value=0.998), CurvePoint(resolution=2.259, value=1.0), CurvePoint(resolution=2.242, value=0.995), CurvePoint(resolution=2.209, value=1.0), CurvePoint(resolution=2.186, value=1.0), CurvePoint(resolution=2.175, value=0.997), CurvePoint(resolution=2.165, value=0.999), CurvePoint(resolution=2.113, value=1.0), CurvePoint(resolution=2.041, value=1.0), CurvePoint(resolution=1.997, value=0.994), CurvePoint(resolution=1.993, value=1.0), CurvePoint(resolution=1.979, value=0.997), CurvePoint(resolution=1.972, value=0.995), CurvePoint(resolution=1.93, value=1.0), CurvePoint(resolution=1.884, value=1.0), CurvePoint(resolution=1.877, value=0.996), CurvePoint(resolution=1.869, value=0.998), CurvePoint(resolution=1.863, value=0.996), CurvePoint(resolution=1.861, value=1.0), CurvePoint(resolution=1.851, value=0.995), CurvePoint(resolution=1.825, value=0.997), CurvePoint(resolution=1.791, value=0.997), CurvePoint(resolution=1.757, value=0.995), CurvePoint(resolution=1.734, value=0.997), CurvePoint(resolution=1.675, value=0.987), CurvePoint(resolution=1.635, value=0.987), CurvePoint(resolution=1.606, value=0.979), CurvePoint(resolution=1.556, value=0.974), CurvePoint(resolution=1.53, value=0.972), CurvePoint(resolution=1.466, value=0.958), CurvePoint(resolution=1.443, value=0.945), CurvePoint(resolution=1.435, value=0.947), CurvePoint(resolution=1.409, value=0.936), CurvePoint(resolution=1.344, value=0.897), CurvePoint(resolution=1.305, value=0.873), CurvePoint(resolution=1.275, value=0.839), CurvePoint(resolution=1.194, value=0.729), CurvePoint(resolution=1.163, value=0.664), CurvePoint(resolution=1.149, value=0.625), CurvePoint(resolution=1.142, value=0.609), CurvePoint(resolution=1.116, value=0.54), CurvePoint(resolution=1.037, value=0.218), CurvePoint(resolution=1.027, value=0.164)], completeness=85.1, multiplicity=3.28, nobs=53636, total_refl=140858, unique_refl=24272, comments='Random auto-generated test entry'))\n" ] } ], - "execution_count": 8 + "execution_count": 31 }, { "metadata": { "ExecuteTime": { - "end_time": "2025-03-17T21:11:17.101900Z", - "start_time": "2025-03-17T21:11:17.053250Z" + "end_time": "2025-05-05T13:24:47.091043Z", + "start_time": "2025-05-05T13:24:47.082140Z" } }, "cell_type": "code", @@ -1006,182 +1027,81 @@ "id": "6079a4f10102e906", "outputs": [ { - "name": "stderr", - "output_type": "stream", - "text": [ - "DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): 127.0.0.1:8000\n", - "/Users/gotthardg/PycharmProjects/aaredb/.venv/lib/python3.12/site-packages/urllib3/connectionpool.py:1097: InsecureRequestWarning: Unverified HTTPS request is being made to host '127.0.0.1'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#tls-warnings\n", - " warnings.warn(\n", - "DEBUG:urllib3.connectionpool:https://127.0.0.1:8000 \"GET /samples/results?active_pgroup=p20003 HTTP/1.1\" 200 7927\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "[SampleResult(sample_id=215, sample_name='Sample215', puck_name='PKK004', dewar_name='Dewar Five', images=[], experiment_runs=[]),\n", - " SampleResult(sample_id=216, sample_name='Sample216', puck_name='PKK004', dewar_name='Dewar Five', images=[], experiment_runs=[]),\n", - " SampleResult(sample_id=217, sample_name='Sample217', puck_name='PKK005', dewar_name='Dewar Five', images=[], experiment_runs=[]),\n", - " SampleResult(sample_id=218, sample_name='Sample218', puck_name='PKK005', dewar_name='Dewar Five', images=[], experiment_runs=[]),\n", - " SampleResult(sample_id=219, sample_name='Sample219', puck_name='PKK005', dewar_name='Dewar Five', images=[], experiment_runs=[]),\n", - " SampleResult(sample_id=220, sample_name='Sample220', puck_name='PKK005', dewar_name='Dewar Five', images=[], experiment_runs=[]),\n", - " SampleResult(sample_id=221, sample_name='Sample221', puck_name='PKK005', dewar_name='Dewar Five', images=[], experiment_runs=[]),\n", - " SampleResult(sample_id=222, sample_name='Sample222', puck_name='PKK005', dewar_name='Dewar Five', images=[], experiment_runs=[]),\n", - " SampleResult(sample_id=223, sample_name='Sample223', puck_name='PKK005', dewar_name='Dewar Five', images=[], experiment_runs=[]),\n", - " SampleResult(sample_id=224, sample_name='Sample224', puck_name='PKK005', dewar_name='Dewar Five', images=[], experiment_runs=[]),\n", - " SampleResult(sample_id=225, sample_name='Sample225', puck_name='PKK005', dewar_name='Dewar Five', images=[], experiment_runs=[]),\n", - " SampleResult(sample_id=226, sample_name='Sample226', puck_name='PKK005', dewar_name='Dewar Five', images=[], experiment_runs=[]),\n", - " SampleResult(sample_id=227, sample_name='Sample227', puck_name='PKK005', dewar_name='Dewar Five', images=[], experiment_runs=[]),\n", - " SampleResult(sample_id=228, sample_name='Sample228', puck_name='PKK005', dewar_name='Dewar Five', images=[], experiment_runs=[]),\n", - " SampleResult(sample_id=229, sample_name='Sample229', puck_name='PKK005', dewar_name='Dewar Five', images=[], experiment_runs=[]),\n", - " SampleResult(sample_id=230, sample_name='Sample230', puck_name='PKK005', dewar_name='Dewar Five', images=[], experiment_runs=[]),\n", - " SampleResult(sample_id=231, sample_name='Sample231', puck_name='PKK006', dewar_name='Dewar Five', images=[], experiment_runs=[]),\n", - " SampleResult(sample_id=232, sample_name='Sample232', puck_name='PKK006', dewar_name='Dewar Five', images=[], experiment_runs=[]),\n", - " SampleResult(sample_id=233, sample_name='Sample233', puck_name='PKK006', dewar_name='Dewar Five', images=[], experiment_runs=[]),\n", - " SampleResult(sample_id=234, sample_name='Sample234', puck_name='PKK006', dewar_name='Dewar Five', images=[], experiment_runs=[]),\n", - " SampleResult(sample_id=235, sample_name='Sample235', puck_name='PKK006', dewar_name='Dewar Five', images=[], experiment_runs=[]),\n", - " SampleResult(sample_id=236, sample_name='Sample236', puck_name='PKK007', dewar_name='Dewar Five', images=[], experiment_runs=[]),\n", - " SampleResult(sample_id=237, sample_name='Sample237', puck_name='PKK007', dewar_name='Dewar Five', images=[], experiment_runs=[]),\n", - " SampleResult(sample_id=238, sample_name='Sample238', puck_name='PKK007', dewar_name='Dewar Five', images=[], experiment_runs=[]),\n", - " SampleResult(sample_id=239, sample_name='Sample239', puck_name='PKK007', dewar_name='Dewar Five', images=[], experiment_runs=[]),\n", - " SampleResult(sample_id=240, sample_name='Sample240', puck_name='PKK007', dewar_name='Dewar Five', images=[], experiment_runs=[]),\n", - " SampleResult(sample_id=241, sample_name='Sample241', puck_name='PKK007', dewar_name='Dewar Five', images=[], experiment_runs=[]),\n", - " SampleResult(sample_id=242, sample_name='Sample242', puck_name='PKK007', dewar_name='Dewar Five', images=[], experiment_runs=[]),\n", - " SampleResult(sample_id=243, sample_name='Sample243', puck_name='PKK007', dewar_name='Dewar Five', images=[], experiment_runs=[]),\n", - " SampleResult(sample_id=244, sample_name='Sample244', puck_name='PKK007', dewar_name='Dewar Five', images=[], experiment_runs=[]),\n", - " SampleResult(sample_id=245, sample_name='Sample245', puck_name='PKK007', dewar_name='Dewar Five', images=[], experiment_runs=[]),\n", - " SampleResult(sample_id=246, sample_name='Sample246', puck_name='PKK007', dewar_name='Dewar Five', images=[], experiment_runs=[]),\n", - " SampleResult(sample_id=247, sample_name='Sample247', puck_name='PKK007', dewar_name='Dewar Five', images=[ImageInfo(id=1, filepath='images/p20003/2025-03-14/Dewar Five/PKK007/16/Mounting_2025-03-13_13-39-00/mount.jpeg.jpg', comment=None, event_type='Mounting'), ImageInfo(id=2, filepath='images/p20003/2025-03-14/Dewar Five/PKK007/16/Centering_2025-03-14_20-35-49/0_200.jpg', comment=None, event_type='Centering'), ImageInfo(id=3, filepath='images/p20003/2025-03-14/Dewar Five/PKK007/16/Centering_2025-03-14_20-35-49/90_200.jpg', comment=None, event_type='Centering'), ImageInfo(id=4, filepath='images/p20003/2025-03-14/Dewar Five/PKK007/16/Centering_2025-03-14_20-35-49/0_700.jpg', comment=None, event_type='Centering'), ImageInfo(id=5, filepath='images/p20003/2025-03-14/Dewar Five/PKK007/16/Centering_2025-03-14_20-35-49/90_700.jpg', comment=None, event_type='Centering'), ImageInfo(id=6, filepath='images/p20003/2025-03-14/Dewar Five/PKK007/16/Collecting_2025-03-14_20-37-45/bb_raster_0.jpg', comment=None, event_type='Collecting'), ImageInfo(id=7, filepath='images/p20003/2025-03-14/Dewar Five/PKK007/16/Collecting_2025-03-14_20-54-05/bb_raster_90.jpg', comment=None, event_type='Collecting'), ImageInfo(id=8, filepath='images/p20003/2025-03-14/Dewar Five/PKK007/16/Collecting_2025-03-14_20-54-48/after_dc.jpeg.jpg', comment=None, event_type='Collecting')], experiment_runs=[ExperimentParametersRead(run_number=1, beamline_parameters=BeamlineParameters(synchrotron='Swiss Light Source', beamline='PXIII', detector=Detector(manufacturer='DECTRIS', model='PILATUS4 2M', type='photon-counting', serial_number='16684dscsd668468', detector_distance_mm=95.0, beam_center_x_px=512.0, beam_center_y_px=512.0, pixel_size_x_um=150.0, pixel_size_y_um=150.0), wavelength=1.0, ring_current_a=0.0, ring_mode='Machine Down', undulator=None, undulatorgap_mm=None, monochromator='Si111', transmission=1.0, focusing_optic='Kirkpatrick-Baez', beamline_flux_at_sample_ph_s=0.0, beam_size_width=30.0, beam_size_height=30.0, characterization=None, rotation=None, grid_scan=GridScanParamers(x_start=0.0, x_step=0.1, y_start=0.0, y_step=0.1, z_start=0.0, z_step=0.0, number_of_images=4600, exposure_time_s=0.001), jet=None, cryojet_temperature_k=None, humidifier_temperature_k=None, humidifier_humidity=None), sample_id=247, id=1), ExperimentParametersRead(run_number=2, beamline_parameters=BeamlineParameters(synchrotron='Swiss Light Source', beamline='PXIII', detector=Detector(manufacturer='DECTRIS', model='PILATUS4 2M', type='photon-counting', serial_number='16684dscsd668468', detector_distance_mm=95.0, beam_center_x_px=512.0, beam_center_y_px=512.0, pixel_size_x_um=150.0, pixel_size_y_um=150.0), wavelength=1.0, ring_current_a=0.0, ring_mode='Machine Down', undulator=None, undulatorgap_mm=None, monochromator='Si111', transmission=1.0, focusing_optic='Kirkpatrick-Baez', beamline_flux_at_sample_ph_s=0.0, beam_size_width=30.0, beam_size_height=30.0, characterization=None, rotation=None, grid_scan=GridScanParamers(x_start=90.0, x_step=0.1, y_start=0.0, y_step=0.1, z_start=0.0, z_step=0.0, number_of_images=4600, exposure_time_s=0.001), jet=None, cryojet_temperature_k=None, humidifier_temperature_k=None, humidifier_humidity=None), sample_id=247, id=2), ExperimentParametersRead(run_number=3, beamline_parameters=BeamlineParameters(synchrotron='Swiss Light Source', beamline='PXIII', detector=Detector(manufacturer='DECTRIS', model='PILATUS4 2M', type='photon-counting', serial_number='16684dscsd668468', detector_distance_mm=95.0, beam_center_x_px=512.0, beam_center_y_px=512.0, pixel_size_x_um=150.0, pixel_size_y_um=150.0), wavelength=1.0, ring_current_a=0.0, ring_mode='Machine Down', undulator=None, undulatorgap_mm=None, monochromator='Si111', transmission=1.0, focusing_optic='Kirkpatrick-Baez', beamline_flux_at_sample_ph_s=0.0, beam_size_width=30.0, beam_size_height=30.0, characterization=None, rotation=RotationParameters(omega_start_deg=0.0, omega_step=0.1, chi=0.0, phi=10.0, number_of_images=3600, exposure_time_s=0.02), grid_scan=None, jet=None, cryojet_temperature_k=None, humidifier_temperature_k=None, humidifier_humidity=None), sample_id=247, id=3)])]\n" + "ename": "AttributeError", + "evalue": "'SamplesApi' object has no attribute 'get_sample_results_samples_results_get'", + "output_type": "error", + "traceback": [ + "\u001B[0;31m---------------------------------------------------------------------------\u001B[0m", + "\u001B[0;31mAttributeError\u001B[0m Traceback (most recent call last)", + "Cell \u001B[0;32mIn[4], line 10\u001B[0m\n\u001B[1;32m 7\u001B[0m \u001B[38;5;66;03m# GET request: Fetch all pucks in the tell\u001B[39;00m\n\u001B[1;32m 8\u001B[0m \u001B[38;5;28;01mtry\u001B[39;00m:\n\u001B[1;32m 9\u001B[0m \u001B[38;5;66;03m# Call the API method to fetch pucks\u001B[39;00m\n\u001B[0;32m---> 10\u001B[0m all_results_response \u001B[38;5;241m=\u001B[39m \u001B[43mapi_instance\u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mget_sample_results_samples_results_get\u001B[49m(active_pgroup\u001B[38;5;241m=\u001B[39m\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mp20003\u001B[39m\u001B[38;5;124m\"\u001B[39m)\n\u001B[1;32m 11\u001B[0m pprint(all_results_response)\n\u001B[1;32m 12\u001B[0m \u001B[38;5;66;03m## Debug response structure by printing it in JSON format\u001B[39;00m\n\u001B[1;32m 13\u001B[0m \u001B[38;5;66;03m#formatted_response = json.dumps(\u001B[39;00m\n\u001B[1;32m 14\u001B[0m \u001B[38;5;66;03m# [p.to_dict() for p in all_results_response], # Assuming the API response can be converted to dicts\u001B[39;00m\n\u001B[0;32m (...)\u001B[0m\n\u001B[1;32m 29\u001B[0m \u001B[38;5;66;03m# print(\" No samples found in this puck.\")\u001B[39;00m\n\u001B[1;32m 30\u001B[0m \u001B[38;5;66;03m#\u001B[39;00m\n", + "\u001B[0;31mAttributeError\u001B[0m: 'SamplesApi' object has no attribute 'get_sample_results_samples_results_get'" ] } ], - "execution_count": 6 + "execution_count": 4 }, { "metadata": { "ExecuteTime": { - "end_time": "2025-04-28T19:27:24.672540Z", - "start_time": "2025-04-28T19:25:49.421881Z" + "end_time": "2025-05-05T13:39:17.528508Z", + "start_time": "2025-05-05T13:39:17.496188Z" } }, "cell_type": "code", "source": [ - "import requests\n", - "import sseclient\n", - "import json\n", - "\n", - "# Replace clearly according to backend\n", - "SSE_URL = \"https://127.0.0.1:8000/processing/jobs/stream\"\n", - "#SSE_URL = \"https://mx-aare-test.psi.ch:1492/processing/jobs/stream\"\n", + "with aareDBclient.ApiClient(configuration) as api_client:\n", + " api_client.default_headers[\"Authorization\"] = f\"Bearer {token}\"\n", + " api_instance = aareDBclient.BeamtimesApi(api_client)\n", "\n", "\n", - "def listen_and_process_jobs(url):\n", - " print(\"Starting processing pipeline...\")\n", - " with requests.get(url, stream=True, verify=False) as response:\n", - " if response.status_code != 200:\n", - " print(f\"Failed to connect with status code: {response.status_code}\")\n", - " return\n", - "\n", - " client = sseclient.SSEClient(response)\n", - "\n", - " for event in client.events():\n", - " try:\n", - " jobs = json.loads(event.data)\n", - " print(f\"Jobs received: {jobs}\")\n", - "\n", - " for job in jobs:\n", - " job_id = job[\"id\"]\n", - " parameters = job[\"parameters\"]\n", - " print(f\"Processing job ID: {job_id} with parameters: {parameters}\")\n", - "\n", - " # TODO: your custom job-processing logic clearly goes here\n", - " process_job_logic(job_id, parameters)\n", - "\n", - " # After job processing completes, send results & update job status\n", - " submit_job_result(job_id, processing_result={'success': True})\n", - " except json.JSONDecodeError as e:\n", - " print(f\"Error decoding event data: {e}\")\n", - "\n", - "\n", - "def process_job_logic(job_id, parameters):\n", - " # Here: insert your application-specific processing logic\n", - " print(f\"📦 {job_id} - Processing detailed logic clearly here: {parameters}\")\n", - " # simulate execution:\n", - " import time\n", - " time.sleep(5) # Simulating task clearly\n", - " print(f\"✅ Job {job_id} processing complete\")\n", - "\n", - "\n", - "def submit_job_result(job_id, processing_result):\n", - " # Using autogenerated client or direct HTTP calls clearly:\n", - " import backend.aareDBclient as aareDBclient\n", - " from aareDBclient.models import ResultCreate\n", - "\n", - " configuration = aareDBclient.Configuration(\n", - " host=\"https://127.0.0.1:8000\",\n", - " verify_ssl=False\n", - " )\n", - "\n", - " with aareDBclient.ApiClient(configuration) as api_client:\n", - " api_instance = aareDBclient.ProcessingApi(api_client) # assuming this exists!\n", - "\n", - " result = ResultCreate(\n", - " job_id=job_id, # Assuming you have such a field clearly\n", - " result=processing_result\n", + " payload = BeamtimeCreate(\n", + " pgroups = \"p20003\",\n", + " shift = \"morning\",\n", + " beamtime_name = \"unscheduled beamtime\",\n", + " beamline = \"X06DA\",\n", + " start_date = \"2025-05-05\",\n", + " end_date = \"2025-05-05\",\n", + " status = \"unscheduled\",\n", + " comments = \"unscheduled beamtime created by test functions\",\n", + " proposal_id = 1,\n", + " local_contact_id= 1\n", " )\n", - " try:\n", - " res = api_instance.submit_processing_result(result_create=result)\n", - " print(f\"Job {job_id} result submitted successfully! Backend Response: {res}\")\n", - " except aareDBclient.rest.ApiException as e:\n", - " print(f\"Failed to submit result for Job {job_id}: {e}\")\n", "\n", + " try:\n", + " api_response = api_instance.create_beamtime_protected_beamtimes_post(payload.dict())\n", + " pprint(api_response)\n", "\n", - "if __name__ == \"__main__\":\n", - " listen_and_process_jobs(SSE_URL)\n" + " print(\"The response of BeamtimesApi->beamtime_create:\\n\")\n", + " pprint(api_response)\n", + "\n", + " except Exception as e:\n", + " print(f\"Exception when calling BeamtimesApi: {e}\")\n" ], - "id": "aef43f1265a23cb1", + "id": "deff7388a205e169", "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ - "DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): 127.0.0.1:8000\n", - "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/urllib3/connectionpool.py:1097: InsecureRequestWarning: Unverified HTTPS request is being made to host '127.0.0.1'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#tls-warnings\n", + "DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): localhost:8000\n", + "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/urllib3/connectionpool.py:1103: InsecureRequestWarning: Unverified HTTPS request is being made to host 'localhost'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#tls-warnings\n", " warnings.warn(\n", - "DEBUG:urllib3.connectionpool:https://127.0.0.1:8000 \"GET /processing/jobs/stream HTTP/1.1\" 200 None\n", - "DEBUG:sseclient:Initialized SSE client from event source \n" + "DEBUG:urllib3.connectionpool:https://localhost:8000 \"POST /protected/beamtimes/ HTTP/1.1\" 400 66\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ - "Starting processing pipeline...\n" - ] - }, - { - "ename": "KeyboardInterrupt", - "evalue": "", - "output_type": "error", - "traceback": [ - "\u001B[0;31m---------------------------------------------------------------------------\u001B[0m", - "\u001B[0;31mKeyboardInterrupt\u001B[0m Traceback (most recent call last)", - "Cell \u001B[0;32mIn[16], line 72\u001B[0m\n\u001B[1;32m 68\u001B[0m \u001B[38;5;28mprint\u001B[39m(\u001B[38;5;124mf\u001B[39m\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mFailed to submit result for Job \u001B[39m\u001B[38;5;132;01m{\u001B[39;00mjob_id\u001B[38;5;132;01m}\u001B[39;00m\u001B[38;5;124m: \u001B[39m\u001B[38;5;132;01m{\u001B[39;00me\u001B[38;5;132;01m}\u001B[39;00m\u001B[38;5;124m\"\u001B[39m)\n\u001B[1;32m 71\u001B[0m \u001B[38;5;28;01mif\u001B[39;00m \u001B[38;5;18m__name__\u001B[39m \u001B[38;5;241m==\u001B[39m \u001B[38;5;124m\"\u001B[39m\u001B[38;5;124m__main__\u001B[39m\u001B[38;5;124m\"\u001B[39m:\n\u001B[0;32m---> 72\u001B[0m \u001B[43mlisten_and_process_jobs\u001B[49m\u001B[43m(\u001B[49m\u001B[43mSSE_URL\u001B[49m\u001B[43m)\u001B[49m\n", - "Cell \u001B[0;32mIn[16], line 19\u001B[0m, in \u001B[0;36mlisten_and_process_jobs\u001B[0;34m(url)\u001B[0m\n\u001B[1;32m 15\u001B[0m \u001B[38;5;28;01mreturn\u001B[39;00m\n\u001B[1;32m 17\u001B[0m client \u001B[38;5;241m=\u001B[39m sseclient\u001B[38;5;241m.\u001B[39mSSEClient(response)\n\u001B[0;32m---> 19\u001B[0m \u001B[43m\u001B[49m\u001B[38;5;28;43;01mfor\u001B[39;49;00m\u001B[43m \u001B[49m\u001B[43mevent\u001B[49m\u001B[43m \u001B[49m\u001B[38;5;129;43;01min\u001B[39;49;00m\u001B[43m \u001B[49m\u001B[43mclient\u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mevents\u001B[49m\u001B[43m(\u001B[49m\u001B[43m)\u001B[49m\u001B[43m:\u001B[49m\n\u001B[1;32m 20\u001B[0m \u001B[43m \u001B[49m\u001B[38;5;28;43;01mtry\u001B[39;49;00m\u001B[43m:\u001B[49m\n\u001B[1;32m 21\u001B[0m \u001B[43m \u001B[49m\u001B[43mjobs\u001B[49m\u001B[43m \u001B[49m\u001B[38;5;241;43m=\u001B[39;49m\u001B[43m \u001B[49m\u001B[43mjson\u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mloads\u001B[49m\u001B[43m(\u001B[49m\u001B[43mevent\u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mdata\u001B[49m\u001B[43m)\u001B[49m\n", - "File \u001B[0;32m/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/sseclient/__init__.py:55\u001B[0m, in \u001B[0;36mSSEClient.events\u001B[0;34m(self)\u001B[0m\n\u001B[1;32m 54\u001B[0m \u001B[38;5;28;01mdef\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[38;5;21mevents\u001B[39m(\u001B[38;5;28mself\u001B[39m):\n\u001B[0;32m---> 55\u001B[0m \u001B[43m \u001B[49m\u001B[38;5;28;43;01mfor\u001B[39;49;00m\u001B[43m \u001B[49m\u001B[43mchunk\u001B[49m\u001B[43m \u001B[49m\u001B[38;5;129;43;01min\u001B[39;49;00m\u001B[43m \u001B[49m\u001B[38;5;28;43mself\u001B[39;49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43m_read\u001B[49m\u001B[43m(\u001B[49m\u001B[43m)\u001B[49m\u001B[43m:\u001B[49m\n\u001B[1;32m 56\u001B[0m \u001B[43m \u001B[49m\u001B[43mevent\u001B[49m\u001B[43m \u001B[49m\u001B[38;5;241;43m=\u001B[39;49m\u001B[43m \u001B[49m\u001B[43mEvent\u001B[49m\u001B[43m(\u001B[49m\u001B[43m)\u001B[49m\n\u001B[1;32m 57\u001B[0m \u001B[43m \u001B[49m\u001B[38;5;66;43;03m# Split before decoding so splitlines() only uses \\r and \\n\u001B[39;49;00m\n", - "File \u001B[0;32m/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/sseclient/__init__.py:45\u001B[0m, in \u001B[0;36mSSEClient._read\u001B[0;34m(self)\u001B[0m\n\u001B[1;32m 38\u001B[0m \u001B[38;5;250m\u001B[39m\u001B[38;5;124;03m\"\"\"Read the incoming event source stream and yield event chunks.\u001B[39;00m\n\u001B[1;32m 39\u001B[0m \n\u001B[1;32m 40\u001B[0m \u001B[38;5;124;03mUnfortunately it is possible for some servers to decide to break an\u001B[39;00m\n\u001B[1;32m 41\u001B[0m \u001B[38;5;124;03mevent into multiple HTTP chunks in the response. It is thus necessary\u001B[39;00m\n\u001B[1;32m 42\u001B[0m \u001B[38;5;124;03mto correctly stitch together consecutive response chunks and find the\u001B[39;00m\n\u001B[1;32m 43\u001B[0m \u001B[38;5;124;03mSSE delimiter (empty new line) to yield full, correct event chunks.\"\"\"\u001B[39;00m\n\u001B[1;32m 44\u001B[0m data \u001B[38;5;241m=\u001B[39m \u001B[38;5;124mb\u001B[39m\u001B[38;5;124m'\u001B[39m\u001B[38;5;124m'\u001B[39m\n\u001B[0;32m---> 45\u001B[0m \u001B[43m\u001B[49m\u001B[38;5;28;43;01mfor\u001B[39;49;00m\u001B[43m \u001B[49m\u001B[43mchunk\u001B[49m\u001B[43m \u001B[49m\u001B[38;5;129;43;01min\u001B[39;49;00m\u001B[43m \u001B[49m\u001B[38;5;28;43mself\u001B[39;49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43m_event_source\u001B[49m\u001B[43m:\u001B[49m\n\u001B[1;32m 46\u001B[0m \u001B[43m \u001B[49m\u001B[38;5;28;43;01mfor\u001B[39;49;00m\u001B[43m \u001B[49m\u001B[43mline\u001B[49m\u001B[43m \u001B[49m\u001B[38;5;129;43;01min\u001B[39;49;00m\u001B[43m \u001B[49m\u001B[43mchunk\u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43msplitlines\u001B[49m\u001B[43m(\u001B[49m\u001B[38;5;28;43;01mTrue\u001B[39;49;00m\u001B[43m)\u001B[49m\u001B[43m:\u001B[49m\n\u001B[1;32m 47\u001B[0m \u001B[43m \u001B[49m\u001B[43mdata\u001B[49m\u001B[43m \u001B[49m\u001B[38;5;241;43m+\u001B[39;49m\u001B[38;5;241;43m=\u001B[39;49m\u001B[43m \u001B[49m\u001B[43mline\u001B[49m\n", - "File \u001B[0;32m/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/requests/models.py:820\u001B[0m, in \u001B[0;36mResponse.iter_content..generate\u001B[0;34m()\u001B[0m\n\u001B[1;32m 818\u001B[0m \u001B[38;5;28;01mif\u001B[39;00m \u001B[38;5;28mhasattr\u001B[39m(\u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39mraw, \u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mstream\u001B[39m\u001B[38;5;124m\"\u001B[39m):\n\u001B[1;32m 819\u001B[0m \u001B[38;5;28;01mtry\u001B[39;00m:\n\u001B[0;32m--> 820\u001B[0m \u001B[38;5;28;01myield from\u001B[39;00m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39mraw\u001B[38;5;241m.\u001B[39mstream(chunk_size, decode_content\u001B[38;5;241m=\u001B[39m\u001B[38;5;28;01mTrue\u001B[39;00m)\n\u001B[1;32m 821\u001B[0m \u001B[38;5;28;01mexcept\u001B[39;00m ProtocolError \u001B[38;5;28;01mas\u001B[39;00m e:\n\u001B[1;32m 822\u001B[0m \u001B[38;5;28;01mraise\u001B[39;00m ChunkedEncodingError(e)\n", - "File \u001B[0;32m/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/urllib3/response.py:1063\u001B[0m, in \u001B[0;36mstream\u001B[0;34m(self, amt, decode_content)\u001B[0m\n\u001B[1;32m 1059\u001B[0m \u001B[38;5;28;01mif\u001B[39;00m \u001B[38;5;129;01mnot\u001B[39;00m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39mauto_close:\n\u001B[1;32m 1060\u001B[0m io\u001B[38;5;241m.\u001B[39mIOBase\u001B[38;5;241m.\u001B[39mclose(\u001B[38;5;28mself\u001B[39m)\n\u001B[1;32m 1062\u001B[0m \u001B[38;5;129m@property\u001B[39m\n\u001B[0;32m-> 1063\u001B[0m \u001B[38;5;28;01mdef\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[38;5;21mclosed\u001B[39m(\u001B[38;5;28mself\u001B[39m) \u001B[38;5;241m-\u001B[39m\u001B[38;5;241m>\u001B[39m \u001B[38;5;28mbool\u001B[39m:\n\u001B[1;32m 1064\u001B[0m \u001B[38;5;28;01mif\u001B[39;00m \u001B[38;5;129;01mnot\u001B[39;00m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39mauto_close:\n\u001B[1;32m 1065\u001B[0m \u001B[38;5;28;01mreturn\u001B[39;00m io\u001B[38;5;241m.\u001B[39mIOBase\u001B[38;5;241m.\u001B[39mclosed\u001B[38;5;241m.\u001B[39m\u001B[38;5;21m__get__\u001B[39m(\u001B[38;5;28mself\u001B[39m) \u001B[38;5;66;03m# type: ignore[no-any-return]\u001B[39;00m\n", - "File \u001B[0;32m/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/urllib3/response.py:1219\u001B[0m, in \u001B[0;36mread_chunked\u001B[0;34m(self, amt, decode_content)\u001B[0m\n\u001B[1;32m 1215\u001B[0m \u001B[38;5;129m@property\u001B[39m\n\u001B[1;32m 1216\u001B[0m \u001B[38;5;28;01mdef\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[38;5;21murl\u001B[39m(\u001B[38;5;28mself\u001B[39m) \u001B[38;5;241m-\u001B[39m\u001B[38;5;241m>\u001B[39m \u001B[38;5;28mstr\u001B[39m \u001B[38;5;241m|\u001B[39m \u001B[38;5;28;01mNone\u001B[39;00m:\n\u001B[1;32m 1217\u001B[0m \u001B[38;5;250m \u001B[39m\u001B[38;5;124;03m\"\"\"\u001B[39;00m\n\u001B[1;32m 1218\u001B[0m \u001B[38;5;124;03m Returns the URL that was the source of this response.\u001B[39;00m\n\u001B[0;32m-> 1219\u001B[0m \u001B[38;5;124;03m If the request that generated this response redirected, this method\u001B[39;00m\n\u001B[1;32m 1220\u001B[0m \u001B[38;5;124;03m will return the final redirect location.\u001B[39;00m\n\u001B[1;32m 1221\u001B[0m \u001B[38;5;124;03m \"\"\"\u001B[39;00m\n\u001B[1;32m 1222\u001B[0m \u001B[38;5;28;01mreturn\u001B[39;00m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39m_request_url\n", - "File \u001B[0;32m/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/urllib3/response.py:1138\u001B[0m, in \u001B[0;36m_update_chunk_length\u001B[0;34m(self)\u001B[0m\n\u001B[1;32m 1136\u001B[0m returned_chunk \u001B[38;5;241m=\u001B[39m value\n\u001B[1;32m 1137\u001B[0m \u001B[38;5;28;01melse\u001B[39;00m: \u001B[38;5;66;03m# amt > self.chunk_left\u001B[39;00m\n\u001B[0;32m-> 1138\u001B[0m returned_chunk \u001B[38;5;241m=\u001B[39m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39m_fp\u001B[38;5;241m.\u001B[39m_safe_read(\u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39mchunk_left) \u001B[38;5;66;03m# type: ignore[union-attr]\u001B[39;00m\n\u001B[1;32m 1139\u001B[0m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39m_fp\u001B[38;5;241m.\u001B[39m_safe_read(\u001B[38;5;241m2\u001B[39m) \u001B[38;5;66;03m# type: ignore[union-attr] # Toss the CRLF at the end of the chunk.\u001B[39;00m\n\u001B[1;32m 1140\u001B[0m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39mchunk_left \u001B[38;5;241m=\u001B[39m \u001B[38;5;28;01mNone\u001B[39;00m\n", - "File \u001B[0;32m/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/socket.py:707\u001B[0m, in \u001B[0;36mSocketIO.readinto\u001B[0;34m(self, b)\u001B[0m\n\u001B[1;32m 705\u001B[0m \u001B[38;5;28;01mwhile\u001B[39;00m \u001B[38;5;28;01mTrue\u001B[39;00m:\n\u001B[1;32m 706\u001B[0m \u001B[38;5;28;01mtry\u001B[39;00m:\n\u001B[0;32m--> 707\u001B[0m \u001B[38;5;28;01mreturn\u001B[39;00m \u001B[38;5;28;43mself\u001B[39;49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43m_sock\u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mrecv_into\u001B[49m\u001B[43m(\u001B[49m\u001B[43mb\u001B[49m\u001B[43m)\u001B[49m\n\u001B[1;32m 708\u001B[0m \u001B[38;5;28;01mexcept\u001B[39;00m timeout:\n\u001B[1;32m 709\u001B[0m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39m_timeout_occurred \u001B[38;5;241m=\u001B[39m \u001B[38;5;28;01mTrue\u001B[39;00m\n", - "File \u001B[0;32m/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/ssl.py:1216\u001B[0m, in \u001B[0;36mSSLSocket.recv_into\u001B[0;34m(self, buffer, nbytes, flags)\u001B[0m\n\u001B[1;32m 1212\u001B[0m \u001B[38;5;28;01mif\u001B[39;00m flags \u001B[38;5;241m!=\u001B[39m \u001B[38;5;241m0\u001B[39m:\n\u001B[1;32m 1213\u001B[0m \u001B[38;5;28;01mraise\u001B[39;00m \u001B[38;5;167;01mValueError\u001B[39;00m(\n\u001B[1;32m 1214\u001B[0m \u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mnon-zero flags not allowed in calls to recv_into() on \u001B[39m\u001B[38;5;132;01m%s\u001B[39;00m\u001B[38;5;124m\"\u001B[39m \u001B[38;5;241m%\u001B[39m\n\u001B[1;32m 1215\u001B[0m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39m\u001B[38;5;18m__class__\u001B[39m)\n\u001B[0;32m-> 1216\u001B[0m \u001B[38;5;28;01mreturn\u001B[39;00m \u001B[38;5;28;43mself\u001B[39;49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mread\u001B[49m\u001B[43m(\u001B[49m\u001B[43mnbytes\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mbuffer\u001B[49m\u001B[43m)\u001B[49m\n\u001B[1;32m 1217\u001B[0m \u001B[38;5;28;01melse\u001B[39;00m:\n\u001B[1;32m 1218\u001B[0m \u001B[38;5;28;01mreturn\u001B[39;00m \u001B[38;5;28msuper\u001B[39m()\u001B[38;5;241m.\u001B[39mrecv_into(buffer, nbytes, flags)\n", - "File \u001B[0;32m/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/ssl.py:1072\u001B[0m, in \u001B[0;36mSSLSocket.read\u001B[0;34m(self, len, buffer)\u001B[0m\n\u001B[1;32m 1070\u001B[0m \u001B[38;5;28;01mtry\u001B[39;00m:\n\u001B[1;32m 1071\u001B[0m \u001B[38;5;28;01mif\u001B[39;00m buffer \u001B[38;5;129;01mis\u001B[39;00m \u001B[38;5;129;01mnot\u001B[39;00m \u001B[38;5;28;01mNone\u001B[39;00m:\n\u001B[0;32m-> 1072\u001B[0m \u001B[38;5;28;01mreturn\u001B[39;00m \u001B[38;5;28;43mself\u001B[39;49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43m_sslobj\u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mread\u001B[49m\u001B[43m(\u001B[49m\u001B[38;5;28;43mlen\u001B[39;49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mbuffer\u001B[49m\u001B[43m)\u001B[49m\n\u001B[1;32m 1073\u001B[0m \u001B[38;5;28;01melse\u001B[39;00m:\n\u001B[1;32m 1074\u001B[0m \u001B[38;5;28;01mreturn\u001B[39;00m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39m_sslobj\u001B[38;5;241m.\u001B[39mread(\u001B[38;5;28mlen\u001B[39m)\n", - "\u001B[0;31mKeyboardInterrupt\u001B[0m: " + "Exception when calling BeamtimesApi: (400)\n", + "Reason: Bad Request\n", + "HTTP response headers: HTTPHeaderDict({'date': 'Mon, 05 May 2025 13:39:16 GMT', 'server': 'uvicorn', 'content-length': '66', 'content-type': 'application/json'})\n", + "HTTP response body: {\"detail\":\"A beamtime for this pgroup/shift/date already exists.\"}\n", + "\n" ] } ], - "execution_count": 16 + "execution_count": 18 } ], "metadata": {