Add default values to optional fields in SampleUpdate
This commit is contained in:
parent
1e766fa620
commit
d6910411f1
@ -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),
|
Retrieve all pucks with a `tell_position` set (not null),
|
||||||
their associated samples, and the latest `tell_position` value (if any).
|
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
|
# Step 1: Prepare a subquery to fetch the latest event timestamp for each
|
||||||
# puck with a non-null tell_position
|
# 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,
|
PuckEventModel.puck_id,
|
||||||
func.max(PuckEventModel.timestamp).label("latest_timestamp"),
|
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
|
.group_by(PuckEventModel.puck_id) # Group by puck
|
||||||
.subquery()
|
.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
|
# Step 3: Construct the response with pucks and their latest tell_position
|
||||||
results = []
|
results = []
|
||||||
for puck, event, dewar in pucks_with_events:
|
# Debug output for verification
|
||||||
# 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}")
|
print(f"Pucks with Events and Dewars: {pucks_with_events}")
|
||||||
for puck, event, dewar in pucks_with_events:
|
for puck, event, dewar in pucks_with_events:
|
||||||
print(f"Puck: {puck}, Event: {event}, Dewar: {dewar}")
|
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()
|
||||||
|
|
||||||
# Construct the response model
|
# Construct the response model
|
||||||
results.append(
|
results.append(
|
||||||
PuckWithTellPosition(
|
PuckWithTellPosition(
|
||||||
|
@ -661,9 +661,13 @@ class PuckWithTellPosition(BaseModel):
|
|||||||
id: int
|
id: int
|
||||||
puck_name: str
|
puck_name: str
|
||||||
puck_type: str
|
puck_type: str
|
||||||
puck_location_in_dewar: Optional[str]
|
puck_location_in_dewar: Optional[int]
|
||||||
dewar_id: Optional[int]
|
dewar_id: Optional[
|
||||||
dewar_name: Optional[str]
|
int
|
||||||
|
] # was changed to optional but probably needs to be not optional
|
||||||
|
dewar_name: Optional[
|
||||||
|
str
|
||||||
|
] # was changed to optional but probably needs to be not optional
|
||||||
user: str = "e16371"
|
user: str = "e16371"
|
||||||
samples: Optional[List[Sample]] = None
|
samples: Optional[List[Sample]] = None
|
||||||
tell_position: Optional[str]
|
tell_position: Optional[str]
|
||||||
|
3356
testfunctions.ipynb
3356
testfunctions.ipynb
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user