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