Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(app): ensure proper API cal data is associated to protocol labware #6280

Merged
merged 1 commit into from
Aug 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions app/src/calibration/labware/__tests__/selectors.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ describe('labware calibration selectors', () => {

it('grabs calibration data for labware if present, rounding to 1 decimal', () => {
getModulesBySlot.mockReturnValue({})

const lwCalibration = Fixtures.mockLabwareCalibration1
const { attributes } = lwCalibration
const { calibrationData } = attributes
Expand All @@ -151,6 +152,7 @@ describe('labware calibration selectors', () => {
loadName: wellPlate96Def.parameters.loadName,
namespace: wellPlate96Def.namespace,
version: wellPlate96Def.version,
parent: '',
calibrationData: {
...calibrationData,
offset: {
Expand Down Expand Up @@ -191,6 +193,7 @@ describe('labware calibration selectors', () => {
...lwCalibration,
attributes: {
...attributes,
parent: '',
loadName: wellPlate96Def.parameters.loadName,
namespace: wellPlate96Def.namespace,
version: wellPlate96Def.version,
Expand Down Expand Up @@ -250,6 +253,77 @@ describe('labware calibration selectors', () => {
])
})

it('grabs calibration data for labware not on module if on-module cal data is present', () => {
const lwCalibration = Fixtures.mockLabwareCalibration1
const { attributes } = lwCalibration
const { calibrationData } = attributes

const calNotOnModule = {
...lwCalibration,
attributes: {
...attributes,
parent: '',
loadName: wellPlate96Def.parameters.loadName,
namespace: wellPlate96Def.namespace,
version: wellPlate96Def.version,
calibrationData: {
...calibrationData,
offset: {
...calibrationData.offset,
value: [1.23, 4.56, 7.89],
},
},
},
}

const calOnModule = {
...lwCalibration,
attributes: {
...attributes,
parent: 'magneticModuleV1',
loadName: wellPlate96Def.parameters.loadName,
namespace: wellPlate96Def.namespace,
version: wellPlate96Def.version,
calibrationData: {
...calibrationData,
offset: {
...calibrationData.offset,
value: [0, 0, 0],
},
},
},
}

getModulesBySlot.mockReturnValue({})

state = ({
calibration: {
robotName: {
calibrationStatus: null,
labwareCalibrations: {
meta: {},
data: [calOnModule, calNotOnModule],
},
},
},
}: $Shape<State>)

expect(Selectors.getProtocolLabwareList(state, robotName)).toEqual([
{
displayName: wellPlate96Def.metadata.displayName,
parentDisplayName: null,
quantity: 1,
calibration: { x: 1.2, y: 4.6, z: 7.9 },
},
{
displayName: 'some_v1_labware',
parentDisplayName: null,
quantity: 1,
calibration: null,
},
])
})

it('flattens out duplicate labware using quantity field', () => {
getLabware.mockReturnValue([
({
Expand Down
37 changes: 21 additions & 16 deletions app/src/calibration/labware/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { selectors as robotSelectors } from '../../robot'

import type { LabwareDefinition2, ModuleModel } from '@opentrons/shared-data'
import type { State } from '../../types'
import type { LabwareCalibrationModel } from './../types'
import type { LabwareCalibration, LabwareCalibrationModel } from './../types'
import type { LabwareSummary } from './types'

export const getLabwareCalibrations = (
Expand Down Expand Up @@ -70,25 +70,30 @@ export const getProtocolLabwareList: (
const { definition: def, loadName, namespace, version, parent } = lw
const displayName = def ? getLabwareDisplayName(def) : loadName
const parentDisplayName = parent ? getModuleDisplayName(parent) : null
const matchesLabwareIdentityForQuantity = target =>
target.loadName === loadName &&
target.namespace === namespace &&
target.version === version &&
target.parent === parent
const matchesLabwareIdentity = (
compare: LabwareCalibration | BaseProtocolLabware
) => {
// target may be an internal protocol labware or API calibration data
// internal protocol labware model uses null for no parent
// API calibration model uses empty string for no parent
// normalize to null to do the comparison
const compareParent =
compare.parent === '' || compare.parent === null
? null
: compare.parent

const quantity = baseLabwareList.filter(matchesLabwareIdentityForQuantity)
.length
return (
loadName === compare.loadName &&
namespace === compare.namespace &&
version === compare.version &&
parent === compareParent
)
}

const matchesLabwareIdentityForCalibration = target =>
target.loadName === loadName &&
target.namespace === namespace &&
target.version === version &&
(parent === null || target.parent === parent)
const quantity = baseLabwareList.filter(matchesLabwareIdentity).length

const calData = calibrations
.filter(({ attributes }) =>
matchesLabwareIdentityForCalibration(attributes)
)
.filter(({ attributes }) => matchesLabwareIdentity(attributes))
.map(({ attributes }) => {
const calVector = attributes.calibrationData.offset.value.map(n =>
round(n, 1)
Expand Down