From 6616cc799f016a0ead7d1a3b703a414d45938193 Mon Sep 17 00:00:00 2001 From: Csaba Kiraly Date: Mon, 20 Mar 2023 14:26:42 +0100 Subject: [PATCH] move traffic stats calculation to observer Signed-off-by: Csaba Kiraly --- DAS/observer.py | 13 +++++++++++++ DAS/simulator.py | 10 +++------- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/DAS/observer.py b/DAS/observer.py index 0b80638..26b0632 100644 --- a/DAS/observer.py +++ b/DAS/observer.py @@ -1,5 +1,6 @@ #!/bin/python3 +from statistics import mean from DAS.block import * class Observer: @@ -65,3 +66,15 @@ class Observer: validatorProgress = validated / validatorCnt return missingSamples, sampleProgress, nodeProgress, validatorProgress + + def getTrafficStats(self, validators): + statsTxInSlot = [v.statsTxInSlot for v in validators] + statsRxInSlot = [v.statsRxInSlot for v in validators] + TX_prod = statsTxInSlot[0] + RX_prod = statsRxInSlot[0] + TX_avg = mean(statsTxInSlot[1:]) + TX_max = max(statsTxInSlot[1:]) + Rx_avg = mean(statsRxInSlot[1:]) + Rx_max = max(statsRxInSlot[1:]) + + return (TX_prod, RX_prod, TX_avg, TX_max, Rx_avg, Rx_max) diff --git a/DAS/simulator.py b/DAS/simulator.py index 1744bf8..82d9594 100644 --- a/DAS/simulator.py +++ b/DAS/simulator.py @@ -4,7 +4,6 @@ import networkx as nx import logging, random from functools import partial, partialmethod from datetime import datetime -from statistics import mean from DAS.tools import * from DAS.results import * from DAS.observer import * @@ -189,12 +188,9 @@ class Simulator: self.validators[i].logColumns() # log TX and RX statistics - statsTxInSlot = [v.statsTxInSlot for v in self.validators] - statsRxInSlot = [v.statsRxInSlot for v in self.validators] - self.logger.debug("step %d: TX_prod=%.1f, RX_prod=%.1f, TX_avg=%.1f, TX_max=%.1f, Rx_avg=%.1f, Rx_max=%.1f" % - (steps, statsTxInSlot[0], statsRxInSlot[0], - mean(statsTxInSlot[1:]), max(statsTxInSlot[1:]), - mean(statsRxInSlot[1:]), max(statsRxInSlot[1:])), extra=self.format) + TX_prod, RX_prod, TX_avg, TX_max, Rx_avg, Rx_max = self.glob.getTrafficStats(self.validators) + self.logger.debug("step %d: TX_prod=%.1f, RX_prod=%.1f, TX_avg=%.1f, TX_max=%.1f, Rx_avg=%.1f, Rx_max=%.1f" % + (steps, TX_prod, RX_prod, TX_avg, TX_max, Rx_avg, Rx_max), extra=self.format) for i in range(0,self.shape.numberNodes): self.validators[i].updateStats()