-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfinal.html
389 lines (355 loc) · 19.9 KB
/
final.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Satark- A driver safety app</title>
<style>
body, html {
margin: 0;
padding: 0;
height: 100%;
width: 100%;
}
.container {
display: flex;
height: 100vh;
}
.left, .right {
display: flex;
flex-direction: column;
}
.right {
width: 70%;
}
.left > .top {
height: 65%;
border: 1px solid #000;
display: flex;
justify-content: center;
align-items: center;
background-color: #ffffff;
}
.right > .top, .right > .bottom {
flex: 1;
display: flex;
}
.right > .top > .left {
width: 40%;
border: 1px solid #000;
}
.right > .top > .right {
width: 60%;
border: 1px solid #000;
}
.right > .bottom > .left {
width: 45%;
border: 1px solid #000;
}
.right > .bottom > .right {
width: 55%;
border: 1px solid #000;
}
.left {
display: flex;
flex-direction: column;
width: 30%;
}
.left .top {
height: 65%;
border: 1px solid #000;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
background-color: #ffffff;
}
.left .bottom {
height: 35%;
border: 1px solid #000;
background-color: #ec4242;
}
.left .top .reading-container {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100%;
}
.left .top img {
width: 100px;
height: auto;
}
#carIcon{
width: 300px;
height: 250px;
}
</style>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
</head>
<body>
<div class="container">
<div class="left">
<div class="top">
<div class="reading-container">
<div id="frontReading" style="padding-bottom: 20px;">-- cm</div>
<div class="left-top-middle">
<img src="data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAkGBwgHBgkIBwgKCgkLDRYPDQwMDRsUFRAWIB0iIiAdHx8kKDQsJCYxJx8fLT0tMTU3Ojo6Iys/RD84QzQ5OjcBCgoKDQwNGg8PGjclHyU3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3N//AABEIAI8A4QMBIgACEQEDEQH/xAAcAAEAAwEBAQEBAAAAAAAAAAAABgcIBQQDAgH/xABFEAABBAECAgYFCAYIBwAAAAAAAQIDBAUGEQcSCCExQVGRE1JhgaIUIiZxobHB0SQyU5KTwhYjY2VysuHwM0JkdHWjw//EABQBAQAAAAAAAAAAAAAAAAAAAAD/xAAUEQEAAAAAAAAAAAAAAAAAAAAA/9oADAMBAAIRAxEAPwC8QAAAAAAA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AAAAAAVD0km/RjFu8L23wOIZpPX1SbipVzeVVa1SSoynzSL1RKkbW7qvgr0Xr7kd19hPukVXdLoirM1N0hvsc72IrHp96oZvA3BFJHNG2SJ7XxuTdrmruip7FP2Yrx+ayuMTbG5O7UTffavYfH9ynbg4j6ygYjWahuqiftHo9fNyKBrk/iqjUVXKiInWqr3GSZeJWs5Wq12obiIvqK1q+aIcXIagzWTYrMjl79ti9rZ7L3p5KoFn8TNdUYeKGGyOLkbbiw6NbO+J26PVXLztavYvzV238V9h0ujnO65lNUW5E+fMsL3fW50ilGF8dGisraWetqnVJLDGi/4Ucq/5kAusAAAAAAAAAAAAAAAAAAAAAAAAAAAABxdZYCLU+mb+HlcjFsR/wBW9exkiLu1fqRyJ7jIeYxV7C5CbH5StJXswu2cx6be9PFF7lTqU2seDL4XF5qFIcvj6txjf1UniR3L9Sr2e4DFYNTW+D2ibCqrcXJAq98VmRPsVVQ5EvAfSr3K5l3Lx7/8qTRqiebNwM4A0dHwG0s1UV97MP27vTRoi/8ArOrV4N6Jrqivx01hU/a2X/yqgGY6VSxftRVaUEk9iV3LHFG1XOcvgiGseGWll0jpKtj5+VbkirPaVvZ6R3d7kRG+3bfvOvhdOYXAtVuHxlWpzJs50UaI5ye13avvOoAAAAAAAAAAAAAAAAB//9k=" alt="Car" id="carIcon">
</div>
<div id="rearReading" style="padding-top: 20px;">-- cm</div>
</div>
</div>
<div class="bottom" id="majorityMessage" style="text-align: center; padding-top: 65px; padding-left: 10px; padding-right: 10px; font-size: medium; font-weight: bold; font-family: 'Times New Roman', Times, serif;"></div>
</div>
<div class="right">
<div class="top">
<div class="left" style="background-color: #ffffff;">
<canvas id="myPieChart2" style="width: 90%; height: 90%;"></canvas>
</div>
<div class="right">
<iframe id="video_frame" src="/video_feed" frameborder="0" style="height:100%;" allowfullscreen></iframe>
</div>
</div>
<div class="bottom">
<div class="left" style="background-color: #ffffff;">
<canvas id="myPieChart" style="width: 90%; height: 90%; background-color:rgb(255, 255, 255);"></canvas>
</div>
<div class="right" id="resultsContainer" style="padding-top: 50px;">
<button id="fetchDataButton" type="submit" style="
font-size: 16px;
background-color: #007bff;
color: #fff;
border: none;
border-radius: 5px;
cursor: pointer;
transition: background-color 0.3s ease;
display: inline-block;
padding: 10px 20px;
line-height: 1; /* Ensure the button height adjusts correctly */">
Find Your Nearest Helper
</button>
</div>
</div>
</div>
</div>
</div>
<script>
let myPieChart;
function updatePieChart() {
fetch('/current_driving_data?id=1') // Change ID as needed
.then(response => response.json())
.then(data => {
// Calculate total count
const currentTotal = data.current_drowsiness_count +
data.current_movement_count +
data.current_objects_count;
// Prepare data for the pie chart
const labels = ['Drowsiness', 'Movement', 'Objects'];
const values = [
data.current_drowsiness_count || 0,
data.current_movement_count || 0,
data.current_objects_count || 0
];
// Calculate percentages
const percentages = values.map(value => ((value / currentTotal) * 100).toFixed(2) + '%');
// Update pie chart data
if (myPieChart) {
myPieChart.data.labels = labels.map((label, index) => `${label} (${percentages[index]})`);
myPieChart.data.datasets[0].data = values;
myPieChart.update();
} else {
// Render pie chart using Chart.js
const ctx = document.getElementById('myPieChart').getContext('2d');
myPieChart = new Chart(ctx, {
type: 'pie',
data: {
labels: labels.map((label, index) => `${label} (${percentages[index]})`),
datasets: [{
label: 'Current Driving Data',
data: values,
backgroundColor: [
'rgba(255, 99, 132, 0.7)', // Drowsiness color
'rgba(54, 162, 235, 0.7)', // Movement color
'rgba(255, 206, 86, 0.7)' // Objects color
],
borderColor: [
'rgba(255, 99, 132, 1)',
'rgba(54, 162, 235, 1)',
'rgba(255, 206, 86, 1)'
],
borderWidth: 1
}]
},
options: {
responsive: false, // Disable responsiveness
plugins: {
legend: {
position: 'top',
},
title: {
display: true,
text: `Current Driving Data Distribution (Total: ${currentTotal})`
}
}
}
});
}
})
.catch(error => console.error('Error fetching data:', error));
}
// Update pie chart every 5 seconds
setInterval(updatePieChart, 5000);
// Initial update on page load
document.addEventListener('DOMContentLoaded', updatePieChart);
</script>
<script>
let myPieChart2;
function updatePieChart2() {
fetch('/total_driving_data?id=1') // Change ID as needed
.then(response => response.json())
.then(data => {
// Calculate total count
const allTimeTotal = data.drowsiness_count +
data.movement_count +
data.objects_count;
// Prepare data for the pie chart
const labels = ['Drowsiness', 'Movement', 'Objects'];
const values = [
data.drowsiness_count || 0,
data.movement_count || 0,
data.objects_count || 0
];
// Calculate percentages
const percentages = values.map(value => ((value / allTimeTotal) * 100).toFixed(2) + '%');
// Render pie chart using Chart.js
const ctx = document.getElementById('myPieChart2').getContext('2d');
myPieChart2 = new Chart(ctx, {
type: 'pie',
data: {
labels: labels.map((label, index) => `${label} (${percentages[index]})`),
datasets: [{
label: 'All time stats',
data: values,
backgroundColor: [
'rgba(167, 201, 87, 0.7)', // Drowsiness color
'rgba(106, 153, 78, 0.7)', // Movement color
'rgba(56, 102, 65, 0.7)' // Objects color
],
borderColor: [
'rgba(167, 201, 87, 1)', // Drowsiness color
'rgba(106, 153, 78, 1)', // Movement color
'rgba(56, 102, 65, 1)' // Objects color
],
borderWidth: 1
}]
},
options: {
responsive: false, // Disable responsiveness
plugins: {
legend: {
position: 'top',
},
title: {
display: true,
text: `All time stats (Total: ${allTimeTotal})`
}
}
}
});
})
.catch(error => console.error('Error fetching data:', error));
}
// Initial update on page load
document.addEventListener('DOMContentLoaded', updatePieChart2);
</script>
<script>
const majorityMessage = document.getElementById('majorityMessage');
function displayMajorityMessage() {
fetch('/current_driving_data?id=1') // Change ID as needed
.then(response => response.json())
.then(data => {
const { current_drowsiness_count, current_movement_count, current_objects_count } = data;
if (current_drowsiness_count > current_movement_count && current_drowsiness_count > current_objects_count) {
majorityMessage.textContent = 'Your attention seems to be declining, indicating signs of drowsiness. For your safety and the safety of others: Pull over to a safe location. Take a short break and rest.Consider switching drivers, if possible. Safety comes first. Stay alert and stay safe!';
} else if (current_movement_count > current_drowsiness_count && current_movement_count > current_objects_count) {
majorityMessage.textContent = 'Your movement inside the vehicle has been detected. For your safety and the safety of others: Keep both hands on the wheel. Maintain proper driving posture.Stay focused on the road. Safety comes first. Please drive responsibly!';
} else if (current_objects_count > current_drowsiness_count && current_objects_count > current_movement_count) {
majorityMessage.textContent = 'It appears that you are using objects while driving. For your safety and the safety of others: Put down any objects immediately. Keep both hands on the wheel.Stay focused on the road. Safety comes first. Avoid distractions and drive responsibly!';
} else {
majorityMessage.textContent = 'No clear majority';
}
majorityMessage.classList.add('active');
})
.catch(error => {
console.error('Error fetching data:', error);
});
}
// Start displaying majority message after 15 seconds and repeat every 10 seconds
setTimeout(() => {
displayMajorityMessage();
setInterval(displayMajorityMessage, 10000); // Repeat every 10 seconds
}, 15000);
</script>
<script>
// Fetch ultrasonic data periodically
function fetchUltrasonicData() {
fetch('/ultrasonic')
.then(response => response.json())
.then(data => {
document.getElementById('frontReading').innerText = `Front Distance: ${data.distance1} cm`;
document.getElementById('rearReading').innerText = `Back Distance: ${data.distance2} cm`;
})
.catch(error => {
console.error('Error fetching ultrasonic data:', error);
});
}
setInterval(fetchUltrasonicData, 1000); // Fetch ultrasonic data every second
</script>
<script>
document.addEventListener('DOMContentLoaded', function() {
const fetchDataButton = document.getElementById('fetchDataButton');
fetchDataButton.addEventListener('click', function() {
// Make an AJAX request to your Flask server
fetch('/fetch_nearby_places') // Adjust the endpoint as per your Flask route
.then(response => response.json())
.then(data => {
// Process the JSON response
console.log('Received data:', data);
// Assuming data structure: { "hotel": [...], "restaurant": [...], "hospital": [...] }
if (data && Object.keys(data).length > 0) {
const resultsContainer = document.getElementById('resultsContainer');
resultsContainer.innerHTML = ''; // Clear previous results
// Iterate over categories
for (const category in data) {
if (data.hasOwnProperty(category)) {
const places = data[category];
// Create a heading for each category
const categoryHeading = document.createElement('h2');
categoryHeading.textContent = category.charAt(0).toUpperCase() + category.slice(1) + 's:';
resultsContainer.appendChild(categoryHeading);
// Create a list for places in the category
const placesList = document.createElement('ul');
// Iterate over places
places.forEach(place => {
// Create list item for each place
const placeItem = document.createElement('li');
placeItem.textContent = `${place.name} (${place.distance_km} km)`;
placesList.appendChild(placeItem);
});
// Append the places list to results container
resultsContainer.appendChild(placesList);
}
}
} else {
console.log('No data received.');
}
})
.catch(error => {
console.error('Error fetching data:', error);
// Handle errors gracefully
});
});
});
</script>
</body>
</html>