-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAverageComputer.py
More file actions
54 lines (46 loc) · 1.89 KB
/
AverageComputer.py
File metadata and controls
54 lines (46 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import os
import numpy as np
# List of directories containing the files
directories = [
'backups/2xScaleFactor',
'backups/3xScaleFactor',
'backups/10gbps',
'backups/10mbps',
'backups/distributedHeavyTraffic',
'backups/distributedTraffic',
'backups/mainDisruption',
'backups/retransmission',
'backups/retransmissionAll',
'backups/traffic'
]
# Initialize a dictionary to hold the average latency for each directory
average_latencies = {}
# Loop through each directory
for directory in directories:
second_values = []
# Loop through each file in the directory
for filename in os.listdir(directory):
# Check if the file starts with "collector"
if not filename.startswith("collector"):
continue
filepath = os.path.join(directory, filename)
if os.path.isfile(filepath): # Check if it's a file
with open(filepath, 'r') as file:
for line in file:
# Split the line by comma and extract the second value
try:
value = float(line.split(',')[1])
if value < 150:
second_values.append(value)
except (IndexError, ValueError):
print(f"Skipping line in {filename}: {line.strip()}")
# Ensure that second_values is not empty before proceeding
if len(second_values) == 0:
raise ValueError(f"No valid second values were found in the files of {directory}.")
# Calculate the average latency for the directory
average_latency = np.mean(second_values)
average_latencies[directory] = average_latency
# Display the average latencies for each directory
print("Average Latency for each directory:")
for directory, average_latency in average_latencies.items():
print(f"{directory}: {average_latency:.2f} ms")