{ "cells": [ { "cell_type": "code", "id": "initial_id", "metadata": { "collapsed": true, "ExecuteTime": { "end_time": "2025-01-10T11:42:48.076458Z", "start_time": "2025-01-10T11:42:48.071372Z" } }, "source": [ "import json\n", "import aareDBclient\n", "from aareDBclient.rest import ApiException\n", "from pprint import pprint\n", "from aareDBclient import SamplesApi\n", "from aareDBclient.models import SampleEventCreate, SetTellPosition\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", "configuration.verify_ssl = False # Disable SSL verification\n", "print(dir(SamplesApi))" ], "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0.1.0a18\n", "['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getstate__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_create_sample_event_samples_samples_sample_id_events_post_serialize', '_get_all_pucks_with_samples_and_events_samples_pucks_samples_get_serialize', '_get_last_sample_event_samples_samples_sample_id_events_last_get_serialize', '_get_samples_with_events_samples_puck_id_samples_get_serialize', 'create_sample_event_samples_samples_sample_id_events_post', 'create_sample_event_samples_samples_sample_id_events_post_with_http_info', 'create_sample_event_samples_samples_sample_id_events_post_without_preload_content', 'get_all_pucks_with_samples_and_events_samples_pucks_samples_get', 'get_all_pucks_with_samples_and_events_samples_pucks_samples_get_with_http_info', 'get_all_pucks_with_samples_and_events_samples_pucks_samples_get_without_preload_content', 'get_last_sample_event_samples_samples_sample_id_events_last_get', 'get_last_sample_event_samples_samples_sample_id_events_last_get_with_http_info', 'get_last_sample_event_samples_samples_sample_id_events_last_get_without_preload_content', 'get_samples_with_events_samples_puck_id_samples_get', 'get_samples_with_events_samples_puck_id_samples_get_with_http_info', 'get_samples_with_events_samples_puck_id_samples_get_without_preload_content']\n" ] } ], "execution_count": 8 }, { "metadata": { "ExecuteTime": { "end_time": "2025-01-10T11:42:50.424118Z", "start_time": "2025-01-10T11:42:50.385515Z" } }, "cell_type": "code", "source": [ "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": "bbee7c94bf14000c", "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='CPS-4093', puck_type='unipuck', puck_location_in_dewar=1, dewar_id=1, dewar_name='Dewar_test', user='e16371', samples=None, tell_position='D1'),\n", " PuckWithTellPosition(id=2, puck_name='CPS-4178', puck_type='unipuck', puck_location_in_dewar=2, dewar_id=1, dewar_name='Dewar_test', user='e16371', samples=None, tell_position=None),\n", " PuckWithTellPosition(id=3, puck_name='PSIMX-122', puck_type='unipuck', puck_location_in_dewar=3, dewar_id=1, dewar_name='Dewar_test', user='e16371', samples=None, tell_position=None),\n", " PuckWithTellPosition(id=4, puck_name='E-07', puck_type='unipuck', puck_location_in_dewar=4, dewar_id=1, dewar_name='Dewar_test', user='e16371', samples=None, tell_position=None),\n", " PuckWithTellPosition(id=5, puck_name='CPS-6597', puck_type='unipuck', puck_location_in_dewar=5, dewar_id=1, dewar_name='Dewar_test', user='e16371', samples=None, tell_position=None),\n", " PuckWithTellPosition(id=6, puck_name='PSIMX-078', puck_type='unipuck', puck_location_in_dewar=6, dewar_id=1, dewar_name='Dewar_test', user='e16371', samples=None, tell_position=None),\n", " PuckWithTellPosition(id=7, puck_name='1002', puck_type='unipuck', puck_location_in_dewar=7, dewar_id=1, dewar_name='Dewar_test', user='e16371', samples=None, tell_position=None),\n", " PuckWithTellPosition(id=15, puck_name='PSIMX123', puck_type='unipuck', puck_location_in_dewar=1, dewar_id=4, dewar_name='Huang', user='e16371', samples=None, tell_position=None),\n", " PuckWithTellPosition(id=16, puck_name='PSIMX125', puck_type='unipuck', puck_location_in_dewar=2, dewar_id=4, dewar_name='Huang', user='e16371', samples=None, tell_position=None),\n", " PuckWithTellPosition(id=17, puck_name='PSIMX127', puck_type='unipuck', puck_location_in_dewar=3, dewar_id=4, dewar_name='Huang', user='e16371', samples=None, tell_position=None),\n", " PuckWithTellPosition(id=18, puck_name='PSIMX128', puck_type='unipuck', puck_location_in_dewar=4, dewar_id=4, dewar_name='Huang', user='e16371', samples=None, tell_position=None),\n", " PuckWithTellPosition(id=19, puck_name='PSIMX130', puck_type='unipuck', puck_location_in_dewar=5, dewar_id=4, dewar_name='Huang', user='e16371', samples=None, tell_position=None),\n", " PuckWithTellPosition(id=20, puck_name='PSIMX131', puck_type='unipuck', puck_location_in_dewar=6, dewar_id=4, dewar_name='Huang', user='e16371', samples=None, tell_position=None),\n", " PuckWithTellPosition(id=21, puck_name='PSIMX132', puck_type='unipuck', puck_location_in_dewar=7, dewar_id=4, dewar_name='Huang', user='e16371', 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 'mx-aare-test.psi.ch'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#tls-warnings\n", " warnings.warn(\n" ] } ], "execution_count": 9 }, { "metadata": { "ExecuteTime": { "end_time": "2025-01-09T16:38:00.334741Z", "start_time": "2025-01-09T16:38:00.302589Z" } }, "cell_type": "code", "source": [ "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", " # This part is commented but will be used to attribute a puck to a position of the TELL\n", " # Define the puck ID and payload\n", "\n", " payload = [SetTellPosition(puck_name='CPS-4093', segment='C', puck_in_segment=2),SetTellPosition(puck_name='CPS-4178', segment='C', puck_in_segment=3)]\n", " #payload = []\n", "\n", " try:\n", " # Call the PUT method to update the tell_position\n", " api_response = api_instance.set_tell_positions_pucks_set_tell_positions_put(payload)\n", " print(\"The response of PucksApi->pucks_puck_id_tell_position_put:\\n\")\n", " pprint(api_response)\n", "\n", " except ApiException as e:\n", " print(\"Exception when calling PucksApi->pucks_puck_id_tell_position_put: %s\\n\" % e)" ], "id": "d52d12287dd63299", "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "The response of PucksApi->pucks_puck_id_tell_position_put:\n", "\n", "[{'message': 'The tell_position was updated successfully.',\n", " 'new_position': 'C2',\n", " 'previous_position': None,\n", " 'puck_name': 'CPS-4093',\n", " 'status': 'updated'},\n", " {'message': 'The tell_position was updated successfully.',\n", " 'new_position': 'C3',\n", " 'previous_position': None,\n", " 'puck_name': 'CPS-4178',\n", " 'status': 'updated'}]\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": 36 }, { "metadata": { "ExecuteTime": { "end_time": "2025-01-10T10:17:48.013415Z", "start_time": "2025-01-10T10:17:47.983861Z" } }, "cell_type": "code", "source": [ "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", " all_pucks_response = api_instance.get_pucks_with_tell_position_pucks_with_tell_position_get() # Replace with appropriate method\n", " # Convert the response to a JSON-like string for pretty printing\n", " formatted_response = json.dumps(\n", " [puck.to_dict() for puck in all_pucks_response], # .to_dict() assumes API models can convert to Python dict\n", " indent=4 # Use indentation for readability\n", " )\n", "\n", " print(\"The response of PucksApi->get_all_pucks_in_tell:\\n\")\n", " #print(formatted_response)\n", " for p in all_pucks_response:\n", " print(p.puck_name)\n", "\n", " except ApiException as e:\n", " print(\"Exception when calling PucksApi->get_all_pucks_in_tell: %s\\n\" % e)" ], "id": "95f8c133359945d5", "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "The response of PucksApi->get_all_pucks_in_tell:\n", "\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" ] }, { "ename": "AttributeError", "evalue": "'PuckWithTellPosition' object has no attribute 'sample_id'", "output_type": "error", "traceback": [ "\u001B[0;31m---------------------------------------------------------------------------\u001B[0m", "\u001B[0;31mAttributeError\u001B[0m Traceback (most recent call last)", "Cell \u001B[0;32mIn[7], line 17\u001B[0m\n\u001B[1;32m 15\u001B[0m \u001B[38;5;66;03m#print(formatted_response)\u001B[39;00m\n\u001B[1;32m 16\u001B[0m \u001B[38;5;28;01mfor\u001B[39;00m p \u001B[38;5;129;01min\u001B[39;00m all_pucks_response:\n\u001B[0;32m---> 17\u001B[0m \u001B[38;5;28mprint\u001B[39m(p\u001B[38;5;241m.\u001B[39mpuck_name, \u001B[43mp\u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43msample_id\u001B[49m)\n\u001B[1;32m 19\u001B[0m \u001B[38;5;28;01mexcept\u001B[39;00m ApiException \u001B[38;5;28;01mas\u001B[39;00m e:\n\u001B[1;32m 20\u001B[0m \u001B[38;5;28mprint\u001B[39m(\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mException when calling PucksApi->get_all_pucks_in_tell: \u001B[39m\u001B[38;5;132;01m%s\u001B[39;00m\u001B[38;5;130;01m\\n\u001B[39;00m\u001B[38;5;124m\"\u001B[39m \u001B[38;5;241m%\u001B[39m e)\n", "File \u001B[0;32m/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages/pydantic/main.py:856\u001B[0m, in \u001B[0;36mBaseModel.__getattr__\u001B[0;34m(self, item)\u001B[0m\n\u001B[1;32m 853\u001B[0m \u001B[38;5;28;01mreturn\u001B[39;00m \u001B[38;5;28msuper\u001B[39m()\u001B[38;5;241m.\u001B[39m\u001B[38;5;21m__getattribute__\u001B[39m(item) \u001B[38;5;66;03m# Raises AttributeError if appropriate\u001B[39;00m\n\u001B[1;32m 854\u001B[0m \u001B[38;5;28;01melse\u001B[39;00m:\n\u001B[1;32m 855\u001B[0m \u001B[38;5;66;03m# this is the current error\u001B[39;00m\n\u001B[0;32m--> 856\u001B[0m \u001B[38;5;28;01mraise\u001B[39;00m \u001B[38;5;167;01mAttributeError\u001B[39;00m(\u001B[38;5;124mf\u001B[39m\u001B[38;5;124m'\u001B[39m\u001B[38;5;132;01m{\u001B[39;00m\u001B[38;5;28mtype\u001B[39m(\u001B[38;5;28mself\u001B[39m)\u001B[38;5;241m.\u001B[39m\u001B[38;5;18m__name__\u001B[39m\u001B[38;5;132;01m!r}\u001B[39;00m\u001B[38;5;124m object has no attribute \u001B[39m\u001B[38;5;132;01m{\u001B[39;00mitem\u001B[38;5;132;01m!r}\u001B[39;00m\u001B[38;5;124m'\u001B[39m)\n", "\u001B[0;31mAttributeError\u001B[0m: 'PuckWithTellPosition' object has no attribute 'sample_id'" ] } ], "execution_count": 7 }, { "metadata": { "ExecuteTime": { "end_time": "2025-01-09T19:41:14.264895Z", "start_time": "2025-01-09T19:41:14.245643Z" } }, "cell_type": "code", "source": [ "\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", " # Define the sample ID and event payload using the expected model\n", " sample_id = 261\n", " event_payload = SampleEventCreate(\n", " event_type=\"Failed\" # Replace with actual event type if different\n", " )\n", "\n", " try:\n", " # Post the sample event\n", " api_response = api_instance.create_sample_event_samples_samples_sample_id_events_post(\n", " sample_id=sample_id,\n", " sample_event_create=event_payload # Pass the model instance here\n", " )\n", " print(\"The response of post_sample_event:\\n\")\n", " pprint(api_response)\n", "\n", " except ApiException as e:\n", " print(\"Exception when calling post_sample_event: %s\\n\" % e)\n" ], "id": "ee8abb293096334a", "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "The response of post_sample_event:\n", "\n", "SampleEventResponse(id=418, sample_id=261, event_type='Failed', timestamp=datetime.datetime(2025, 1, 9, 20, 41, 14))\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": 70 }, { "metadata": { "ExecuteTime": { "end_time": "2025-01-10T11:43:57.303671Z", "start_time": "2025-01-10T11:43:57.285551Z" } }, "cell_type": "code", "source": [ "\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(14)\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": "6a808ee09f97ae13", "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "The response of get_last_sample_event:\n", "\n", "SampleEventResponse(id=3, sample_id=14, event_type='Unmounted', timestamp=datetime.datetime(2025, 1, 10, 5, 53, 38))\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 'mx-aare-test.psi.ch'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#tls-warnings\n", " warnings.warn(\n" ] } ], "execution_count": 11 } ], "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 }