move traffic stats calculation to observer

Signed-off-by: Csaba Kiraly <csaba.kiraly@gmail.com>
This commit is contained in:
Csaba Kiraly 2023-03-20 14:26:42 +01:00
parent 119777787e
commit 6616cc799f
No known key found for this signature in database
GPG Key ID: 0FE274EE8C95166E
2 changed files with 16 additions and 7 deletions

View File

@ -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)

View File

@ -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()