Skip to content

Commit dd83d94

Browse files
committed
ft-analyzer calculate mbps and pps after other metrics
1 parent c78bfca commit dd83d94

1 file changed

Lines changed: 13 additions & 16 deletions

File tree

tools/ft-analyzer/ftanalyzer/models/statistical_model.py

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,9 @@ def validate(
349349
rule.segment,
350350
value,
351351
reference,
352-
abs(np.int64(value) - np.int64(reference)) / reference,
352+
round(
353+
abs(np.int64(value) - np.int64(reference)) / reference, 4
354+
),
353355
)
354356
)
355357

@@ -435,32 +437,20 @@ def _validate_helper(
435437
) / 1000
436438

437439
for metric in rule.metrics:
438-
is_rate = False
439440
match metric.key:
440441
case SMMetricType.FLOWS:
441442
value = len(flows.index)
442443
case SMMetricType.MBPS:
443-
value = (
444-
flows[SMMetricType.BYTES.value].sum()
445-
/ duration
446-
/ pow(10, 6)
447-
)
448-
is_rate = True
444+
value = 0 # later calculated
449445
case SMMetricType.PPS:
450-
value = flows[SMMetricType.PACKETS.value].sum() / duration
451-
is_rate = True
446+
value = 0 # later calculated
452447
case SMMetricType.DURATION:
453448
value = duration
454449
case _:
455450
value = flows[metric.key.value].sum()
456451

457452
if metric.key in values_dict:
458-
if not is_rate:
459-
values_dict[metric.key] += value
460-
else:
461-
values_dict[metric.key] = (
462-
values_dict[metric.key] + value
463-
) / 2
453+
values_dict[metric.key] += value
464454
else:
465455
values_dict[metric.key] = value
466456

@@ -469,6 +459,13 @@ def _validate_helper(
469459
else:
470460
values[i] = values_dict
471461

462+
for values_dict in values:
463+
duration = values_dict[SMMetricType.DURATION]
464+
values_dict[SMMetricType.MBPS] = (
465+
values_dict[SMMetricType.BYTES] / duration / 10**6
466+
)
467+
values_dict[SMMetricType.PPS] = values_dict[SMMetricType.PACKETS] / duration
468+
472469
return values, all_flow_masks
473470

474471
def _filter_multicast(self, flows: pd.DataFrame):

0 commit comments

Comments
 (0)