-
Notifications
You must be signed in to change notification settings - Fork 175
/
constructInvariantContextFromRunCommands.ts
140 lines (136 loc) · 4.14 KB
/
constructInvariantContextFromRunCommands.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import {
getModuleType,
getLabwareDefURI,
getPipetteSpecsV2,
} from '@opentrons/shared-data'
import type {
LoadLabwareRunTimeCommand,
RunTimeCommand,
PickUpTipRunTimeCommand,
} from '@opentrons/shared-data'
import type {
InvariantContext,
LabwareEntities,
PipetteEntities,
ModuleEntities,
AdditionalEquipmentEntities,
AdditionalEquipmentName,
} from '../types'
import { uuid } from '.'
export function constructInvariantContextFromRunCommands(
commands: RunTimeCommand[]
): InvariantContext {
return commands.reduce(
(acc: InvariantContext, command: RunTimeCommand) => {
if (command.commandType === 'loadLabware' && command.result != null) {
const result = command.result
const labwareEntities: LabwareEntities = {
...acc.labwareEntities,
[result.labwareId]: {
id: result.labwareId,
labwareDefURI: getLabwareDefURI(result.definition),
def: result.definition,
},
}
return {
...acc,
labwareEntities,
}
} else if (
command.commandType === 'loadModule' &&
command.result != null
) {
const result = command.result
const moduleEntities: ModuleEntities = {
...acc.moduleEntities,
[result.moduleId]: {
id: result.moduleId,
type: getModuleType(command.params.model),
model: command.params.model,
},
}
return {
...acc,
moduleEntities,
}
} else if (
command.commandType === 'loadPipette' &&
command.result != null
) {
const result = command.result
const labwareId =
commands.find(
(c): c is PickUpTipRunTimeCommand =>
c.commandType === 'pickUpTip' &&
c.params.pipetteId === result.pipetteId
)?.params.labwareId ?? null
const matchingCommand =
commands.find(
(c): c is LoadLabwareRunTimeCommand =>
c.commandType === 'loadLabware' &&
c.result != null &&
c.result.labwareId === labwareId
) ?? null
const tiprackLabwareDef =
matchingCommand != null && matchingCommand.result != null
? matchingCommand.result.definition ?? null
: null
const specs: any = getPipetteSpecsV2(command.params.pipetteName)
const pipetteEntities: PipetteEntities = {
...acc.pipetteEntities,
[result.pipetteId]: {
name: command.params.pipetteName,
id: command.params.pipetteId,
tiprackLabwareDef:
tiprackLabwareDef != null ? [tiprackLabwareDef] : [],
tiprackDefURI:
tiprackLabwareDef != null
? [getLabwareDefURI(tiprackLabwareDef)]
: [],
spec: specs,
},
}
return {
...acc,
pipetteEntities,
}
} else if (
command.commandType === 'moveToAddressableArea' ||
command.commandType === 'moveToAddressableAreaForDropTip'
) {
const addressableAreaName = command.params.addressableAreaName
const id = `${uuid()}:${addressableAreaName}`
let name: AdditionalEquipmentName = 'trashBin'
let location
if (addressableAreaName === 'fixedTrash') {
location = '12'
} else if (addressableAreaName.includes('WasteChute')) {
location = 'D3'
name = 'wasteChute'
} else if (addressableAreaName.includes('movableTrash')) {
location = addressableAreaName.split('movableTrash')[1]
}
const additionalEquipmentEntities: AdditionalEquipmentEntities = {
...acc.additionalEquipmentEntities,
[id]: {
name,
id,
location,
},
}
return {
...acc,
additionalEquipmentEntities,
}
}
return acc
},
{
labwareEntities: {},
moduleEntities: {},
pipetteEntities: {},
additionalEquipmentEntities: {},
config: { OT_PD_DISABLE_MODULE_RESTRICTIONS: true },
}
)
}