From 3d804c16350d9e0eed939d2f726da9a72425dd4d Mon Sep 17 00:00:00 2001
From: GotthardG <51994228+GotthardG@users.noreply.github.com>
Date: Fri, 17 Jan 2025 15:59:49 +0100
Subject: [PATCH] Update logistics data display and dewar event handling
Renamed "Retrieved Timestamp" to "Last Event" for clarity in the UI. Improved backend logic to handle dewar events, including associating refill events with specific slots and retrieving the last slot ID for new events.
---
backend/app/routers/logistics.py | 27 +++++++++++++++++++++++++--
logistics/src/pages/LogisticsView.tsx | 2 +-
2 files changed, 26 insertions(+), 3 deletions(-)
diff --git a/backend/app/routers/logistics.py b/backend/app/routers/logistics.py
index 0ae75a3..faefb8a 100644
--- a/backend/app/routers/logistics.py
+++ b/backend/app/routers/logistics.py
@@ -228,7 +228,6 @@ async def get_all_slots(db: Session = Depends(get_db)):
.first()
)
- # Determine if the dewar is at the beamline
if last_event:
if last_event.event_type == "beamline":
at_beamline = True
@@ -243,6 +242,22 @@ async def get_all_slots(db: Session = Depends(get_db)):
beamlineLocation = (
associated_slot.label if associated_slot else None
)
+ elif last_event.event_type == "refill" and last_event.slot_id in [
+ 47,
+ 48,
+ 49,
+ ]:
+ # Check if last event is a refill and slot_id matches beamline slots
+ at_beamline = True
+ retrievedTimestamp = last_event.timestamp.isoformat()
+ associated_slot = (
+ db.query(SlotModel)
+ .filter(SlotModel.id == last_event.slot_id)
+ .first()
+ )
+ beamlineLocation = (
+ associated_slot.label if associated_slot else None
+ )
elif last_event.event_type == "returned":
at_beamline = False
@@ -291,10 +306,18 @@ async def refill_dewar(qr_code: str, db: Session = Depends(get_db)):
raise HTTPException(status_code=404, detail="Dewar not found")
now = datetime.now()
+ # Retrieve the last associated slot_id for the dewar
+ last_event = (
+ db.query(LogisticsEventModel)
+ .filter(LogisticsEventModel.dewar_id == dewar.id)
+ .order_by(LogisticsEventModel.timestamp.desc())
+ .first()
+ )
+ slot_id = last_event.slot_id if last_event else None
new_event = LogisticsEventModel(
dewar_id=dewar.id,
- slot_id=None,
+ slot_id=slot_id,
event_type="refill",
timestamp=now,
)
diff --git a/logistics/src/pages/LogisticsView.tsx b/logistics/src/pages/LogisticsView.tsx
index 51e1a6b..1c7ae3a 100644
--- a/logistics/src/pages/LogisticsView.tsx
+++ b/logistics/src/pages/LogisticsView.tsx
@@ -461,7 +461,7 @@ const LogisticsView: React.FC = () => {
{`Occupied: ${selectedSlotData.occupied ? 'Yes' : 'No'}`}
{`Needs Refill: ${selectedSlotData.needsRefillWarning ? 'Yes' : 'No'}`}
{`Time Until Refill: ${selectedSlotData.time_until_refill ?? 'N/A'}`}
- {`Retrieved Timestamp: ${formatTimestamp(selectedSlotData.retrievedTimestamp)}`}
+ {`Last Event: ${formatTimestamp(selectedSlotData.retrievedTimestamp)}`}
{`Local Contact: ${selectedSlotData.local_contact}`}
{`Beamline Location: ${selectedSlotData.beamlineLocation || 'N/A'}`}