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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>Animal Health Monitor</title>
|
| 7 |
+
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css" rel="stylesheet">
|
| 8 |
+
<style>
|
| 9 |
+
:root {
|
| 10 |
+
--primary-color: #3498db;
|
| 11 |
+
--secondary-color: #2ecc71;
|
| 12 |
+
--background-color: #ecf0f1;
|
| 13 |
+
--text-color: #34495e;
|
| 14 |
+
--card-background: #ffffff;
|
| 15 |
+
}
|
| 16 |
+
body {
|
| 17 |
+
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
| 18 |
+
background-color: var(--background-color);
|
| 19 |
+
color: var(--text-color);
|
| 20 |
+
margin: 0;
|
| 21 |
+
padding: 20px;
|
| 22 |
+
line-height: 1.6;
|
| 23 |
+
}
|
| 24 |
+
.container {
|
| 25 |
+
max-width: 1200px;
|
| 26 |
+
margin: 0 auto;
|
| 27 |
+
padding: 20px;
|
| 28 |
+
}
|
| 29 |
+
h1 {
|
| 30 |
+
color: var(--primary-color);
|
| 31 |
+
text-align: center;
|
| 32 |
+
margin-bottom: 30px;
|
| 33 |
+
font-size: 2.5em;
|
| 34 |
+
}
|
| 35 |
+
.dashboard {
|
| 36 |
+
display: grid;
|
| 37 |
+
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
|
| 38 |
+
gap: 20px;
|
| 39 |
+
}
|
| 40 |
+
.card {
|
| 41 |
+
background: var(--card-background);
|
| 42 |
+
border-radius: 10px;
|
| 43 |
+
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
| 44 |
+
padding: 20px;
|
| 45 |
+
text-align: center;
|
| 46 |
+
transition: transform 0.3s ease;
|
| 47 |
+
}
|
| 48 |
+
.card:hover {
|
| 49 |
+
transform: translateY(-5px);
|
| 50 |
+
}
|
| 51 |
+
.card-title {
|
| 52 |
+
font-size: 1.2em;
|
| 53 |
+
color: var(--primary-color);
|
| 54 |
+
margin-bottom: 10px;
|
| 55 |
+
}
|
| 56 |
+
.card-value {
|
| 57 |
+
font-size: 2em;
|
| 58 |
+
font-weight: bold;
|
| 59 |
+
margin: 10px 0;
|
| 60 |
+
}
|
| 61 |
+
.card i {
|
| 62 |
+
font-size: 2em;
|
| 63 |
+
margin-bottom: 10px;
|
| 64 |
+
color: var(--secondary-color);
|
| 65 |
+
}
|
| 66 |
+
#map {
|
| 67 |
+
height: 300px;
|
| 68 |
+
border-radius: 10px;
|
| 69 |
+
margin-top: 20px;
|
| 70 |
+
}
|
| 71 |
+
@media (max-width: 768px) {
|
| 72 |
+
.dashboard {
|
| 73 |
+
grid-template-columns: 1fr;
|
| 74 |
+
}
|
| 75 |
+
}
|
| 76 |
+
</style>
|
| 77 |
+
</head>
|
| 78 |
+
<body>
|
| 79 |
+
<div class="container">
|
| 80 |
+
<h1>Animal Health Monitor</h1>
|
| 81 |
+
<div class="dashboard">
|
| 82 |
+
<div class="card">
|
| 83 |
+
<i class="fas fa-thermometer-half"></i>
|
| 84 |
+
<div class="card-title">Temperature</div>
|
| 85 |
+
<div class="card-value"><span id="tempCelsius">--</span>°C</div>
|
| 86 |
+
<div class="card-value"><span id="tempFahrenheit">--</span>°F</div>
|
| 87 |
+
</div>
|
| 88 |
+
<div class="card">
|
| 89 |
+
<i class="fas fa-heartbeat"></i>
|
| 90 |
+
<div class="card-title">Heart Rate</div>
|
| 91 |
+
<div class="card-value"><span id="bpm">--</span> BPM</div>
|
| 92 |
+
</div>
|
| 93 |
+
<div class="card">
|
| 94 |
+
<i class="fas fa-lungs"></i>
|
| 95 |
+
<div class="card-title">Blood Oxygen</div>
|
| 96 |
+
<div class="card-value"><span id="spo2">--</span>%</div>
|
| 97 |
+
</div>
|
| 98 |
+
<div class="card">
|
| 99 |
+
<i class="fas fa-map-marker-alt"></i>
|
| 100 |
+
<div class="card-title">GPS Location</div>
|
| 101 |
+
<div class="card-value">
|
| 102 |
+
<div>Lat: <span id="latitude">--</span></div>
|
| 103 |
+
<div>Long: <span id="longitude">--</span></div>
|
| 104 |
+
</div>
|
| 105 |
+
</div>
|
| 106 |
+
</div>
|
| 107 |
+
<div id="map"></div>
|
| 108 |
+
</div>
|
| 109 |
+
|
| 110 |
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/firebase/9.22.2/firebase-app-compat.min.js"></script>
|
| 111 |
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/firebase/9.22.2/firebase-database-compat.min.js"></script>
|
| 112 |
+
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyAOVYRIgupAurZup5y1PRh8Ismb1A3lLao&callback=initMap" async defer></script>
|
| 113 |
+
<script>
|
| 114 |
+
// Initialize Google Map
|
| 115 |
+
let map;
|
| 116 |
+
let marker;
|
| 117 |
+
function initMap() {
|
| 118 |
+
try {
|
| 119 |
+
map = new google.maps.Map(document.getElementById('map'), {
|
| 120 |
+
center: {lat: 7.2297, lng: 3.4392}, // Center map at the original coordinates
|
| 121 |
+
zoom: 15 // Adjust zoom level to focus on the area
|
| 122 |
+
});
|
| 123 |
+
marker = new google.maps.Marker({
|
| 124 |
+
position: {lat: 7.2297, lng: 3.4392}, // Start marker at the original coordinates
|
| 125 |
+
map: map
|
| 126 |
+
});
|
| 127 |
+
console.log("Map initialized successfully");
|
| 128 |
+
} catch (error) {
|
| 129 |
+
console.error("Error initializing map:", error);
|
| 130 |
+
document.getElementById('map').innerHTML = '<p>Error loading map. Please check the console for details.</p>';
|
| 131 |
+
}
|
| 132 |
+
}
|
| 133 |
+
|
| 134 |
+
// Function to fetch the latest data from the FastAPI endpoint
|
| 135 |
+
async function fetchLatestData() {
|
| 136 |
+
try {
|
| 137 |
+
const response = await fetch('http://localhost:8000/latest-data');
|
| 138 |
+
const data = await response.json();
|
| 139 |
+
return data;
|
| 140 |
+
} catch (error) {
|
| 141 |
+
console.error("Error fetching data:", error);
|
| 142 |
+
return null;
|
| 143 |
+
}
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
// Function to update the dashboard with real data
|
| 147 |
+
async function updateDashboard() {
|
| 148 |
+
const data = await fetchLatestData();
|
| 149 |
+
|
| 150 |
+
if (data) {
|
| 151 |
+
document.getElementById('tempCelsius').textContent = data.temperature || '--';
|
| 152 |
+
document.getElementById('tempFahrenheit').textContent = data.temperature_in_F || '--';
|
| 153 |
+
document.getElementById('bpm').textContent = data.heart_rate || '--';
|
| 154 |
+
document.getElementById('spo2').textContent = data.blood_oxygen || '--';
|
| 155 |
+
document.getElementById('latitude').textContent = data.latitude || '--';
|
| 156 |
+
document.getElementById('longitude').textContent = data.longitude || '--';
|
| 157 |
+
|
| 158 |
+
if (map && marker && data.latitude && data.longitude) {
|
| 159 |
+
try {
|
| 160 |
+
const newPosition = new google.maps.LatLng(parseFloat(data.latitude), parseFloat(data.longitude));
|
| 161 |
+
marker.setPosition(newPosition);
|
| 162 |
+
map.panTo(newPosition);
|
| 163 |
+
} catch (error) {
|
| 164 |
+
console.error("Error updating map:", error);
|
| 165 |
+
}
|
| 166 |
+
} else {
|
| 167 |
+
console.warn("Map or marker not initialized or invalid data");
|
| 168 |
+
}
|
| 169 |
+
} else {
|
| 170 |
+
console.warn("No data fetched");
|
| 171 |
+
}
|
| 172 |
+
}
|
| 173 |
+
|
| 174 |
+
// Initialize the dashboard on load
|
| 175 |
+
window.onload = function() {
|
| 176 |
+
initMap();
|
| 177 |
+
updateDashboard();
|
| 178 |
+
};
|
| 179 |
+
|
| 180 |
+
// Update dashboard every 5 seconds
|
| 181 |
+
setInterval(updateDashboard, 5000);
|
| 182 |
+
</script>
|
| 183 |
+
</body>
|
| 184 |
+
</html>
|