echons commited on
Commit
b43e4df
1 Parent(s): 594d078
Files changed (5) hide show
  1. app.py +102 -184
  2. backend.py +182 -0
  3. images/fly.jpg +0 -0
  4. images/fly2.jpg +0 -0
  5. images/fly3.jpg +0 -0
app.py CHANGED
@@ -4,7 +4,14 @@ import pandas as pd
4
  import streamlit_authenticator as stauth
5
  import yaml
6
  from yaml.loader import SafeLoader
7
- import datetime
 
 
 
 
 
 
 
8
 
9
  # from langchain.chat_models import ChatAnthropic
10
  # from langchain.callbacks.base import BaseCallbackHandler
@@ -12,184 +19,6 @@ import datetime
12
  # from langchain.chains import LLMChain
13
 
14
 
15
- # Function to fetch simulated fly situation data
16
- def get_fly_situation(canteen):
17
- if canteen == "Deck":
18
- # Sample fly situation data
19
- fly_situation = {
20
- "temperature": 28,
21
- "humidity": 60,
22
- "fly_count": 9,
23
- "last_updated": "2023-11-10 12:00:00"
24
- }
25
- delta1 = '0.2'
26
- delta2 = '2'
27
- delta3 = '1'
28
- elif canteen == "Frontier":
29
- # Sample fly situation data
30
- fly_situation = {
31
- "temperature": 28.1,
32
- "humidity": 62,
33
- "fly_count": 21,
34
- "last_updated": "2023-11-10 12:00:00"
35
- }
36
- delta1 = '0.1'
37
- delta2 = '1'
38
- delta3 = '3'
39
- return fly_situation, delta1, delta2, delta3
40
-
41
- # Function to generate a sample fly situation dataset with time series
42
- def get_fly_situation_history(canteen):
43
- if canteen == "Deck":
44
- # Sample fly situation time series data
45
- fly_situation_history = [
46
- {"timestamp": "2023-11-10 11:00:00", "fly_count": 2, "sensor":1},
47
- {"timestamp": "2023-11-10 11:05:00", "fly_count": 1, "sensor": 1},
48
- {"timestamp": "2023-11-10 11:10:00", "fly_count": 2, "sensor": 1},
49
- {"timestamp": "2023-11-10 11:15:00", "fly_count": 2, "sensor": 1},
50
- {"timestamp": "2023-11-10 11:20:00", "fly_count": 3, "sensor": 1},
51
- {"timestamp": "2023-11-10 11:25:00", "fly_count": 1, "sensor": 1},
52
- {"timestamp": "2023-11-10 11:30:00", "fly_count": 2, "sensor": 1},
53
- {"timestamp": "2023-11-10 11:35:00", "fly_count": 1, "sensor": 1},
54
- {"timestamp": "2023-11-10 11:40:00", "fly_count": 3, "sensor": 1},
55
- {"timestamp": "2023-11-10 11:45:00", "fly_count": 1, "sensor": 1},
56
- {"timestamp": "2023-11-10 11:50:00", "fly_count": 2, "sensor": 1},
57
- {"timestamp": "2023-11-10 11:55:00", "fly_count": 3, "sensor": 1},
58
- {"timestamp": "2023-11-10 12:00:00", "fly_count": 1, "sensor": 1},
59
- {"timestamp": "2023-11-10 11:00:00", "fly_count": 1, "sensor": 2},
60
- {"timestamp": "2023-11-10 11:05:00", "fly_count": 2, "sensor": 2},
61
- {"timestamp": "2023-11-10 11:10:00", "fly_count": 3, "sensor": 2},
62
- {"timestamp": "2023-11-10 11:15:00", "fly_count": 1, "sensor": 2},
63
- {"timestamp": "2023-11-10 11:20:00", "fly_count": 2, "sensor": 2},
64
- {"timestamp": "2023-11-10 11:25:00", "fly_count": 2, "sensor": 2},
65
- {"timestamp": "2023-11-10 11:30:00", "fly_count": 1, "sensor": 2},
66
- {"timestamp": "2023-11-10 11:35:00", "fly_count": 3, "sensor": 2},
67
- {"timestamp": "2023-11-10 11:40:00", "fly_count": 2, "sensor": 2},
68
- {"timestamp": "2023-11-10 11:45:00", "fly_count": 1, "sensor": 2},
69
- {"timestamp": "2023-11-10 11:50:00", "fly_count": 3, "sensor": 2},
70
- {"timestamp": "2023-11-10 11:55:00", "fly_count": 2, "sensor": 2},
71
- {"timestamp": "2023-11-10 12:00:00", "fly_count": 2, "sensor": 2},
72
- {"timestamp": "2023-11-10 11:00:00", "fly_count": 3, "sensor": 3},
73
- {"timestamp": "2023-11-10 11:05:00", "fly_count": 1, "sensor": 3},
74
- {"timestamp": "2023-11-10 11:10:00", "fly_count": 2, "sensor": 3},
75
- {"timestamp": "2023-11-10 11:15:00", "fly_count": 2, "sensor": 3},
76
- {"timestamp": "2023-11-10 11:20:00", "fly_count": 1, "sensor": 3},
77
- {"timestamp": "2023-11-10 11:25:00", "fly_count": 3, "sensor": 3},
78
- {"timestamp": "2023-11-10 11:30:00", "fly_count": 2, "sensor": 3},
79
- {"timestamp": "2023-11-10 11:35:00", "fly_count": 1, "sensor": 3},
80
- {"timestamp": "2023-11-10 11:40:00", "fly_count": 1, "sensor": 3},
81
- {"timestamp": "2023-11-10 11:45:00", "fly_count": 2, "sensor": 3},
82
- {"timestamp": "2023-11-10 11:50:00", "fly_count": 2, "sensor": 3},
83
- {"timestamp": "2023-11-10 11:55:00", "fly_count": 3, "sensor": 3},
84
- {"timestamp": "2023-11-10 12:00:00", "fly_count": 6, "sensor": 3},
85
- ]
86
- elif canteen == "Frontier":
87
- # Sample fly situation time series data
88
- fly_situation_history = [
89
- {"timestamp": "2023-11-10 11:00:00", "fly_count": 2, "sensor":1},
90
- {"timestamp": "2023-11-10 11:05:00", "fly_count": 5, "sensor": 1},
91
- {"timestamp": "2023-11-10 11:10:00", "fly_count": 6, "sensor": 1},
92
- {"timestamp": "2023-11-10 11:15:00", "fly_count": 4, "sensor": 1},
93
- {"timestamp": "2023-11-10 11:20:00", "fly_count": 5, "sensor": 1},
94
- {"timestamp": "2023-11-10 11:25:00", "fly_count": 2, "sensor": 1},
95
- {"timestamp": "2023-11-10 11:30:00", "fly_count": 5, "sensor": 1},
96
- {"timestamp": "2023-11-10 11:35:00", "fly_count": 6, "sensor": 1},
97
- {"timestamp": "2023-11-10 11:40:00", "fly_count": 7, "sensor": 1},
98
- {"timestamp": "2023-11-10 11:45:00", "fly_count": 8, "sensor": 1},
99
- {"timestamp": "2023-11-10 11:50:00", "fly_count": 10, "sensor": 1},
100
- {"timestamp": "2023-11-10 11:55:00", "fly_count": 9, "sensor": 1},
101
- {"timestamp": "2023-11-10 12:00:00", "fly_count": 8, "sensor": 1},
102
- {"timestamp": "2023-11-10 11:00:00", "fly_count": 1, "sensor": 2},
103
- {"timestamp": "2023-11-10 11:05:00", "fly_count": 2, "sensor": 2},
104
- {"timestamp": "2023-11-10 11:10:00", "fly_count": 3, "sensor": 2},
105
- {"timestamp": "2023-11-10 11:15:00", "fly_count": 2, "sensor": 2},
106
- {"timestamp": "2023-11-10 11:20:00", "fly_count": 3, "sensor": 2},
107
- {"timestamp": "2023-11-10 11:25:00", "fly_count": 4, "sensor": 2},
108
- {"timestamp": "2023-11-10 11:30:00", "fly_count": 6, "sensor": 2},
109
- {"timestamp": "2023-11-10 11:35:00", "fly_count": 7, "sensor": 2},
110
- {"timestamp": "2023-11-10 11:40:00", "fly_count": 8, "sensor": 2},
111
- {"timestamp": "2023-11-10 11:45:00", "fly_count": 10, "sensor": 2},
112
- {"timestamp": "2023-11-10 11:50:00", "fly_count": 9, "sensor": 2},
113
- {"timestamp": "2023-11-10 11:55:00", "fly_count": 8, "sensor": 2},
114
- {"timestamp": "2023-11-10 12:00:00", "fly_count": 6, "sensor": 2},
115
- {"timestamp": "2023-11-10 11:00:00", "fly_count": 3, "sensor": 3},
116
- {"timestamp": "2023-11-10 11:05:00", "fly_count": 2, "sensor": 3},
117
- {"timestamp": "2023-11-10 11:10:00", "fly_count": 2, "sensor": 3},
118
- {"timestamp": "2023-11-10 11:15:00", "fly_count": 2, "sensor": 3},
119
- {"timestamp": "2023-11-10 11:20:00", "fly_count": 1, "sensor": 3},
120
- {"timestamp": "2023-11-10 11:25:00", "fly_count": 3, "sensor": 3},
121
- {"timestamp": "2023-11-10 11:30:00", "fly_count": 5, "sensor": 3},
122
- {"timestamp": "2023-11-10 11:35:00", "fly_count": 7, "sensor": 3},
123
- {"timestamp": "2023-11-10 11:40:00", "fly_count": 6, "sensor": 3},
124
- {"timestamp": "2023-11-10 11:45:00", "fly_count": 3, "sensor": 3},
125
- {"timestamp": "2023-11-10 11:50:00", "fly_count": 2, "sensor": 3},
126
- {"timestamp": "2023-11-10 11:55:00", "fly_count": 1, "sensor": 3},
127
- {"timestamp": "2023-11-10 12:00:00", "fly_count": 7, "sensor": 3},
128
- ]
129
-
130
- return fly_situation_history
131
-
132
- # Function to get dataframe of camera locations
133
- def get_camera_locations(canteen):
134
- if canteen == 'Frontier':
135
- camera_locations = pd.DataFrame({
136
- "latitude": [1.2963134225592299, 1.2965099487866827, 1.296561127489237],
137
- "longitude": [103.78033553238319, 103.78067954132742, 103.7807614482189],
138
- "size": [1 for i in range(3)]
139
- })
140
- elif canteen == 'Deck':
141
- camera_locations = pd.DataFrame({
142
- "latitude": [1.2948580016451805, 1.2947091254796532, 1.2944617283028779],
143
- "longitude": [103.77238596429575, 103.77266955821814, 103.77246151634456],
144
- "size": [1 for i in range(3)]
145
- })
146
-
147
- return camera_locations
148
-
149
- def get_pheremone_levels(sensor):
150
- pheremone_levels_history = [
151
- {"timestamp": "2023-11-10 11:00:00", "pheremone_level": 75, "sensor":1},
152
- {"timestamp": "2023-11-10 11:05:00", "pheremone_level": 75, "sensor": 1},
153
- {"timestamp": "2023-11-10 11:10:00", "pheremone_level": 74, "sensor": 1},
154
- {"timestamp": "2023-11-10 11:15:00", "pheremone_level": 74, "sensor": 1},
155
- {"timestamp": "2023-11-10 11:20:00", "pheremone_level": 74, "sensor": 1},
156
- {"timestamp": "2023-11-10 11:25:00", "pheremone_level": 74, "sensor": 1},
157
- {"timestamp": "2023-11-10 11:30:00", "pheremone_level": 73, "sensor": 1},
158
- {"timestamp": "2023-11-10 11:35:00", "pheremone_level": 72, "sensor": 1},
159
- {"timestamp": "2023-11-10 11:40:00", "pheremone_level": 71, "sensor": 1},
160
- {"timestamp": "2023-11-10 11:45:00", "pheremone_level": 65, "sensor": 1},
161
- {"timestamp": "2023-11-10 11:50:00", "pheremone_level": 63, "sensor": 1},
162
- {"timestamp": "2023-11-10 11:55:00", "pheremone_level": 62, "sensor": 1},
163
- {"timestamp": "2023-11-10 12:00:00", "pheremone_level": 58, "sensor": 1},
164
- {"timestamp": "2023-11-10 11:00:00", "pheremone_level": 95, "sensor": 2},
165
- {"timestamp": "2023-11-10 11:05:00", "pheremone_level": 91, "sensor": 2},
166
- {"timestamp": "2023-11-10 11:10:00", "pheremone_level": 91, "sensor": 2},
167
- {"timestamp": "2023-11-10 11:15:00", "pheremone_level": 90, "sensor": 2},
168
- {"timestamp": "2023-11-10 11:20:00", "pheremone_level": 90, "sensor": 2},
169
- {"timestamp": "2023-11-10 11:25:00", "pheremone_level": 90, "sensor": 2},
170
- {"timestamp": "2023-11-10 11:30:00", "pheremone_level": 90, "sensor": 2},
171
- {"timestamp": "2023-11-10 11:35:00", "pheremone_level": 90, "sensor": 2},
172
- {"timestamp": "2023-11-10 11:40:00", "pheremone_level": 87, "sensor": 2},
173
- {"timestamp": "2023-11-10 11:45:00", "pheremone_level": 84, "sensor": 2},
174
- {"timestamp": "2023-11-10 11:50:00", "pheremone_level": 80, "sensor": 2},
175
- {"timestamp": "2023-11-10 11:55:00", "pheremone_level": 73, "sensor": 2},
176
- {"timestamp": "2023-11-10 12:00:00", "pheremone_level": 72, "sensor": 2},
177
- {"timestamp": "2023-11-10 11:00:00", "pheremone_level": 41, "sensor": 3},
178
- {"timestamp": "2023-11-10 11:05:00", "pheremone_level": 41, "sensor": 3},
179
- {"timestamp": "2023-11-10 11:10:00", "pheremone_level": 40, "sensor": 3},
180
- {"timestamp": "2023-11-10 11:15:00", "pheremone_level": 40, "sensor": 3},
181
- {"timestamp": "2023-11-10 11:20:00", "pheremone_level": 39, "sensor": 3},
182
- {"timestamp": "2023-11-10 11:25:00", "pheremone_level": 38, "sensor": 3},
183
- {"timestamp": "2023-11-10 11:30:00", "pheremone_level": 38, "sensor": 3},
184
- {"timestamp": "2023-11-10 11:35:00", "pheremone_level": 35, "sensor": 3},
185
- {"timestamp": "2023-11-10 11:40:00", "pheremone_level": 34, "sensor": 3},
186
- {"timestamp": "2023-11-10 11:45:00", "pheremone_level": 33, "sensor": 3},
187
- {"timestamp": "2023-11-10 11:50:00", "pheremone_level": 33, "sensor": 3},
188
- {"timestamp": "2023-11-10 11:55:00", "pheremone_level": 30, "sensor": 3},
189
- {"timestamp": "2023-11-10 12:00:00", "pheremone_level": 26, "sensor": 3},
190
- ]
191
- return pheremone_levels_history
192
-
193
  # # Streaming LLM output class
