fixup: avoid warning on mean if empty

Signed-off-by: Csaba Kiraly <csaba.kiraly@gmail.com>
This commit is contained in:
Csaba Kiraly 2023-03-27 23:27:49 +02:00
parent eb4f451303
commit cb0a3ea1ba
No known key found for this signature in database
GPG Key ID: 0FE274EE8C95166E
1 changed files with 5 additions and 3 deletions

View File

@ -70,6 +70,8 @@ class Observer:
def getTrafficStats(self, validators):
def maxOrNan(l):
return np.max(l) if l else np.NaN
def meanOrNan(l):
return np.mean(l) if l else np.NaN
trafficStats = {}
for cl in range(0,3):
@ -77,9 +79,9 @@ class Observer:
Rx = [v.statsRxInSlot for v in validators if v.nodeClass == cl]
RxDup = [v.statsRxDupInSlot for v in validators if v.nodeClass == cl]
trafficStats[cl] = {
"Tx": {"mean": np.mean(Tx), "max": maxOrNan(Tx)},
"Rx": {"mean": np.mean(Rx), "max": maxOrNan(Rx)},
"RxDup": {"mean": np.mean(RxDup), "max": maxOrNan(RxDup)},
"Tx": {"mean": meanOrNan(Tx), "max": maxOrNan(Tx)},
"Rx": {"mean": meanOrNan(Rx), "max": maxOrNan(Rx)},
"RxDup": {"mean": meanOrNan(RxDup), "max": maxOrNan(RxDup)},
}
return trafficStats