From 4654e584425a0f5d62eab0c19d95dc1de93fc4ae Mon Sep 17 00:00:00 2001
From: stedif <stefano.difrischia@inaf.it>
Date: Mon, 4 Apr 2022 16:31:05 +0200
Subject: [PATCH] L2SS-630: refactor statistics_collector

---
 .../devices/sdp/statistics_collector.py          | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/tangostationcontrol/tangostationcontrol/devices/sdp/statistics_collector.py b/tangostationcontrol/tangostationcontrol/devices/sdp/statistics_collector.py
index d8ac93d22..7eeee3869 100644
--- a/tangostationcontrol/tangostationcontrol/devices/sdp/statistics_collector.py
+++ b/tangostationcontrol/tangostationcontrol/devices/sdp/statistics_collector.py
@@ -210,12 +210,7 @@ class XSTCollector(StatisticsCollector):
         assert 0 <= subband_slot < self.MAX_PARALLEL_SUBBANDS, f"Selected slot {subband_slot}, but only have room for {self.MAX_PARALLEL_SUBBANDS}. Existing slots are {self.parameters['xst_subbands']}, processing subband {fields.subband_index}."
 
         # log if we're replacing a subband we were once recording
-        previous_subband_in_slot   = self.parameters["xst_subbands"][subband_slot]
-        if previous_subband_in_slot != fields.subband_index:
-            previous_subband_timestamp = datetime.datetime.fromtimestamp(self.parameters["xst_timestamps"][subband_slot])
-
-            if previous_subband_timestamp.timestamp() > 0:
-                logger.info(f"Stopped recording XSTs for subband {previous_subband_in_slot}. Last data for this subband was received at {previous_subband_timestamp}.")
+        self._log_replacing_subband(subband_slot, fields)
 
         # the payload contains complex values for the block of baselines of size BLOCK_LENGTH x BLOCK_LENGTH
         # starting at baseline first_baseline.
@@ -236,6 +231,15 @@ class XSTCollector(StatisticsCollector):
         self.parameters["xst_subbands"][subband_slot]                = numpy.uint16(fields.subband_index)
         self.parameters["xst_integration_intervals"][subband_slot]   = fields.integration_interval()
 
+    def _log_replacing_subband(self, subband_slot, fields):
+        # log if we're replacing a subband we were once recording
+        previous_subband_in_slot   = self.parameters["xst_subbands"][subband_slot]
+        if previous_subband_in_slot != fields.subband_index:
+            previous_subband_timestamp = datetime.datetime.fromtimestamp(self.parameters["xst_timestamps"][subband_slot])
+
+            if previous_subband_timestamp.timestamp() > 0:
+                logger.info(f"Stopped recording XSTs for subband {previous_subband_in_slot}. Last data for this subband was received at {previous_subband_timestamp}.")
+   
     def xst_values(self, subband_indices = None):
         """ xst_blocks, but as a matrix[len(subband_indices)][MAX_INPUTS][MAX_INPUTS] of complex values.
         
-- 
GitLab