Spaces:
Runtime error
Runtime error
add application file
Browse files- app.py +75 -0
- requirements.txt +45 -0
app.py
ADDED
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
+
import numpy as np
|
4 |
+
import requests
|
5 |
+
import time
|
6 |
+
|
7 |
+
st.set_page_config(
|
8 |
+
page_title="Real-Time IoT",
|
9 |
+
page_icon="β
",
|
10 |
+
layout="wide",
|
11 |
+
)
|
12 |
+
|
13 |
+
st.title("Iot Data")
|
14 |
+
|
15 |
+
DATA_URL = 'https://trace.vfsc.vn/iot/xxx'
|
16 |
+
|
17 |
+
# def stream():
|
18 |
+
# s = requests.Session()
|
19 |
+
# with requests.get(DATA_URL, headers=None, stream=True, params={"items":160}) as response:
|
20 |
+
# # print(response.status_code)
|
21 |
+
# for line in response.iter_lines():
|
22 |
+
# if line: print(line)
|
23 |
+
# # print(line.decode('utf-8')['data'])
|
24 |
+
|
25 |
+
# stream()
|
26 |
+
|
27 |
+
|
28 |
+
def load_data(n):
|
29 |
+
print(n)
|
30 |
+
response = requests.get(DATA_URL, params = {"items": n})
|
31 |
+
|
32 |
+
plan = response.json()['plan']
|
33 |
+
data = response.json()['data']
|
34 |
+
|
35 |
+
return data
|
36 |
+
|
37 |
+
df = pd.DataFrame.from_dict(load_data(1))
|
38 |
+
df.rename({'Lat' : 'LAT', 'Lng' : 'LON'}, axis='columns', inplace=True)
|
39 |
+
|
40 |
+
|
41 |
+
if "count" not in st.session_state:
|
42 |
+
st.session_state['count'] = 1
|
43 |
+
|
44 |
+
|
45 |
+
col1, col2 = st.columns(2)
|
46 |
+
|
47 |
+
graph_type = "Bar"
|
48 |
+
data_col = "STemp"
|
49 |
+
|
50 |
+
|
51 |
+
with col1:
|
52 |
+
data_col = st.selectbox(
|
53 |
+
"Choose column to plot",
|
54 |
+
[col for col in df.columns if col.lower() in "upt, batv, solv, stemp, moment".split(", ")],
|
55 |
+
)
|
56 |
+
|
57 |
+
# st.checkbox("Disable selectbox widget", key="disabled")
|
58 |
+
graph_type = st.radio(
|
59 |
+
"Choose graph type π",
|
60 |
+
('Bar', 'Line'),
|
61 |
+
)
|
62 |
+
|
63 |
+
with col2:
|
64 |
+
placeholder = st.empty()
|
65 |
+
while True:
|
66 |
+
df = pd.DataFrame.from_dict(load_data(st.session_state["count"]))
|
67 |
+
df.rename({'Lat' : 'LAT', 'Lng' : 'LON'}, axis='columns', inplace=True)
|
68 |
+
with placeholder.container():
|
69 |
+
st.map(df)
|
70 |
+
if graph_type == 'Line':
|
71 |
+
st.line_chart(df[data_col])
|
72 |
+
elif graph_type == 'Bar':
|
73 |
+
st.bar_chart(df[data_col])
|
74 |
+
time.sleep(3)
|
75 |
+
st.session_state["count"] += 1
|
requirements.txt
ADDED
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
altair==4.2.0
|
2 |
+
attrs==22.2.0
|
3 |
+
blinker==1.5
|
4 |
+
cachetools==5.2.0
|
5 |
+
certifi==2022.12.7
|
6 |
+
charset-normalizer==2.1.1
|
7 |
+
click==8.1.3
|
8 |
+
commonmark==0.9.1
|
9 |
+
decorator==5.1.1
|
10 |
+
entrypoints==0.4
|
11 |
+
gitdb==4.0.10
|
12 |
+
GitPython==3.1.29
|
13 |
+
idna==3.4
|
14 |
+
importlib-metadata==5.2.0
|
15 |
+
Jinja2==3.1.2
|
16 |
+
jsonschema==4.17.3
|
17 |
+
MarkupSafe==2.1.1
|
18 |
+
numpy==1.24.1
|
19 |
+
packaging==22.0
|
20 |
+
pandas==1.5.2
|
21 |
+
Pillow==9.3.0
|
22 |
+
protobuf==3.20.3
|
23 |
+
pyarrow==10.0.1
|
24 |
+
pydeck==0.8.0
|
25 |
+
Pygments==2.13.0
|
26 |
+
Pympler==1.0.1
|
27 |
+
pyrsistent==0.19.2
|
28 |
+
python-dateutil==2.8.2
|
29 |
+
pytz==2022.7
|
30 |
+
pytz-deprecation-shim==0.1.0.post0
|
31 |
+
requests==2.28.1
|
32 |
+
rich==12.6.0
|
33 |
+
semver==2.13.0
|
34 |
+
six==1.16.0
|
35 |
+
smmap==5.0.0
|
36 |
+
streamlit==1.16.0
|
37 |
+
toml==0.10.2
|
38 |
+
toolz==0.12.0
|
39 |
+
tornado==6.2
|
40 |
+
typing_extensions==4.4.0
|
41 |
+
tzdata==2022.7
|
42 |
+
tzlocal==4.2
|
43 |
+
urllib3==1.26.13
|
44 |
+
validators==0.20.0
|
45 |
+
zipp==3.11.0
|