194
  # class StreamHandler(BaseCallbackHandler):
195
  # # Referenced from: https://discuss.streamlit.io/t/langchain-stream/43782
@@ -206,8 +35,7 @@ def get_pheremone_levels(sensor):
206
  # else:
207
  # raise ValueError(f'Invalid display_method: {self.display_method}')
208
 
209
-
210
- # Start of Streamlit Apps
211
  st.set_page_config(layout="centered")
212
  hide_streamlit_style = '''
213
  <style>
@@ -217,6 +45,35 @@ hide_streamlit_style = '''
217
  '''
218
  st.markdown(hide_streamlit_style, unsafe_allow_html=True)
219
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
220
  # Import configuration file for user authentication
221
  with open('credentials.yaml') as file:
222
  config = yaml.load(file, Loader=SafeLoader)
@@ -265,7 +122,7 @@ if st.session_state['authentication_status']:
265
  if not st.session_state['username'] in advanced_users:
266
 
267
  # Tabs
268
- tab1, tab2 = st.tabs(["Current", "History"])
269
 
270
  # Tab 1: Fly Situation
271
  with tab1:
@@ -337,9 +194,70 @@ if st.session_state['authentication_status']:
337
  prompt = st.text_input("Ask a Question:")
338
  submit = st.form_submit_button("Submit")
339
  if prompt:
340
- with st.spinner("Generating..."):
341
- pass
 
342
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
343
  # Logout
344
  logout_col1, logout_col2 = st.columns([6,1])
345
  with logout_col2:
 
4
  import streamlit_authenticator as stauth
5
  import yaml
6
  from yaml.loader import SafeLoader
7
+ import plotly.graph_objects as go
8
+
9
+ from transformers import pipeline
10
+ from PIL import Image, ImageDraw, ImageFont
11
+ from transformers import TapexTokenizer, BartForConditionalGeneration
12
+
13
+
14
+ from backend import *
15
 
16
  # from langchain.chat_models import ChatAnthropic
17
  # from langchain.callbacks.base import BaseCallbackHandler
 
19
  # from langchain.chains import LLMChain
20
 
21
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
  # # Streaming LLM output class
23
  # class StreamHandler(BaseCallbackHandler):
24
  # # Referenced from: https://discuss.streamlit.io/t/langchain-stream/43782
 
35
  # else:
36
  # raise ValueError(f'Invalid display_method: {self.display_method}')
37
 
38
+ # Start of Streamlit App
 
39
  st.set_page_config(layout="centered")
40
  hide_streamlit_style = '''
