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.
This commit is contained in:
parent
6825421f20
commit
3d804c1635
@ -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,
|
||||
)
|
||||
|
@ -461,7 +461,7 @@ const LogisticsView: React.FC = () => {
|
||||
<Typography variant="body2">{`Occupied: ${selectedSlotData.occupied ? 'Yes' : 'No'}`}</Typography>
|
||||
<Typography variant="body2">{`Needs Refill: ${selectedSlotData.needsRefillWarning ? 'Yes' : 'No'}`}</Typography>
|
||||
<Typography variant="body2">{`Time Until Refill: ${selectedSlotData.time_until_refill ?? 'N/A'}`}</Typography>
|
||||
<Typography variant="body2">{`Retrieved Timestamp: ${formatTimestamp(selectedSlotData.retrievedTimestamp)}`}</Typography>
|
||||
<Typography variant="body2">{`Last Event: ${formatTimestamp(selectedSlotData.retrievedTimestamp)}`}</Typography>
|
||||
<Typography variant="body2">{`Local Contact: ${selectedSlotData.local_contact}`}</Typography>
|
||||
<Typography variant="body2">{`Beamline Location: ${selectedSlotData.beamlineLocation || 'N/A'}`}</Typography>
|
||||
</DetailPanel>
|
||||
|
Loading…
x
Reference in New Issue
Block a user