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 7ad8c7a..34f24a3 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 * @@ -168,12 +167,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] + 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, statsTxInSlot[0], statsRxInSlot[0], - mean(statsTxInSlot[1:]), max(statsTxInSlot[1:]), - mean(statsRxInSlot[1:]), max(statsRxInSlot[1:])), extra=self.format) + (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()