echons commited on
Commit
c145d80
1 Parent(s): 37c08f2

first commit

Browse files
Files changed (3) hide show
  1. .gitignore +160 -0
  2. app.py +366 -0
  3. credentials.yaml +22 -0
.gitignore ADDED
@@ -0,0 +1,160 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py,cover
50
+ .hypothesis/
51
+ .pytest_cache/
52
+ cover/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ .pybuilder/
76
+ target/
77
+
78
+ # Jupyter Notebook
79
+ .ipynb_checkpoints
80
+
81
+ # IPython
82
+ profile_default/
83
+ ipython_config.py
84
+
85
+ # pyenv
86
+ # For a library or package, you might want to ignore these files since the code is
87
+ # intended to run in multiple environments; otherwise, check them in:
88
+ # .python-version
89
+
90
+ # pipenv
91
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
93
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
94
+ # install all needed dependencies.
95
+ #Pipfile.lock
96
+
97
+ # poetry
98
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
99
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
100
+ # commonly ignored for libraries.
101
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
102
+ #poetry.lock
103
+
104
+ # pdm
105
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
106
+ #pdm.lock
107
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
108
+ # in version control.
109
+ # https://pdm.fming.dev/#use-with-ide
110
+ .pdm.toml
111
+
112
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
113
+ __pypackages__/
114
+
115
+ # Celery stuff
116
+ celerybeat-schedule
117
+ celerybeat.pid
118
+
119
+ # SageMath parsed files
120
+ *.sage.py
121
+
122
+ # Environments
123
+ .env
124
+ .venv
125
+ env/
126
+ venv/
127
+ ENV/
128
+ env.bak/
129
+ venv.bak/
130
+
131
+ # Spyder project settings
132
+ .spyderproject
133
+ .spyproject
134
+
135
+ # Rope project settings
136
+ .ropeproject
137
+
138
+ # mkdocs documentation
139
+ /site
140
+
141
+ # mypy
142
+ .mypy_cache/
143
+ .dmypy.json
144
+ dmypy.json
145
+
146
+ # Pyre type checker
147
+ .pyre/
148
+
149
+ # pytype static type analyzer
150
+ .pytype/
151
+
152
+ # Cython debug symbols
153
+ cython_debug/
154
+
155
+ # PyCharm
156
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
157
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
158
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
159
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
160
+ #.idea/
app.py ADDED
@@ -0,0 +1,366 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import plotly.express as px
3
+ import pandas as pd
4
+ import streamlit_authenticator as stauth
5
+ import yaml
6
+ from yaml.loader import SafeLoader
7
+
8
+ # from langchain.chat_models import ChatAnthropic
9
+ # from langchain.callbacks.base import BaseCallbackHandler
10
+ # from langchain.prompts import PromptTemplate
11
+ # from langchain.chains import LLMChain
12
+
13
+
14
+ # Function to fetch simulated fly situation data
15
+ def get_fly_situation(canteen):
16
+ if canteen == "Deck":
17
+ # Sample fly situation data
18
+ fly_situation = {
19
+ "temperature": 28,
20
+ "humidity": 60,
21
+ "fly_count": 9,
22
+ "last_updated": "2023-11-10 12:00:00"
23
+ }
24
+ delta1 = '0.2'
25
+ delta2 = '2'
26
+ delta3 = '1'
27
+ elif canteen == "Frontier":
28
+ # Sample fly situation data
29
+ fly_situation = {
30
+ "temperature": 28.1,
31
+ "humidity": 62,
32
+ "fly_count": 21,
33
+ "last_updated": "2023-11-10 12:00:00"
34
+ }
35
+ delta1 = '0.1'
36
+ delta2 = '1'
37
+ delta3 = '3'
38
+ return fly_situation, delta1, delta2, delta3
39
+
40
+ # Function to generate a sample fly situation dataset with time series
41
+ def get_fly_situation_history(canteen):
42
+ if canteen == "Deck":
43
+ # Sample fly situation time series data
44
+ fly_situation_history = [
45
+ {"timestamp": "2023-11-10 11:00:00", "fly_count": 2, "sensor":1},
46
+ {"timestamp": "2023-11-10 11:05:00", "fly_count": 1, "sensor": 1},
47
+ {"timestamp": "2023-11-10 11:10:00", "fly_count": 2, "sensor": 1},
48
+ {"timestamp": "2023-11-10 11:15:00", "fly_count": 2, "sensor": 1},
49
+ {"timestamp": "2023-11-10 11:20:00", "fly_count": 3, "sensor": 1},
50
+ {"timestamp": "2023-11-10 11:25:00", "fly_count": 1, "sensor": 1},
51
+ {"timestamp": "2023-11-10 11:30:00", "fly_count": 2, "sensor": 1},
52
+ {"timestamp": "2023-11-10 11:35:00", "fly_count": 1, "sensor": 1},
53
+ {"timestamp": "2023-11-10 11:40:00", "fly_count": 3, "sensor": 1},
54
+ {"timestamp": "2023-11-10 11:45:00", "fly_count": 1, "sensor": 1},
55
+ {"timestamp": "2023-11-10 11:50:00", "fly_count": 2, "sensor": 1},
56
+ {"timestamp": "2023-11-10 11:55:00", "fly_count": 3, "sensor": 1},
57
+ {"timestamp": "2023-11-10 12:00:00", "fly_count": 1, "sensor": 1},
58
+ {"timestamp": "2023-11-10 11:00:00", "fly_count": 1, "sensor": 2},
59
+ {"timestamp": "2023-11-10 11:05:00", "fly_count": 2, "sensor": 2},
60
+ {"timestamp": "2023-11-10 11:10:00", "fly_count": 3, "sensor": 2},
61
+ {"timestamp": "2023-11-10 11:15:00", "fly_count": 1, "sensor": 2},
62
+ {"timestamp": "2023-11-10 11:20:00", "fly_count": 2, "sensor": 2},
63
+ {"timestamp": "2023-11-10 11:25:00", "fly_count": 2, "sensor": 2},
64
+ {"timestamp": "2023-11-10 11:30:00", "fly_count": 1, "sensor": 2},
65
+ {"timestamp": "2023-11-10 11:35:00", "fly_count": 3, "sensor": 2},
66
+ {"timestamp": "2023-11-10 11:40:00", "fly_count": 2, "sensor": 2},
67
+ {"timestamp": "2023-11-10 11:45:00", "fly_count": 1, "sensor": 2},
68
+ {"timestamp": "2023-11-10 11:50:00", "fly_count": 3, "sensor": 2},
69
+ {"timestamp": "2023-11-10 11:55:00", "fly_count": 2, "sensor": 2},
70
+ {"timestamp": "2023-11-10 12:00:00", "fly_count": 2, "sensor": 2},
71
+ {"timestamp": "2023-11-10 11:00:00", "fly_count": 3, "sensor": 3},
72
+ {"timestamp": "2023-11-10 11:05:00", "fly_count": 1, "sensor": 3},
73
+ {"timestamp": "2023-11-10 11:10:00", "fly_count": 2, "sensor": 3},
74
+ {"timestamp": "2023-11-10 11:15:00", "fly_count": 2, "sensor": 3},
75
+ {"timestamp": "2023-11-10 11:20:00", "fly_count": 1, "sensor": 3},
76
+ {"timestamp": "2023-11-10 11:25:00", "fly_count": 3, "sensor": 3},
77
+ {"timestamp": "2023-11-10 11:30:00", "fly_count": 2, "sensor": 3},
78
+ {"timestamp": "2023-11-10 11:35:00", "fly_count": 1, "sensor": 3},
79
+ {"timestamp": "2023-11-10 11:40:00", "fly_count": 1, "sensor": 3},
80
+ {"timestamp": "2023-11-10 11:45:00", "fly_count": 2, "sensor": 3},
81
+ {"timestamp": "2023-11-10 11:50:00", "fly_count": 2, "sensor": 3},
82
+ {"timestamp": "2023-11-10 11:55:00", "fly_count": 3, "sensor": 3},
83
+ {"timestamp": "2023-11-10 12:00:00", "fly_count": 6, "sensor": 3},
84
+ ]
85
+ elif canteen == "Frontier":
86
+ # Sample fly situation time series data
87
+ fly_situation_history = [
88
+ {"timestamp": "2023-11-10 11:00:00", "fly_count": 2, "sensor":1},
89
+ {"timestamp": "2023-11-10 11:05:00", "fly_count": 5, "sensor": 1},
90
+ {"timestamp": "2023-11-10 11:10:00", "fly_count": 6, "sensor": 1},
91
+ {"timestamp": "2023-11-10 11:15:00", "fly_count": 4, "sensor": 1},
92
+ {"timestamp": "2023-11-10 11:20:00", "fly_count": 5, "sensor": 1},
93
+ {"timestamp": "2023-11-10 11:25:00", "fly_count": 2, "sensor": 1},
94
+ {"timestamp": "2023-11-10 11:30:00", "fly_count": 5, "sensor": 1},
95
+ {"timestamp": "2023-11-10 11:35:00", "fly_count": 6, "sensor": 1},
96
+ {"timestamp": "2023-11-10 11:40:00", "fly_count": 7, "sensor": 1},
97
+ {"timestamp": "2023-11-10 11:45:00", "fly_count": 8, "sensor": 1},
98
+ {"timestamp": "2023-11-10 11:50:00", "fly_count": 10, "sensor": 1},
99
+ {"timestamp": "2023-11-10 11:55:00", "fly_count": 9, "sensor": 1},
100
+ {"timestamp": "2023-11-10 12:00:00", "fly_count": 8, "sensor": 1},
101
+ {"timestamp": "2023-11-10 11:00:00", "fly_count": 1, "sensor": 2},
102
+ {"timestamp": "2023-11-10 11:05:00", "fly_count": 2, "sensor": 2},
103
+ {"timestamp": "2023-11-10 11:10:00", "fly_count": 3, "sensor": 2},
104
+ {"timestamp": "2023-11-10 11:15:00", "fly_count": 2, "sensor": 2},
105
+ {"timestamp": "2023-11-10 11:20:00", "fly_count": 3, "sensor": 2},
106
+ {"timestamp": "2023-11-10 11:25:00", "fly_count": 4, "sensor": 2},
107
+ {"timestamp": "2023-11-10 11:30:00", "fly_count": 6, "sensor": 2},
108
+ {"timestamp": "2023-11-10 11:35:00", "fly_count": 7, "sensor": 2},
109
+ {"timestamp": "2023-11-10 11:40:00", "fly_count": 8, "sensor": 2},
110
+ {"timestamp": "2023-11-10 11:45:00", "fly_count": 10, "sensor": 2},
111
+ {"timestamp": "2023-11-10 11:50:00", "fly_count": 9, "sensor": 2},
112
+ {"timestamp": "2023-11-10 11:55:00", "fly_count": 8, "sensor": 2},
113
+ {"timestamp": "2023-11-10 12:00:00", "fly_count": 6, "sensor": 2},
114
+ {"timestamp": "2023-11-10 11:00:00", "fly_count": 3, "sensor": 3},
115
+ {"timestamp": "2023-11-10 11:05:00", "fly_count": 2, "sensor": 3},
116
+ {"timestamp": "2023-11-10 11:10:00", "fly_count": 2, "sensor": 3},
117
+ {"timestamp": "2023-11-10 11:15:00", "fly_count": 2, "sensor": 3},
118
+ {"timestamp": "2023-11-10 11:20:00", "fly_count": 1, "sensor": 3},
119
+ {"timestamp": "2023-11-10 11:25:00", "fly_count": 3, "sensor": 3},
120
+ {"timestamp": "2023-11-10 11:30:00", "fly_count": 5, "sensor": 3},
121
+ {"timestamp": "2023-11-10 11:35:00", "fly_count": 7, "sensor": 3},
122
+ {"timestamp": "2023-11-10 11:40:00", "fly_count": 6, "sensor": 3},
123
+ {"timestamp": "2023-11-10 11:45:00", "fly_count": 3, "sensor": 3},
124
+ {"timestamp": "2023-11-10 11:50:00", "fly_count": 2, "sensor": 3},
125
+ {"timestamp": "2023-11-10 11:55:00", "fly_count": 1, "sensor": 3},
126
+ {"timestamp": "2023-11-10 12:00:00", "fly_count": 7, "sensor": 3},
127
+ ]
128
+
129
+ return fly_situation_history
130
+
131
+
132
+ # # Streaming LLM output class
133
+ # class StreamHandler(BaseCallbackHandler):
134
+ # # Referenced from: https://discuss.streamlit.io/t/langchain-stream/43782
135
+ # def __init__(self, container, initial_text='', display_method='markdown'):
136
+ # self.container = container
137
+ # self.text = initial_text
138
+ # self.display_method = display_method
139
+
140
+ # def on_llm_new_token(self, token: str, **kwargs) -> None:
141
+ # self.text += token
142
+ # display_function = getattr(self.container, self.display_method, None)
143
+ # if display_function is not None:
144
+ # display_function(self.text)
145
+ # else:
146
+ # raise ValueError(f'Invalid display_method: {self.display_method}')
147
+
148
+
149
+ st.set_page_config(layout="centered")
150
+
151
+ # Import configuration file for user authentication
152
+ with open('credentials.yaml') as file:
153
+ config = yaml.load(file, Loader=SafeLoader)
154
+
155
+ # Create an authentication object.
156
+ authenticator = stauth.Authenticate(
157
+ config['credentials'],
158
+ config['cookie']['name'],
159
+ config['cookie']['key'],
160
+ config['cookie']['expiry_days']
161
+ )
162
+ # List of advanced users
163
+ advanced_users = ['advanced']
164
+
165
+ # Landing page if user not logged in
166
+ if st.session_state['authentication_status'] is None:
167
+ # Landing page copy and banner
168
+ st.markdown('<h1 style="text-align: left;">Fly Situation Monitoring App</h1>', unsafe_allow_html=True)
169
+ st.markdown('<h4 style="text-align: left;">Keeping You Informed, Keeping Flies at Bay</h4>', unsafe_allow_html=True)
170
+ st.write('\n')
171
+ st.write('\n')
172
+
173
+ # Loging log-in details
174
+ name, authentication_status, username = authenticator.login('', 'main')
175
+
176
+ # If log-in failed
177
+ if st.session_state['authentication_status'] is False:
178
+ st.error('Username/password is incorrect.')
179
+ st.write('\n')
180
+ st.write('\n')
181
+
182
+
183
+ # App if user is logged in and authenticated
184
+ if st.session_state['authentication_status']:
185
+
186
+ # Streamlit app start
187
+ st.title("Fly Situation Monitoring App")
188
+ st.markdown("Keeping You Informed, Keeping Flies at Bay")
189
+ st.write('\n')
190
+
191
+ # User selects a canteen
192
+ canteen = st.selectbox("Select a Canteen:", options=["Deck", "Frontier"])
193
+ st.write('\n')
194
+
195
+ # If user is a student, show basic app layout
196
+ if not st.session_state['username'] in advanced_users:
197
+
198
+ # Tabs
199
+ tab1, tab2 = st.tabs(["Current", "History"])
200
+
201
+ # Tab 1: Fly Situation
202
+ with tab1:
203
+ st.header("Current Fly Situation")
204
+
205
+ # Get data
206
+ fly_situation, delta1, delta2, delta3 = get_fly_situation(canteen)
207
+
208
+ # Display key information using cards
209
+ col1_fly_curr, col2_fly_curr, col3_fly_curr = st.columns(3)
210
+ col1_fly_curr.metric("Temperature", str(fly_situation["temperature"]) + " °C", delta=delta1)
211
+ col2_fly_curr.metric("Humidty", str(fly_situation["humidity"]) + " %", delta=delta2)
212
+ col3_fly_curr.metric("Fly Count", str(fly_situation["fly_count"]), delta=delta3, delta_color="inverse")
213
+ st.caption("Last updated at " + fly_situation["last_updated"] + " (5 min intervals)")
214
+
215
+ # Alert level
216
+ if fly_situation["fly_count"] > 20:
217
+ alert_level = "High"
218
+ alert_colour = "red"
219
+ elif fly_situation["fly_count"] > 10:
220
+ alert_level = "Moderate"
221
+ alert_colour = "orange"
222
+ else:
223
+ alert_level = "Low"
224
+ alert_colour = "green"
225
+ st.markdown(f"<h2 style='color:{alert_colour}; text-align: left'>Alert Level: {alert_level}</h3>", unsafe_allow_html=True)
226
+ st.markdown('---')
227
+
228
+ # Feedback
229
+ st.header("Feedback")
230
+ # Gather feedback
231
+ user_feedback = st.text_area("Provide Feedback on the Fly Situation:")
232
+ if st.button("Submit Feedback"):
233
+ st.success("Feedback submitted successfully!")
234
+ st.write('\n')
235
+ st.write('\n')
236
+ st.write('\n')
237
+
238
+ # Tab 2: History
239
+ with tab2:
240
+ st.header("Fly Count Over Time")
241
+
242
+ # Get history data
243
+ fly_situation_history = get_fly_situation_history(canteen)
244
+
245
+ # Create a DataFrame for the time series data
246
+ df = pd.DataFrame(fly_situation_history)
247
+ sum_by_timestamp = df.groupby('timestamp')['fly_count'].sum().reset_index()
248
+ sum_by_timestamp["timestamp"] = pd.to_datetime(sum_by_timestamp["timestamp"])
249
+
250
+ # Plot the time series using Plotly Express
251
+ fig = px.line(sum_by_timestamp, x="timestamp", y="fly_count", title="Fly Count Over Time", labels={"fly_count": "Fly Count", "timestamp": "Timestamp"})
252
+ st.plotly_chart(fig)
253
+
254
+ # Question-and-Answer
255
+ with st.form("form"):
256
+ prompt = st.text_input("Ask a Question:")
257
+ submit = st.form_submit_button("Submit")
258
+ if prompt:
259
+ with st.spinner("Generating..."):
260
+ pass
261
+
262
+ # Logout
263
+ logout_col1, logout_col2 = st.columns([6,1])
264
+ with logout_col2:
265
+ st.write('\n')
266
+ st.write('\n')
267
+ st.write('\n')
268
+ authenticator.logout('Logout', 'main')
269
+
270
+ else:
271
+ # Tabs
272
+ tab1, tab2, tab3 = st.tabs(["Current", "History", "Control System"])
273
+
274
+ # Tab 1: Fly Situation
275
+ with tab1:
276
+ st.header("Current Fly Situation")
277
+ # Get current data
278
+ fly_situation, delta1, delta2, delta3 = get_fly_situation(canteen)
279
+ # Display key information using cards
280
+ col1_fly_curr, col2_fly_curr, col3_fly_curr = st.columns(3)
281
+ col1_fly_curr.metric("Temperature", str(fly_situation["temperature"]) + " °C", delta=delta1)
282
+ col2_fly_curr.metric("Humidty", str(fly_situation["humidity"]) + " %", delta=delta2)
283
+ col3_fly_curr.metric("Fly Count", str(fly_situation["fly_count"]), delta=delta3, delta_color="inverse")
284
+ st.caption("Last updated at " + fly_situation["last_updated"] + " (5 min intervals)")
285
+
286
+ # Alert
287
+ if fly_situation["fly_count"] > 20:
288
+ alert_level = "High"
289
+ alert_colour = "red"
290
+ elif fly_situation["fly_count"] > 10:
291
+ alert_level = "Moderate"
292
+ alert_colour = "orange"
293
+ else:
294
+ alert_level = "Low"
295
+ alert_colour = "green"
296
+ st.markdown(f"<h2 style='color:{alert_colour}; text-align: left'>Alert Level: {alert_level}</h3>", unsafe_allow_html=True)
297
+ st.markdown('---')
298
+
299
+ # Feedback
300
+ st.header("Feedback")
301
+ # Gather feedback
302
+ user_feedback = st.text_area("Provide Feedback on the Fly Situation:")
303
+ if st.button("Submit Feedback"):
304
+ st.success("Feedback submitted successfully!")
305
+ st.write('\n')
306
+ st.write('\n')
307
+ st.write('\n')
308
+
309
+
310
+ # Tab 2: History
311
+ with tab2:
312
+ st.header("Fly Count Over Time")
313
+ # Select sensor
314
+ selected_sensor = st.selectbox("Select Sensor:", ["All", "Sensor 1", "Sensor 2", "Sensor 3"])
315
+ # Get history data
316
+ fly_situation_history = get_fly_situation_history(canteen)
317
+ # Create a DataFrame for the time series data
318
+ df = pd.DataFrame(fly_situation_history)
319
+ if selected_sensor != "All":
320
+ df = df[df["sensor"]==int(selected_sensor[-1])]
321
+ sum_by_timestamp = df.groupby('timestamp')['fly_count'].sum().reset_index()
322
+ sum_by_timestamp["timestamp"] = pd.to_datetime(sum_by_timestamp["timestamp"])
323
+ # Plot the time series using Plotly Express
324
+ fig = px.line(sum_by_timestamp, x="timestamp", y="fly_count", title="Fly Count Over Time", labels={"fly_count": "Fly Count", "timestamp": "Timestamp"})
325
+ st.plotly_chart(fig)
326
+
327
+ # Question-and-Answer
328
+ with st.form("form"):
329
+ prompt = st.text_input("Ask a Question:")
330
+ submit = st.form_submit_button("Submit")
331
+ if prompt:
332
+ with st.spinner("Generating..."):
333
+ pass
334
+
335
+ # Tab 3: Control System
336
+ with tab3:
337
+ st.write('\n')
338
+
339
+ # Enable/disable automatic pest control system
340
+ automatic_control_enabled = st.checkbox("Enable Automatic Pest Control", value=True)
341
+ st.write('\n')
342
+ if not automatic_control_enabled:
343
+ disabled = False
344
+ else:
345
+ disabled = True
346
+ # Accoustic
347
+ accoustic = st.selectbox("Accoustic Audio", ["Audio 1", "Audio 2", "Audio 3"], disabled=disabled)
348
+ st.write('\n')
349
+
350
+ # Time interval for pheremones discharge in minutes)
351
+ pheremones_interval = st.slider("Pheremones Discharge Interval (minutes)", min_value=5, max_value=60, value=15, step=5, disabled=disabled)
352
+ st.write('\n')
353
+
354
+ # Pest activity threshold for alerts
355
+ pest_activity_threshold = st.slider("Fly Count Threshold to Send Out Alerts", min_value=0, max_value=100, value=30, step=5, disabled=disabled)
356
+ st.write('\n')
357
+
358
+ # Logout
359
+ logout_col1, logout_col2 = st.columns([6,1])
360
+ with logout_col2:
361
+ st.write('\n')
362
+ st.write('\n')
363
+ st.write('\n')
364
+ authenticator.logout('Logout', 'main')
365
+
366
+
credentials.yaml ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ credentials:
2
+ usernames:
3
+ student:
4
+ email: student
5
+ name: NUS Student
6
+ password: $2b$12$W8tHKNQBu4GBvCA246tr7O1vZdfDrYXFJFG2DmTcAGl4IxeGSdf3e
7
+ staff:
8
+ email: staff
9
+ name: NUS Staff
10
+ password: $2b$12$W8tHKNQBu4GBvCA246tr7O1vZdfDrYXFJFG2DmTcAGl4IxeGSdf3e
11
+ advanced:
12
+ email: advanced
13
+ name: Advanced User
14
+ password: $2b$12$W8tHKNQBu4GBvCA246tr7O1vZdfDrYXFJFG2DmTcAGl4IxeGSdf3e
15
+
16
+ cookie:
17
+ expiry_days: 30
18
+ key: r3#dsd7k&SDFjd*393B
19
+ name: cookie
20
+ preauthorized:
21
+ emails:
22
+ -