store summary
This commit is contained in:
@@ -108,6 +108,20 @@ class VideoCaptureInterface(abc.ABC):
|
||||
logger.error(f"Error creating tracker with conf {cfg}: {e}")
|
||||
self._tracker = None
|
||||
|
||||
def _flush_current_well(self, uuid=""):
|
||||
"""Stocke les résumés du puits courant — appelé avant tout changement."""
|
||||
if not self._metrics or not self._params:
|
||||
return
|
||||
for pid, m in enumerate(self._metrics):
|
||||
async_to_sync(self._client.store_summary)(
|
||||
summary = m.summary(),
|
||||
experiment = self._params.experiment,
|
||||
well = self._params.well,
|
||||
planarian = pid,
|
||||
uuid = uuid,
|
||||
)
|
||||
self._metrics_.clear()
|
||||
|
||||
|
||||
def on_well_change(self, cfg, uuid="", draw_contours=False):
|
||||
"""
|
||||
@@ -119,17 +133,9 @@ class VideoCaptureInterface(abc.ABC):
|
||||
return
|
||||
|
||||
# 1. Sauvegarder les résumés du puits qu'on quitte
|
||||
if self._metrics and self._params:
|
||||
for pid, m in enumerate(self._metrics):
|
||||
async_to_sync(self._clientDB.store_summary)(
|
||||
summary = m.summary(),
|
||||
experiment = self._params.experiment,
|
||||
well = self._params.well,
|
||||
planarian = pid,
|
||||
uuid = uuid,
|
||||
)
|
||||
self._flush_current_well(uuid) # ← ferme le puits courant
|
||||
|
||||
# 2. Reconstruire pour le nouveau puits
|
||||
# 2. Reconstruire pour le nouveau puit _metrics_list
|
||||
params = cfg.to_params_dict()
|
||||
self._params = ExperimentParams(params)
|
||||
self._metrics = [self._params.build_metrics() for _ in range(self._params.planarian_count)]
|
||||
@@ -144,6 +150,10 @@ class VideoCaptureInterface(abc.ABC):
|
||||
draw_contours = draw_contours,
|
||||
)
|
||||
|
||||
def on_scan_complete(self):
|
||||
if self.use_tracking:
|
||||
self._flush_current_well() # ← ferme le dernier puits
|
||||
|
||||
def set_draw_contours(self, draw: bool = True):
|
||||
if self._tracker:
|
||||
self._tracker.draw_contours = draw
|
||||
|
||||
@@ -146,19 +146,20 @@ class MultiWellManager:
|
||||
|
||||
#def _grid_scanning_capture(self, uuid, duration):
|
||||
def _grid_scanning_capture(self, experiment, well_position, simulate=False):
|
||||
uuid = None
|
||||
try:
|
||||
well = well_position.well
|
||||
multiwell = experiment.multiwell
|
||||
|
||||
## create uuid for this capture
|
||||
uuid = f'{self.process.data.session}-{multiwell.position}-{well.name}'
|
||||
|
||||
if self.process.use_tracking:
|
||||
cfg = ExperimentConfig.objects.filter(experiment_key_id=experiment.id, well=well.name).first()
|
||||
if not cfg:
|
||||
raise Exception(f"Configuration d'expérience introuvable pour {experiment} / {well}")
|
||||
# reset PlanarianTracker => on_well_change
|
||||
self.process.cam.on_well_change(cfg, draw_contours=False)
|
||||
|
||||
## create uuid for this capture
|
||||
uuid = f'{self.process.data.session}-{multiwell.position}-{well.name}'
|
||||
self.process.cam.on_well_change(cfg, uuid=uuid, raw_contours=False)
|
||||
|
||||
## start recording
|
||||
self.process.data.uuid = uuid
|
||||
@@ -177,6 +178,8 @@ class MultiWellManager:
|
||||
break
|
||||
self.cnc_controller.wait_for(0.1)
|
||||
|
||||
self.process.cam._flush_current_well(uuid)
|
||||
|
||||
self.process.data.record = False
|
||||
self.process.data.uuid = None
|
||||
|
||||
@@ -184,6 +187,8 @@ class MultiWellManager:
|
||||
except Exception as e:
|
||||
msg = f"error during capture - {e}"
|
||||
logger.error(msg)
|
||||
finally:
|
||||
self.process.cam._flush_current_well(uuid)
|
||||
|
||||
logger.info(msg)
|
||||
self.process._send(scan_state=msg)
|
||||
|
||||
Reference in New Issue
Block a user