athan37 commited on
Commit
7f00a8d
1 Parent(s): 762f7b9

matplotlib

Browse files
Files changed (2) hide show
  1. app.py +18 -6
  2. requirements.txt +7 -0
app.py CHANGED
@@ -6,6 +6,10 @@ 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",
@@ -82,7 +86,7 @@ with col2:
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):
@@ -94,7 +98,7 @@ with col2:
94
 
95
  # df = pd.concat([df, pd.DataFrame(new_ele)])
96
 
97
- chart_data = pd.DataFrame(
98
  df[data_col].tolist(),
99
  df["moment"].apply(lambda timestr : datetime.strptime(timestr, '%d/%m/%Y %H:%M:%S').time().strftime("%H:%M:%S")).tolist()
100
  )
@@ -102,10 +106,18 @@ with col2:
102
  # chart_data.set_index('date')
103
 
104
  with placeholder.container():
105
- if graph_type == 'Line':
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)
 
6
  from datetime import datetime
7
  from timeit import default_timer as timer
8
  from datetime import timedelta
9
+ import matplotlib.pyplot as plt
10
+ # import warnings
11
+ # warnings.filterwarnings("ignore")
12
+ # import seaborn as sns
13
 
14
  st.set_page_config(
15
  page_title="Real-Time IoT",
 
86
 
87
  # st.write(timedelta(seconds = curr_time - st.session_state['time']))
88
  if curr_time - st.session_state['time'] >= 2:
89
+ # st.write("Passed")
90
  new_data = pd.DataFrame.from_dict(load_data(0)).rename({'Lat' : 'lat', 'Lng' : 'lon'}, axis='columns').iloc[-1]
91
  # print(df.iloc[-1]["Id"], new_data["Id"])
92
  if is_duplicate(new_data):
 
98
 
99
  # df = pd.concat([df, pd.DataFrame(new_ele)])
100
 
101
+ chart_data = (
102
  df[data_col].tolist(),
103
  df["moment"].apply(lambda timestr : datetime.strptime(timestr, '%d/%m/%Y %H:%M:%S').time().strftime("%H:%M:%S")).tolist()
104
  )
 
106
  # chart_data.set_index('date')
107
 
108
  with placeholder.container():
109
+ try:
110
+ fig, ax = plt.subplots()
111
+ plt.rcParams["figure.figsize"] = (20, 8)
112
+ if graph_type == 'Line':
113
+ ax.plot(range(len(chart_data[0])), chart_data[0])
114
+ elif graph_type == 'Bar':
115
+ ax.bar(range(len(chart_data[0])), chart_data[0])
116
+ plt.xticks(range(len(chart_data[0])), chart_data[1])
117
+ # st.bar_chart(chart_data)
118
+ st.pyplot(fig)
119
+ except Exception as e:
120
+ pass
121
  # st.map(df)
122
  st.write(df)
123
  # time.sleep(15)
requirements.txt CHANGED
@@ -6,15 +6,20 @@ 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
@@ -24,12 +29,14 @@ 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
 
6
  charset-normalizer==2.1.1
7
  click==8.1.3
8
  commonmark==0.9.1
9
+ contourpy==1.0.6
10
+ cycler==0.11.0
11
  decorator==5.1.1
12
  entrypoints==0.4
13
+ fonttools==4.38.0
14
  gitdb==4.0.10
15
  GitPython==3.1.29
16
  idna==3.4
17
  importlib-metadata==5.2.0
18
  Jinja2==3.1.2
19
  jsonschema==4.17.3
20
+ kiwisolver==1.4.4
21
  MarkupSafe==2.1.1
22
+ matplotlib==3.6.2
23
  numpy==1.24.1
24
  packaging==22.0
25
  pandas==1.5.2
 
29
  pydeck==0.8.0
30
  Pygments==2.13.0
31
  Pympler==1.0.1
32
+ pyparsing==3.0.9
33
  pyrsistent==0.19.2
34
  python-dateutil==2.8.2
35
  pytz==2022.7
36
  pytz-deprecation-shim==0.1.0.post0
37
  requests==2.28.1
38
  rich==12.6.0
39
+ seaborn==0.12.1
40
  semver==2.13.0
41
  six==1.16.0
42
  smmap==5.0.0