Skip to content

Commit 2872349

Browse files
committed
extensive logging
1 parent ac01c06 commit 2872349

2 files changed

Lines changed: 63 additions & 2 deletions

File tree

src/opentrons_resources.py

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,44 +31,66 @@ def parse_logfile(self, ot_log):
3131
if not log_path.exists():
3232
raise FileNotFoundError(f"Log file not found: {log_path}")
3333

34+
self.logger.log("Log File" + log_path + " Grabbed")
3435
with open(log_path, 'r') as file:
3536
ot_log = json.load(file)
3637

38+
self.logger.log(ot_log)
39+
3740
#two passes, one for all "load labware" commands, and one for all actions
3841

42+
self.logger.log("Processing setup commands")
3943
self.process_setup_commands(ot_log)
40-
44+
self.logger.log("Processing protocol commands")
4145
self.process_protocol_commands(ot_log)
4246

4347
def process_setup_commands(self, ot_log):
4448
"""process setup commands (loadLabware, loadPipette)"""
4549
commands = ot_log.get('commands', {}).get('data', [])
50+
self.logger.log("COMMANDS")
51+
self.logger.log(commands)
4652

4753
for command in commands:
4854
cmd_type = command.get('commandType')
55+
self.logger.log("COMMAND")
56+
self.logger.log(command)
57+
self.logger.log("COMMAND TYPE")
58+
self.logger.log(cmd_type)
4959

5060
if cmd_type == 'loadLabware':
61+
self.logger.log("LOADING LABWARE")
5162
self.load_labware(command, ot_log)
5263
elif cmd_type == 'loadPipette':
64+
self.logger.log("LAODING PIPETTE")
5365
self.load_pipette(command, ot_log)
5466

5567

5668

5769
def process_protocol_commands(self, ot_log):
5870
"""process protocol actions"""
5971
commands = ot_log.get('commands', {}).get('data', [])
72+
self.logger.log("COMMANDS")
73+
self.logger.log(commands)
6074

6175
for command in commands:
6276
cmd_type = command.get('commandType')
77+
self.logger.log("COMMAND")
78+
self.logger.log(command)
79+
self.logger.log("COMMAND TYPE")
80+
self.logger.log(cmd_type)
6381

6482
try:
6583
if cmd_type == 'pickUpTip':
6684
self.pick_up_tip(command, ot_log)
85+
self.logger.log("PICKING UP TIP")
6786
elif cmd_type == 'aspirate':
87+
self.logger.log("ASPIRATING")
6888
self.aspirate(command, ot_log)
6989
elif cmd_type == 'dispense':
90+
self.logger.log("DISPENSING")
7091
self.dispense(command, ot_log)
7192
elif cmd_type == 'dropTip':
93+
self.logger.log("DROPPING TIP")
7294
self.drop_tip(command, ot_log)
7395
except Exception as e:
7496
error_msg = f"Error processing {cmd_type} at {command.get('id', 'unknown')}: {str(e)}"
@@ -78,6 +100,9 @@ def load_labware(self, command, ot_log):
78100
"""loads labware, tracks labware present in each deck slot"""
79101
params = command.get('params', {})
80102
result = command.get('result', {})
103+
self.logger.log("LABWARE PARAMS AND RESULT")
104+
self.logger.log("PARAMS", params)
105+
self.logger.log("RESULT", result)
81106

82107
#get labware id
83108
location = params.get('location', {})
@@ -86,23 +111,31 @@ def load_labware(self, command, ot_log):
86111
#string number 1-11
87112
slot_name = location.get('slotName', 'unknown')
88113

114+
self.logger.log("LOCATION, LOADNAME, AND SLOT NAME")
115+
self.logger.log("LOCATION", location)
116+
self.logger.log("LOADNAME", load_name)
117+
self.logger.log("SLOTNAME", slot_name)
118+
89119
#find matching id
90120
labware_id = None
91121
display_name = load_name
92122
for labware in ot_log.get('data', {}).get('labware', []):
93123
if (labware.get('loadName') == load_name and
94124
labware.get('location', {}).get('slotName') == slot_name):
95125
labware_id = labware.get('id')
126+
self.logger.log("MATCHING ID FOUND")
96127
break
97128

98129
if not labware_id:
130+
self.logger.log("MATCHING ID NOT FOUND")
99131
#just in case not found
100132
labware_id = f"labware_{slot_name}_{load_name}"
101133

102134
slot_name = location.get('slotName', 'unknown')
103135

104136

105137
#store info
138+
self.logger.log("STORING LABWARE INFO")
106139
self.labware_id_to_info[labware_id] = {
107140
'load_name': load_name,
108141
'display_name': display_name,
@@ -112,14 +145,21 @@ def load_labware(self, command, ot_log):
112145
}
113146

