From 4800240b67ae7095d296a9ff5d37931227ec97c5 Mon Sep 17 00:00:00 2001
From: stedif <stefano.difrischia@inaf.it>
Date: Mon, 11 Apr 2022 18:27:34 +0200
Subject: [PATCH] L2SS-630: fix statistics client functions

---
 .../clients/statistics_client.py              | 25 +++++++++++--------
 1 file changed, 14 insertions(+), 11 deletions(-)

diff --git a/tangostationcontrol/tangostationcontrol/clients/statistics_client.py b/tangostationcontrol/tangostationcontrol/clients/statistics_client.py
index 2075f2f6a..6981c31a5 100644
--- a/tangostationcontrol/tangostationcontrol/clients/statistics_client.py
+++ b/tangostationcontrol/tangostationcontrol/clients/statistics_client.py
@@ -97,7 +97,7 @@ class StatisticsClient(AsyncCommClient):
         # redirect to right object. this works as long as the parameter names are unique among them.
         if annotation["type"] == "statistics":
             def read_function():
-                process_statistics_annotation(annotation, attribute, parameter)
+                return _process_statistics_annotation()
         elif annotation["type"] == "udp":
             def read_function():
                 return self.udp.parameters[parameter]
@@ -111,17 +111,10 @@ class StatisticsClient(AsyncCommClient):
             else:
                 raise ValueError(f"Unknown queue parameter requested: {parameter}")
         elif annotation["type"] == "replicator":
-            parameters_dict = {"clients":           numpy.array(self.tcp.clients(),dtype=numpy.str),
-                            "nof_bytes_sent":       numpy.uint64(self.tcp.nof_bytes_sent),
-                            "nof_packets_sent":     numpy.uint64(self.tcp.nof_packets_sent),
-                            "nof_tasks_pending":    numpy.uint64(self.tcp.nof_tasks_pending)}
-            for k,v in parameters_dict.items():
-                if parameter == k:
-                    def read_function():
-                        return v
-            raise ValueError(f"Unknown replicator parameter requested: {parameter}")
+            def read_function():
+                return _process_replicator_annotation()
 
-        def process_statistics_annotation(annotation, attribute, parameter):
+        def _process_statistics_annotation():
             if annotation.get("reshape", False):
                 # force array into the shape of the attribute
                 if attribute.dim_y > 1:
@@ -131,6 +124,16 @@ class StatisticsClient(AsyncCommClient):
             else:
                 return self.collector.parameters[parameter]
         
+        def _process_replicator_annotation():
+            parameters_dict = {"clients":           numpy.array(self.tcp.clients(),dtype=numpy.str),
+                            "nof_bytes_sent":       numpy.uint64(self.tcp.nof_bytes_sent),
+                            "nof_packets_sent":     numpy.uint64(self.tcp.nof_packets_sent),
+                            "nof_tasks_pending":    numpy.uint64(self.tcp.nof_tasks_pending)}
+            for k,v in parameters_dict.items():
+                if parameter == k:
+                    return v
+            raise ValueError(f"Unknown replicator parameter requested: {parameter}")
+        
         def write_function(value):
             """
             Not used here
-- 
GitLab