-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanalyze-data.py
More file actions
executable file
·68 lines (57 loc) · 1.89 KB
/
analyze-data.py
File metadata and controls
executable file
·68 lines (57 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import matplotlib.pyplot as plt
import datetime
import re
# Initialize lists to hold the data
timestamps = []
pings = []
downloads = []
uploads = []
# Open and read the log file
with open('log/wifi_speed.log', 'r') as file:
for line in file:
# Skip empty lines
if not line.strip():
continue
# Check for error lines and skip them
if 'Error' in line:
continue
try:
# Use regex to extract data
match = re.match(r'(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}), Ping: ([\d.]+) ms, Download: ([\d.]+) Mbit/s, Upload: ([\d.]+) Mbit/s', line)
if match:
timestamp_str = match.group(1)
ping = float(match.group(2))
download = float(match.group(3))
upload = float(match.group(4))
# Convert timestamp string to datetime object
timestamp = datetime.datetime.strptime(timestamp_str, '%Y-%m-%d %H:%M:%S')
# Append data to lists
timestamps.append(timestamp)
pings.append(ping)
downloads.append(download)
uploads.append(upload)
except Exception as e:
print(f"Error parsing line: {line}")
print(e)
# Plotting
plt.figure(figsize=(15, 10))
# Plot Ping
plt.subplot(3, 1, 1)
plt.plot(timestamps, pings, marker='o', linestyle='-', color='blue')
plt.title('Internet Speed Over Time')
plt.ylabel('Ping (ms)')
plt.grid(True)
# Plot Download Speed
plt.subplot(3, 1, 2)
plt.plot(timestamps, downloads, marker='o', linestyle='-', color='green')
plt.ylabel('Download Speed (Mbit/s)')
plt.grid(True)
# Plot Upload Speed
plt.subplot(3, 1, 3)
plt.plot(timestamps, uploads, marker='o', linestyle='-', color='red')
plt.xlabel('Time')
plt.ylabel('Upload Speed (Mbit/s)')
plt.grid(True)
plt.tight_layout()
plt.show()
plt.savefig('wifi_speed_over_time.png')