Add default values to optional fields in SampleUpdate

This commit is contained in:
GotthardG
2025-01-10 10:44:03 +01:00
parent 1e766fa620
commit d6910411f1
3 changed files with 47 additions and 3334 deletions

View File

@ -195,6 +195,8 @@ async def get_pucks_with_tell_position(db: Session = Depends(get_db)):
"""
Retrieve all pucks with a `tell_position` set (not null),
their associated samples, and the latest `tell_position` value (if any).
Only include pucks when their latest event has a `tell_position`
set and matches "tell_position_set".
"""
# Step 1: Prepare a subquery to fetch the latest event timestamp for each
# puck with a non-null tell_position
@ -203,9 +205,6 @@ async def get_pucks_with_tell_position(db: Session = Depends(get_db)):
PuckEventModel.puck_id,
func.max(PuckEventModel.timestamp).label("latest_timestamp"),
)
.filter(
PuckEventModel.tell_position.isnot(None)
) # Filter non-null tell_positions
.group_by(PuckEventModel.puck_id) # Group by puck
.subquery()
)
@ -230,13 +229,15 @@ async def get_pucks_with_tell_position(db: Session = Depends(get_db)):
# Step 3: Construct the response with pucks and their latest tell_position
results = []
# Debug output for verification
print(f"Pucks with Events and Dewars: {pucks_with_events}")
for puck, event, dewar in pucks_with_events:
print(f"Puck: {puck}, Event: {event}, Dewar: {dewar}")
if event.tell_position is None:
continue
# Fetch associated samples for this puck
samples = db.query(SampleModel).filter(SampleModel.puck_id == puck.id).all()
# Print fetched data for debugging
print(f"Pucks with Events and Dewars: {pucks_with_events}")
for puck, event, dewar in pucks_with_events:
print(f"Puck: {puck}, Event: {event}, Dewar: {dewar}")
# Construct the response model
results.append(
PuckWithTellPosition(