diff --git a/tangostationcontrol/tangostationcontrol/clients/statistics_client.py b/tangostationcontrol/tangostationcontrol/clients/statistics_client.py index 08d2889d0b61c5bd9c9ce5468e35ac6bf82fdffb..5d11e0d38f7e004b56dd4e0dff846d0d1759b9ad 100644 --- a/tangostationcontrol/tangostationcontrol/clients/statistics_client.py +++ b/tangostationcontrol/tangostationcontrol/clients/statistics_client.py @@ -97,14 +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(): - if annotation.get("reshape", False): - # force array into the shape of the attribute - if attribute.dim_y > 1: - return self.collector.parameters[parameter].reshape(attribute.dim_y, attribute.dim_x) - else: - return self.collector.parameters[parameter].reshape(attribute.dim_x) - else: - return self.collector.parameters[parameter] + process_statistics_annotation(self, annotation, attribute, parameter) elif annotation["type"] == "udp": def read_function(): return self.udp.parameters[parameter] @@ -118,25 +111,31 @@ class StatisticsClient(AsyncCommClient): else: raise ValueError(f"Unknown queue parameter requested: {parameter}") elif annotation["type"] == "replicator": - if parameter == "clients": - def read_function(): - return numpy.array(self.tcp.clients(),dtype=numpy.str) - elif parameter == "nof_bytes_sent": - def read_function(): - return numpy.uint64(self.tcp.nof_bytes_sent) - elif parameter == "nof_packets_sent": - def read_function(): - return numpy.uint64(self.tcp.nof_packets_sent) - elif parameter == "nof_tasks_pending": - def read_function(): - return numpy.uint64(self.tcp.nof_tasks_pending) + 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 process_statistics_annotation(annotation, attribute, parameter): + if annotation.get("reshape", False): + # force array into the shape of the attribute + if attribute.dim_y > 1: + return self.collector.parameters[parameter].reshape(attribute.dim_y, attribute.dim_x) + else: + return self.collector.parameters[parameter].reshape(attribute.dim_x) else: - raise ValueError(f"Unknown replicator parameter requested: {parameter}") - + return self.collector.parameters[parameter] + def write_function(value): """ Not used here """ pass - return read_function, write_function + return read_function, write_function +