1083 lines
74 KiB
Plaintext
1083 lines
74 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"metadata": {
|
|
"ExecuteTime": {
|
|
"end_time": "2025-03-19T11:01:53.035111Z",
|
|
"start_time": "2025-03-19T11:01:52.510182Z"
|
|
}
|
|
},
|
|
"cell_type": "code",
|
|
"source": [
|
|
"import json\n",
|
|
"\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",
|
|
"\n",
|
|
"#from app.data.data import sample\n",
|
|
"\n",
|
|
"#from aareDBclient import SamplesApi, ShipmentsApi, PucksApi\n",
|
|
"#from aareDBclient.models import SampleEventCreate, SetTellPosition\n",
|
|
"#from examples.examples import api_response\n",
|
|
"\n",
|
|
"print(aareDBclient.__version__)\n",
|
|
"\n",
|
|
"configuration = aareDBclient.Configuration(\n",
|
|
" #host = \"https://mx-aare-test.psi.ch:1492\"\n",
|
|
" host = \"https://127.0.0.1:8000\"\n",
|
|
")\n",
|
|
"\n",
|
|
"print(configuration.host)\n",
|
|
"\n",
|
|
"configuration.verify_ssl = False # Disable SSL verification\n",
|
|
"#print(dir(SamplesApi))"
|
|
],
|
|
"id": "3b7c27697a4d5c83",
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"0.1.0a26\n",
|
|
"https://127.0.0.1:8000\n"
|
|
]
|
|
}
|
|
],
|
|
"execution_count": 1
|
|
},
|
|
{
|
|
"metadata": {},
|
|
"cell_type": "code",
|
|
"outputs": [],
|
|
"execution_count": null,
|
|
"source": [
|
|
"## Fetch all Shipments, list corresponding dewars and pucks\n",
|
|
"\n",
|
|
"from datetime import date, datetime\n",
|
|
"from aareDBclient import ShipmentsApi, SamplesApi, GridScanParamers\n",
|
|
"from aareDBclient.models import Shipment\n",
|
|
"\n",
|
|
"with aareDBclient.ApiClient(configuration) as api_client:\n",
|
|
" api_instance = aareDBclient.ShipmentsApi(api_client)\n",
|
|
"\n",
|
|
" try:\n",
|
|
" # Fetch all shipments\n",
|
|
" all_shipments_response = api_instance.fetch_shipments_shipments_get()\n",
|
|
"\n",
|
|
" # Print shipment names and their associated puck names\n",
|
|
" for shipment in all_shipments_response:\n",
|
|
" print(f\"Shipment ID: {shipment.id}, Shipment Name: {shipment.shipment_name}\")\n",
|
|
" if hasattr(shipment, 'dewars') and shipment.dewars: # Ensure 'dewars' exists\n",
|
|
" for dewar in shipment.dewars:\n",
|
|
" print(f\" Dewar ID: {dewar.id}, Dewar Name: {dewar.dewar_name}, Dewar Unique ID: {dewar.unique_id} \")\n",
|
|
"\n",
|
|
" if hasattr(dewar, 'pucks') and dewar.pucks: # Ensure 'pucks' exists\n",
|
|
" for puck in dewar.pucks:\n",
|
|
" print(f\" Puck ID: {puck.id}, Puck Name: {puck.puck_name}\")\n",
|
|
" else:\n",
|
|
" print(\" No pucks found in this dewar.\")\n",
|
|
" else:\n",
|
|
" print(\" No dewars found in this shipment.\")\n",
|
|
"\n",
|
|
" except ApiException as e:\n",
|
|
" print(f\"Exception when calling ShipmentsApi->fetch_shipments_shipments_get: {e}\")\n"
|
|
],
|
|
"id": "4955b858f2cef93e"
|
|
},
|
|
{
|
|
"metadata": {
|
|
"ExecuteTime": {
|
|
"end_time": "2025-02-25T15:47:34.956061Z",
|
|
"start_time": "2025-02-25T15:47:34.941372Z"
|
|
}
|
|
},
|
|
"cell_type": "code",
|
|
"source": [
|
|
"from datetime import date\n",
|
|
"from aareDBclient import LogisticsApi\n",
|
|
"from aareDBclient.models import LogisticsEventCreate # Import required model\n",
|
|
"\n",
|
|
"with aareDBclient.ApiClient(configuration) as api_client:\n",
|
|
" api_instance = aareDBclient.LogisticsApi(api_client)\n",
|
|
"\n",
|
|
" try:\n",
|
|
" # Create payload using the required model\n",
|
|
" logistics_event_create = LogisticsEventCreate(\n",
|
|
" dewar_qr_code='923db239427869be',\n",
|
|
" location_qr_code='A2-X06SA',\n",
|
|
" transaction_type='incoming',\n",
|
|
" timestamp=date.today() # Adjust if the API expects datetime\n",
|
|
" )\n",
|
|
"\n",
|
|
" # Pass the payload to the API function\n",
|
|
" api_response = api_instance.scan_dewar_logistics_dewar_scan_post(\n",
|
|
" logistics_event_create=logistics_event_create # Pass as an object\n",
|
|
" )\n",
|
|
" print(\"API Response:\", api_response)\n",
|
|
"\n",
|
|
" except ApiException as e:\n",
|
|
" print(f\"Exception when calling LogisticsApi->scan_dewar_logistics_dewar_scan_post: {e}\")\n",
|
|
"\n",
|
|
" try:\n",
|
|
" # Create payload using the required model\n",
|
|
" logistics_event_create = LogisticsEventCreate(\n",
|
|
" dewar_qr_code='923db239427869be',\n",
|
|
" location_qr_code='A2-X06SA',\n",
|
|
" transaction_type='refill',\n",
|
|
" timestamp=date.today() # Adjust if the API expects datetime\n",
|
|
" )\n",
|
|
"\n",
|
|
" # Pass the payload to the API function\n",
|
|
" api_response = api_instance.scan_dewar_logistics_dewar_scan_post(\n",
|
|
" logistics_event_create=logistics_event_create # Pass as an object\n",
|
|
" )\n",
|
|
" print(\"API Response:\", api_response)\n",
|
|
"\n",
|
|
" except ApiException as e:\n",
|
|
" print(f\"Exception when calling LogisticsApi->scan_dewar_logistics_dewar_scan_post: {e}\")\n",
|
|
"\n",
|
|
" try:\n",
|
|
" # Create payload using the required model\n",
|
|
" logistics_event_create = LogisticsEventCreate(\n",
|
|
" dewar_qr_code='923db239427869be',\n",
|
|
" location_qr_code='X06DA-Beamline',\n",
|
|
" transaction_type='beamline',\n",
|
|
" timestamp=date.today() # Adjust if the API expects datetime\n",
|
|
" )\n",
|
|
"\n",
|
|
" # Pass the payload to the API function\n",
|
|
" api_response = api_instance.scan_dewar_logistics_dewar_scan_post(\n",
|
|
" logistics_event_create=logistics_event_create # Pass as an object\n",
|
|
" )\n",
|
|
" print(\"API Response:\", api_response)\n",
|
|
"\n",
|
|
" except ApiException as e:\n",
|
|
" print(f\"Exception when calling LogisticsApi->scan_dewar_logistics_dewar_scan_post: {e}\")\n"
|
|
],
|
|
"id": "8fd3638bffaecd23",
|
|
"outputs": [
|
|
{
|
|
"ename": "TypeError",
|
|
"evalue": "ApiClient.call_api() got an unexpected keyword argument 'path_params'",
|
|
"output_type": "error",
|
|
"traceback": [
|
|
"\u001B[0;31m---------------------------------------------------------------------------\u001B[0m",
|
|
"\u001B[0;31mTypeError\u001B[0m Traceback (most recent call last)",
|
|
"Cell \u001B[0;32mIn[43], line 19\u001B[0m\n\u001B[1;32m 15\u001B[0m \u001B[38;5;28;01mtry\u001B[39;00m:\n\u001B[1;32m 16\u001B[0m \u001B[38;5;28;01mwith\u001B[39;00m \u001B[38;5;28mopen\u001B[39m(file_path, \u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mrb\u001B[39m\u001B[38;5;124m\"\u001B[39m) \u001B[38;5;28;01mas\u001B[39;00m file_data:\n\u001B[1;32m 17\u001B[0m \u001B[38;5;66;03m# Use the low-level call_api method; note that the files parameter here is\u001B[39;00m\n\u001B[1;32m 18\u001B[0m \u001B[38;5;66;03m# a dictionary with key matching the FastAPI parameter name.\u001B[39;00m\n\u001B[0;32m---> 19\u001B[0m response \u001B[38;5;241m=\u001B[39m \u001B[43mapi_client\u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mcall_api\u001B[49m\u001B[43m(\u001B[49m\n\u001B[1;32m 20\u001B[0m \u001B[43m \u001B[49m\u001B[38;5;124;43mf\u001B[39;49m\u001B[38;5;124;43m\"\u001B[39;49m\u001B[38;5;124;43m/\u001B[39;49m\u001B[38;5;132;43;01m{\u001B[39;49;00m\u001B[43msample_id\u001B[49m\u001B[38;5;132;43;01m}\u001B[39;49;00m\u001B[38;5;124;43m/upload_images\u001B[39;49m\u001B[38;5;124;43m\"\u001B[39;49m\u001B[43m,\u001B[49m\n\u001B[1;32m 21\u001B[0m \u001B[43m \u001B[49m\u001B[38;5;124;43m\"\u001B[39;49m\u001B[38;5;124;43mPOST\u001B[39;49m\u001B[38;5;124;43m\"\u001B[39;49m\u001B[43m,\u001B[49m\n\u001B[1;32m 22\u001B[0m \u001B[43m \u001B[49m\u001B[43mpath_params\u001B[49m\u001B[38;5;241;43m=\u001B[39;49m\u001B[43m{\u001B[49m\u001B[38;5;124;43m\"\u001B[39;49m\u001B[38;5;124;43msample_id\u001B[39;49m\u001B[38;5;124;43m\"\u001B[39;49m\u001B[43m:\u001B[49m\u001B[43m \u001B[49m\u001B[43msample_id\u001B[49m\u001B[43m}\u001B[49m\u001B[43m,\u001B[49m\n\u001B[1;32m 23\u001B[0m \u001B[43m \u001B[49m\u001B[43mfiles\u001B[49m\u001B[38;5;241;43m=\u001B[39;49m\u001B[43m{\u001B[49m\u001B[38;5;124;43m\"\u001B[39;49m\u001B[38;5;124;43muploaded_file\u001B[39;49m\u001B[38;5;124;43m\"\u001B[39;49m\u001B[43m:\u001B[49m\u001B[43m \u001B[49m\u001B[43m(\u001B[49m\u001B[43mfilename\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mfile_data\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mmime_type\u001B[49m\u001B[43m)\u001B[49m\u001B[43m}\u001B[49m\n\u001B[1;32m 24\u001B[0m \u001B[43m \u001B[49m\u001B[43m)\u001B[49m\n\u001B[1;32m 25\u001B[0m \u001B[38;5;28mprint\u001B[39m(\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mAPI Response:\u001B[39m\u001B[38;5;124m\"\u001B[39m)\n\u001B[1;32m 26\u001B[0m \u001B[38;5;28mprint\u001B[39m(response)\n",
|
|
"\u001B[0;31mTypeError\u001B[0m: ApiClient.call_api() got an unexpected keyword argument 'path_params'"
|
|
]
|
|
}
|
|
],
|
|
"execution_count": 43
|
|
},
|
|
{
|
|
"metadata": {
|
|
"ExecuteTime": {
|
|
"end_time": "2025-03-03T10:06:33.111482Z",
|
|
"start_time": "2025-03-03T10:06:33.082367Z"
|
|
}
|
|
},
|
|
"cell_type": "code",
|
|
"source": [
|
|
"# Get a list of pucks that are \"at the beamline\"\n",
|
|
"\n",
|
|
"with aareDBclient.ApiClient(configuration) as api_client:\n",
|
|
" # Create an instance of the API class\n",
|
|
" api_instance = aareDBclient.PucksApi(api_client)\n",
|
|
" get_pucks_at_beamline = aareDBclient.PucksApi(api_client)\n",
|
|
"\n",
|
|
" try:\n",
|
|
" # Create Return Address\n",
|
|
" api_response = api_instance.get_pucks_by_slot_pucks_slot_slot_identifier_get(slot_identifier='X06DA')\n",
|
|
" print(\"The response of PucksApi->get_pucks_by_slot_pucks_slot_slot_identifier_get:\\n\")\n",
|
|
" pprint(api_response)\n",
|
|
"\n",
|
|
" except ApiException as e:\n",
|
|
" print(\"Exception when calling PucksApi->get_pucks_by_slot_pucks_slot_slot_identifier_get: %s\\n\" % e)"
|
|
],
|
|
"id": "9cf3457093751b61",
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"The response of PucksApi->get_pucks_by_slot_pucks_slot_slot_identifier_get:\n",
|
|
"\n",
|
|
"[PuckWithTellPosition(id=1, puck_name='PUCK-001', puck_type='Unipuck', puck_location_in_dewar=1, dewar_id=1, dewar_name='Dewar One', pgroup='p20001', samples=None, tell_position='A2'),\n",
|
|
" PuckWithTellPosition(id=2, puck_name='PUCK002', puck_type='Unipuck', puck_location_in_dewar=2, dewar_id=1, dewar_name='Dewar One', pgroup='p20001', samples=None, tell_position='A1'),\n",
|
|
" PuckWithTellPosition(id=3, puck_name='PUCK003', puck_type='Unipuck', puck_location_in_dewar=3, dewar_id=1, dewar_name='Dewar One', pgroup='p20001', samples=None, tell_position='F2'),\n",
|
|
" PuckWithTellPosition(id=4, puck_name='PUCK004', puck_type='Unipuck', puck_location_in_dewar=4, dewar_id=1, dewar_name='Dewar One', pgroup='p20001', samples=None, tell_position=None),\n",
|
|
" PuckWithTellPosition(id=5, puck_name='PUCK005', puck_type='Unipuck', puck_location_in_dewar=5, dewar_id=1, dewar_name='Dewar One', pgroup='p20001', samples=None, tell_position=None),\n",
|
|
" PuckWithTellPosition(id=6, puck_name='PUCK006', puck_type='Unipuck', puck_location_in_dewar=6, dewar_id=1, dewar_name='Dewar One', pgroup='p20001', samples=None, tell_position='F1'),\n",
|
|
" PuckWithTellPosition(id=7, puck_name='PUCK007', puck_type='Unipuck', puck_location_in_dewar=7, dewar_id=1, dewar_name='Dewar One', pgroup='p20001', samples=None, tell_position=None)]\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stderr",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"/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",
|
|
" warnings.warn(\n"
|
|
]
|
|
}
|
|
],
|
|
"execution_count": 2
|
|
},
|
|
{
|
|
"metadata": {
|
|
"ExecuteTime": {
|
|
"end_time": "2025-02-26T12:04:33.644201Z",
|
|
"start_time": "2025-02-26T12:04:33.625894Z"
|
|
}
|
|
},
|
|
"cell_type": "code",
|
|
"source": [
|
|
"from aareDBclient import SetTellPosition, SetTellPositionRequest\n",
|
|
"\n",
|
|
"with aareDBclient.ApiClient(configuration) as api_client:\n",
|
|
" # Create an instance of the API class\n",
|
|
" api_instance = aareDBclient.PucksApi(api_client)\n",
|
|
"\n",
|
|
" # Payload with SetTellPosition objects\n",
|
|
" payload = SetTellPositionRequest(\n",
|
|
" tell=\"X06DA\",\n",
|
|
" #pucks=[\n",
|
|
" # SetTellPosition(puck_name='PSIMX074', segment='B', puck_in_segment=1),\n",
|
|
" # SetTellPosition(puck_name='PSIMX080', segment='B', puck_in_segment=2),\n",
|
|
" # SetTellPosition(puck_name='PSIMX081', segment='C', puck_in_segment=3),\n",
|
|
" # SetTellPosition(puck_name='PSIMX084', segment='C', puck_in_segment=4),\n",
|
|
" # SetTellPosition(puck_name='PSIMX104', segment='E', puck_in_segment=5),\n",
|
|
" # SetTellPosition(puck_name='PSIMX107', segment='E', puck_in_segment=1),\n",
|
|
" # SetTellPosition(puck_name='PSIMX117', segment='F', puck_in_segment=2),\n",
|
|
" #]\n",
|
|
" #pucks=[\n",
|
|
" # SetTellPosition(puck_name='PSIMX074', segment='F', puck_in_segment=1),\n",
|
|
" # SetTellPosition(puck_name='PSIMX080', segment='F', puck_in_segment=2),\n",
|
|
" # SetTellPosition(puck_name='PSIMX107', segment='A', puck_in_segment=1),\n",
|
|
" # SetTellPosition(puck_name='PSIMX117', segment='A', puck_in_segment=2),\n",
|
|
" #]\n",
|
|
" pucks=[\n",
|
|
" SetTellPosition(puck_name='PUCK006', segment='F', puck_in_segment=1),\n",
|
|
" SetTellPosition(puck_name='PUCK003', segment='F', puck_in_segment=2),\n",
|
|
" SetTellPosition(puck_name='PUCK002', segment='A', puck_in_segment=1),\n",
|
|
" SetTellPosition(puck_name='PUCK001', segment='A', puck_in_segment=2),\n",
|
|
" ]\n",
|
|
" #pucks = []\n",
|
|
" )\n",
|
|
"\n",
|
|
" # Call the PUT method to update the tell_position\n",
|
|
" try:\n",
|
|
" api_response = api_instance.set_tell_positions_pucks_set_tell_positions_put(\n",
|
|
" set_tell_position_request=payload\n",
|
|
" ) # Pass the entire payload as a single parameter\n",
|
|
"\n",
|
|
" print(\"The response of PucksApi->pucks_puck_id_tell_position_put:\\n\")\n",
|
|
" pprint(api_response)\n",
|
|
"\n",
|
|
" except Exception as e:\n",
|
|
" print(f\"Exception when calling PucksApi: {e}\")\n"
|
|
],
|
|
"id": "37e3eac6760150ee",
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"The response of PucksApi->pucks_puck_id_tell_position_put:\n",
|
|
"\n",
|
|
"[{'message': 'Tell position updated successfully.',\n",
|
|
" 'new_position': 'F1',\n",
|
|
" 'previous_position': None,\n",
|
|
" 'puck_name': 'PUCK006',\n",
|
|
" 'status': 'updated',\n",
|
|
" 'tell': 'X06DA'},\n",
|
|
" {'message': 'Tell position updated successfully.',\n",
|
|
" 'new_position': 'F2',\n",
|
|
" 'previous_position': None,\n",
|
|
" 'puck_name': 'PUCK003',\n",
|
|
" 'status': 'updated',\n",
|
|
" 'tell': 'X06DA'},\n",
|
|
" {'message': 'Tell position updated successfully.',\n",
|
|
" 'new_position': 'A1',\n",
|
|
" 'previous_position': None,\n",
|
|
" 'puck_name': 'PUCK002',\n",
|
|
" 'status': 'updated',\n",
|
|
" 'tell': 'X06DA'},\n",
|
|
" {'message': 'Tell position updated successfully.',\n",
|
|
" 'new_position': 'A2',\n",
|
|
" 'previous_position': None,\n",
|
|
" 'puck_name': 'PUCK001',\n",
|
|
" 'status': 'updated',\n",
|
|
" 'tell': 'X06DA'}]\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stderr",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"/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",
|
|
" warnings.warn(\n"
|
|
]
|
|
}
|
|
],
|
|
"execution_count": 78
|
|
},
|
|
{
|
|
"metadata": {
|
|
"ExecuteTime": {
|
|
"end_time": "2025-03-07T12:40:09.769132Z",
|
|
"start_time": "2025-03-07T12:40:09.752103Z"
|
|
}
|
|
},
|
|
"cell_type": "code",
|
|
"source": [
|
|
"# Get puck_id puck_name sample_id sample_name of pucks in the tell\n",
|
|
"\n",
|
|
"with aareDBclient.ApiClient(configuration) as api_client:\n",
|
|
" # Create an instance of the API class\n",
|
|
" api_instance = aareDBclient.PucksApi(api_client)\n",
|
|
"\n",
|
|
" # GET request: Fetch all pucks in the tell\n",
|
|
" try:\n",
|
|
" # Call the API method to fetch pucks\n",
|
|
" all_pucks_response = api_instance.get_pucks_with_tell_position_pucks_with_tell_position_get(tell='X06DA')\n",
|
|
"\n",
|
|
" # Debug response structure by printing it in JSON format\n",
|
|
" formatted_response = json.dumps(\n",
|
|
" [p.to_dict() for p in all_pucks_response], # Assuming the API response can be converted to dicts\n",
|
|
" indent=4 # Use indentation for readability\n",
|
|
" )\n",
|
|
" #print(\"The response of PucksApi->get_all_pucks_in_tell (formatted):\\n\")\n",
|
|
" #print(formatted_response)\n",
|
|
"\n",
|
|
" # Iterate through each puck and print information\n",
|
|
" for p in all_pucks_response:\n",
|
|
" print(f\"Puck ID: {p.id}, Puck Name: {p.puck_name}\")\n",
|
|
"\n",
|
|
" ## Check if the puck has any samples\n",
|
|
" if hasattr(p, 'samples') and p.samples: # Ensure 'samples' attribute exists and is not empty\n",
|
|
" for sample in p.samples:\n",
|
|
" print(f\" Sample ID: {sample.id}, Sample Name: {sample.sample_name}, Position: {sample.position}, Mount count: {sample.mount_count}\")\n",
|
|
" else:\n",
|
|
" print(\" No samples found in this puck.\")\n",
|
|
"\n",
|
|
" except ApiException as e:\n",
|
|
" print(\"Exception when calling PucksApi->get_all_pucks_in_tell: %s\\n\" % e)"
|
|
],
|
|
"id": "51578d944878db6a",
|
|
"outputs": [
|
|
{
|
|
"name": "stderr",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"/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",
|
|
" warnings.warn(\n"
|
|
]
|
|
}
|
|
],
|
|
"execution_count": 2
|
|
},
|
|
{
|
|
"metadata": {
|
|
"ExecuteTime": {
|
|
"end_time": "2025-03-17T20:58:01.971747Z",
|
|
"start_time": "2025-03-17T20:58:01.969438Z"
|
|
}
|
|
},
|
|
"cell_type": "code",
|
|
"source": "sample_id = 247",
|
|
"id": "54d4d46ca558e7b9",
|
|
"outputs": [],
|
|
"execution_count": 2
|
|
},
|
|
{
|
|
"metadata": {
|
|
"ExecuteTime": {
|
|
"end_time": "2025-03-14T19:35:49.714724Z",
|
|
"start_time": "2025-03-14T19:35:49.691388Z"
|
|
}
|
|
},
|
|
"cell_type": "code",
|
|
"source": [
|
|
"from aareDBclient import SampleEventCreate\n",
|
|
"\n",
|
|
"# Create an event for a sample\n",
|
|
"\n",
|
|
"with aareDBclient.ApiClient(configuration) as api_client:\n",
|
|
" # Instance of the API client\n",
|
|
" api_instance = aareDBclient.SamplesApi(api_client)\n",
|
|
" #sample_id=293\n",
|
|
" try:\n",
|
|
" # Define the payload with only `event_type`\n",
|
|
" sample_event_create = SampleEventCreate(\n",
|
|
" sample_id=sample_id,\n",
|
|
" event_type=\"Centering\" # Valid event type\n",
|
|
" #event_type=\"Collecting\" # Valid event type\n",
|
|
" )\n",
|
|
"\n",
|
|
" # Debug the payload before sending\n",
|
|
" print(\"Payload being sent to API:\")\n",
|
|
" print(sample_event_create.json()) # Ensure it matches `SampleEventCreate`\n",
|
|
"\n",
|
|
" # Call the API\n",
|
|
" api_response = api_instance.create_sample_event_samples_samples_sample_id_events_post(\n",
|
|
" sample_id=sample_id, # Ensure this matches a valid sample ID in the database\n",
|
|
" sample_event_create=sample_event_create\n",
|
|
" )\n",
|
|
"\n",
|
|
" print(\"API response:\")\n",
|
|
" #pprint(api_response)\n",
|
|
"\n",
|
|
" for p in api_response:\n",
|
|
" print(p)\n",
|
|
"\n",
|
|
" except ApiException as e:\n",
|
|
" print(\"Exception when calling post_sample_event:\")\n",
|
|
" print(f\"Status Code: {e.status}\")\n",
|
|
" if e.body:\n",
|
|
" print(f\"Error Details: {e.body}\")\n"
|
|
],
|
|
"id": "4a0665f92756b486",
|
|
"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",
|
|
" warnings.warn(\n",
|
|
"DEBUG:urllib3.connectionpool:https://127.0.0.1:8000 \"POST /samples/samples/247/events HTTP/1.1\" 200 405\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"Payload being sent to API:\n",
|
|
"{\"event_type\":\"Centering\"}\n",
|
|
"API response:\n",
|
|
"('id', 247)\n",
|
|
"('sample_name', 'Sample247')\n",
|
|
"('position', 16)\n",
|
|
"('puck_id', 30)\n",
|
|
"('crystalname', None)\n",
|
|
"('proteinname', None)\n",
|
|
"('positioninpuck', None)\n",
|
|
"('priority', None)\n",
|
|
"('comments', None)\n",
|
|
"('data_collection_parameters', None)\n",
|
|
"('events', [SampleEventResponse(event_type='Mounting', id=482, sample_id=247, timestamp=datetime.datetime(2025, 3, 13, 13, 39)), SampleEventResponse(event_type='Centering', id=483, sample_id=247, timestamp=datetime.datetime(2025, 3, 14, 20, 35, 49))])\n",
|
|
"('mount_count', 0)\n",
|
|
"('unmount_count', 0)\n"
|
|
]
|
|
}
|
|
],
|
|
"execution_count": 5
|
|
},
|
|
{
|
|
"metadata": {},
|
|
"cell_type": "code",
|
|
"outputs": [],
|
|
"execution_count": null,
|
|
"source": [
|
|
"### not working\n",
|
|
"with aareDBclient.ApiClient(configuration) as api_client:\n",
|
|
" # Create an instance of the Samples API class\n",
|
|
" api_instance = aareDBclient.SamplesApi(api_client)\n",
|
|
"\n",
|
|
" try:\n",
|
|
" # Get the last sample event\n",
|
|
" last_event_response = api_instance.get_last_sample_event_samples_samples_sample_id_events_last_get(27)\n",
|
|
" print(\"The response of get_last_sample_event:\\n\")\n",
|
|
" pprint(last_event_response)\n",
|
|
"\n",
|
|
" except ApiException as e:\n",
|
|
" print(\"Exception when calling get_last_sample_event: %s\\n\" % e)\n"
|
|
],
|
|
"id": "f1d171700d6cf7fe"
|
|
},
|
|
{
|
|
"metadata": {
|
|
"ExecuteTime": {
|
|
"end_time": "2025-03-14T19:55:02.036739Z",
|
|
"start_time": "2025-03-14T19:55:02.011806Z"
|
|
}
|
|
},
|
|
"cell_type": "code",
|
|
"source": [
|
|
"# Post multiple images to the sample database\n",
|
|
"\n",
|
|
"import os\n",
|
|
"import mimetypes\n",
|
|
"import requests\n",
|
|
"\n",
|
|
"# List of file paths to the images you want to upload\n",
|
|
"#file_paths = [\n",
|
|
"# \"backend/tests/sample_image/0_200.jpg\",\n",
|
|
"# \"backend/tests/sample_image/90_200.jpg\",\n",
|
|
"# \"backend/tests/sample_image/0_700.jpg\",\n",
|
|
"# \"backend/tests/sample_image/90_700.jpg\",\n",
|
|
"#]\n",
|
|
"\n",
|
|
"#file_paths = [\"backend/tests/sample_image/mount.jpeg.jpg\"]\n",
|
|
"\n",
|
|
"#file_paths = [\n",
|
|
"# \"backend/tests/sample_image/bb_raster_90.jpg\"\n",
|
|
"#]\n",
|
|
"\n",
|
|
"file_paths = [\"backend/tests/sample_image/after_dc.jpeg.jpg\"]\n",
|
|
"\n",
|
|
"\n",
|
|
"\n",
|
|
"# Base URL for the upload endpoint\n",
|
|
"url = f\"https://127.0.0.1:8000/samples/{sample_id}/upload-images\"\n",
|
|
"\n",
|
|
"# Iterate through each file and upload it\n",
|
|
"for file_path in file_paths:\n",
|
|
" # Determine file name and MIME type\n",
|
|
" filename = os.path.basename(file_path)\n",
|
|
" mime_type, _ = mimetypes.guess_type(file_path)\n",
|
|
" if mime_type is None:\n",
|
|
" mime_type = \"application/octet-stream\"\n",
|
|
"\n",
|
|
" # Open the file for uploading\n",
|
|
" with open(file_path, \"rb\") as file_data:\n",
|
|
" files = {\n",
|
|
" # Use key \"uploaded_file\" as required by your API\n",
|
|
" \"uploaded_file\": (filename, file_data, mime_type)\n",
|
|
" }\n",
|
|
" headers = {\n",
|
|
" \"accept\": \"application/json\"\n",
|
|
" }\n",
|
|
"\n",
|
|
" # Send the POST request\n",
|
|
" print(f\"Uploading {filename}...\")\n",
|
|
" response = requests.post(url, headers=headers, files=files, verify=False)\n",
|
|
"\n",
|
|
" # Check the API response\n",
|
|
" print(f\"API Response for {filename}:\")\n",
|
|
" print(response.status_code)\n",
|
|
" try:\n",
|
|
" print(response.json())\n",
|
|
" except Exception:\n",
|
|
" print(response.text)\n"
|
|
],
|
|
"id": "11f62976d2e7d9b1",
|
|
"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",
|
|
" warnings.warn(\n",
|
|
"DEBUG:urllib3.connectionpool:https://127.0.0.1:8000 \"POST /samples/247/upload-images HTTP/1.1\" 200 205\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"Uploading after_dc.jpeg.jpg...\n",
|
|
"API Response for after_dc.jpeg.jpg:\n",
|
|
"200\n",
|
|
"{'pgroup': 'p20003', 'sample_id': 247, 'sample_event_id': 486, 'filepath': 'images/p20003/2025-03-14/Dewar Five/PKK007/16/Collecting_2025-03-14_20-54-48/after_dc.jpeg.jpg', 'status': 'active', 'comment': None, 'id': 8}\n"
|
|
]
|
|
}
|
|
],
|
|
"execution_count": 12
|
|
},
|
|
{
|
|
"metadata": {},
|
|
"cell_type": "code",
|
|
"outputs": [],
|
|
"execution_count": null,
|
|
"source": "help(api_instance.upload_sample_images_samples_samples_sample_id_upload_images_post)",
|
|
"id": "cb1b99e6327fff84"
|
|
},
|
|
{
|
|
"metadata": {
|
|
"ExecuteTime": {
|
|
"end_time": "2025-03-14T19:54:48.102322Z",
|
|
"start_time": "2025-03-14T19:54:48.080070Z"
|
|
}
|
|
},
|
|
"cell_type": "code",
|
|
"source": [
|
|
"# post experiment results to sample database\n",
|
|
"\n",
|
|
"from aareDBclient.models import (\n",
|
|
" ExperimentParametersCreate,\n",
|
|
" RotationParameters,\n",
|
|
" BeamlineParameters,\n",
|
|
" GridScanParamers\n",
|
|
")\n",
|
|
"\n",
|
|
"\n",
|
|
"# Build the nested parameters\n",
|
|
"rotation = RotationParameters(\n",
|
|
" omegaStart_deg=0.0,\n",
|
|
" omegaStep=0.1,\n",
|
|
" phi=10.0,\n",
|
|
" chi=0.0,\n",
|
|
" numberOfImages=3600,\n",
|
|
" exposureTime_s=0.02\n",
|
|
")\n",
|
|
"\n",
|
|
"#characterization = characterizationParameters(\n",
|
|
"# omegaStart_deg=0.0,\n",
|
|
"# omegaStep=90.0,\n",
|
|
"# oscillation_deg=1.0,\n",
|
|
"# phi=10.0,\n",
|
|
"# chi=0.0,\n",
|
|
"# numberOfImages=4,\n",
|
|
"# exposureTime_s=0.02\n",
|
|
"#)\n",
|
|
"\n",
|
|
"#gridscan = GridScanParamers(\n",
|
|
"# xStart=90.0,\n",
|
|
"# xStep=0.1,\n",
|
|
"# yStart=0.0,\n",
|
|
"# yStep= 0.1,\n",
|
|
"# zStart=0.0,\n",
|
|
"# zStep=0.0,\n",
|
|
"# numberOfImages=4600,\n",
|
|
"# exposureTime_s=0.001\n",
|
|
"#)\n",
|
|
"\n",
|
|
"# If your client code requires you to build a detector model,\n",
|
|
"# you can either use a Detector model or pass a dictionary.\n",
|
|
"# Here we pass a dictionary.\n",
|
|
"detector_data = {\n",
|
|
" \"manufacturer\": \"DECTRIS\",\n",
|
|
" \"model\": \"PILATUS4 2M\",\n",
|
|
" \"type\": \"photon-counting\",\n",
|
|
" \"serialNumber\": \"16684dscsd668468\",\n",
|
|
" \"detectorDistance_mm\": 95.0,\n",
|
|
" \"beamCenterX_px\": 512.0,\n",
|
|
" \"beamCenterY_px\": 512.0,\n",
|
|
" \"pixelSizeX_um\": 150.0,\n",
|
|
" \"pixelSizeY_um\": 150.0,\n",
|
|
"}\n",
|
|
"\n",
|
|
"beamline_params = BeamlineParameters(\n",
|
|
" synchrotron=\"Swiss Light Source\",\n",
|
|
" beamline=\"PXIII\",\n",
|
|
" detector=detector_data,\n",
|
|
" wavelength=1.0,\n",
|
|
" ringCurrent_A=0.0,\n",
|
|
" ringMode=\"Machine Down\",\n",
|
|
" monochromator=\"Si111\",\n",
|
|
" transmission=1.00,\n",
|
|
" focusingOptic=\"Kirkpatrick-Baez\",\n",
|
|
" beamlineFluxAtSample_ph_s=0,\n",
|
|
" beamSizeWidth=30.0,\n",
|
|
" beamSizeHeight=30.0,\n",
|
|
" #characterization=characterization\n",
|
|
" rotation=rotation # Optional nested parameter\n",
|
|
" #gridScan=gridscan\n",
|
|
" # gridScan and jet are optional and can be added similarly\n",
|
|
")\n",
|
|
"\n",
|
|
"# Prepare the experiment parameters payload.\n",
|
|
"# Note that the run_number will be set on the server side, so you can leave\n",
|
|
"# it out or set it to a dummy value if your client model requires it.\n",
|
|
"experiment_params_payload = ExperimentParametersCreate(\n",
|
|
" # run_number can be omitted/ignored if computed on the server\n",
|
|
" beamline_parameters=beamline_params,\n",
|
|
" sample_id=sample_id # change sample_id to an existing sample in your database\n",
|
|
")\n",
|
|
"\n",
|
|
"# Now, use the API instance to send the POST request\n",
|
|
"with aareDBclient.ApiClient(configuration) as api_client:\n",
|
|
" api_instance = aareDBclient.SamplesApi(api_client)\n",
|
|
"\n",
|
|
" try:\n",
|
|
" # Call the endpoint. The endpoint path expects the sample_id.\n",
|
|
" api_response = api_instance.create_experiment_parameters_for_sample(\n",
|
|
" sample_id=experiment_params_payload.sample_id,\n",
|
|
" experiment_parameters_create=experiment_params_payload\n",
|
|
")\n",
|
|
"\n",
|
|
" print(\"API Response:\")\n",
|
|
" print(api_response)\n",
|
|
" except ApiException as e:\n",
|
|
" print(\"Exception when calling ExperimentParametersApi->create_experiment_parameters_for_sample:\")\n",
|
|
" print(e)\n"
|
|
],
|
|
"id": "421ba0710f29a5fa",
|
|
"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",
|
|
" warnings.warn(\n",
|
|
"DEBUG:urllib3.connectionpool:https://127.0.0.1:8000 \"POST /samples/samples/247/experiment_parameters HTTP/1.1\" 200 860\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"API Response:\n",
|
|
"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"
|
|
]
|
|
}
|
|
],
|
|
"execution_count": 11
|
|
},
|
|
{
|
|
"metadata": {
|
|
"ExecuteTime": {
|
|
"end_time": "2025-03-17T22:16:50.829755Z",
|
|
"start_time": "2025-03-17T22:16:50.791016Z"
|
|
}
|
|
},
|
|
"cell_type": "code",
|
|
"source": [
|
|
"from app.schemas import CurvePoint\n",
|
|
"# %%\n",
|
|
"from app.schemas import ResultCreate, Results\n",
|
|
"from pprint import pprint\n",
|
|
"import random\n",
|
|
"import math\n",
|
|
"import aareDBclient\n",
|
|
"from aareDBclient.rest import ApiException\n",
|
|
"\n",
|
|
"# Your actual sample and experiment IDs\n",
|
|
"sample_id = sample_id # Replace with valid IDs\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",
|
|
" resolutions = sorted([round(random.uniform(min_res, max_res), decimals) for _ in range(length)], reverse=True) # Reverse order\n",
|
|
"\n",
|
|
" curve = []\n",
|
|
" for res in resolutions:\n",
|
|
" # Exponential-like decay: Higher resolution (small number) -> value ~1, Lower resolution (big number) -> value ~0\n",
|
|
" decay_factor = (res - max_res) / (min_res - max_res) # Normalize res to [0,1]\n",
|
|
" value = max_value - ( math.exp(- 20 * decay_factor ) ) # Exponential decay\n",
|
|
"\n",
|
|
" # Add small random noise for realism\n",
|
|
" noise_value = random.uniform(-noise, noise)\n",
|
|
" value = min(max(value + noise_value, min_value), max_value) # Clamp between min_value and max_value\n",
|
|
"\n",
|
|
" curve.append(CurvePoint(resolution=res, value=round(value, decimals)))\n",
|
|
"\n",
|
|
" return curve\n",
|
|
"\n",
|
|
"# Create random Results payload\n",
|
|
"results_data = Results(\n",
|
|
" pipeline=\"autoproc\",\n",
|
|
" resolution=round(random.uniform(1.0, 4.0), 2),\n",
|
|
" unit_cell=f\"{random.uniform(20, 120):.2f}, {random.uniform(20, 120):.2f}, \"\n",
|
|
" f\"{random.uniform(20, 120):.2f}, {random.uniform(60, 120):.2f}, \"\n",
|
|
" f\"{random.uniform(60, 120):.2f}, {random.uniform(60, 120):.2f}\",\n",
|
|
" spacegroup=random.choice(['P212121', 'C2', 'P1', 'P21', 'P21212', 'P41212']),\n",
|
|
" rmerge=round(random.uniform(0.02, 0.10), 3),\n",
|
|
" rmeas=round(random.uniform(0.02, 0.15), 3),\n",
|
|
" isig=round(random.uniform(1.0, 30.0), 2),\n",
|
|
" cc=logarithmic_decay_curve(100), # List of CurvePoint for CC curve\n",
|
|
" cchalf=logarithmic_decay_curve(100), # List of CurvePoint for CC(1/2) curve\n",
|
|
" completeness=round(random.uniform(85.0, 100.0), 2),\n",
|
|
" multiplicity=round(random.uniform(1.0, 10.0), 2),\n",
|
|
" nobs=random.randint(10000, 500000),\n",
|
|
" total_refl=random.randint(5000, 250000),\n",
|
|
" unique_refl=random.randint(5000, 100000),\n",
|
|
" comments=\"Random auto-generated test entry\"\n",
|
|
")\n",
|
|
"\n",
|
|
"payload = ResultCreate(sample_id=sample_id, run_id=run_id, result=results_data)\n",
|
|
"\n",
|
|
"# correct serialization, passing exact required dict structure\n",
|
|
"payload_dict = {\n",
|
|
" \"sample_id\": sample_id,\n",
|
|
" \"run_id\": run_id,\n",
|
|
" \"result\": results_data.model_dump(),\n",
|
|
"}\n",
|
|
"\n",
|
|
"with aareDBclient.ApiClient(configuration) as api_client:\n",
|
|
" api_instance = aareDBclient.SamplesApi(api_client)\n",
|
|
"\n",
|
|
" try:\n",
|
|
" api_response = api_instance.create_result(\n",
|
|
" result_create=payload_dict\n",
|
|
" )\n",
|
|
"\n",
|
|
" print(\"API call successful:\")\n",
|
|
" pprint(api_response)\n",
|
|
"\n",
|
|
" except ApiException as e:\n",
|
|
" print(f\"API call failed: {e}\")\n"
|
|
],
|
|
"id": "3e3974d5df795c32",
|
|
"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 \"POST /samples/processing-results HTTP/1.1\" 200 7218\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"API call successful:\n",
|
|
"ResultResponse(id=36, sample_id=247, run_id=1, result=Results(pipeline='autoproc', resolution=1.81, unit_cell='56.82, 75.31, 82.06, 91.76, 79.97, 79.75', spacegroup='P1', rmerge=0.097, rmeas=0.122, isig=13.86, cc=[CurvePoint(resolution=3.979, value=1.0), CurvePoint(resolution=3.964, value=0.997), CurvePoint(resolution=3.879, value=1.0), CurvePoint(resolution=3.814, value=0.999), CurvePoint(resolution=3.787, value=0.997), CurvePoint(resolution=3.767, value=1.0), CurvePoint(resolution=3.706, value=0.998), CurvePoint(resolution=3.68, value=1.0), CurvePoint(resolution=3.678, value=0.998), CurvePoint(resolution=3.677, value=0.998), CurvePoint(resolution=3.627, value=1.0), CurvePoint(resolution=3.619, value=1.0), CurvePoint(resolution=3.614, value=1.0), CurvePoint(resolution=3.598, value=0.998), CurvePoint(resolution=3.568, value=1.0), CurvePoint(resolution=3.477, value=0.999), CurvePoint(resolution=3.46, value=1.0), CurvePoint(resolution=3.44, value=1.0), CurvePoint(resolution=3.414, value=0.999), CurvePoint(resolution=3.341, value=0.997), CurvePoint(resolution=3.315, value=0.998), CurvePoint(resolution=3.258, value=0.995), CurvePoint(resolution=3.204, value=0.997), CurvePoint(resolution=3.182, value=0.996), CurvePoint(resolution=3.168, value=0.997), CurvePoint(resolution=3.07, value=0.997), CurvePoint(resolution=3.044, value=1.0), CurvePoint(resolution=3.037, value=0.999), CurvePoint(resolution=3.037, value=0.997), CurvePoint(resolution=3.024, value=0.996), CurvePoint(resolution=3.014, value=0.996), CurvePoint(resolution=3.009, value=0.998), CurvePoint(resolution=2.882, value=0.998), CurvePoint(resolution=2.798, value=0.997), CurvePoint(resolution=2.728, value=1.0), CurvePoint(resolution=2.722, value=0.998), CurvePoint(resolution=2.713, value=0.996), CurvePoint(resolution=2.712, value=1.0), CurvePoint(resolution=2.703, value=1.0), CurvePoint(resolution=2.587, value=0.998), CurvePoint(resolution=2.586, value=0.996), CurvePoint(resolution=2.57, value=0.996), CurvePoint(resolution=2.553, value=1.0), CurvePoint(resolution=2.539, value=0.999), CurvePoint(resolution=2.493, value=0.997), CurvePoint(resolution=2.483, value=0.998), CurvePoint(resolution=2.454, value=0.997), CurvePoint(resolution=2.435, value=1.0), CurvePoint(resolution=2.431, value=0.998), CurvePoint(resolution=2.418, value=1.0), CurvePoint(resolution=2.396, value=0.995), CurvePoint(resolution=2.36, value=1.0), CurvePoint(resolution=2.332, value=0.996), CurvePoint(resolution=2.323, value=0.998), CurvePoint(resolution=2.299, value=0.998), CurvePoint(resolution=2.294, value=1.0), CurvePoint(resolution=2.271, value=0.999), CurvePoint(resolution=2.267, value=1.0), CurvePoint(resolution=2.234, value=0.998), CurvePoint(resolution=2.216, value=1.0), CurvePoint(resolution=2.108, value=1.0), CurvePoint(resolution=2.028, value=0.994), CurvePoint(resolution=2.012, value=0.996), CurvePoint(resolution=2.007, value=0.996), CurvePoint(resolution=1.964, value=0.996), CurvePoint(resolution=1.92, value=1.0), CurvePoint(resolution=1.883, value=0.995), CurvePoint(resolution=1.824, value=0.996), CurvePoint(resolution=1.818, value=0.993), CurvePoint(resolution=1.817, value=0.993), CurvePoint(resolution=1.812, value=0.991), CurvePoint(resolution=1.769, value=0.99), CurvePoint(resolution=1.743, value=0.988), CurvePoint(resolution=1.732, value=0.992), CurvePoint(resolution=1.729, value=0.995), CurvePoint(resolution=1.689, value=0.993), CurvePoint(resolution=1.658, value=0.988), CurvePoint(resolution=1.654, value=0.984), CurvePoint(resolution=1.634, value=0.987), CurvePoint(resolution=1.608, value=0.984), CurvePoint(resolution=1.586, value=0.975), CurvePoint(resolution=1.559, value=0.974), CurvePoint(resolution=1.512, value=0.971), CurvePoint(resolution=1.485, value=0.965), CurvePoint(resolution=1.482, value=0.964), CurvePoint(resolution=1.479, value=0.963), CurvePoint(resolution=1.477, value=0.962), CurvePoint(resolution=1.434, value=0.948), CurvePoint(resolution=1.43, value=0.942), CurvePoint(resolution=1.401, value=0.931), CurvePoint(resolution=1.373, value=0.922), CurvePoint(resolution=1.333, value=0.889), CurvePoint(resolution=1.305, value=0.873), CurvePoint(resolution=1.253, value=0.814), CurvePoint(resolution=1.252, value=0.81), CurvePoint(resolution=1.216, value=0.765), CurvePoint(resolution=1.041, value=0.235), CurvePoint(resolution=1.04, value=0.23), CurvePoint(resolution=1.033, value=0.197), CurvePoint(resolution=1.015, value=0.096)], cchalf=[CurvePoint(resolution=3.985, value=1.0), CurvePoint(resolution=3.984, value=1.0), CurvePoint(resolution=3.974, value=1.0), CurvePoint(resolution=3.934, value=1.0), CurvePoint(resolution=3.895, value=0.998), CurvePoint(resolution=3.884, value=0.998), CurvePoint(resolution=3.833, value=0.996), CurvePoint(resolution=3.817, value=0.997), CurvePoint(resolution=3.794, value=0.995), CurvePoint(resolution=3.783, value=1.0), CurvePoint(resolution=3.782, value=1.0), CurvePoint(resolution=3.728, value=0.996), CurvePoint(resolution=3.728, value=0.999), CurvePoint(resolution=3.685, value=0.999), CurvePoint(resolution=3.637, value=1.0), CurvePoint(resolution=3.607, value=0.999), CurvePoint(resolution=3.606, value=1.0), CurvePoint(resolution=3.599, value=1.0), CurvePoint(resolution=3.549, value=0.995), CurvePoint(resolution=3.543, value=1.0), CurvePoint(resolution=3.464, value=1.0), CurvePoint(resolution=3.34, value=0.998), CurvePoint(resolution=3.295, value=1.0), CurvePoint(resolution=3.257, value=0.999), CurvePoint(resolution=3.254, value=1.0), CurvePoint(resolution=3.251, value=1.0), CurvePoint(resolution=3.251, value=1.0), CurvePoint(resolution=3.228, value=1.0), CurvePoint(resolution=3.227, value=1.0), CurvePoint(resolution=3.226, value=1.0), CurvePoint(resolution=3.184, value=0.995), CurvePoint(resolution=3.173, value=0.997), CurvePoint(resolution=3.08, value=1.0), CurvePoint(resolution=3.062, value=1.0), CurvePoint(resolution=3.04, value=1.0), CurvePoint(resolution=3.013, value=1.0), CurvePoint(resolution=2.965, value=1.0), CurvePoint(resolution=2.913, value=0.998), CurvePoint(resolution=2.876, value=1.0), CurvePoint(resolution=2.866, value=0.998), CurvePoint(resolution=2.849, value=1.0), CurvePoint(resolution=2.839, value=0.998), CurvePoint(resolution=2.816, value=1.0), CurvePoint(resolution=2.773, value=1.0), CurvePoint(resolution=2.747, value=0.995), CurvePoint(resolution=2.737, value=1.0), CurvePoint(resolution=2.733, value=0.998), CurvePoint(resolution=2.723, value=1.0), CurvePoint(resolution=2.713, value=1.0), CurvePoint(resolution=2.626, value=0.997), CurvePoint(resolution=2.583, value=0.996), CurvePoint(resolution=2.501, value=1.0), CurvePoint(resolution=2.493, value=1.0), CurvePoint(resolution=2.411, value=0.998), CurvePoint(resolution=2.31, value=1.0), CurvePoint(resolution=2.287, value=0.997), CurvePoint(resolution=2.246, value=0.995), CurvePoint(resolution=2.233, value=1.0), CurvePoint(resolution=2.191, value=0.998), CurvePoint(resolution=2.167, value=0.995), CurvePoint(resolution=2.149, value=0.996), CurvePoint(resolution=2.127, value=1.0), CurvePoint(resolution=2.114, value=1.0), CurvePoint(resolution=2.046, value=1.0), CurvePoint(resolution=2.004, value=0.996), CurvePoint(resolution=1.987, value=0.995), CurvePoint(resolution=1.908, value=0.993), CurvePoint(resolution=1.899, value=1.0), CurvePoint(resolution=1.856, value=0.995), CurvePoint(resolution=1.822, value=0.993), CurvePoint(resolution=1.812, value=0.997), CurvePoint(resolution=1.802, value=0.992), CurvePoint(resolution=1.796, value=0.995), CurvePoint(resolution=1.773, value=0.996), CurvePoint(resolution=1.767, value=0.991), CurvePoint(resolution=1.76, value=0.989), CurvePoint(resolution=1.742, value=0.991), CurvePoint(resolution=1.725, value=0.996), CurvePoint(resolution=1.723, value=0.995), CurvePoint(resolution=1.718, value=0.987), CurvePoint(resolution=1.687, value=0.989), CurvePoint(resolution=1.639, value=0.984), CurvePoint(resolution=1.598, value=0.982), CurvePoint(resolution=1.592, value=0.985), CurvePoint(resolution=1.494, value=0.963), CurvePoint(resolution=1.475, value=0.961), CurvePoint(resolution=1.449, value=0.954), CurvePoint(resolution=1.427, value=0.946), CurvePoint(resolution=1.402, value=0.929), CurvePoint(resolution=1.377, value=0.918), CurvePoint(resolution=1.324, value=0.889), CurvePoint(resolution=1.296, value=0.859), CurvePoint(resolution=1.253, value=0.814), CurvePoint(resolution=1.227, value=0.784), CurvePoint(resolution=1.225, value=0.773), CurvePoint(resolution=1.146, value=0.619), CurvePoint(resolution=1.118, value=0.547), CurvePoint(resolution=1.03, value=0.179), CurvePoint(resolution=1.013, value=0.087), CurvePoint(resolution=1.011, value=0.07)], completeness=86.92, multiplicity=5.46, nobs=48062, total_refl=73724, unique_refl=93185, comments='Random auto-generated test entry'))\n"
|
|
]
|
|
}
|
|
],
|
|
"execution_count": 36
|
|
},
|
|
{
|
|
"metadata": {
|
|
"ExecuteTime": {
|
|
"end_time": "2025-03-17T21:11:17.101900Z",
|
|
"start_time": "2025-03-17T21:11:17.053250Z"
|
|
}
|
|
},
|
|
"cell_type": "code",
|
|
"source": [
|
|
"# get experiment results to sample database\n",
|
|
"\n",
|
|
"with aareDBclient.ApiClient(configuration) as api_client:\n",
|
|
" # Create an instance of the API class\n",
|
|
" api_instance = aareDBclient.SamplesApi(api_client)\n",
|
|
"\n",
|
|
" # GET request: Fetch all pucks in the tell\n",
|
|
" try:\n",
|
|
" # Call the API method to fetch pucks\n",
|
|
" all_results_response = api_instance.get_sample_results_samples_results_get(active_pgroup=\"p20003\")\n",
|
|
" pprint(all_results_response)\n",
|
|
" ## Debug response structure by printing it in JSON format\n",
|
|
" #formatted_response = json.dumps(\n",
|
|
" # [p.to_dict() for p in all_results_response], # Assuming the API response can be converted to dicts\n",
|
|
" # indent=4 # Use indentation for readability\n",
|
|
" #)\n",
|
|
" #print(\"The response of PucksApi->get_all_pucks_in_tell (formatted):\\n\")\n",
|
|
" #print(formatted_response)\n",
|
|
"\n",
|
|
" ## Iterate through each puck and print information\n",
|
|
" #for p in all_results_response:\n",
|
|
" # print(f\"Puck ID: {p.id}, Puck Name: {p.puck_name}\")\n",
|
|
" #\n",
|
|
" # ## Check if the puck has any samples\n",
|
|
" # if hasattr(p, 'samples') and p.samples: # Ensure 'samples' attribute exists and is not empty\n",
|
|
" # for sample in p.samples:\n",
|
|
" # print(f\" Sample ID: {sample.id}, Sample Name: {sample.sample_name}, Position: {sample.position}, Mount count: {sample.mount_count}\")\n",
|
|
" # else:\n",
|
|
" # print(\" No samples found in this puck.\")\n",
|
|
" #\n",
|
|
" except ApiException as e:\n",
|
|
" print(\"Exception when calling PucksApi->get_all_pucks_in_tell: %s\\n\" % e)"
|
|
],
|
|
"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"
|
|
]
|
|
}
|
|
],
|
|
"execution_count": 6
|
|
},
|
|
{
|
|
"metadata": {
|
|
"ExecuteTime": {
|
|
"end_time": "2025-04-11T11:57:22.504015Z",
|
|
"start_time": "2025-04-11T11:56:30.723778Z"
|
|
}
|
|
},
|
|
"cell_type": "code",
|
|
"source": [
|
|
"import requests\n",
|
|
"import sseclient\n",
|
|
"import json\n",
|
|
"\n",
|
|
"SSE_URL = \"https://127.0.0.1:8000/processing/jobs/stream\" # Replace clearly according to backend\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",
|
|
" )\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",
|
|
"\n",
|
|
"if __name__ == \"__main__\":\n",
|
|
" listen_and_process_jobs(SSE_URL)\n"
|
|
],
|
|
"id": "aef43f1265a23cb1",
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"Starting processing pipeline...\n"
|
|
]
|
|
},
|
|
{
|
|
"name": "stderr",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"/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"
|
|
]
|
|
},
|
|
{
|
|
"ename": "KeyboardInterrupt",
|
|
"evalue": "",
|
|
"output_type": "error",
|
|
"traceback": [
|
|
"\u001B[31m---------------------------------------------------------------------------\u001B[39m",
|
|
"\u001B[31mKeyboardInterrupt\u001B[39m Traceback (most recent call last)",
|
|
"\u001B[36mCell\u001B[39m\u001B[36m \u001B[39m\u001B[32mIn[3]\u001B[39m\u001B[32m, line 70\u001B[39m\n\u001B[32m 66\u001B[39m \u001B[38;5;28mprint\u001B[39m(\u001B[33mf\u001B[39m\u001B[33m\"\u001B[39m\u001B[33mFailed 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[33m: \u001B[39m\u001B[38;5;132;01m{\u001B[39;00me\u001B[38;5;132;01m}\u001B[39;00m\u001B[33m\"\u001B[39m)\n\u001B[32m 69\u001B[39m \u001B[38;5;28;01mif\u001B[39;00m \u001B[34m__name__\u001B[39m == \u001B[33m\"\u001B[39m\u001B[33m__main__\u001B[39m\u001B[33m\"\u001B[39m:\n\u001B[32m---> \u001B[39m\u001B[32m70\u001B[39m \u001B[43mlisten_and_process_jobs\u001B[49m\u001B[43m(\u001B[49m\u001B[43mSSE_URL\u001B[49m\u001B[43m)\u001B[49m\n",
|
|
"\u001B[36mCell\u001B[39m\u001B[36m \u001B[39m\u001B[32mIn[3]\u001B[39m\u001B[32m, line 17\u001B[39m, in \u001B[36mlisten_and_process_jobs\u001B[39m\u001B[34m(url)\u001B[39m\n\u001B[32m 13\u001B[39m \u001B[38;5;28;01mreturn\u001B[39;00m\n\u001B[32m 15\u001B[39m client = sseclient.SSEClient(response)\n\u001B[32m---> \u001B[39m\u001B[32m17\u001B[39m \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[43m.\u001B[49m\u001B[43mevents\u001B[49m\u001B[43m(\u001B[49m\u001B[43m)\u001B[49m\u001B[43m:\u001B[49m\n\u001B[32m 18\u001B[39m \u001B[43m \u001B[49m\u001B[38;5;28;43;01mtry\u001B[39;49;00m\u001B[43m:\u001B[49m\n\u001B[32m 19\u001B[39m \u001B[43m \u001B[49m\u001B[43mjobs\u001B[49m\u001B[43m \u001B[49m\u001B[43m=\u001B[49m\u001B[43m \u001B[49m\u001B[43mjson\u001B[49m\u001B[43m.\u001B[49m\u001B[43mloads\u001B[49m\u001B[43m(\u001B[49m\u001B[43mevent\u001B[49m\u001B[43m.\u001B[49m\u001B[43mdata\u001B[49m\u001B[43m)\u001B[49m\n",
|
|
"\u001B[36mFile \u001B[39m\u001B[32m~/PycharmProjects/aaredb/.venv/lib/python3.12/site-packages/sseclient/__init__.py:55\u001B[39m, in \u001B[36mSSEClient.events\u001B[39m\u001B[34m(self)\u001B[39m\n\u001B[32m 54\u001B[39m \u001B[38;5;28;01mdef\u001B[39;00m\u001B[38;5;250m \u001B[39m\u001B[34mevents\u001B[39m(\u001B[38;5;28mself\u001B[39m):\n\u001B[32m---> \u001B[39m\u001B[32m55\u001B[39m \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[43m.\u001B[49m\u001B[43m_read\u001B[49m\u001B[43m(\u001B[49m\u001B[43m)\u001B[49m\u001B[43m:\u001B[49m\n\u001B[32m 56\u001B[39m \u001B[43m \u001B[49m\u001B[43mevent\u001B[49m\u001B[43m \u001B[49m\u001B[43m=\u001B[49m\u001B[43m \u001B[49m\u001B[43mEvent\u001B[49m\u001B[43m(\u001B[49m\u001B[43m)\u001B[49m\n\u001B[32m 57\u001B[39m \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",
|
|
"\u001B[36mFile \u001B[39m\u001B[32m~/PycharmProjects/aaredb/.venv/lib/python3.12/site-packages/sseclient/__init__.py:45\u001B[39m, in \u001B[36mSSEClient._read\u001B[39m\u001B[34m(self)\u001B[39m\n\u001B[32m 38\u001B[39m \u001B[38;5;250m\u001B[39m\u001B[33;03m\"\"\"Read the incoming event source stream and yield event chunks.\u001B[39;00m\n\u001B[32m 39\u001B[39m \n\u001B[32m 40\u001B[39m \u001B[33;03mUnfortunately it is possible for some servers to decide to break an\u001B[39;00m\n\u001B[32m 41\u001B[39m \u001B[33;03mevent into multiple HTTP chunks in the response. It is thus necessary\u001B[39;00m\n\u001B[32m 42\u001B[39m \u001B[33;03mto correctly stitch together consecutive response chunks and find the\u001B[39;00m\n\u001B[32m 43\u001B[39m \u001B[33;03mSSE delimiter (empty new line) to yield full, correct event chunks.\"\"\"\u001B[39;00m\n\u001B[32m 44\u001B[39m data = \u001B[33mb\u001B[39m\u001B[33m'\u001B[39m\u001B[33m'\u001B[39m\n\u001B[32m---> \u001B[39m\u001B[32m45\u001B[39m \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[43m.\u001B[49m\u001B[43m_event_source\u001B[49m\u001B[43m:\u001B[49m\n\u001B[32m 46\u001B[39m \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[43m.\u001B[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[32m 47\u001B[39m \u001B[43m \u001B[49m\u001B[43mdata\u001B[49m\u001B[43m \u001B[49m\u001B[43m+\u001B[49m\u001B[43m=\u001B[49m\u001B[43m \u001B[49m\u001B[43mline\u001B[49m\n",
|
|
"\u001B[36mFile \u001B[39m\u001B[32m~/PycharmProjects/aaredb/.venv/lib/python3.12/site-packages/requests/models.py:820\u001B[39m, in \u001B[36mResponse.iter_content.<locals>.generate\u001B[39m\u001B[34m()\u001B[39m\n\u001B[32m 818\u001B[39m \u001B[38;5;28;01mif\u001B[39;00m \u001B[38;5;28mhasattr\u001B[39m(\u001B[38;5;28mself\u001B[39m.raw, \u001B[33m\"\u001B[39m\u001B[33mstream\u001B[39m\u001B[33m\"\u001B[39m):\n\u001B[32m 819\u001B[39m \u001B[38;5;28;01mtry\u001B[39;00m:\n\u001B[32m--> \u001B[39m\u001B[32m820\u001B[39m \u001B[38;5;28;01myield from\u001B[39;00m \u001B[38;5;28mself\u001B[39m.raw.stream(chunk_size, decode_content=\u001B[38;5;28;01mTrue\u001B[39;00m)\n\u001B[32m 821\u001B[39m \u001B[38;5;28;01mexcept\u001B[39;00m ProtocolError \u001B[38;5;28;01mas\u001B[39;00m e:\n\u001B[32m 822\u001B[39m \u001B[38;5;28;01mraise\u001B[39;00m ChunkedEncodingError(e)\n",
|
|
"\u001B[36mFile \u001B[39m\u001B[32m~/PycharmProjects/aaredb/.venv/lib/python3.12/site-packages/urllib3/response.py:1063\u001B[39m, in \u001B[36mHTTPResponse.stream\u001B[39m\u001B[34m(self, amt, decode_content)\u001B[39m\n\u001B[32m 1047\u001B[39m \u001B[38;5;250m\u001B[39m\u001B[33;03m\"\"\"\u001B[39;00m\n\u001B[32m 1048\u001B[39m \u001B[33;03mA generator wrapper for the read() method. A call will block until\u001B[39;00m\n\u001B[32m 1049\u001B[39m \u001B[33;03m``amt`` bytes have been read from the connection or until the\u001B[39;00m\n\u001B[32m (...)\u001B[39m\u001B[32m 1060\u001B[39m \u001B[33;03m 'content-encoding' header.\u001B[39;00m\n\u001B[32m 1061\u001B[39m \u001B[33;03m\"\"\"\u001B[39;00m\n\u001B[32m 1062\u001B[39m \u001B[38;5;28;01mif\u001B[39;00m \u001B[38;5;28mself\u001B[39m.chunked \u001B[38;5;129;01mand\u001B[39;00m \u001B[38;5;28mself\u001B[39m.supports_chunked_reads():\n\u001B[32m-> \u001B[39m\u001B[32m1063\u001B[39m \u001B[38;5;28;01myield from\u001B[39;00m \u001B[38;5;28mself\u001B[39m.read_chunked(amt, decode_content=decode_content)\n\u001B[32m 1064\u001B[39m \u001B[38;5;28;01melse\u001B[39;00m:\n\u001B[32m 1065\u001B[39m \u001B[38;5;28;01mwhile\u001B[39;00m \u001B[38;5;129;01mnot\u001B[39;00m is_fp_closed(\u001B[38;5;28mself\u001B[39m._fp) \u001B[38;5;129;01mor\u001B[39;00m \u001B[38;5;28mlen\u001B[39m(\u001B[38;5;28mself\u001B[39m._decoded_buffer) > \u001B[32m0\u001B[39m:\n",
|
|
"\u001B[36mFile \u001B[39m\u001B[32m~/PycharmProjects/aaredb/.venv/lib/python3.12/site-packages/urllib3/response.py:1219\u001B[39m, in \u001B[36mHTTPResponse.read_chunked\u001B[39m\u001B[34m(self, amt, decode_content)\u001B[39m\n\u001B[32m 1216\u001B[39m amt = \u001B[38;5;28;01mNone\u001B[39;00m\n\u001B[32m 1218\u001B[39m \u001B[38;5;28;01mwhile\u001B[39;00m \u001B[38;5;28;01mTrue\u001B[39;00m:\n\u001B[32m-> \u001B[39m\u001B[32m1219\u001B[39m \u001B[38;5;28;43mself\u001B[39;49m\u001B[43m.\u001B[49m\u001B[43m_update_chunk_length\u001B[49m\u001B[43m(\u001B[49m\u001B[43m)\u001B[49m\n\u001B[32m 1220\u001B[39m \u001B[38;5;28;01mif\u001B[39;00m \u001B[38;5;28mself\u001B[39m.chunk_left == \u001B[32m0\u001B[39m:\n\u001B[32m 1221\u001B[39m \u001B[38;5;28;01mbreak\u001B[39;00m\n",
|
|
"\u001B[36mFile \u001B[39m\u001B[32m~/PycharmProjects/aaredb/.venv/lib/python3.12/site-packages/urllib3/response.py:1138\u001B[39m, in \u001B[36mHTTPResponse._update_chunk_length\u001B[39m\u001B[34m(self)\u001B[39m\n\u001B[32m 1136\u001B[39m \u001B[38;5;28;01mif\u001B[39;00m \u001B[38;5;28mself\u001B[39m.chunk_left \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[32m 1137\u001B[39m \u001B[38;5;28;01mreturn\u001B[39;00m \u001B[38;5;28;01mNone\u001B[39;00m\n\u001B[32m-> \u001B[39m\u001B[32m1138\u001B[39m line = \u001B[38;5;28;43mself\u001B[39;49m\u001B[43m.\u001B[49m\u001B[43m_fp\u001B[49m\u001B[43m.\u001B[49m\u001B[43mfp\u001B[49m\u001B[43m.\u001B[49m\u001B[43mreadline\u001B[49m\u001B[43m(\u001B[49m\u001B[43m)\u001B[49m \u001B[38;5;66;03m# type: ignore[union-attr]\u001B[39;00m\n\u001B[32m 1139\u001B[39m line = line.split(\u001B[33mb\u001B[39m\u001B[33m\"\u001B[39m\u001B[33m;\u001B[39m\u001B[33m\"\u001B[39m, \u001B[32m1\u001B[39m)[\u001B[32m0\u001B[39m]\n\u001B[32m 1140\u001B[39m \u001B[38;5;28;01mtry\u001B[39;00m:\n",
|
|
"\u001B[36mFile \u001B[39m\u001B[32m~/anaconda3/lib/python3.12/socket.py:720\u001B[39m, in \u001B[36mSocketIO.readinto\u001B[39m\u001B[34m(self, b)\u001B[39m\n\u001B[32m 718\u001B[39m \u001B[38;5;28;01mwhile\u001B[39;00m \u001B[38;5;28;01mTrue\u001B[39;00m:\n\u001B[32m 719\u001B[39m \u001B[38;5;28;01mtry\u001B[39;00m:\n\u001B[32m--> \u001B[39m\u001B[32m720\u001B[39m \u001B[38;5;28;01mreturn\u001B[39;00m \u001B[38;5;28;43mself\u001B[39;49m\u001B[43m.\u001B[49m\u001B[43m_sock\u001B[49m\u001B[43m.\u001B[49m\u001B[43mrecv_into\u001B[49m\u001B[43m(\u001B[49m\u001B[43mb\u001B[49m\u001B[43m)\u001B[49m\n\u001B[32m 721\u001B[39m \u001B[38;5;28;01mexcept\u001B[39;00m timeout:\n\u001B[32m 722\u001B[39m \u001B[38;5;28mself\u001B[39m._timeout_occurred = \u001B[38;5;28;01mTrue\u001B[39;00m\n",
|
|
"\u001B[36mFile \u001B[39m\u001B[32m~/anaconda3/lib/python3.12/ssl.py:1251\u001B[39m, in \u001B[36mSSLSocket.recv_into\u001B[39m\u001B[34m(self, buffer, nbytes, flags)\u001B[39m\n\u001B[32m 1247\u001B[39m \u001B[38;5;28;01mif\u001B[39;00m flags != \u001B[32m0\u001B[39m:\n\u001B[32m 1248\u001B[39m \u001B[38;5;28;01mraise\u001B[39;00m \u001B[38;5;167;01mValueError\u001B[39;00m(\n\u001B[32m 1249\u001B[39m \u001B[33m\"\u001B[39m\u001B[33mnon-zero flags not allowed in calls to recv_into() on \u001B[39m\u001B[38;5;132;01m%s\u001B[39;00m\u001B[33m\"\u001B[39m %\n\u001B[32m 1250\u001B[39m \u001B[38;5;28mself\u001B[39m.\u001B[34m__class__\u001B[39m)\n\u001B[32m-> \u001B[39m\u001B[32m1251\u001B[39m \u001B[38;5;28;01mreturn\u001B[39;00m \u001B[38;5;28;43mself\u001B[39;49m\u001B[43m.\u001B[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[32m 1252\u001B[39m \u001B[38;5;28;01melse\u001B[39;00m:\n\u001B[32m 1253\u001B[39m \u001B[38;5;28;01mreturn\u001B[39;00m \u001B[38;5;28msuper\u001B[39m().recv_into(buffer, nbytes, flags)\n",
|
|
"\u001B[36mFile \u001B[39m\u001B[32m~/anaconda3/lib/python3.12/ssl.py:1103\u001B[39m, in \u001B[36mSSLSocket.read\u001B[39m\u001B[34m(self, len, buffer)\u001B[39m\n\u001B[32m 1101\u001B[39m \u001B[38;5;28;01mtry\u001B[39;00m:\n\u001B[32m 1102\u001B[39m \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[32m-> \u001B[39m\u001B[32m1103\u001B[39m \u001B[38;5;28;01mreturn\u001B[39;00m \u001B[38;5;28;43mself\u001B[39;49m\u001B[43m.\u001B[49m\u001B[43m_sslobj\u001B[49m\u001B[43m.\u001B[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[32m 1104\u001B[39m \u001B[38;5;28;01melse\u001B[39;00m:\n\u001B[32m 1105\u001B[39m \u001B[38;5;28;01mreturn\u001B[39;00m \u001B[38;5;28mself\u001B[39m._sslobj.read(\u001B[38;5;28mlen\u001B[39m)\n",
|
|
"\u001B[31mKeyboardInterrupt\u001B[39m: "
|
|
]
|
|
}
|
|
],
|
|
"execution_count": 3
|
|
}
|
|
],
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"display_name": "Python 3",
|
|
"language": "python",
|
|
"name": "python3"
|
|
},
|
|
"language_info": {
|
|
"codemirror_mode": {
|
|
"name": "ipython",
|
|
"version": 2
|
|
},
|
|
"file_extension": ".py",
|
|
"mimetype": "text/x-python",
|
|
"name": "python",
|
|
"nbconvert_exporter": "python",
|
|
"pygments_lexer": "ipython2",
|
|
"version": "2.7.6"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 5
|
|
}
|