41
  <style>
 
45
  '''
46
  st.markdown(hide_streamlit_style, unsafe_allow_html=True)
47
 
48
+
49
+ @st.cache_resource
50
+ # Function to initialise object_detection model
51
+ def initialise_object_detection_model():
52
+ checkpoint = "google/owlvit-base-patch32"
53
+ detector = pipeline(model=checkpoint, task="zero-shot-object-detection")
54
+ return detector
55
+
56
+ # Function to get result from object detection
57
+ def get_object_detection_results(detector, image_path):
58
+ image = Image.open(image_path)
59
+ predictions = detector(
60
+ image,
61
+ candidate_labels=["fly", "human face", "insect", "flies"],
62
+ )
63
+ draw = ImageDraw.Draw(image)
64
+ for prediction in predictions:
65
+ box = prediction["box"]
66
+ label = prediction["label"]
67
+ score = prediction["score"]
68
+ xmin, ymin, xmax, ymax = box.values()
69
+ draw.rectangle((xmin, ymin, xmax, ymax), outline="red", width=1)
70
+ font = ImageFont.truetype("arial.ttf", 30)
71
+ draw.text((xmin, ymin), f"{label}: {round(score,2)}", fill="white", font=font)
72
+ return image
73
+
74
+ detector = initialise_object_detection_model()
75
+
76
+
77
  # Import configuration file for user authentication
78
  with open('credentials.yaml') as file:
79
  config = yaml.load(file, Loader=SafeLoader)
 
122
  if not st.session_state['username'] in advanced_users:
123
 
124
  # Tabs
125
+ tab1, tab2, tab3 = st.tabs(["Current", "History", "FAQ"])
126
 
127
  # Tab 1: Fly Situation
128
  with tab1:
 
194
  prompt = st.text_input("Ask a Question:")
195
  submit = st.form_submit_button("Submit")
196
  if prompt:
197
+ pass
198
+ #with st.spinner("Generating..."):
199
+ #st.write(get_table_qa_results(table_model, table_tokenizer, df=df, question=prompt))
200
 
201
+ # Tab 3: FAQ
202
+ with tab3:
203
+ st.header("Frequently Asked Questions")
204
+ with st.expander("What is this app about?"):
205
+ st.write("This app provides you real-time information on fly activity by the smart fly monitoring system.")
206
+ with st.expander("How do the sensors work/detect fly activity?"):
207
+ st.write("The sensors built into the fly traps leverages cutting-edge AI methodologies for advanced fly detection.")
208
+ st.write("1) Object Detection - Using OWL-ViT, an open-vocabulary object detector, we can finetune the model specifically to recognise flies.")
209
+ st.write('\n')
210
+ st.write('\n')
211
+ st.write("Try OWL-ViT:")
212
+ object_labels = st.multiselect("Enter your labels for the model to detect", options=["insect"], default="insect")
213
+ image_file = st.file_uploader("Upload an image", type=["jpg", "png"])
214
+ demo_image = st.checkbox("Load in demo image")
215
+ if image_file:
216
+ st.write('Before:')
217
+ st.image(image_file)
218
+ if image_file and object_labels:
219
+ st.write('After:')
220
+ with st.spinner("Detecting"):
221
+ st.image(image = get_object_detection_results(detector, image_file))
222
+ if demo_image:
223
+ st.write('Before:')
224
+ st.image("images/fly.jpg")
225
+ if demo_image and object_labels:
226
+ st.write('After:')
227
+ with st.spinner("Detecting"):
228
+ st.image(image = get_object_detection_results(detector, "images/fly.jpg"))
229
+ st.write('\n')
230
+ st.write('\n')
231
+ st.write("2) Behaviour Analysis - By comparing consecutive frames, the system can extract data such as the trajectory, speed, and direction of each fly's movement. Training the system on these data can improve the system's detection of flies.")
232
+ trajectory_data = pd.DataFrame({
233
+ 'X': [1, 2, 3, 4, 5],
234
+ 'Y': [10, 25, 20, 25, 30],
235
+ 'Timestamp': pd.date_range('2023-01-01', '2023-01-05', freq='D')
236
+ })
237
+ # Create a Plotly figure
238
+ fig = go.Figure()
239
+ # Add a trace for the trajectory
240
+ fig.add_trace(go.Scatter(x=trajectory_data['X'], y=trajectory_data['Y'], mode='lines'))
241
+ # Update layout
242
+ fig.update_layout(
243
+ xaxis_title='X-Coordinate',
244
+ yaxis_title='Y-Coordinate',
245
+ title='Example of a Fly Trajectory'
246
+ )
247
+ # Display the Plotly figure
248
+ st.plotly_chart(fig, use_container_width=True)
249
+ st.write('\n')
250
+ st.write('\n')
251
+ st.write('3) Training Augmentation - The fly detection system employs generative adversial networks, which generates synthetic fly images for training the fly detection model. This makes the system more robust at detecting flies in all scenarios.')
252
+ with st.expander("How accurate is the fly detection in the system?"):
253
+ st.write("The system is still in experimental phase.")
254
+ with st.expander("How often is the data updated or refreshed in real-time?"):
255
+ st.write("5 minute intervals.")
256
+ with st.expander("Why do I hear some sounds coming out from the fly traps?"):
257
+ st.write("The fly traps are built to emit accoustic sounds to attract flies.")
258
+ with st.expander("The traps seem to release some gas. What is that?"):
259
+ st.write("The fly traps release non-toxic pheremones that attract flies.")
260
+
261
  # Logout
262
  logout_col1, logout_col2 = st.columns([6,1])
263
  with logout_col2:
backend.py ADDED
@@ -0,0 +1,182 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Import packages
2
+ import pandas as pd
3
+
4
+
5
+ # Function to fetch simulated fly situation data
6
+ def get_fly_situation(canteen):
7
+ if canteen == "Deck":
8
+ # Sample fly situation data
9
+ fly_situation = {
10
+ "temperature": 28,
11
+ "humidity": 60,
12
+ "fly_count": 9,
13
+ "last_updated": "2023-11-10 12:00:00"
14
+ }
15
+ delta1 = '0.2'
16
+ delta2 = '2'
17
+ delta3 = '1'
18
+ elif canteen == "Frontier":
19
+ # Sample fly situation data
20
+ fly_situation = {
21
+ "temperature": 28.1,
22
+ "humidity": 62,
23
+ "fly_count": 21,
24
+ "last_updated": "2023-11-10 12:00:00"
25
+ }
26
+ delta1 = '0.1'
27
+ delta2 = '1'
28
+ delta3 = '3'
29
+ return fly_situation, delta1, delta2, delta3
30
+
31
+ # Function to generate a sample fly situation dataset with time series
32
+ def get_fly_situation_history(canteen):
33
+ if canteen == "Deck":
34
+ # Sample fly situation time series data
35
+ fly_situation_history = [
36
+ {"timestamp": "2023-11-10 11:00:00", "fly_count": 2, "sensor":1},
37
+ {"timestamp": "2023-11-10 11:05:00", "fly_count": 1, "sensor": 1},
38
+ {"timestamp": "2023-11-10 11:10:00", "fly_count": 2, "sensor": 1},
39
+ {"timestamp": "2023-11-10 11:15:00", "fly_count": 2, "sensor": 1},
40
+ {"timestamp": "2023-11-10 11:20:00", "fly_count": 3, "sensor": 1},
41
+ {"timestamp": "2023-11-10 11:25:00", "fly_count": 1, "sensor": 1},
42
+ {"timestamp": "2023-11-10 11:30:00", "fly_count": 2, "sensor": 1},
43
+ {"timestamp": "2023-11-10 11:35:00", "fly_count": 1, "sensor": 1},
44
+ {"timestamp": "2023-11-10 11:40:00", "fly_count": 3, "sensor": 1},
45
+ {"timestamp": "2023-11-10 11:45:00", "fly_count": 1, "sensor": 1},
46
+ {"timestamp": "2023-11-10 11:50:00", "fly_count": 2, "sensor": 1},
47
+ {"timestamp": "2023-11-10 11:55:00", "fly_count": 3, "sensor": 1},
48
+ {"timestamp": "2023-11-10 12:00:00", "fly_count": 1, "sensor": 1},
49
+ {"timestamp": "2023-11-10 11:00:00", "fly_count": 1, "sensor": 2},
50
+ {"timestamp": "2023-11-10 11:05:00", "fly_count": 2, "sensor": 2},
51
+ {"timestamp": "2023-11-10 11:10:00", "fly_count": 3, "sensor": 2},
52
+ {"timestamp": "2023-11-10 11:15:00", "fly_count": 1, "sensor": 2},
53
+ {"timestamp": "2023-11-10 11:20:00", "fly_count": 2, "sensor": 2},
54
+ {"timestamp": "2023-11-10 11:25:00", "fly_count": 2, "sensor": 2},
55
+ {"timestamp": "2023-11-10 11:30:00", "fly_count": 1, "sensor": 2},
56
+ {"timestamp": "2023-11-10 11:35:00", "fly_count": 3, "sensor": 2},
57
+ {"timestamp": "2023-11-10 11:40:00", "fly_count": 2, "sensor": 2},
58
+ {"timestamp": "2023-11-10 11:45:00", "fly_count": 1, "sensor": 2},
59
+ {"timestamp": "2023-11-10 11:50:00", "fly_count": 3, "sensor": 2},
60
+ {"timestamp": "2023-11-10 11:55:00", "fly_count": 2, "sensor": 2},
61
+ {"timestamp": "2023-11-10 12:00:00", "fly_count": 2, "sensor": 2},
62
+ {"timestamp": "2023-11-10 11:00:00", "fly_count": 3, "sensor": 3},
63
+ {"timestamp": "2023-11-10 11:05:00", "fly_count": 1, "sensor": 3},
64
+ {"timestamp": "2023-11-10 11:10:00", "fly_count": 2, "sensor": 3},
65
+ {"timestamp": "2023-11-10 11:15:00", "fly_count": 2, "sensor": 3},
66
+ {"timestamp": "2023-11-10 11:20:00", "fly_count": 1, "sensor": 3},
67
+ {"timestamp": "2023-11-10 11:25:00", "fly_count": 3, "sensor": 3},
68
+ {"timestamp": "2023-11-10 11:30:00", "fly_count": 2, "sensor": 3},
69
+ {"timestamp": "2023-11-10 11:35:00", "fly_count": 1, "sensor": 3},
70
+ {"timestamp": "2023-11-10 11:40:00", "fly_count": 1, "sensor": 3},
71
+ {"timestamp": "2023-11-10 11:45:00", "fly_count": 2, "sensor": 3},
72
+ {"timestamp": "2023-11-10 11:50:00", "fly_count": 2, "sensor": 3},
73
+ {"timestamp": "2023-11-10 11:55:00", "fly_count": 3, "sensor": 3},
74
+ {"timestamp": "2023-11-10 12:00:00", "fly_count": 6, "sensor": 3},
75
+ ]
76
+ elif canteen == "Frontier":
77
+ # Sample fly situation time series data
78
+ fly_situation_history = [
79
+ {"timestamp": "2023-11-10 11:00:00", "fly_count": 2, "sensor":1},
80
+ {"timestamp": "2023-11-10 11:05:00", "fly_count": 5, "sensor": 1},
81
+ {"timestamp": "2023-11-10 11:10:00", "fly_count": 6, "sensor": 1},
82
+ {"timestamp": "2023-11-10 11:15:00", "fly_count": 4, "sensor": 1},
83
+ {"timestamp": "2023-11-10 11:20:00", "fly_count": 5, "sensor": 1},
84
+ {"timestamp": "2023-11-10 11:25:00", "fly_count": 2, "sensor": 1},
85
+ {"timestamp": "2023-11-10 11:30:00", "fly_count": 5, "sensor": 1},
86
+ {"timestamp": "2023-11-10 11:35:00", "fly_count": 6, "sensor": 1},
87
+ {"timestamp": "2023-11-10 11:40:00", "fly_count": 7, "sensor": 1},
88
+ {"timestamp": "2023-11-10 11:45:00", "fly_count": 8, "sensor": 1},
89
+ {"timestamp": "2023-11-10 11:50:00", "fly_count": 10, "sensor": 1},
90
+ {"timestamp": "2023-11-10 11:55:00", "fly_count": 9, "sensor": 1},
91
+ {"timestamp": "2023-11-10 12:00:00", "fly_count": 8, "sensor": 1},
92
+ {"timestamp": "2023-11-10 11:00:00", "fly_count": 1, "sensor": 2},
93
+ {"timestamp": "2023-11-10 11:05:00", "fly_count": 2, "sensor": 2},
94
+ {"timestamp": "2023-11-10 11:10:00", "fly_count": 3, "sensor": 2},
95
+ {"timestamp": "2023-11-10 11:15:00", "fly_count": 2, "sensor": 2},
96
+ {"timestamp": "2023-11-10 11:20:00", "fly_count": 3, "sensor": 2},
97
+ {"timestamp": "2023-11-10 11:25:00", "fly_count": 4, "sensor": 2},
98
+ {"timestamp": "2023-11-10 11:30:00", "fly_count": 6, "sensor": 2},
99
+ {"timestamp": "2023-11-10 11:35:00", "fly_count": 7, "sensor": 2},
100
+ {"timestamp": "2023-11-10 11:40:00", "fly_count": 8, "sensor": 2},
101
+ {"timestamp": "2023-11-10 11:45:00", "fly_count": 10, "sensor": 2},
102
+ {"timestamp": "2023-11-10 11:50:00", "fly_count": 9, "sensor": 2},
103
+ {"timestamp": "2023-11-10 11:55:00", "fly_count": 8, "sensor": 2},
104
+ {"timestamp": "2023-11-10 12:00:00", "fly_count": 6, "sensor": 2},
105
+ {"timestamp": "2023-11-10 11:00:00", "fly_count": 3, "sensor": 3},
106
+ {"timestamp": "2023-11-10 11:05:00", "fly_count": 2, "sensor": 3},
107
+ {"timestamp": "2023-11-10 11:10:00", "fly_count": 2, "sensor": 3},
108
+ {"timestamp": "2023-11-10 11:15:00", "fly_count": 2, "sensor": 3},
109
+ {"timestamp": "2023-11-10 11:20:00", "fly_count": 1, "sensor": 3},
110
+ {"timestamp": "2023-11-10 11:25:00", "fly_count": 3, "sensor": 3},
111
+ {"timestamp": "2023-11-10 11:30:00", "fly_count": 5, "sensor": 3},
112
+ {"timestamp": "2023-11-10 11:35:00", "fly_count": 7, "sensor": 3},
113
+ {"timestamp": "2023-11-10 11:40:00", "fly_count": 6, "sensor": 3},
114
+ {"timestamp": "2023-11-10 11:45:00", "fly_count": 3, "sensor": 3},
115
+ {"timestamp": "2023-11-10 11:50:00", "fly_count": 2, "sensor": 3},
116
+ {"timestamp": "2023-11-10 11:55:00", "fly_count": 1, "sensor": 3},
117
+ {"timestamp": "2023-11-10 12:00:00", "fly_count": 7, "sensor": 3},
118
+ ]
119
+
120
+ return fly_situation_history
121
+
122
+ # Function to get dataframe of camera locations
123
+ def get_camera_locations(canteen):
124
+ if canteen == 'Frontier':
125
+ camera_locations = pd.DataFrame({
126
+ "latitude": [1.2963134225592299, 1.2965099487866827, 1.296561127489237],
127
+ "longitude": [103.78033553238319, 103.78067954132742, 103.7807614482189],
128
+ "size": [1 for i in range(3)]
129
+ })
130
+ elif canteen == 'Deck':
131
+ camera_locations = pd.DataFrame({
132
+ "latitude": [1.2948580016451805, 1.2947091254796532, 1.2944617283028779],
133
+ "longitude": [103.77238596429575, 103.77266955821814, 103.77246151634456],
134
+ "size": [1 for i in range(3)]
135
+ })
136
+
137
+ return camera_locations
138
+
139
+ # Function to get pheremone levels
140
+ def get_pheremone_levels(sensor):
141
+ pheremone_levels_history = [
142
+ {"timestamp": "2023-11-10 11:00:00", "pheremone_level": 75, "sensor":1},
143
+ {"timestamp": "2023-11-10 11:05:00", "pheremone_level": 75, "sensor": 1},
144
+ {"timestamp": "2023-11-10 11:10:00", "pheremone_level": 74, "sensor": 1},
145
+ {"timestamp": "2023-11-10 11:15:00", "pheremone_level": 74, "sensor": 1},
146
+ {"timestamp": "2023-11-10 11:20:00", "pheremone_level": 74, "sensor": 1},
147
+ {"timestamp": "2023-11-10 11:25:00", "pheremone_level": 74, "sensor": 1},
148
+ {"timestamp": "2023-11-10 11:30:00", "pheremone_level": 73, "sensor": 1},
149
+ {"timestamp": "2023-11-10 11:35:00", "pheremone_level": 72, "sensor": 1},
150
+ {"timestamp": "2023-11-10 11:40:00", "pheremone_level": 71, "sensor": 1},
151
+ {"timestamp": "2023-11-10 11:45:00", "pheremone_level": 65, "sensor": 1},
152
+ {"timestamp": "2023-11-10 11:50:00", "pheremone_level": 63, "sensor": 1},
153
+ {"timestamp": "2023-11-10 11:55:00", "pheremone_level": 62, "sensor": 1},
154
+ {"timestamp": "2023-11-10 12:00:00", "pheremone_level": 58, "sensor": 1},
155
+ {"timestamp": "2023-11-10 11:00:00", "pheremone_level": 95, "sensor": 2},
156
+ {"timestamp": "2023-11-10 11:05:00", "pheremone_level": 91, "sensor": 2},
157
+ {"timestamp": "2023-11-10 11:10:00", "pheremone_level": 91, "sensor": 2},
158
+ {"timestamp": "2023-11-10 11:15:00", "pheremone_level": 90, "sensor": 2},
159
+ {"timestamp": "2023-11-10 11:20:00", "pheremone_level": 90, "sensor": 2},
160
+ {"timestamp": "2023-11-10 11:25:00", "pheremone_level": 90, "sensor": 2},
161
+ {"timestamp": "2023-11-10 11:30:00", "pheremone_level": 90, "sensor": 2},
162
+ {"timestamp": "2023-11-10 11:35:00", "pheremone_level": 90, "sensor": 2},
163
+ {"timestamp": "2023-11-10 11:40:00", "pheremone_level": 87, "sensor": 2},
164
+ {"timestamp": "2023-11-10 11:45:00", "pheremone_level": 84, "sensor": 2},
165
+ {"timestamp": "2023-11-10 11:50:00", "pheremone_level": 80, "sensor": 2},
166
+ {"timestamp": "2023-11-10 11:55:00", "pheremone_level": 73, "sensor": 2},
167
+ {"timestamp": "2023-11-10 12:00:00", "pheremone_level": 72, "sensor": 2},
168
+ {"timestamp": "2023-11-10 11:00:00", "pheremone_level": 41, "sensor": 3},
169
+ {"timestamp": "2023-11-10 11:05:00", "pheremone_level": 41, "sensor": 3},
170
+ {"timestamp": "2023-11-10 11:10:00", "pheremone_level": 40, "sensor": 3},
171
+ {"timestamp": "2023-11-10 11:15:00", "pheremone_level": 40, "sensor": 3},
172
+ {"timestamp": "2023-11-10 11:20:00", "pheremone_level": 39, "sensor": 3},
173
+ {"timestamp": "2023-11-10 11:25:00", "pheremone_level": 38, "sensor": 3},
174
+ {"timestamp": "2023-11-10 11:30:00", "pheremone_level": 38, "sensor": 3},
175
+ {"timestamp": "2023-11-10 11:35:00", "pheremone_level": 35, "sensor": 3},
176
+ {"timestamp": "2023-11-10 11:40:00", "pheremone_level": 34, "sensor": 3},
177
+ {"timestamp": "2023-11-10 11:45:00", "pheremone_level": 33, "sensor": 3},
178
+ {"timestamp": "2023-11-10 11:50:00", "pheremone_level": 33, "sensor": 3},
179
+ {"timestamp": "2023-11-10 11:55:00", "pheremone_level": 30, "sensor": 3},
180
+ {"timestamp": "2023-11-10 12:00:00", "pheremone_level": 26, "sensor": 3},
181
+ ]
182
+ return pheremone_levels_history
images/fly.jpg ADDED
images/fly2.jpg ADDED
images/fly3.jpg ADDED