fixing bugs with ci pipeline

This commit is contained in:
GotthardG
2024-12-16 22:50:04 +01:00
parent e0e176881b
commit 0178de96fd
14 changed files with 145 additions and 96 deletions

View File

@ -34,7 +34,8 @@ def calculate_time_until_refill(
@router.post("/dewars/return", response_model=DewarSchema)
async def return_to_storage(data: LogisticsEventCreate, db: Session = Depends(get_db)):
logger.info(
f"Returning dewar to storage: {data.dewar_qr_code} at location {data.location_qr_code}"
f"Returning dewar to storage: {data.dewar_qr_code}"
f"at location {data.location_qr_code}"
)
try:
@ -57,11 +58,13 @@ async def return_to_storage(data: LogisticsEventCreate, db: Session = Depends(ge
)
if original_slot and original_slot.qr_code != data.location_qr_code:
logger.error(
f"Dewar {data.dewar_qr_code} is associated with slot {original_slot.qr_code}"
f"Dewar {data.dewar_qr_code} is"
f"associated with slot {original_slot.qr_code}"
)
raise HTTPException(
status_code=400,
detail=f"Dewar {data.dewar_qr_code} is associated with a different slot {original_slot.qr_code}.",
detail=f"Dewar {data.dewar_qr_code} is associated"
f"with a different slot {original_slot.qr_code}.",
)
slot = (
@ -87,12 +90,16 @@ async def return_to_storage(data: LogisticsEventCreate, db: Session = Depends(ge
slot.occupied = True
dewar.last_retrieved_timestamp = None
# Set the `at_beamline` attribute to False
dewar.at_beamline = False
# Log the event
log_event(db, dewar.id, slot.id, "returned")
db.commit()
logger.info(
f"Dewar {data.dewar_qr_code} successfully returned to storage slot {slot.qr_code}."
f"Dewar {data.dewar_qr_code} successfully"
f"returned to storage slot {slot.qr_code}."
)
db.refresh(dewar)
return dewar
@ -174,7 +181,8 @@ async def scan_dewar(event_data: LogisticsEventCreate, db: Session = Depends(get
log_event(db, dewar.id, slot.id if slot else None, transaction_type)
db.commit()
logger.info(
f"Transaction completed: {transaction_type} for dewar {dewar_qr_code} in slot {slot.qr_code if slot else 'N/A'}"
f"Transaction completed: {transaction_type}"
f"for dewar {dewar_qr_code} in slot {slot.qr_code if slot else 'N/A'}"
)
return {"message": "Status updated successfully"}
@ -191,7 +199,6 @@ async def get_all_slots(db: Session = Depends(get_db)):
retrievedTimestamp = None
beamlineLocation = None
at_beamline = False
retrieved = False
if slot.dewar_unique_id:
# Calculate time until refill
@ -212,32 +219,32 @@ async def get_all_slots(db: Session = Depends(get_db)):
else:
time_until_refill = -1
# Fetch the latest beamline event
last_beamline_event = (
# Fetch the latest event for the dewar
last_event = (
db.query(LogisticsEventModel)
.join(DewarModel, DewarModel.id == LogisticsEventModel.dewar_id)
.filter(
DewarModel.unique_id == slot.dewar.unique_id,
LogisticsEventModel.event_type == "beamline",
)
.filter(DewarModel.unique_id == slot.dewar.unique_id)
.order_by(LogisticsEventModel.timestamp.desc())
.first()
)
if last_beamline_event:
# Set retrievedTimestamp to the timestamp of the beamline event
retrievedTimestamp = last_beamline_event.timestamp.isoformat()
# Fetch the associated slot's label for beamlineLocation
associated_slot = (
db.query(SlotModel)
.filter(SlotModel.id == last_beamline_event.slot_id)
.first()
)
beamlineLocation = associated_slot.label if associated_slot else None
# Mark as being at a beamline
at_beamline = True
# Determine if the dewar is at the beamline
if last_event:
if last_event.event_type == "beamline":
at_beamline = True
# Optionally set retrievedTimestamp and beamlineLocation for
# beamline events
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
# Correct the contact_person assignment
contact_person = None
@ -296,7 +303,8 @@ async def refill_dewar(qr_code: str, db: Session = Depends(get_db)):
time_until_refill_seconds = calculate_time_until_refill(now)
logger.info(
f"Dewar refilled successfully with time_until_refill: {time_until_refill_seconds}"
f"Dewar refilled successfully"
f"with time_until_refill: {time_until_refill_seconds}"
)
return {
@ -334,5 +342,6 @@ def log_event(db: Session, dewar_id: int, slot_id: Optional[int], event_type: st
db.add(new_event)
db.commit()
logger.info(
f"Logged event: {event_type} for dewar: {dewar_id} in slot: {slot_id if slot_id else 'N/A'}"
f"Logged event: {event_type} for dewar: {dewar_id} "
f"in slot: {slot_id if slot_id else 'N/A'}"
)