114147
#get or create labware in deck slot
148+
self.logger.log("LOOK FOR SLOT NAME IN DECK SLOTS")
149+
self.logger.log("SLOT NAME", slot_name)
150+
self.logger.log("DECK SLOTS", self.deck_slots)
115151
if slot_name in self.deck_slots:
152+
self.logger.log("FOUND SLOT RESOURCE", slot_resource)
116153
slot_resource = self.deck_slots[slot_name]
117154
try:
118155
# #check if slot already has labware (child)
119156
# # query for existing labware in slot
120157

121158
# # Grid resource if tip rack
159+
self.logger.log("CHECKING IF RESOURCE IS A TIP RACK")
160+
self.logger.log("LOAD NAME LOWER", load_name.lower())
122161
if 'tip' in load_name.lower():
162+
self.logger.log("IS TIP RACK")
123163
#tip rack always 8x12 grid
124164
# labware_resource = Grid(
125165
# resource_name = f"{self.node_name}_{display_name}_{slot_name}",
@@ -133,18 +173,25 @@ def load_labware(self, command, ot_log):
133173
# }
134174
# )
135175
# labware_resource = self.client.add_resource(labware_resource)
136-
176+
self.logger.log("CREATING TIP RACK RESOURCE FROM TEMPLATE")
177+
self.logger.log("TEMPLATE NAME", load_name)
178+
self.logger.log("RESOURCE NAME", labware_id)
137179
labware_resource = self.client.create_resource_from_template(
138180
template_name = load_name,
139181
resource_name = labware_id
140182
)
141183

142184

143185
#set as child of the deck slot
186+
self.logger.log("LABWARE RESOURCE", labware_resource)
187+
self.logger.log("SETTING LABWARE RESOURCE AS CHILD OF DECK SLOT")
188+
self.logger.log("SLOT RESOURCE", slot_resource)
144189
self.client.set_child(resource=slot_resource, key="labware", child=labware_resource)
145190
self.labware_id_to_resource[labware_id] = labware_resource
146191

147192
elif 'plate' in load_name.lower() or 'well' in load_name.loawer():
193+
self.logger.log("RESOURCE IS A PLATE")
194+
self.logger.log("LOAD NAME LOWER", load_name.lower())
148195
#plate as grid, either 96 or 384
149196
if '96' in load_name:
150197
rows, cols = 8, 12
@@ -166,15 +213,23 @@ def load_labware(self, command, ot_log):
166213
# }
167214
# )
168215
# labware_resource = self.client.add_resource(labware_resource)
216+
self.logger.log("CREATING PLATE RESOURCE FROM TEMPLATE")
217+
self.logger.log("TEMPLATE NAME", load_name)
218+
self.logger.log("RESOURCE NAME", labware_id)
169219
labware_resource = self.client.create_resource_from_template(
170220
template_name = load_name,
171221
resource_name = labware_id
172222
)
223+
224+
self.logger.log("LABWARE RESOURCE", labware_resource)
225+
self.logger.log("SETTING LABWARE RESOURCE AS CHILD OF DECK SLOT")
226+
self.logger.log("SLOT RESOURCE", slot_resource)
173227

174228
self.client.set_child(resource=slot_resource, key="labware", child=labware_resource)
175229
self.labware_id_to_resource[labware_id] = labware_resource
176230

177231
else:
232+
self.logger.log("REGISTERING AS NEITHER PLATE OR TIP RACK")
178233
#TODO: add addional labware types, tuberacks and modules etc, generic container for now
179234
# labware_resource = Container(
180235
# resource_name=f"{self.node_name}_{display_name}_{slot_name}",
@@ -204,6 +259,10 @@ def load_pipette(self, command, ot_log):
204259
params = command.get('params', {})
205260
result = command.get('result', {})
206261

262+
self.logger.log("PIPETTE PARAMS AND RESULT")
263+
self.logger.log("PARAMS", params)
264+
self.logger.log("RESULT", result)
265+
207266
pipette_id = result.get('pipetteId', params.get('pipetteId'))
208267
mount = params.get('mount', 'unknown')
209268
pipette_name = params.get('pipetteName', 'unknown')

src/ot2_rest_node.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ def startup_handler(self) -> None:
4848
# Create templates
4949
self._create_ot2_templates()
5050

51+
#TODO: delete instances if already exist
52+
5153
# Create deck instance
5254
self.deck = self.resource_client.create_resource_from_template(
5355
template_name="ot2_deck",

0 commit comments

Comments
 (0)