-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfrontend.py
More file actions
108 lines (93 loc) · 2.94 KB
/
frontend.py
File metadata and controls
108 lines (93 loc) · 2.94 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
import time
import random
import streamlit as st
import pandas as pd
import requests
import datetime
st.set_page_config(layout="wide")
menu = [
"Test",
"Metrics",
"Nodes",
]
page = st.sidebar.selectbox("Menu", menu)
def view_metrics():
st.title('Metrics Dashboard')
# st.write(str(random.randint(3, 9)))
placeholder = st.empty()
try:
d = requests.get('http://127.0.0.1:5000/get_metrics')
except:
st.write("Server is down")
return
metrics = d.json()
with placeholder.container():
for test_id in metrics.keys():
st.subheader(test_id)
df = pd.DataFrame(metrics[test_id])
st.write(df)
def view_nodes():
st.title("Nodes Status")
# st.write(str(random.randint(3, 9)))
placeholder = st.empty()
while True:
try:
d = requests.get(f'http://127.0.0.1:5000/get_nodes')
except:
placeholder = st.empty()
st.write("Server is down")
return
try:
nodes = d.json()
except:
placeholder = st.empty()
continue
with placeholder.container():
for test_id in nodes.keys():
# st.subheader(test_id)
nodes[test_id] = {"Last Updated": datetime.datetime.fromtimestamp(nodes[test_id]['last_updated']), "Node IP":nodes[test_id]['node_IP'], "Status": nodes[test_id]['status']}
# df = pd.DataFrame(node_ans, index=[test_id])
# st.write(df)
df = pd.DataFrame(nodes)
st.write(df)
time.sleep(1)
def results(test_id):
st.title(test_id)
# st.write(str(random.randint(3, 9)))
placeholder = st.empty()
while True:
d = requests.get(f'http://127.0.0.1:5000/get_metrics/{test_id}')
try:
l = d.json()
except:
continue
df = pd.DataFrame(l)
with placeholder.container():
st.write(df)
time.sleep(1)
def req():
st.title('Test Configuration')
col1, col2 = st.columns(2)
with col1:
test_type = st.radio(
"Select Test",
key="visibility",
options=["Avalanche", "Tsunami"],
)
messages = st.number_input("Number of messages per driver", min_value=1, step=1, value=1, key="messages")
if test_type == "Tsunami":
delay = st.number_input("Delay between messages", min_value=1, step=1, value=1, key="delay")
if st.button("Submit"):
if test_type == 'Avalanche':
res = requests.get(f'http://127.0.0.1:5000/avalanche?messages_per_driver={str(messages)}')
else:
res = requests.get(f'http://127.0.0.1:5000/tsunami?delay={str(delay)}&messages_per_driver={str(messages)}')
test_id = res.text
# st.print(test_id)
results(test_id)
if page == "Metrics":
view_metrics()
elif page == "Nodes":
view_nodes()
elif page == "Test":
req()