Skip to content
Snippets Groups Projects
Commit 90fc794c authored by Stefano Di Frischia's avatar Stefano Di Frischia
Browse files

L2SS-630: refactor statistics_client

parent 4654e584
No related branches found
No related tags found
1 merge request!296Resolve L2SS-630 "Refactor functions graded c"
...@@ -97,14 +97,7 @@ class StatisticsClient(AsyncCommClient): ...@@ -97,14 +97,7 @@ class StatisticsClient(AsyncCommClient):
# redirect to right object. this works as long as the parameter names are unique among them. # redirect to right object. this works as long as the parameter names are unique among them.
if annotation["type"] == "statistics": if annotation["type"] == "statistics":
def read_function(): def read_function():
if annotation.get("reshape", False): process_statistics_annotation(self, annotation, attribute, parameter)
# 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]
elif annotation["type"] == "udp": elif annotation["type"] == "udp":
def read_function(): def read_function():
return self.udp.parameters[parameter] return self.udp.parameters[parameter]
...@@ -118,21 +111,26 @@ class StatisticsClient(AsyncCommClient): ...@@ -118,21 +111,26 @@ class StatisticsClient(AsyncCommClient):
else: else:
raise ValueError(f"Unknown queue parameter requested: {parameter}") raise ValueError(f"Unknown queue parameter requested: {parameter}")
elif annotation["type"] == "replicator": elif annotation["type"] == "replicator":
if parameter == "clients": parameters_dict = {"clients": numpy.array(self.tcp.clients(),dtype=numpy.str),
def read_function(): "nof_bytes_sent": numpy.uint64(self.tcp.nof_bytes_sent),
return numpy.array(self.tcp.clients(),dtype=numpy.str) "nof_packets_sent": numpy.uint64(self.tcp.nof_packets_sent),
elif parameter == "nof_bytes_sent": "nof_tasks_pending": numpy.uint64(self.tcp.nof_tasks_pending)}
def read_function(): for k,v in parameters_dict.items():
return numpy.uint64(self.tcp.nof_bytes_sent) if parameter == k:
elif parameter == "nof_packets_sent":
def read_function():
return numpy.uint64(self.tcp.nof_packets_sent)
elif parameter == "nof_tasks_pending":
def read_function(): def read_function():
return numpy.uint64(self.tcp.nof_tasks_pending) return v
else:
raise ValueError(f"Unknown replicator parameter requested: {parameter}") 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:
return self.collector.parameters[parameter]
def write_function(value): def write_function(value):
""" """
Not used here Not used here
...@@ -140,3 +138,4 @@ class StatisticsClient(AsyncCommClient): ...@@ -140,3 +138,4 @@ class StatisticsClient(AsyncCommClient):
pass pass
return read_function, write_function return read_function, write_function
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment