Spaces:
Runtime error
Runtime error
unfix
Browse files
app.py
CHANGED
|
@@ -4,7 +4,8 @@ import numpy as np
|
|
| 4 |
import requests
|
| 5 |
import time
|
| 6 |
from datetime import datetime
|
| 7 |
-
import
|
|
|
|
| 8 |
|
| 9 |
st.set_page_config(
|
| 10 |
page_title="Real-Time IoT",
|
|
@@ -38,16 +39,16 @@ def load_data(n):
|
|
| 38 |
|
| 39 |
def is_duplicate(s):
|
| 40 |
# st.write(s)
|
| 41 |
-
|
|
|
|
| 42 |
check_candidate = (s["Id"], s["Time"])
|
| 43 |
res = check_candidate in st.session_state["duplicates"]
|
| 44 |
-
|
| 45 |
-
else:
|
| 46 |
-
st.session_state["duplicates"] = set()
|
| 47 |
return res
|
| 48 |
|
| 49 |
-
|
| 50 |
-
|
|
|
|
| 51 |
|
| 52 |
df = pd.DataFrame.from_dict(load_data(10))
|
| 53 |
df.rename({'Lat' : 'lat', 'Lng' : 'lon'}, axis='columns', inplace=True)
|
|
@@ -77,13 +78,19 @@ with col2:
|
|
| 77 |
# new_df = pd.DataFrame.from_dict(load_data(st.session_state["count"]))
|
| 78 |
# new_df.rename({'Lat' : 'lat', 'Lng' : 'lon'}, axis='columns', inplace=True)
|
| 79 |
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
|
| 88 |
# df = pd.concat([df, pd.DataFrame(new_ele)])
|
| 89 |
|
|
@@ -99,9 +106,8 @@ with col2:
|
|
| 99 |
st.line_chart(chart_data)
|
| 100 |
elif graph_type == 'Bar':
|
| 101 |
st.bar_chart(chart_data)
|
| 102 |
-
# st.bar_chart(chart_data["data"], y = chart_data["label"])
|
| 103 |
# st.map(df)
|
| 104 |
st.write(df)
|
| 105 |
-
time.sleep(
|
| 106 |
# st.write(st.session_state)
|
| 107 |
# st.session_state["count"] += 1
|
|
|
|
| 4 |
import requests
|
| 5 |
import time
|
| 6 |
from datetime import datetime
|
| 7 |
+
from timeit import default_timer as timer
|
| 8 |
+
from datetime import timedelta
|
| 9 |
|
| 10 |
st.set_page_config(
|
| 11 |
page_title="Real-Time IoT",
|
|
|
|
| 39 |
|
| 40 |
def is_duplicate(s):
|
| 41 |
# st.write(s)
|
| 42 |
+
res = False
|
| 43 |
+
if "duplicates" in st.session_state:
|
| 44 |
check_candidate = (s["Id"], s["Time"])
|
| 45 |
res = check_candidate in st.session_state["duplicates"]
|
| 46 |
+
st.session_state["duplicates"].add(check_candidate)
|
|
|
|
|
|
|
| 47 |
return res
|
| 48 |
|
| 49 |
+
if 'time' not in st.session_state:
|
| 50 |
+
st.session_state['time'] = timer()
|
| 51 |
+
|
| 52 |
|
| 53 |
df = pd.DataFrame.from_dict(load_data(10))
|
| 54 |
df.rename({'Lat' : 'lat', 'Lng' : 'lon'}, axis='columns', inplace=True)
|
|
|
|
| 78 |
# new_df = pd.DataFrame.from_dict(load_data(st.session_state["count"]))
|
| 79 |
# new_df.rename({'Lat' : 'lat', 'Lng' : 'lon'}, axis='columns', inplace=True)
|
| 80 |
|
| 81 |
+
curr_time = timer()
|
| 82 |
+
|
| 83 |
+
# st.write(timedelta(seconds = curr_time - st.session_state['time']))
|
| 84 |
+
if curr_time - st.session_state['time'] >= 2:
|
| 85 |
+
st.write("Passed")
|
| 86 |
+
new_data = pd.DataFrame.from_dict(load_data(0)).rename({'Lat' : 'lat', 'Lng' : 'lon'}, axis='columns').iloc[-1]
|
| 87 |
+
# print(df.iloc[-1]["Id"], new_data["Id"])
|
| 88 |
+
if is_duplicate(new_data):
|
| 89 |
+
pass
|
| 90 |
+
# st.write("Dup")
|
| 91 |
+
else:
|
| 92 |
+
df.loc[len(df)] = new_data
|
| 93 |
+
st.session_state['time'] = curr_time
|
| 94 |
|
| 95 |
# df = pd.concat([df, pd.DataFrame(new_ele)])
|
| 96 |
|
|
|
|
| 106 |
st.line_chart(chart_data)
|
| 107 |
elif graph_type == 'Bar':
|
| 108 |
st.bar_chart(chart_data)
|
|
|
|
| 109 |
# st.map(df)
|
| 110 |
st.write(df)
|
| 111 |
+
# time.sleep(15)
|
| 112 |
# st.write(st.session_state)
|
| 113 |
# st.session_state["count"] += 1
|