Refactor set_tell_positions logic with updated rules.

Revised the set_tell_positions endpoint to handle updated business rules for puck positioning. Improved event handling to ensure proper nullification, updates, and removal of tell_positions based on the provided payload. Enhanced query performance and normalized puck name processing for consistency.
This commit is contained in:
GotthardG 2025-01-09 09:44:59 +01:00
parent 0fdd5e54b7
commit a9cb7a41b0
3 changed files with 8 additions and 2 deletions

View File

@ -338,6 +338,7 @@ async def get_pucks_by_slot(slot_identifier: str, db: Session = Depends(get_db))
)
dewar_ids = [dewar.id for dewar in dewars]
dewar_map = {dewar.id: dewar.dewar_name for dewar in dewars}
# Subquery to fetch the latest tell_position for each puck
subquery = (
@ -380,6 +381,8 @@ async def get_pucks_by_slot(slot_identifier: str, db: Session = Depends(get_db))
f" Tell Position: {tell_position}"
)
dewar_name = dewar_map.get(puck.dewar_id, "Unknown")
# Prepare the PuckWithTellPosition instance
results.append(
PuckWithTellPosition(
@ -390,6 +393,7 @@ async def get_pucks_by_slot(slot_identifier: str, db: Session = Depends(get_db))
if puck.puck_location_in_dewar
else None,
dewar_id=puck.dewar_id,
dewar_name=dewar_name,
tell_position=tell_position, # Latest tell_position from subquery
)
)

View File

@ -478,7 +478,7 @@ class Puck(BaseModel):
puck_location_in_dewar: int
dewar_id: int
events: List[PuckEvent] = []
samples: List[Sample] = [] # List of samples within this puck
samples: List[Sample] = []
class Config:
from_attributes = True
@ -645,6 +645,8 @@ class PuckWithTellPosition(BaseModel):
puck_type: str
puck_location_in_dewar: Optional[str]
dewar_id: int
dewar_name: str
user: str = "e16371"
samples: Optional[List[Sample]] = None
tell_position: Optional[str]

View File

@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
[project]
name = "aareDB"
version = "0.1.0a13"
version = "0.1.0a14"
description = "Backend for next gen sample management system"
authors = [{name = "Guillaume Gotthard", email = "guillaume.gotthard@psi.ch"}]
license = {text = "MIT"}