Skip to content

Commit 9ad5eb2

Browse files
committed
Iteratively update color flaggs using 'setattr'
1 parent 2d23e57 commit 9ad5eb2

2 files changed

Lines changed: 10 additions & 29 deletions

File tree

src/murfey/server/ispyb.py

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import ispyb
88
import workflows.transport
99
from fastapi import Depends
10-
from ispyb.sqlalchemy import (
10+
from ispyb.sqlalchemy._auto_db_schema import (
1111
Atlas,
1212
AutoProcProgram,
1313
BLSample,
@@ -198,13 +198,8 @@ def do_update_atlas(
198198
atlas.mode = collection_mode or atlas.mode
199199
# Optionally insert colour flags if present
200200
if color_flags:
201-
atlas.hasGrey = color_flags.get("hasGrey")
202-
atlas.hasRed = color_flags.get("hasRed")
203-
atlas.hasGreen = color_flags.get("hasGreen")
204-
atlas.hasBlue = color_flags.get("hasBlue")
205-
atlas.hasCyan = color_flags.get("hasCyan")
206-
atlas.hasYellow = color_flags.get("hasYellow")
207-
atlas.hasMagenta = color_flags.get("hasMagenta")
201+
for col_name, value in color_flags.items():
202+
setattr(atlas, col_name, value)
208203
db.add(atlas)
209204
db.commit()
210205
return {"success": True, "return_value": atlas.atlasId}
@@ -247,16 +242,12 @@ def do_insert_grid_square(
247242
stageLocationX=grid_square_parameters.x_stage_position,
248243
stageLocationY=grid_square_parameters.y_stage_position,
249244
pixelSize=grid_square_parameters.pixel_size,
245+
mode=grid_square_parameters.collection_mode,
250246
)
251247
# Optionally insert colour flags
252248
if color_flags:
253-
record.hasGrey = color_flags.get("hasGrey")
254-
record.hasRed = color_flags.get("hasRed")
255-
record.hasGreen = color_flags.get("hasGreen")
256-
record.hasBlue = color_flags.get("hasBlue")
257-
record.hasCyan = color_flags.get("hasCyan")
258-
record.hasYellow = color_flags.get("hasYellow")
259-
record.hasMagenta = color_flags.get("hasMagenta")
249+
for col_name, value in color_flags.items():
250+
setattr(record, col_name, value)
260251
try:
261252
with ISPyBSession() as db:
262253
db.add(record)
@@ -319,13 +310,8 @@ def do_update_grid_square(
319310
grid_square.mode = grid_square_parameters.collection_mode
320311
# Optionally insert colour flags
321312
if color_flags:
322-
grid_square.hasGrey = color_flags.get("hasGrey")
323-
grid_square.hasRed = color_flags.get("hasRed")
324-
grid_square.hasGreen = color_flags.get("hasGreen")
325-
grid_square.hasBlue = color_flags.get("hasBlue")
326-
grid_square.hasCyan = color_flags.get("hasCyan")
327-
grid_square.hasYellow = color_flags.get("hasYellow")
328-
grid_square.hasMagenta = color_flags.get("hasMagenta")
313+
for col_name, value in color_flags.items():
314+
setattr(grid_square, col_name, value)
329315
db.add(grid_square)
330316
db.commit()
331317
return {"success": True, "return_value": grid_square.gridSquareId}

src/murfey/workflows/register_data_collection_group.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,8 @@ def run(message: dict, murfey_db: SQLModelSession) -> dict[str, bool]:
7171
if collection_mode := message.get("collection_mode"):
7272
atlas_record.mode = collection_mode
7373
if color_flags := message.get("color_flags", {}):
74-
atlas_record.hasGrey = color_flags.get("hasGrey")
75-
atlas_record.hasRed = color_flags.get("hasRed")
76-
atlas_record.hasGreen = color_flags.get("hasGreen")
77-
atlas_record.hasBlue = color_flags.get("hasBlue")
78-
atlas_record.hasCyan = color_flags.get("hasCyan")
79-
atlas_record.hasYellow = color_flags.get("hasYellow")
80-
atlas_record.hasMagenta = color_flags.get("hasMagenta")
74+
for col_name, value in color_flags.items():
75+
setattr(atlas_record, col_name, value)
8176
atlas_id = _transport_object.do_insert_atlas(atlas_record).get(
8277
"return_value", None
8378
)

0 commit comments

Comments
 (0)