Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
aaron-kulkarni committed Jul 22, 2024
1 parent 34e15e2 commit 3395c6c
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 10 deletions.
4 changes: 2 additions & 2 deletions api/src/opentrons/protocol_engine/state/state_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
from ..errors import ErrorOccurrence
from ..types import (
EngineStatus,
LiquidHeightSummary,
LoadedLabware,
LabwareOffset,
LoadedModule,
LoadedPipette,
Liquid,
LiquidHeightInfo,
)


Expand All @@ -29,4 +29,4 @@ class StateSummary(BaseModel):
startedAt: Optional[datetime]
completedAt: Optional[datetime]
liquids: List[Liquid] = Field(default_factory=list)
wells: List[LiquidHeightInfo] = Field(default_factory=list)
wells: List[LiquidHeightSummary] = Field(default_factory=list)
35 changes: 27 additions & 8 deletions api/src/opentrons/protocol_engine/state/wells.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
)
from opentrons.protocol_engine.commands.liquid_probe import LiquidProbeResult
from opentrons.protocol_engine.commands.pipetting_common import LiquidNotFoundError
from opentrons.protocol_engine.types import LiquidHeightInfo
from opentrons.protocol_engine.types import LiquidHeightInfo, LiquidHeightSummary

from .abstract_store import HasState, HandlesActions
from ..actions import Action
Expand All @@ -19,7 +19,6 @@
class WellState:
"""State of all wells."""

# Dict[Labware: Dict[Wellname: [Height,TimeRecorded]]]
measured_liquid_heights: Dict[str, Dict[str, LiquidHeightInfo]]


Expand Down Expand Up @@ -82,16 +81,36 @@ def __init__(self, state: WellState) -> None:
"""
self._state = state

def get_all(self) -> List[LiquidHeightInfo]:
def get_all(self) -> List[LiquidHeightSummary]:
"""Get all well liquid heights."""
allHeights = [] # type: List[LiquidHeightInfo]
for val in self._state.measured_liquid_heights.values():
allHeights.extend(a for a in val.values())
allHeights = [] # type: List[LiquidHeightSummary]
# for key, in self._state.measured_liquid_heights.items():
# lhs = LiquidHeightSummary(labware_id=)
# allHeights.extend(a for a in val.values())
# return allHeights
for labware in self._state.measured_liquid_heights.keys():
for well, lhi in self._state.measured_liquid_heights[labware].items():
lhs = LiquidHeightSummary(
labware_id=labware,
well_name=well,
height=lhi.height,
last_measured=lhi.last_measured,
)
allHeights.append(lhs)
return allHeights

def get_all_in_labware(self, labware_id: str) -> List[LiquidHeightInfo]:
def get_all_in_labware(self, labware_id: str) -> List[LiquidHeightSummary]:
"""Get all well liquid heights for a particular labware."""
return list(self._state.measured_liquid_heights[labware_id].values())
allHeights = [] # type: List[LiquidHeightSummary]
for well, lhi in self._state.measured_liquid_heights[labware_id].items():
lhs = LiquidHeightSummary(
labware_id=labware_id,
well_name=well,
height=lhi.height,
last_measured=lhi.last_measured,
)
allHeights.append(lhs)
return allHeights

def get_last_measured_liquid_height(
self, labware_id: str, well_name: str
Expand Down
9 changes: 9 additions & 0 deletions api/src/opentrons/protocol_engine/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,15 @@ class LiquidHeightInfo(BaseModel):
last_measured: datetime


class LiquidHeightSummary(BaseModel):
"""Payload for liquid state height in StateSummary."""

labware_id: str
well_name: str
height: float
last_measured: datetime


@dataclass(frozen=True)
class CurrentAddressableArea:
"""The latest addressable area the robot has accessed."""
Expand Down

0 comments on commit 3395c6c

Please sign in to comment.