Fix type and handle missing dewar_id in sample router.

Updated puck_id type from str to int for better type consistency. Added a fallback value of -1 for pucks with missing dewar_id to prevent potential errors when querying pucks.
This commit is contained in:
GotthardG 2025-01-10 13:39:10 +01:00
parent fa99e3fa63
commit 19ef20e6b0
3 changed files with 33 additions and 24 deletions

View File

@ -22,7 +22,7 @@ router = APIRouter()
@router.get("/{puck_id}/samples", response_model=List[SampleSchema]) @router.get("/{puck_id}/samples", response_model=List[SampleSchema])
async def get_samples_with_events(puck_id: str, db: Session = Depends(get_db)): async def get_samples_with_events(puck_id: int, db: Session = Depends(get_db)):
puck = db.query(PuckModel).filter(PuckModel.id == puck_id).first() puck = db.query(PuckModel).filter(PuckModel.id == puck_id).first()
if not puck: if not puck:
raise HTTPException(status_code=404, detail="Puck not found") raise HTTPException(status_code=404, detail="Puck not found")
@ -46,6 +46,8 @@ async def get_all_pucks_with_samples_and_events(db: Session = Depends(get_db)):
pucks = db.query(PuckModel).all() pucks = db.query(PuckModel).all()
logging.info(f"Found {len(pucks)} pucks in the database") logging.info(f"Found {len(pucks)} pucks in the database")
for puck in pucks: for puck in pucks:
if puck.dewar_id is None:
puck.dewar_id = -1
logging.info(f"Puck ID: {puck.id}, Name: {puck.puck_name}") logging.info(f"Puck ID: {puck.id}, Name: {puck.puck_name}")
if not pucks: if not pucks:

View File

@ -32,7 +32,7 @@ const SampleTracker: React.FC = () => {
const fetchPucks = async () => { const fetchPucks = async () => {
try { try {
const data: Puck[] = await SamplesService.getAllPucksWithSamplesAndEventsSamplesPucksSamplesGet(); const data: Puck[] = await SamplesService.getAllPucksWithSamplesAndEventsSamplesPucksSamplesGet();
console.log(data); // Log the data to inspect it console.log(data);
setPucks(data); setPucks(data);
} catch (error) { } catch (error) {
console.error("Error fetching pucks", error); console.error("Error fetching pucks", error);

View File

@ -6,8 +6,8 @@
"metadata": { "metadata": {
"collapsed": true, "collapsed": true,
"ExecuteTime": { "ExecuteTime": {
"end_time": "2025-01-10T10:16:49.228369Z", "end_time": "2025-01-10T11:42:48.076458Z",
"start_time": "2025-01-10T10:16:49.224212Z" "start_time": "2025-01-10T11:42:48.071372Z"
} }
}, },
"source": [ "source": [
@ -21,8 +21,8 @@
"print(aareDBclient.__version__)\n", "print(aareDBclient.__version__)\n",
"\n", "\n",
"configuration = aareDBclient.Configuration(\n", "configuration = aareDBclient.Configuration(\n",
" #host = \"https://mx-aare-test.psi.ch:1492\"\n", " host = \"https://mx-aare-test.psi.ch:1492\"\n",
" host = \"https://127.0.0.1:8000\"\n", " #host = \"https://127.0.0.1:8000\"\n",
")\n", ")\n",
"\n", "\n",
"configuration.verify_ssl = False # Disable SSL verification\n", "configuration.verify_ssl = False # Disable SSL verification\n",
@ -38,13 +38,13 @@
] ]
} }
], ],
"execution_count": 3 "execution_count": 8
}, },
{ {
"metadata": { "metadata": {
"ExecuteTime": { "ExecuteTime": {
"end_time": "2025-01-10T10:16:52.480280Z", "end_time": "2025-01-10T11:42:50.424118Z",
"start_time": "2025-01-10T10:16:52.454958Z" "start_time": "2025-01-10T11:42:50.385515Z"
} }
}, },
"cell_type": "code", "cell_type": "code",
@ -71,25 +71,32 @@
"text": [ "text": [
"The response of PucksApi->get_pucks_by_slot_pucks_slot_slot_identifier_get:\n", "The response of PucksApi->get_pucks_by_slot_pucks_slot_slot_identifier_get:\n",
"\n", "\n",
"[PuckWithTellPosition(id=31, puck_name='CPS-4093', puck_type='unipuck', puck_location_in_dewar=1, dewar_id=6, dewar_name='Dewar_test', user='e16371', samples=None, tell_position='C2'),\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=32, puck_name='CPS-4178', puck_type='unipuck', puck_location_in_dewar=2, dewar_id=6, dewar_name='Dewar_test', user='e16371', samples=None, tell_position='C3'),\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=33, puck_name='PSIMX-122', puck_type='unipuck', puck_location_in_dewar=3, dewar_id=6, 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=34, puck_name='E-07', puck_type='unipuck', puck_location_in_dewar=4, dewar_id=6, 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=35, puck_name='CPS-6597', puck_type='unipuck', puck_location_in_dewar=5, dewar_id=6, 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=36, puck_name='PSIMX-078', puck_type='unipuck', puck_location_in_dewar=6, dewar_id=6, 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=37, puck_name='1002', puck_type='unipuck', puck_location_in_dewar=7, dewar_id=6, 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", "name": "stderr",
"output_type": "stream", "output_type": "stream",
"text": [ "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", "/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" " warnings.warn(\n"
] ]
} }
], ],
"execution_count": 4 "execution_count": 9
}, },
{ {
"metadata": { "metadata": {
@ -271,8 +278,8 @@
{ {
"metadata": { "metadata": {
"ExecuteTime": { "ExecuteTime": {
"end_time": "2025-01-09T19:41:23.052434Z", "end_time": "2025-01-10T11:43:57.303671Z",
"start_time": "2025-01-09T19:41:23.036108Z" "start_time": "2025-01-10T11:43:57.285551Z"
} }
}, },
"cell_type": "code", "cell_type": "code",
@ -284,7 +291,7 @@
"\n", "\n",
" try:\n", " try:\n",
" # Get the last sample event\n", " # Get the last sample event\n",
" last_event_response = api_instance.get_last_sample_event_samples_samples_sample_id_events_last_get(261)\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", " print(\"The response of get_last_sample_event:\\n\")\n",
" pprint(last_event_response)\n", " pprint(last_event_response)\n",
"\n", "\n",
@ -299,19 +306,19 @@
"text": [ "text": [
"The response of get_last_sample_event:\n", "The response of get_last_sample_event:\n",
"\n", "\n",
"SampleEventResponse(id=418, sample_id=261, event_type='Failed', timestamp=datetime.datetime(2025, 1, 9, 20, 41, 14))\n" "SampleEventResponse(id=3, sample_id=14, event_type='Unmounted', timestamp=datetime.datetime(2025, 1, 10, 5, 53, 38))\n"
] ]
}, },
{ {
"name": "stderr", "name": "stderr",
"output_type": "stream", "output_type": "stream",
"text": [ "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", "/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" " warnings.warn(\n"
] ]
} }
], ],
"execution_count": 71 "execution_count": 11
} }
], ],
"metadata": { "metadata": {