-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck.py
More file actions
executable file
·128 lines (104 loc) · 3.15 KB
/
Copy pathcheck.py
File metadata and controls
executable file
·128 lines (104 loc) · 3.15 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#!/usr/bin/env python3
#
# This file is part of the IC2E '23 Celestial demo
# (https://github.com/OpenFogStack/celestial-ic2e-demo).
# Copyright (c) 2023 Tobias Pfandzelter, The OpenFogStack Team.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 3.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
import io
import os
import sys
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.animation as animation
import seaborn as sns
if __name__ == "__main__":
sns.set(rc={"figure.figsize": (9, 3)}, style="whitegrid")
# create a lineplot
fig, ax = plt.subplots()
min_t = 0.0
curr = 0.0
interval = 100
max_measurements = 100
# sats_measurements = pd.DataFrame(columns=["t", "sat", "shell", "rtt"])
interesting_sats = [0, 15, 30, 45, 60]
x = []
y = []
sats = []
for i in interesting_sats:
x += [0, 0.1]
y += [0, 0.1]
sats += [i, i]
sns.lineplot(
x=x,
y=y,
hue=sats,
ax=ax,
)
# put the legend outside
ax.legend(loc="upper center", ncol=5, bbox_to_anchor=(0.5, 1.1))
# add labels
ax.set_xlabel("Time [s]")
ax.set_ylabel("RTT [ms]")
def animate(i: int) -> None:
global x
global y
global sats
global min_t
global curr
global max_measurements
# read from stdin
for line in sys.stdin:
try:
# split the line
t, sat, shell, rtt = line.strip().split(",")
if int(sat) not in interesting_sats:
continue
x.append(float(t) - min_t)
y.append(float(rtt))
sats.append(int(sat))
# lines += line.strip() + "\n"
if float(t) - min_t > curr + (interval / 1000):
curr = float(t) - min_t
# print("break")
break
except:
pass
# cut off old measurements
if len(x) > max_measurements:
x = x[-max_measurements:]
y = y[-max_measurements:]
sats = sats[-max_measurements:]
ax.clear()
print(len(x))
# update the graph
sns.lineplot(
x=x,
y=y,
hue=sats,
legend=False,
ax=ax,
)
while True:
try:
# get the first line
line = sys.stdin.readline()
# split the line
t, sat, shell, rtt = line.strip().split(",")
min_t = float(t)
break
except:
pass
ani = animation.FuncAnimation(fig, animate, interval=interval, save_count=1000)
plt.show()